5#include "CustomUserBlank.h"
6#include "CustomJoint.h"
23 m_joint->SetUserDestructorCallback(NULL);
32 supportJoint->SetUserData (
this);
33 supportJoint->SetUserDestructorCallback ((JointUserDestructorCallback)
destructorCallback);
48 const NewtonBody* ntBody;
50 body = (
Body*) NewtonBodyGetUserData(ntBody);
61 const NewtonBody* ntBody;
64 body = (
Body*) NewtonBodyGetUserData(ntBody);
74 const NewtonBody* ntBody;
76 body = (
Body*) NewtonBodyGetUserData(ntBody);
84void Joint::addLinearRow(
const Ogre::Vector3& pt0,
const Ogre::Vector3& pt1,
const Ogre::Vector3& dir )
const
86 NewtonUserJointAddLinearRow (
m_joint->GetJoint(), &pt0.x, &pt1.x, &dir.x );
91 NewtonUserJointAddAngularRow(
m_joint->GetJoint(), relativeAngleError.valueRadians(), &dir.x );
94void Joint::addGeneralRow(
const Ogre::Vector3& linear0,
const Ogre::Vector3& angular0,
const Ogre::Vector3& linear1,
const Ogre::Vector3& angular1)
const
96 dFloat jacobian0[6], jacobian1[6];
98 jacobian0[0] = linear0.x;
99 jacobian0[1] = linear0.y;
100 jacobian0[2] = linear0.z;
101 jacobian0[3] = angular0.x;
102 jacobian0[4] = angular0.y;
103 jacobian0[5] = angular0.z;
105 jacobian1[0] = linear1.x;
106 jacobian1[1] = linear1.y;
107 jacobian1[2] = linear1.z;
108 jacobian1[3] = angular1.x;
109 jacobian1[4] = angular1.y;
110 jacobian1[5] = angular1.z;
112 NewtonUserJointAddGeneralRow(
m_joint->GetJoint(), jacobian0, jacobian1 );
118 NewtonUserJointSetRowMinimumFriction(
m_joint->GetJoint(), friction );
124 NewtonUserJointSetRowMaximumFriction(
m_joint->GetJoint(), friction );
130 NewtonUserJointSetRowAcceleration(
m_joint->GetJoint(), accel );
135 NewtonUserJointSetRowStiffness(
m_joint->GetJoint(), stiffness );
140 NewtonUserJointSetRowSpringDamperAcceleration(
m_joint->GetJoint(), springK, springD );
145 return NewtonJointGetCollisionState(
m_joint->GetJoint() );
150 NewtonJointSetCollisionState(
m_joint->GetJoint(), state );
155 return (Ogre::Real)NewtonJointGetStiffness(
m_joint->GetJoint() );
160 NewtonJointSetStiffness(
m_joint->GetJoint(), stiffness );
167 jnt = (
Joint*)me->GetUserData ();
177 jnt = (
Joint*)me->GetUserData ();
183 CustomJoint* suppportJoint;
199 Ogre::Quaternion& localOrient0, Ogre::Vector3& localPos0, Ogre::Quaternion& localOrient1, Ogre::Vector3& localPos1 )
const
201 localOrient0 = localOrient1 = Ogre::Quaternion::IDENTITY;
202 localPos0 = localPos1 = Ogre::Vector3::ZERO;
204 Ogre::Quaternion bodyOrient0 = Ogre::Quaternion::IDENTITY;
205 Ogre::Quaternion bodyOrient1 = Ogre::Quaternion::IDENTITY;
206 Ogre::Vector3 bodyPos0 = Ogre::Vector3::ZERO;
207 Ogre::Vector3 bodyPos1 = Ogre::Vector3::ZERO;
218 localPos0 = bodyOrient0.Inverse() * (pinpt - bodyPos0);
219 localOrient0 = pinOrient * bodyOrient0.Inverse();
221 localPos1 = bodyOrient1.Inverse() * (pinpt - bodyPos1);
222 localOrient1 = pinOrient * bodyOrient1.Inverse();
226void OgCustomJoint::localToGlobal(
const Ogre::Quaternion& localOrient,
const Ogre::Vector3& localPos, Ogre::Quaternion& globalOrient, Ogre::Vector3& globalPos,
int bodyIndex )
const
228 globalOrient = Ogre::Quaternion::IDENTITY;
229 globalPos= Ogre::Vector3::ZERO;
231 const Body* bdy = NULL;
237 Ogre::Quaternion bodyOrient = Ogre::Quaternion::IDENTITY;
238 Ogre::Vector3 bodyPos = Ogre::Vector3::ZERO;
245 globalPos = (bodyOrient * localPos) + bodyPos;
246 globalOrient = bodyOrient * localOrient;
249void OgCustomJoint::localToGlobalVisual(
const Ogre::Quaternion& localOrient,
const Ogre::Vector3& localPos, Ogre::Quaternion& globalOrient, Ogre::Vector3& globalPos,
int bodyIndex )
const
251 globalOrient = Ogre::Quaternion::IDENTITY;
252 globalPos= Ogre::Vector3::ZERO;
254 const Body* bdy = NULL;
260 Ogre::Quaternion bodyOrient = Ogre::Quaternion::IDENTITY;
261 Ogre::Vector3 bodyPos = Ogre::Vector3::ZERO;
268 globalPos = (bodyOrient * localPos) + bodyPos;
269 globalOrient = bodyOrient * localOrient;
272void OgCustomJoint::globalToLocal(
const Ogre::Quaternion& globalOrient,
const Ogre::Vector3& globalPos, Ogre::Quaternion& localOrient, Ogre::Vector3& localPos,
int bodyIndex )
const
274 localOrient = Ogre::Quaternion::IDENTITY;
275 localPos= Ogre::Vector3::ZERO;
277 const Body* bdy = NULL;
283 Ogre::Quaternion bodyOrient = Ogre::Quaternion::IDENTITY;
284 Ogre::Vector3 bodyPos = Ogre::Vector3::ZERO;
289 Ogre::Quaternion bodyOrientInv = bodyOrient.Inverse();
291 localOrient = bodyOrientInv * globalOrient;
292 localPos = bodyOrientInv * (globalPos - bodyPos);
297 Ogre::Vector3 front, up, right;
301 if (Ogre::Math::Abs( front.z ) > 0.577f)
302 right = front.crossProduct( Ogre::Vector3(-front.y, front.z, 0.0f) );
304 right = front.crossProduct( Ogre::Vector3(-front.y, front.x, 0.0f) );
306 up = right.crossProduct( front );
309 ret.FromAxes( front, up, right );
311 Ogre::Quaternion quat;
312 quat.FromRotationMatrix( ret );
main class for all Rigid Bodies in the system.
OgreNewt::World *const getWorld() const
get a pointer to the OgreNewt::World this body belongs to.
NewtonBody * getNewtonBody() const
get a pointer to the NewtonBody object
void getVisualPositionOrientation(Ogre::Vector3 &pos, Ogre::Quaternion &orient) const
get the node position and orientation in form of an Ogre::Vector(position) and Ogre::Quaternion(orien...
void getPositionOrientation(Ogre::Vector3 &pos, Ogre::Quaternion &orient) const
get position and orientation in form of an Ogre::Vector(position) and Ogre::Quaternion(orientation)
base class for all joints.
void setRowMaximumFriction(Ogre::Real friction) const
Body * getBody0() const
get the pointer to the first rigid body
void setStiffness(Ogre::Real stiffness) const
set joint stiffness
void addGeneralRow(const Ogre::Vector3 &linear0, const Ogre::Vector3 &angular0, const Ogre::Vector3 &linear1, const Ogre::Vector3 &angular1) const
virtual void submitConstraint(Ogre::Real timeStep, int threadIndex)
must be define for a functioning joint.
void setRowAcceleration(Ogre::Real accel) const
CustomJoint * GetSupportJoint() const
GetSupportJoint.
void setRowMinimumFriction(Ogre::Real friction) const
virtual ~Joint()
destructor
void setRowStiffness(Ogre::Real stiffness) const
int getCollisionState() const
returns collision state
void setCollisionState(int state) const
sets the collision state
void addAngularRow(Ogre::Radian relativeAngleError, const Ogre::Vector3 &dir) const
void setRowSpringDamper(Ogre::Real springK, Ogre::Real springD) const
const OgreNewt::World * getWorld()
get the pointer to the world
void addLinearRow(const Ogre::Vector3 &pt0, const Ogre::Vector3 &pt1, const Ogre::Vector3 &dir) const
static void _CDECL destructorCallback(const CustomJoint *me)
joint destructor callback glue
Ogre::Real getStiffness() const
get joint stiffness
void SetSupportJoint(CustomJoint *supportJoint)
SetSupportJoint.
static void _CDECL submitConstraintCallback(const CustomJoint *me, dFloat timestep, int threadIndex)
submintContraint
Body * getBody1() const
get the pointer to the first rigid body
OgCustomJoint(unsigned int maxDOF, const OgreNewt::Body *child, const OgreNewt::Body *parent)
void globalToLocal(const Ogre::Quaternion &globalOrient, const Ogre::Vector3 &globalPos, Ogre::Quaternion &localOrient, Ogre::Vector3 &localPos, int bodyIndex) const
const OgreNewt::Body * m_body0
void pinAndDirToLocal(const Ogre::Vector3 &pinpt, const Ogre::Vector3 &pindir, Ogre::Quaternion &localOrient0, Ogre::Vector3 &localPos0, Ogre::Quaternion &localOrient1, Ogre::Vector3 &localPos1) const
Ogre::Quaternion grammSchmidt(const Ogre::Vector3 &pin) const
const OgreNewt::Body * m_body1
void localToGlobalVisual(const Ogre::Quaternion &localOrient, const Ogre::Vector3 &localPos, Ogre::Quaternion &globalOrient, Ogre::Vector3 &globalPos, int bodyIndex) const
void localToGlobal(const Ogre::Quaternion &localOrient, const Ogre::Vector3 &localPos, Ogre::Quaternion &globalOrient, Ogre::Vector3 &globalPos, int bodyIndex) const
represents a physics world.