SO3Engine
OgreNewt_ContactJoint.h
Go to the documentation of this file.
1/*
2 OgreNewt Library
3
4 Ogre implementation of Newton Game Dynamics SDK
5
6 OgreNewt basically has no license, you may use any or all of the library however you desire... I hope it can help you in any way.
7
8 by melven
9 some changes by melven
10
11*/
12#ifndef _INCLUDE_OGRENEWT_CONTACTJOINT
13#define _INCLUDE_OGRENEWT_CONTACTJOINT
14
15
17#include "OgreNewt_Body.h"
18
19// OgreNewt namespace. all functions and classes use this namespace.
20namespace OgreNewt
21{
22
23
25
32class _OgreNewtExport ContactJoint
33{
34public:
35
37 ContactJoint(const NewtonJoint* contactJoint);
38
41
43 int getContactCount() const { return NewtonContactJointGetContactCount( m_contactjoint ); }
44
46 Contact getFirstContact();
47
49 OgreNewt::Body* getBody0() { return (OgreNewt::Body*) NewtonBodyGetUserData(NewtonJointGetBody0(m_contactjoint)); }
50
52 OgreNewt::Body* getBody1() { return (OgreNewt::Body*) NewtonBodyGetUserData(NewtonJointGetBody1(m_contactjoint)); }
53
55 const NewtonJoint* _getNewtonContactJoint() { return m_contactjoint; }
56
58
61 MaterialPair* getMaterialPair();
62
63protected:
64 const NewtonJoint* m_contactjoint;
65};
66
67
68
70
77class _OgreNewtExport Contact
78{
79public:
80
82 Contact(void *contact, ContactJoint* parent);
83
85 ~Contact();
86
88 operator bool() const { return m_contact != NULL; }
89
91 Contact getNext() const;
92
93 // basic contact control commands... they can only be used, if this is a valid contact ( !contact == false )
94
96 OgreNewt::Body* getBody0() const { return (OgreNewt::Body*) NewtonBodyGetUserData( NewtonJointGetBody0( m_parent->_getNewtonContactJoint() ) ); }
97 OgreNewt::Body* getBody1() const { return (OgreNewt::Body*) NewtonBodyGetUserData( NewtonJointGetBody1( m_parent->_getNewtonContactJoint() ) ); }
98
100 unsigned getFaceAttribute() const { return NewtonMaterialGetContactFaceAttribute( m_material ); }
101
103 //unsigned getBodyCollisionID( OgreNewt::Body* body ) const { return NewtonMaterialGetBodyCollisionID( m_material, body->getNewtonBody() ); }
104
106 Ogre::Real getNormalSpeed() const { return (Ogre::Real)NewtonMaterialGetContactNormalSpeed( m_material ); }
107
109
112 Ogre::Vector3 getForce() const;
113
115 void getPositionAndNormal( Ogre::Vector3& pos, Ogre::Vector3& norm, OgreNewt::Body* body ) const
116 {
117 dVector fPos;
118 dVector fNorm;
119 NewtonMaterialGetContactPositionAndNormal(m_material, body->getNewtonBody(), &fPos.m_x, &fNorm.m_x);
120
121 pos.x = Ogre::Real(fPos.m_x);
122 pos.y = Ogre::Real(fPos.m_y);
123 pos.z = Ogre::Real(fPos.m_z);
124
125 norm.x = Ogre::Real(fNorm.m_x);
126 norm.y = Ogre::Real(fNorm.m_y);
127 norm.z = Ogre::Real(fNorm.m_z);
128 }
129
131 void getTangentDirections( Ogre::Vector3& dir0, Ogre::Vector3& dir1, OgreNewt::Body* body ) const
132 {
133
134 dVector fDir0;
135 dVector fDir1;
136 NewtonMaterialGetContactTangentDirections(m_material, body->getNewtonBody(), &fDir0.m_x, &fDir1.m_x);
137
138 dir0.x = Ogre::Real(fDir0.m_x);
139 dir0.y = Ogre::Real(fDir0.m_y);
140 dir0.z = Ogre::Real(fDir0.m_z);
141
142 dir1.x = Ogre::Real(fDir1.m_x);
143 dir1.y = Ogre::Real(fDir1.m_y);
144 dir1.z = Ogre::Real(fDir1.m_z);
145 }
146
148 Ogre::Real getTangentSpeed( int index ) const
149 {
150 return (Ogre::Real)NewtonMaterialGetContactTangentSpeed( m_material, index );
151 }
152
154 void setSoftness( Ogre::Real softness ) { NewtonMaterialSetContactSoftness( m_material, dFloat(softness)); }
155
157 void setElasticity( Ogre::Real elasticity ) { NewtonMaterialSetContactElasticity( m_material, dFloat(elasticity)); }
158
160 void setFrictionState( int state, int index ) { NewtonMaterialSetContactFrictionState( m_material, state, index ); }
161
163 void setFrictionCoef( Ogre::Real stat, Ogre::Real kinetic, int index ) { NewtonMaterialSetContactFrictionCoef( m_material, dFloat(stat), dFloat(kinetic), index ); }
164
166 void setTangentAcceleration( Ogre::Real accel, int index ) { NewtonMaterialSetContactTangentAcceleration( m_material, dFloat(accel), index ); }
167
169 void rotateTangentDirections( const Ogre::Vector3& dir )
170 {
171 dVector fdir;
172 fdir.m_x = dFloat(dir.x);
173 fdir.m_y = dFloat(dir.y);
174 fdir.m_z = dFloat(dir.z);
175 NewtonMaterialContactRotateTangentDirections( m_material, &fdir.m_x);
176 }
177
179 void setNormalDirection( const Ogre::Vector3& dir )
180 {
181 dVector fdir;
182 fdir.m_x = dFloat(dir.x);
183 fdir.m_y = dFloat(dir.y);
184 fdir.m_z = dFloat(dir.z);
185 NewtonMaterialSetContactNormalDirection( m_material, &fdir.m_x);
186 }
187
189 void setNormalAcceleration( Ogre::Real accel ) { NewtonMaterialSetContactNormalAcceleration( m_material, dFloat(accel)); }
190
192
196 void remove();
197
199 NewtonMaterial* _getNewtonMaterial() { return m_material; }
200
201protected:
202 NewtonMaterial* m_material;
205};
206
207
208} // end NAMESPACE OgreNewt
209
210#endif
211// _INCLUDE_OGRENEWT_CONTACTJOINT
212
main class for all Rigid Bodies in the system.
NewtonBody * getNewtonBody() const
get a pointer to the NewtonBody object
with the methods from this class you can set the behavior of each contac-point
void setElasticity(Ogre::Real elasticity)
set elasticity of the current contact
NewtonMaterial * _getNewtonMaterial()
get the NewtonMaterial from this callback.
void setNormalAcceleration(Ogre::Real accel)
manually set the acceleration along the collision normal.
void rotateTangentDirections(const Ogre::Vector3 &dir)
align tangent vectors with a user supplied direction
void setFrictionState(int state, int index)
set friction state of current contact
OgreNewt::Body * getBody1() const
NewtonMaterial * m_material
void setFrictionCoef(Ogre::Real stat, Ogre::Real kinetic, int index)
set static friction for current contact
Ogre::Real getNormalSpeed() const
get the Collision ID of a body currently colliding
OgreNewt::Body * getBody0() const
get the first body
unsigned getFaceAttribute() const
get the face ID of a TreeCollision object
void setSoftness(Ogre::Real softness)
set softness of the current contact
void getTangentDirections(Ogre::Vector3 &dir0, Ogre::Vector3 &dir1, OgreNewt::Body *body) const
get the tangent vectors of the collision
void getPositionAndNormal(Ogre::Vector3 &pos, Ogre::Vector3 &norm, OgreNewt::Body *body) const
get positoin and normal of the collision
Ogre::Real getTangentSpeed(int index) const
get tangent speed of the collision
OgreNewt::ContactJoint * m_parent
void setTangentAcceleration(Ogre::Real accel, int index)
set tangent acceleration for contact
void setNormalDirection(const Ogre::Vector3 &dir)
manually set the normal for the collision.
with this class you can iterate through all contacts
OgreNewt::Body * getBody0()
get the first body
const NewtonJoint * _getNewtonContactJoint()
get the newton ContactJoint
OgreNewt::Body * getBody1()
get the second body
const NewtonJoint * m_contactjoint
int getContactCount() const
return the number of contacts
define interaction between materials