BVB Source Codes

CRYENGINE Show TeleportOp.cpp Source code

Return Download CRYENGINE: download TeleportOp.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #include "StdAfx.h"
  4. #include "TeleportOp.h"
  5.  
  6. #include <CrySystem/XML/XMLAttrReader.h>
  7. #include "PipeUser.h"
  8.  
  9. TeleportOp::TeleportOp()
  10.         : m_destinationPosition(ZERO)
  11.         , m_destinationDirection(ZERO)
  12.         , m_waitUntilAgentIsNotMoving(false)
  13. {
  14. }
  15.  
  16. TeleportOp::TeleportOp(const XmlNodeRef& node)
  17.         : m_destinationPosition(ZERO)
  18.         , m_destinationDirection(ZERO)
  19.         , m_waitUntilAgentIsNotMoving(false)
  20. {
  21. }
  22.  
  23. TeleportOp::TeleportOp(const TeleportOp& rhs)
  24.         : m_destinationPosition(rhs.m_destinationPosition)
  25.         , m_destinationDirection(rhs.m_destinationDirection)
  26.         , m_waitUntilAgentIsNotMoving(rhs.m_waitUntilAgentIsNotMoving)
  27. {
  28.         m_destinationDirection.Normalize();
  29. }
  30.  
  31. void TeleportOp::Update(CPipeUser& pipeUser)
  32. {
  33.         if (m_waitUntilAgentIsNotMoving && IsAgentMoving(pipeUser))
  34.         {
  35.                 return;
  36.         }
  37.         Teleport(pipeUser);
  38.  
  39.         GoalOpSucceeded();
  40. }
  41.  
  42. void TeleportOp::Serialize(TSerialize serializer)
  43. {
  44.         serializer.BeginGroup("TeleportOp");
  45.  
  46.         serializer.Value("position", m_destinationPosition);
  47.         serializer.Value("direction", m_destinationDirection);
  48.         serializer.Value("waitUntilAgentIsNotMoving", m_waitUntilAgentIsNotMoving);
  49.  
  50.         serializer.EndGroup();
  51. }
  52.  
  53. void TeleportOp::Teleport(CPipeUser& pipeUser)
  54. {
  55.         if (IEntity* entity = pipeUser.GetEntity())
  56.         {
  57.                 Matrix34 transform = entity->GetWorldTM();
  58.  
  59.                 const float rotationAngleInRadians = atan2f(-m_destinationDirection.x, m_destinationDirection.y);
  60.                 transform.SetRotationZ(rotationAngleInRadians, m_destinationPosition);
  61.  
  62.                 entity->SetWorldTM(transform);
  63.         }
  64. }
  65.  
  66. bool TeleportOp::IsAgentMoving(CPipeUser& pipeUser)
  67. {
  68.         const SAIBodyInfo& bodyInfo = pipeUser.QueryBodyInfo();
  69.  
  70.         return bodyInfo.isMoving;
  71. }
  72.  
  73. void TeleportOp::SetDestination(const Vec3& position, const Vec3& direction)
  74. {
  75.         m_destinationPosition = position;
  76.         m_destinationDirection = direction;
  77.         m_destinationDirection.Normalize();
  78. }
  79.  
  80. void TeleportOp::SetWaitUntilAgentIsNotMovingBeforeTeleport()
  81. {
  82.         m_waitUntilAgentIsNotMoving = true;
  83. }
  84.  
downloadTeleportOp.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top