Project

General

Profile

SO3Engine
SO3SliderContraint.cpp
Go to the documentation of this file.
1
10
11namespace SO3
12{
13
14SSliderContraint::SSliderContraint() : SPhysicContraint(0, 0, 0, SPhysicContraint::SO3_SLIDER_CONTRAINT)
15{
16 // Forbiden, private.
17}
18
19SSliderContraint::SSliderContraint(SScene* scene, SBody* son, SBody* parent, Ogre::Vector3 position, Ogre::Vector3 pin, bool useLimits, bool useSpring) : SPhysicContraint(scene, son, parent, SPhysicContraint::SO3_SLIDER_CONTRAINT)
20{
21 mPosition = position;
22 mPin = pin;
23 mUseLimits = useLimits;
24 mUseSpring = useSpring;
25 mUseMotor = false;
26
27 UpdateJoint();
28}
29
31{
32 //mjoint deleted in SPhysicContraint
33}
34
36{
37 mParentBody = body;
38
39 UpdateJoint();
40}
41
43{
44 mSonBody = body;
45
46 UpdateJoint();
47}
48
49void SSliderContraint::UpdateJoint()
50{
52 SAFE_DELETE(mJoint);
53
54 if (mSonBody)
55 {
56 OgreNewt::Body* bparent = mParentBody != NULL ? mParentBody->getOgreNewtBodyPointer() : NULL;
57 mJoint = static_cast<OgreNewt::Joint*> (new OgreNewt::Slider(mSonBody->getOgreNewtBodyPointer(), bparent, mPosition, mPin));
58 static_cast<OgreNewt::Slider*>(mJoint)->enableLimits(mUseLimits);
59 static_cast<OgreNewt::Slider*>(mJoint)->enableSpring(mUseSpring);
60 static_cast<OgreNewt::Slider*>(mJoint)->enableMotor(mUseMotor);
61 }
62}
63
65{
66 mUseLimits = state;
67 if (mJoint != NULL)
68 static_cast<OgreNewt::Slider*>(mJoint)->enableLimits(mUseLimits);
69}
70
72{
73 mUseMotor = state;
74 if (mJoint != NULL)
75 static_cast<OgreNewt::Slider*>(mJoint)->enableMotor(mUseMotor);
76}
77
78void SSliderContraint::SetMotorVelocity(Ogre::Real velocity, Ogre::Real strength)
79{
80 if (mJoint != NULL)
81 static_cast<OgreNewt::Slider*>(mJoint)->setMotorVelocity(velocity, strength);
82}
83
84void SSliderContraint::SetLimits(Ogre::Real minDist, Ogre::Real maxDist)
85{
86 if (minDist > maxDist)
87 minDist = maxDist;
88
89 if (mJoint != NULL)
90 static_cast<OgreNewt::Slider*>(mJoint)->setLimits(minDist, maxDist);
91}
92
93void SSliderContraint::SetSpring(Ogre::Real springStrength, Ogre::Real springDamping)
94{
95 if (mJoint != NULL)
96 static_cast<OgreNewt::Slider*>(mJoint)->setSpring(springStrength, springDamping);
97}
98
100{
101 mUseSpring = state;
102 if (mJoint != NULL)
103 static_cast<OgreNewt::Slider*>(mJoint)->enableSpring(mUseSpring);
104}
105
107{
108 if (mJoint == NULL)
109 return 0.0f;
110 else
111 return static_cast<OgreNewt::Slider*>(mJoint)->getJointVelocity();
112}
113
115{
116 if (mJoint == NULL)
117 return Ogre::Vector3::ZERO;
118 else
119 return static_cast<OgreNewt::Slider*>(mJoint)->getJointForce();
120}
121
123{
124 if (mJoint == NULL)
125 return 0.0f;
126 else
127 return static_cast<OgreNewt::Slider*>(mJoint)->getDistance();
128}
129
130void SSliderContraint::SetFriction(Ogre::Real friction)
131{
132 if (mJoint != NULL)
133 return static_cast<OgreNewt::Slider*>(mJoint)->setFriction(friction);
134}
135
136}
main class for all Rigid Bodies in the system.
base class for all joints.
void waitForUpdateToFinish() const
OgreNewt::Body * getOgreNewtBodyPointer()
Definition SO3Body.cpp:340
OgreNewt::Joint * mJoint
OgreNewt::World * GetPhysicWorld()
SPhysicWorld * GetPhysicsWorld()
void SetSpring(Ogre::Real springStrength, Ogre::Real springDamping)
virtual void SetSonBody(SBody *body)
void SetLimits(Ogre::Real maxDist, Ogre::Real minDist)
void SetMotorVelocity(Ogre::Real velocity, Ogre::Real strength)
virtual void SetParentBody(SBody *body)
void SetFriction(Ogre::Real friction)
Manage Physics Contraint. .