physicsUserData.h
Engine/source/T3D/physics/physicsUserData.h
Classes:
class
The base class for physics user data.
Public Typedefs
Signal< void(PhysicsUserData *us, PhysicsUserData *them, const Point3F &hitPoint, const Point3F &hitForce)>
PhysicsContactSignal
Signal used for contact reports.
Detailed Description
Public Typedefs
typedef Signal< void(PhysicsUserData *us, PhysicsUserData *them, const Point3F &hitPoint, const Point3F &hitForce)> PhysicsContactSignal
Signal used for contact reports.
Parameters:
us | The physics user data for the signaling object. |
them | The other physics user data involved in the contact. |
hitPoint | The approximate position of the impact. |
hitForce |
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 _PHYSICS_PHYSICSUSERDATA_H_ 25#define _PHYSICS_PHYSICSUSERDATA_H_ 26 27#ifndef _SIGNAL_H_ 28#include "core/util/tSignal.h" 29#endif 30 31class PhysicsUserData; 32class SceneObject; 33class Point3F; 34class PhysicsBody; 35 36 37/// Signal used for contact reports. 38/// 39/// @param us The physics user data for the signaling object. 40/// @param them The other physics user data involved in the contact. 41/// @param hitPoint The approximate position of the impact. 42/// @param hitForce 43/// 44/// @see PhysicsUserData 45/// 46typedef Signal<void( PhysicsUserData *us, 47 PhysicsUserData *them, 48 const Point3F &hitPoint, 49 const Point3F &hitForce )> PhysicsContactSignal; 50 51 52/// The base class for physics user data. 53class PhysicsUserData 54{ 55public: 56 57 /// The constructor. 58 PhysicsUserData() 59 : 60 #ifdef TORQUE_DEBUG 61 mTypeId( smTypeName ), 62 #endif 63 mObject( NULL ), 64 mBody( NULL ) 65 {} 66 67 /// The destructor. 68 virtual ~PhysicsUserData() {} 69 70 /// 71 void setObject( SceneObject *object ) { mObject = object; } 72 SceneObject* getObject() const { return mObject; } 73 74 void setBody( PhysicsBody *body ) { mBody = body; } 75 PhysicsBody* getBody() const { return mBody; } 76 77 /// Helper method for casting a void pointer to a userdata pointer. 78 static inline SceneObject* getObject( void *data ) 79 { 80 PhysicsUserData *result = cast( data ); 81 return result ? result->getObject() : NULL; 82 } 83 84 PhysicsContactSignal& getContactSignal() { return mContactSignal; } 85 86 /// Helper method for casting a void pointer to a userdata pointer. 87 static inline PhysicsUserData* cast( void *data ) 88 { 89 PhysicsUserData *result = (PhysicsUserData*)data; 90 91 // If the typeid doesn't equal the value we assigned to it at 92 // construction then this isn't a PhysicsUserData object. 93 #ifdef TORQUE_DEBUG 94 AssertFatal( !result || result->mTypeId == smTypeName, 95 "PhysicsUserData::cast - The pointer is the wrong type!" ); 96 #endif 97 98 return result; 99 } 100 101protected: 102 103 #ifdef TORQUE_DEBUG 104 105 /// The type string used to validate the void* cast. 106 /// @see cast 107 static const char *smTypeName; 108 109 /// The type string assigned at construction used to 110 /// validate the void* cast. 111 /// @see cast 112 const char *mTypeId; 113 #endif 114 115 PhysicsContactSignal mContactSignal; 116 117 SceneObject *mObject; 118 119 PhysicsBody *mBody; 120}; 121 122#endif // _PHYSICS_PHYSICSUSERDATA_H_ 123