@@ -32,7 +32,7 @@ void Model::Destroy()
32
32
void Model::Render (
33
33
MeshSorter& sorter,
34
34
const GpuBuffer& meshConstants,
35
- const ScaleAndTranslation sphereTransforms[],
35
+ const AffineTransform sphereTransforms[],
36
36
const Joint* skeleton ) const
37
37
{
38
38
// Pointer to current mesh
@@ -45,9 +45,14 @@ void Model::Render(
45
45
{
46
46
const Mesh& mesh = *(const Mesh*)pMesh;
47
47
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 ());
51
56
BoundingSphere sphereVS = BoundingSphere (viewMat * sphereWS.GetCenter (), sphereWS.GetRadius ());
52
57
53
58
if (frustum.IntersectSphere (sphereVS))
@@ -68,7 +73,7 @@ void ModelInstance::Render(MeshSorter& sorter) const
68
73
if (m_Model != nullptr )
69
74
{
70
75
// 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 (),
72
77
m_Skeleton.get ());
73
78
}
74
79
}
@@ -90,7 +95,8 @@ ModelInstance::ModelInstance( std::shared_ptr<const Model> sourceModel )
90
95
{
91
96
m_MeshConstantsCPU.Create (L" Mesh Constant Upload Buffer" , sourceModel->m_NumNodes * sizeof (MeshConstants));
92
97
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 ]);
94
100
m_Skeleton.reset (new Joint[sourceModel->m_NumJoints ]);
95
101
96
102
if (sourceModel->m_NumAnimations > 0 )
@@ -129,7 +135,8 @@ ModelInstance& ModelInstance::operator=( std::shared_ptr<const Model> sourceMode
129
135
{
130
136
m_MeshConstantsCPU.Create (L" Mesh Constant Upload Buffer" , sourceModel->m_NumNodes * sizeof (MeshConstants));
131
137
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 ]);
133
140
m_Skeleton.reset (new Joint[sourceModel->m_NumJoints ]);
134
141
135
142
if (sourceModel->m_NumAnimations > 0 )
@@ -158,7 +165,6 @@ void ModelInstance::Update(GraphicsContext& gfxContext, float deltaTime)
158
165
Matrix4 matrixStack[kMaxStackDepth ];
159
166
Matrix4 ParentMatrix = Matrix4 ((AffineTransform)m_Locator);
160
167
161
- ScaleAndTranslation* boundingSphereTransforms = (ScaleAndTranslation*)m_BoundingSphereTransforms.get ();
162
168
MeshConstants* cb = (MeshConstants*)m_MeshConstantsCPU.Map ();
163
169
164
170
if (m_AnimGraph)
@@ -196,12 +202,12 @@ void ModelInstance::Update(GraphicsContext& gfxContext, float deltaTime)
196
202
cbv.World = xform;
197
203
cbv.WorldIT = InverseTranspose (xform.Get3x3 ());
198
204
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
+ }
205
211
206
212
// If the next node will be a descendent, replace the parent matrix with our new matrix
207
213
if (Node->hasChildren )
0 commit comments