hkpCharacterContext.h
上传用户:yisoukefu
上传日期:2020-08-09
资源大小:39506k
文件大小:6k
源码类别:

其他游戏

开发平台:

Visual C++

  1. /* 
  2.  * 
  3.  * Confidential Information of Telekinesys Research Limited (t/a Havok). Not for disclosure or distribution without Havok's
  4.  * prior written consent. This software contains code, techniques and know-how which is confidential and proprietary to Havok.
  5.  * Level 2 and Level 3 source code contains trade secrets of Havok. Havok Software (C) Copyright 1999-2009 Telekinesys Research Limited t/a Havok. All Rights Reserved. Use of this software is subject to the terms of an end user license agreement.
  6.  * 
  7.  */
  8. #ifndef HK_CHARACTER_CONTEXT_H
  9. #define HK_CHARACTER_CONTEXT_H
  10. #include <Common/Base/hkBase.h>
  11. #include <Common/Base/hkBase.h>
  12. #include <Common/Base/Types/Physics/hkStepInfo.h>
  13. #include <Physics/Dynamics/Motion/hkpMotion.h>
  14. class hkpCharacterStateManager;
  15. class hkpWorld;
  16. /// The input to the character state machine.
  17. /// Fill in the details and pass to a Character Context to cause a transitions in the state machine and produce and ouput
  18. struct hkpCharacterInput
  19. {
  20. HK_DECLARE_NONVIRTUAL_CLASS_ALLOCATOR( HK_MEMORY_CLASS_UTILITIES, hkpCharacterInput );
  21. //
  22. // User input
  23. //
  24. /// Input X range -1 to 1 (left / right) 
  25. hkReal m_inputLR;
  26. /// Input Y range -1 to 1 (forward / back)
  27. hkReal m_inputUD;
  28. /// Set this if you want the character to try and jump
  29. hkBool m_wantJump;
  30. //
  31. // Orientation information
  32. //
  33. /// Up vector in world space - should generally point in the opposite direction to gravity
  34. hkVector4 m_up;
  35. /// Forward vector in world space - point in the direction the character is facing
  36. hkVector4 m_forward;
  37. //
  38. // Spatial info
  39. //
  40. /// Set this if the character is at a ladder and you want it to start to climb
  41. hkBool m_atLadder;
  42. /// Set this if the character is standing on a surface
  43. hkBool m_isSupported;
  44. /// Set this to represent the normal of the surface we're supported by
  45. hkVector4 m_surfaceNormal;
  46. /// Set this to represent the velocity of the surface we're supported by
  47. hkVector4 m_surfaceVelocity;
  48. /// Set this to represent the type of motion of the surface we're supported by
  49. hkpMotion::MotionType m_surfaceMotionType;
  50. //
  51. // Simulation info
  52. //
  53. /// Set this to the timestep between calls to the state machine
  54. hkStepInfo m_stepInfo;
  55. /// Set this to the current position
  56. hkVector4 m_position;
  57. /// Set this to the current Velocity
  58. hkVector4 m_velocity;
  59. /// The gravity that is applied to the character when in the air
  60. hkVector4 m_characterGravity;
  61. //
  62. // User Data
  63. //
  64. /// Tag in extra user data for new user states here
  65. hkUlong m_userData; // +default(0)
  66. };
  67. /// The output from the state machine
  68. struct hkpCharacterOutput
  69. {
  70. HK_DECLARE_NONVIRTUAL_CLASS_ALLOCATOR( HK_MEMORY_CLASS_UTILITIES, hkpCharacterOutput );
  71. /// The output velocity of the character
  72. hkVector4 m_velocity;
  73. };
  74. /// The character context holds the current state of the state machine and is the interface that handles all state machine requests.
  75. class hkpCharacterContext : public hkReferencedObject
  76. {
  77. public:
  78. HK_DECLARE_CLASS_ALLOCATOR(HK_MEMORY_CLASS_CHARACTER);
  79. /// This enum defines type of character controlled by state machine
  80. enum CharacterType
  81. {
  82. HK_CHARACTER_PROXY = 0,
  83. HK_CHARACTER_RIGIDBODY = 1
  84. };
  85. /// Initializes the character context and give the state machine an initial state
  86. /// This adds a reference to the state manager
  87. hkpCharacterContext(const hkpCharacterStateManager* manager, hkpCharacterStateType initialState);
  88. /// Removes the reference from the state manager
  89. ~hkpCharacterContext();
  90. /// Returns the current state
  91. hkpCharacterStateType getState() const;
  92. /// Causes a state transition. This also calls the leaveState and enterState methods
  93. /// for the appropriate states
  94. void setState(hkpCharacterStateType state, const hkpCharacterInput& input, hkpCharacterOutput& output );
  95. /// Updates the state machine using the given input
  96. /// The output structure in initialized before being passed to the state
  97. /// This initialization copies the velocity from the input
  98. void update(const hkpCharacterInput& input, hkpCharacterOutput& output);
  99. /// Set type of character (proxy or rigid body)
  100. void setCharacterType(const CharacterType newType);
  101. /// Enable final output velocity filtration
  102. void setFilterEnable(const hkBool status);
  103. /// Set parameters for final output velocity filtration
  104. void setFilterParameters(const hkReal gain, const hkReal maxVelocity, const hkReal maxAcceleration);
  105. protected:
  106. /// Current character type
  107. CharacterType m_characterType;
  108. const hkpCharacterStateManager* m_stateManager;
  109. hkpCharacterStateType m_currentState;
  110. hkpCharacterStateType m_previousState;
  111. /// Parameters for final output velocity filtering
  112. hkBool m_filterEnable; 
  113. hkReal m_maxLinearAcceleration;
  114. hkReal m_maxLinearVelocity;
  115. hkReal m_gain;
  116. };
  117. #endif // HK_CHARACTER_CONTEXT_H
  118. /*
  119. * Havok SDK - NO SOURCE PC DOWNLOAD, BUILD(#20090216)
  120. * Confidential Information of Havok.  (C) Copyright 1999-2009
  121. * Telekinesys Research Limited t/a Havok. All Rights Reserved. The Havok
  122. * Logo, and the Havok buzzsaw logo are trademarks of Havok.  Title, ownership
  123. * rights, and intellectual property rights in the Havok software remain in
  124. * Havok and/or its suppliers.
  125. * Use of this software for evaluation purposes is subject to and indicates
  126. * acceptance of the End User licence Agreement for this product. A copy of
  127. * the license is included with this software and is also available at www.havok.com/tryhavok.
  128. */