physicsCommon.h
Engine/source/T3D/physics/physicsCommon.h
Classes:
class
Helper structure which defines the state of a single physics body.
Public Enumerations
enum
PhysicsResetEvent { PhysicsResetEvent_Store PhysicsResetEvent_Restore }
The event type passed to the physics reset signal.
Public Typedefs
PhysicsCollisionRef
A strong reference to a physics collision shape.
Signal< void(PhysicsResetEvent reset)>
PhysicsResetSignal
The signal for system wide physics events.
Detailed Description
Public Enumerations
PhysicsResetEvent
Enumerator
- PhysicsResetEvent_Store
- PhysicsResetEvent_Restore
The event type passed to the physics reset signal.
Public Typedefs
typedef StrongRefPtr< PhysicsCollision > PhysicsCollisionRef
A strong reference to a physics collision shape.
typedef Signal< void(PhysicsResetEvent reset)> PhysicsResetSignal
The signal for system wide physics events.
see:
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _T3D_PHYSICSCOMMON_H_ 25#define _T3D_PHYSICSCOMMON_H_ 26 27#ifndef _MPOINT3_H_ 28#include "math/mPoint3.h" 29#endif 30#ifndef _MQUAT_H_ 31#include "math/mQuat.h" 32#endif 33#ifndef _MMATRIX_H_ 34#include "math/mMatrix.h" 35#endif 36#ifndef _REFBASE_H_ 37#include "core/util/refBase.h" 38#endif 39 40 41/// Helper structure which defines the state of a single physics body. 42struct PhysicsState 43{ 44 /// Constructor. 45 PhysicsState() 46 : position( Point3F::Zero ), 47 momentum( Point3F::Zero ), 48 orientation( QuatF::Identity ), 49 angularMomentum( Point3F::Zero ), 50 sleeping( false ), 51 linVelocity( Point3F::Zero ), 52 angVelocity( Point3F::Zero ) 53 { 54 } 55 56 /// The primary physics state. 57 // @{ 58 59 /// The position of the body. 60 Point3F position; 61 62 /// The momentum in kilogram meters per second. 63 Point3F momentum; 64 65 /// The orientation of the body. 66 QuatF orientation; 67 68 /// The angular momentum. 69 Point3F angularMomentum; 70 71 /// Is true if the shape is asleep. 72 bool sleeping; 73 74 // @} 75 76 /// The secondary physics state derived from the primary state. 77 /// @{ 78 79 /// The linear velocity derived from the momentum. 80 Point3F linVelocity; 81 82 /// 83 Point3F angVelocity; 84 85 /* 86 Vector velocity; ///< velocity in meters per second (calculated from momentum). 87 Quaternion spin; ///< quaternion rate of change in orientation. 88 Vector angularVelocity; ///< angular velocity (calculated from angularMomentum). 89 Matrix bodyToWorld; ///< body to world coordinates matrix. 90 Matrix worldToBody; ///< world to body coordinates matrix. 91 */ 92 93 /// @} 94 95 96 /// Interpolates between two physics states leaving the 97 /// result in this physics state. 98 inline PhysicsState& interpolate( const PhysicsState &a, const PhysicsState &b, F32 t ) 99 { 100 F32 inverseT = 1.0f - t; 101 position = a.position*inverseT + b.position*t; 102 momentum = a.momentum*inverseT + b.momentum*t; 103 orientation.interpolate( a.orientation, b.orientation, t ); 104 angularMomentum = a.angularMomentum*inverseT + b.angularMomentum*t; 105 106 // Recalculate the velocities 107 //linVelocity = 108 //angVelocity 109 110 return *this; 111 } 112 113 /// Helper builds the transform from the state. 114 inline MatrixF getTransform() const 115 { 116 MatrixF xfm; 117 orientation.setMatrix( &xfm ); 118 xfm.setPosition( position ); 119 return xfm; 120 } 121 122}; 123 124 125/// The event type passed to the physics reset signal. 126/// @see PhysicsPlugin::getPhysicsResetSignal(). 127enum PhysicsResetEvent 128{ 129 PhysicsResetEvent_Store, 130 PhysicsResetEvent_Restore 131}; 132 133/// The signal for system wide physics events. 134/// @see PhysicsPlugin 135typedef Signal<void(PhysicsResetEvent reset)> PhysicsResetSignal; 136 137class PhysicsCollision; 138 139/// A strong reference to a physics collision shape. 140typedef StrongRefPtr<PhysicsCollision> PhysicsCollisionRef; 141 142#endif // _T3D_PHYSICSCOMMON_H_ 143