| 349 | } |
| 350 | |
| 351 | void 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 | |
| 387 | void NavMeshAgent::syncToAgent() |
| 388 | { |
no test coverage detected