MCPcopy Create free account
hub / github.com/axmolengine/axmol / syncToNode

Method syncToNode

core/navmesh/NavMeshAgent.cpp:351–385  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

349}
350
351void NavMeshAgent::syncToNode()
352{
353 const dtCrowdAgent* agent = nullptr;
354 if (_crowd)
355 {
356 agent = _crowd->getAgent(_agentID);
357 }
358
359 if (agent)
360 {
361 Mat4 wtop;
362 Vec3 pos;
363 if (_owner->getParent())
364 wtop = _owner->getParent()->getWorldToNodeTransform();
365 wtop.transformPoint(Vec3(agent->npos[0], agent->npos[1], agent->npos[2]), &pos);
366 _owner->setPosition3D(pos);
367 _state = agent->state;
368 if (_needAutoOrientation)
369 {
370 if (std::abs(agent->vel[0]) > 0.3f || std::abs(agent->vel[1]) > 0.3f || std::abs(agent->vel[2]) > 0.3f)
371 {
372 Vec3 axes(_rotRefAxes);
373 axes.normalize();
374 Vec3 dir;
375 wtop.transformVector(Vec3(agent->vel[0], agent->vel[1], agent->vel[2]), &dir);
376 dir.normalize();
377 float cosTheta = Vec3::dot(axes, dir);
378 Vec3 rotAxes;
379 Vec3::cross(axes, dir, &rotAxes);
380 Quaternion rot = Quaternion(rotAxes, acosf(cosTheta));
381 _owner->setRotationQuat(rot);
382 }
383 }
384 }
385}
386
387void NavMeshAgent::syncToAgent()
388{

Calls 12

getAgentMethod · 0.80
transformVectorMethod · 0.80
Vec3Function · 0.50
absFunction · 0.50
dotFunction · 0.50
crossFunction · 0.50
QuaternionClass · 0.50
getParentMethod · 0.45
setPosition3DMethod · 0.45
normalizeMethod · 0.45
setRotationQuatMethod · 0.45

Tested by

no test coverage detected