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

Method UpdateLocalR

GTE/Graphics/IKController.cpp:345–419  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

343}
344
345bool IKController::Joint::UpdateLocalR(int32_t axis, std::vector<Goal> const& goals)
346{
347 Vector3<float> U = GetAxis(axis);
348 float numer = 0.0f;
349 float denom = 0.0f;
350
351 float oldNorm = 0.0f;
352 for (auto g : goalIndices)
353 {
354 auto const& goal = goals[g];
355 Vector3<float> EmP = goal.GetEffectorPosition() - object->worldTransform.GetTranslation();
356 Vector3<float> GmP = goal.GetTargetPosition() - object->worldTransform.GetTranslation();
357 Vector3<float> GmE = goal.GetTargetPosition() - goal.GetEffectorPosition();
358 oldNorm += Dot(GmE, GmE);
359 Vector3<float> UxEmP = Cross(U, EmP);
360 Vector3<float> UxUxEmP = Cross(U, UxEmP);
361 numer += goal.weight * Dot(GmP, UxEmP);
362 denom -= goal.weight * Dot(GmP, UxUxEmP);
363 }
364
365 if (numer * numer + denom * denom == 0.0f)
366 {
367 return false;
368 }
369
370 // Desired angle to rotate about axis(i).
371 float theta = std::atan2(numer, denom);
372
373 // Factor local rotation into Euler angles.
374 EulerAngles<float> euler =
375 Rotation<4, float>(object->localTransform.GetRotation())(0, 1, 2);
376
377 // Clamp to range.
378 float desired = euler.angle[axis] + theta;
379 if (desired > minRotation[axis])
380 {
381 if (desired < maxRotation[axis])
382 {
383 euler.angle[axis] = desired;
384 }
385 else
386 {
387 theta = maxRotation[axis] - euler.angle[axis];
388 euler.angle[axis] = maxRotation[axis];
389 }
390 }
391 else
392 {
393 theta = minRotation[axis] - euler.angle[axis];
394 euler.angle[axis] = minRotation[axis];
395 }
396
397 // Test whether step should be taken.
398 float newNorm = 0.0f;
399 Matrix3x3<float> rotate = Rotation<3, float>(AxisAngle<3, float>(U, theta));
400 for (auto g : goalIndices)
401 {
402 auto const& goal = goals[g];

Callers 1

UpdateMethod · 0.80

Calls 8

CrossFunction · 0.85
GetEffectorPositionMethod · 0.80
GetTargetPositionMethod · 0.80
GetRotationMethod · 0.80
SetRotationMethod · 0.80
DotFunction · 0.50
atan2Function · 0.50
GetTranslationMethod · 0.45

Tested by

no test coverage detected