@@ -32,7 +32,7 @@ void Model::Destroy()
3232void Model::Render (
3333 MeshSorter& sorter,
3434 const GpuBuffer& meshConstants,
35- const ScaleAndTranslation sphereTransforms[],
35+ const AffineTransform sphereTransforms[],
3636 const Joint* skeleton ) const
3737{
3838 // Pointer to current mesh
@@ -45,9 +45,14 @@ void Model::Render(
4545 {
4646 const Mesh& mesh = *(const Mesh*)pMesh;
4747
48- const ScaleAndTranslation& sphereXform = sphereTransforms[mesh.meshCBV ];
49- BoundingSphere sphereLS ((const XMFLOAT4*)mesh.bounds );
50- BoundingSphere sphereWS = sphereXform * sphereLS;
48+ const AffineTransform& sphereXform = sphereTransforms[mesh.meshCBV ];
49+ Scalar scaleXSqr = LengthSquare ((Vector3)sphereXform.GetX ());
50+ Scalar scaleYSqr = LengthSquare ((Vector3)sphereXform.GetY ());
51+ Scalar scaleZSqr = LengthSquare ((Vector3)sphereXform.GetZ ());
52+ Scalar sphereScale = Sqrt (Max (Max (scaleXSqr, scaleYSqr), scaleZSqr));
53+
54+ BoundingSphere sphereLS ((const XMFLOAT4*)mesh.bounds );
55+ BoundingSphere sphereWS = BoundingSphere (sphereXform * sphereLS.GetCenter (), sphereScale * sphereLS.GetRadius ());
5156 BoundingSphere sphereVS = BoundingSphere (viewMat * sphereWS.GetCenter (), sphereWS.GetRadius ());
5257
5358 if (frustum.IntersectSphere (sphereVS))
@@ -68,7 +73,7 @@ void ModelInstance::Render(MeshSorter& sorter) const
6873 if (m_Model != nullptr )
6974 {
7075 // const Frustum& frustum = sorter.GetWorldFrustum();
71- m_Model->Render (sorter, m_MeshConstantsGPU, ( const ScaleAndTranslation*) m_BoundingSphereTransforms.get (),
76+ m_Model->Render (sorter, m_MeshConstantsGPU, m_BoundingSphereTransforms.get (),
7277 m_Skeleton.get ());
7378 }
7479}
@@ -90,7 +95,8 @@ ModelInstance::ModelInstance( std::shared_ptr<const Model> sourceModel )
9095 {
9196 m_MeshConstantsCPU.Create (L" Mesh Constant Upload Buffer" , sourceModel->m_NumNodes * sizeof (MeshConstants));
9297 m_MeshConstantsGPU.Create (L" Mesh Constant GPU Buffer" , sourceModel->m_NumNodes , sizeof (MeshConstants));
93- m_BoundingSphereTransforms.reset (new __m128[sourceModel->m_NumNodes ]);
98+
99+ m_BoundingSphereTransforms.reset (new AffineTransform[sourceModel->m_NumNodes ]);
94100 m_Skeleton.reset (new Joint[sourceModel->m_NumJoints ]);
95101
96102 if (sourceModel->m_NumAnimations > 0 )
@@ -129,7 +135,8 @@ ModelInstance& ModelInstance::operator=( std::shared_ptr<const Model> sourceMode
129135 {
130136 m_MeshConstantsCPU.Create (L" Mesh Constant Upload Buffer" , sourceModel->m_NumNodes * sizeof (MeshConstants));
131137 m_MeshConstantsGPU.Create (L" Mesh Constant GPU Buffer" , sourceModel->m_NumNodes , sizeof (MeshConstants));
132- m_BoundingSphereTransforms.reset (new __m128[sourceModel->m_NumNodes ]);
138+
139+ m_BoundingSphereTransforms.reset (new AffineTransform[sourceModel->m_NumNodes ]);
133140 m_Skeleton.reset (new Joint[sourceModel->m_NumJoints ]);
134141
135142 if (sourceModel->m_NumAnimations > 0 )
@@ -158,7 +165,6 @@ void ModelInstance::Update(GraphicsContext& gfxContext, float deltaTime)
158165 Matrix4 matrixStack[kMaxStackDepth ];
159166 Matrix4 ParentMatrix = Matrix4 ((AffineTransform)m_Locator);
160167
161- ScaleAndTranslation* boundingSphereTransforms = (ScaleAndTranslation*)m_BoundingSphereTransforms.get ();
162168 MeshConstants* cb = (MeshConstants*)m_MeshConstantsCPU.Map ();
163169
164170 if (m_AnimGraph)
@@ -196,12 +202,12 @@ void ModelInstance::Update(GraphicsContext& gfxContext, float deltaTime)
196202 cbv.World = xform;
197203 cbv.WorldIT = InverseTranspose (xform.Get3x3 ());
198204
199- Scalar scaleXSqr = LengthSquare ((Vector3)xform. GetX ());
200- Scalar scaleYSqr = LengthSquare (( Vector3)xform.GetY ());
201- Scalar scaleZSqr = LengthSquare (( Vector3)xform.GetZ ());
202- Scalar sphereScale = Sqrt ( Max ( Max (scaleXSqr, scaleYSqr), scaleZSqr));
203- boundingSphereTransforms[Node-> matrixIdx ] = ScaleAndTranslation (( Vector3)xform.GetW (), sphereScale );
204- }
205+ m_BoundingSphereTransforms[Node-> matrixIdx ] = AffineTransform (
206+ ( Vector3)xform.GetX (),
207+ ( Vector3)xform.GetY (),
208+ (Vector3)xform. GetZ (),
209+ ( Vector3)xform.GetW ());
210+ }
205211
206212 // If the next node will be a descendent, replace the parent matrix with our new matrix
207213 if (Node->hasChildren )
0 commit comments