SceneNode.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #ifndef CRYINCLUDE_CRYMOVIE_SCENENODE_H
  9. #define CRYINCLUDE_CRYMOVIE_SCENENODE_H
  10. #pragma once
  11. #include <AzCore/std/containers/map.h>
  12. #include <AzCore/Time/ITime.h>
  13. #include "AnimNode.h"
  14. #include "SoundTrack.h"
  15. #include "SelectTrack.h"
  16. class CGotoTrack;
  17. class CAnimSceneNode
  18. : public CAnimNode
  19. {
  20. public:
  21. AZ_CLASS_ALLOCATOR(CAnimSceneNode, AZ::SystemAllocator);
  22. AZ_RTTI(CAnimSceneNode, "{659BB221-38D3-43C0-BEE4-7EAB49C8CB33}", CAnimNode);
  23. ///////////////////////////////////////////////////////////////////////////////////////////////
  24. // helper interface for a uniform interface to legacy and component entity cameras
  25. class ISceneCamera
  26. {
  27. public:
  28. virtual ~ISceneCamera() = default;
  29. virtual const Vec3& GetPosition() const = 0;
  30. virtual const Quat& GetRotation() const = 0;
  31. virtual void SetPosition(const Vec3& localPosition) = 0;
  32. virtual void SetRotation(const Quat& localRotation) = 0;
  33. virtual float GetFoV() const = 0;
  34. virtual float GetNearZ() const = 0;
  35. // includes check for changes
  36. virtual void SetNearZAndFOVIfChanged(float fov, float nearZ) = 0;
  37. virtual void TransformPositionFromLocalToWorldSpace(Vec3& position) = 0;
  38. virtual void TransformPositionFromWorldToLocalSpace(Vec3& position) = 0;
  39. virtual void TransformRotationFromLocalToWorldSpace(Quat& rotation) = 0;
  40. // keeps existing world position
  41. virtual void SetWorldRotation(const Quat& rotation) = 0;
  42. // returns true if the camera has a parent
  43. virtual bool HasParent() const = 0;
  44. protected:
  45. ISceneCamera() {};
  46. };
  47. CAnimSceneNode(const int id);
  48. CAnimSceneNode();
  49. ~CAnimSceneNode();
  50. static void Initialize();
  51. //////////////////////////////////////////////////////////////////////////
  52. // Overrides from CAnimNode
  53. //////////////////////////////////////////////////////////////////////////
  54. void Animate(SAnimContext& ec) override;
  55. void CreateDefaultTracks() override;
  56. void Serialize(XmlNodeRef& xmlNode, bool bLoading, bool bLoadEmptyTracks) override;
  57. void Activate(bool bActivate) override;
  58. // overridden from IAnimNode/CAnimNode
  59. void OnStart() override;
  60. void OnReset() override;
  61. void OnPause() override;
  62. void OnStop() override;
  63. void OnLoop() override;
  64. //////////////////////////////////////////////////////////////////////////
  65. unsigned int GetParamCount() const override;
  66. CAnimParamType GetParamType(unsigned int nIndex) const override;
  67. void PrecacheStatic(float startTime) override;
  68. void PrecacheDynamic(float time) override;
  69. static void Reflect(AZ::ReflectContext* context);
  70. // Utility function to find the sequence associated with an ISequenceKey
  71. static IAnimSequence* GetSequenceFromSequenceKey(const ISequenceKey& sequenceKey);
  72. protected:
  73. bool GetParamInfoFromType(const CAnimParamType& paramId, SParamInfo& info) const override;
  74. void ResetSounds() override;
  75. void ReleaseSounds(); // Stops audio
  76. private:
  77. void ApplyCameraKey(ISelectKey& key, SAnimContext& ec);
  78. void ApplyEventKey(IEventKey& key, SAnimContext& ec);
  79. void ApplyConsoleKey(IConsoleKey& key, SAnimContext& ec);
  80. void ApplyAudioKey(char const* const sTriggerName, bool const bPlay = true) override;
  81. void ApplySequenceKey(IAnimTrack* pTrack, int nPrevKey, int nCurrKey, ISequenceKey& key, SAnimContext& ec);
  82. void ApplyGotoKey(CGotoTrack* poGotoTrack, SAnimContext& ec);
  83. // fill retInterpolatedCameraParams with interpolated camera data. If firstCameraId is a valid AZ::EntityId, it is used.
  84. // should be non-null. Preference will be given to firstCamera if they are both non-null
  85. void InterpolateCameras(SCameraParams& retInterpolatedCameraParams, ISceneCamera* firstCamera,
  86. ISelectKey& firstKey, ISelectKey& secondKey, float time);
  87. void InitializeTrackDefaultValue(IAnimTrack* pTrack, const CAnimParamType& paramType) override;
  88. // Cached parameters of node at given time.
  89. float m_time = 0.0f;
  90. CSelectTrack* m_CurrentSelectTrack;
  91. int m_CurrentSelectTrackKeyNumber;
  92. IAnimNode* m_pCamNodeOnHoldForInterp;
  93. float m_lastPrecachePoint;
  94. //! Last animated key in track.
  95. int m_lastCameraKey;
  96. int m_lastEventKey;
  97. int m_lastConsoleKey;
  98. int m_lastSequenceKey;
  99. int m_nLastGotoKey;
  100. int m_lastCaptureKey;
  101. bool m_bLastCapturingEnded;
  102. int m_captureFrameCount;
  103. struct InterpolatingCameraStartState
  104. {
  105. Vec3 m_interpolatedCamFirstPos;
  106. Quat m_interpolatedCamFirstRot;
  107. float m_FoV;
  108. float m_nearZ;
  109. };
  110. using keyIdx = int;
  111. // each camera key with a blend time > 0 needs a stashed initial xform for interpolation
  112. AZStd::map<keyIdx, InterpolatingCameraStartState> m_InterpolatingCameraStartStates;
  113. std::vector<SSoundInfo> m_SoundInfo;
  114. AZ::TimeUs m_simulationTickOverrideBackup = AZ::Time::ZeroTimeUs;
  115. float m_timeScaleBackup = 1.0f;
  116. };
  117. #endif // CRYINCLUDE_CRYMOVIE_SCENENODE_H