MCPcopy Create free account
hub / github.com/davideberly/GeometricTools / Update

Method Update

GTE/Samples/Physics/BouncingBall/DeformableBall.cpp:154–208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152}
153
154void DeformableBall::Update(float time)
155{
156 uint32_t const numVertices = mMesh->GetVertexBuffer()->GetNumElements();
157 Vertex* vertices = mMesh->GetVertexBuffer()->Get<Vertex>();
158 uint32_t const numTriangles = mMesh->GetIndexBuffer()->GetNumElements() / 3;
159 uint32_t const* indices = mMesh->GetIndexBuffer()->Get<uint32_t>();
160
161 Vector3<float> zero = Vector3<float>::Zero();
162 std::fill(mNormal.begin(), mNormal.end(), zero);
163 std::fill(mMean.begin(), mMean.end(), zero);
164
165 for (uint32_t i = 0; i < numTriangles; ++i)
166 {
167 int32_t i0 = *indices++;
168 int32_t i1 = *indices++;
169 int32_t i2 = *indices++;
170
171 Vector3<float> v0 = vertices[i0].position;
172 Vector3<float> v1 = vertices[i1].position;
173 Vector3<float> v2 = vertices[i2].position;
174
175 Vector3<float> edge1 = v1 - v0;
176 Vector3<float> edge2 = v2 - v0;
177 Vector3<float> normal = Cross(edge1, edge2);
178
179 mNormal[i0] += normal;
180 mNormal[i1] += normal;
181 mNormal[i2] += normal;
182
183 mMean[i0] += v1 + v2;
184 mMean[i1] += v2 + v0;
185 mMean[i2] += v0 + v1;
186 }
187
188 for (uint32_t i = 0; i < numVertices; ++i)
189 {
190 Normalize(mNormal[i]);
191 mMean[i] /= static_cast<float>(mNeighborCount[i]);
192 }
193
194 for (uint32_t i = 0; i < numVertices; ++i)
195 {
196 Vector3<float> position = vertices[i].position;
197 if (VertexInfluenced(i, time, position))
198 {
199 Vector3<float> localDiff = mMean[i] - position;
200 Vector3<float> surfaceNormal = Dot(localDiff, mNormal[i]) * mNormal[i];
201 Vector3<float> tangent = localDiff - surfaceNormal;
202 float tWeight = GetTangentWeight(i, time, position);
203 float nWeight = GetNormalWeight(i, time, position);
204 position += tWeight * tangent + nWeight * mNormal[i];
205 vertices[i].position = position;
206 }
207 }
208}
209
210bool DeformableBall::DoSimulationStep(float realTime)
211{

Callers 7

GraphicsTickMethod · 0.45
DoCollisionResponseMethod · 0.45
BouncingBallWindow3Method · 0.45
OnIdleMethod · 0.45
PhysicsTickMethod · 0.45
GraphicsTickMethod · 0.45
DoCollisionResponseMethod · 0.45

Calls 8

CrossFunction · 0.85
beginMethod · 0.80
endMethod · 0.80
NormalizeFunction · 0.50
DotFunction · 0.50
GetNumElementsMethod · 0.45
GetVertexBufferMethod · 0.45
GetIndexBufferMethod · 0.45

Tested by

no test coverage detected