SO3Engine
src
SO3PhysicGraph
SO3SliderContraint.cpp
Go to the documentation of this file.
1
8
#include "
SO3PhysicGraph/SO3SliderContraint.h
"
9
#include "
SO3SceneGraph/SO3Scene.h
"
10
11
namespace
SO3
12
{
13
14
SSliderContraint::SSliderContraint() :
SPhysicContraint
(0, 0, 0,
SPhysicContraint
::SO3_SLIDER_CONTRAINT)
15
{
16
// Forbiden, private.
17
}
18
19
SSliderContraint::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
30
SSliderContraint::~SSliderContraint
()
31
{
32
//mjoint deleted in SPhysicContraint
33
}
34
35
void
SSliderContraint::SetParentBody
(
SBody
* body)
36
{
37
mParentBody
= body;
38
39
UpdateJoint();
40
}
41
42
void
SSliderContraint::SetSonBody
(
SBody
* body)
43
{
44
mSonBody
= body;
45
46
UpdateJoint();
47
}
48
49
void
SSliderContraint::UpdateJoint()
50
{
51
mScene
->
GetPhysicsWorld
()->
GetPhysicWorld
()->
waitForUpdateToFinish
();
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
64
void
SSliderContraint::UseLimits
(
bool
state)
65
{
66
mUseLimits = state;
67
if
(
mJoint
!= NULL)
68
static_cast<
OgreNewt::Slider
*
>
(
mJoint
)->enableLimits(mUseLimits);
69
}
70
71
void
SSliderContraint::UseMotor
(
bool
state)
72
{
73
mUseMotor = state;
74
if
(
mJoint
!= NULL)
75
static_cast<
OgreNewt::Slider
*
>
(
mJoint
)->enableMotor(mUseMotor);
76
}
77
78
void
SSliderContraint::SetMotorVelocity
(Ogre::Real velocity, Ogre::Real strength)
79
{
80
if
(
mJoint
!= NULL)
81
static_cast<
OgreNewt::Slider
*
>
(
mJoint
)->setMotorVelocity(velocity, strength);
82
}
83
84
void
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
93
void
SSliderContraint::SetSpring
(Ogre::Real springStrength, Ogre::Real springDamping)
94
{
95
if
(
mJoint
!= NULL)
96
static_cast<
OgreNewt::Slider
*
>
(
mJoint
)->setSpring(springStrength, springDamping);
97
}
98
99
void
SSliderContraint::UseSpring
(
bool
state)
100
{
101
mUseSpring = state;
102
if
(
mJoint
!= NULL)
103
static_cast<
OgreNewt::Slider
*
>
(
mJoint
)->enableSpring(mUseSpring);
104
}
105
106
Ogre::Real
SSliderContraint::GetVelocity
()
107
{
108
if
(
mJoint
== NULL)
109
return
0.0f;
110
else
111
return
static_cast<
OgreNewt::Slider
*
>
(
mJoint
)->getJointVelocity();
112
}
113
114
Ogre::Vector3
SSliderContraint::GetForce
()
115
{
116
if
(
mJoint
== NULL)
117
return
Ogre::Vector3::ZERO;
118
else
119
return
static_cast<
OgreNewt::Slider
*
>
(
mJoint
)->getJointForce();
120
}
121
122
Ogre::Real
SSliderContraint::GetDistance
()
123
{
124
if
(
mJoint
== NULL)
125
return
0.0f;
126
else
127
return
static_cast<
OgreNewt::Slider
*
>
(
mJoint
)->getDistance();
128
}
129
130
void
SSliderContraint::SetFriction
(Ogre::Real friction)
131
{
132
if
(
mJoint
!= NULL)
133
return
static_cast<
OgreNewt::Slider
*
>
(
mJoint
)->setFriction(friction);
134
}
135
136
}
SO3Scene.h
SO3SliderContraint.h
OgreNewt::Body
main class for all Rigid Bodies in the system.
Definition
OgreNewt_Body.h:39
OgreNewt::Joint
base class for all joints.
Definition
OgreNewt_Joint.h:31
OgreNewt::Slider
slider joint.
Definition
OgreNewt_BasicJoints.h:235
OgreNewt::World::waitForUpdateToFinish
void waitForUpdateToFinish() const
Definition
OgreNewt_World.h:361
SO3::SBody
Definition
SO3Body.h:43
SO3::SBody::getOgreNewtBodyPointer
OgreNewt::Body * getOgreNewtBodyPointer()
Definition
SO3Body.cpp:340
SO3::SPhysicContraint
Definition
SO3PhysicContraint.h:42
SO3::SPhysicContraint::mParentBody
SBody * mParentBody
Definition
SO3PhysicContraint.h:54
SO3::SPhysicContraint::mJoint
OgreNewt::Joint * mJoint
Definition
SO3PhysicContraint.h:57
SO3::SPhysicContraint::mScene
SScene * mScene
Definition
SO3PhysicContraint.h:56
SO3::SPhysicContraint::mSonBody
SBody * mSonBody
Definition
SO3PhysicContraint.h:55
SO3::SPhysicWorld::GetPhysicWorld
OgreNewt::World * GetPhysicWorld()
Definition
SO3Physics.cpp:93
SO3::SScene
Definition
SO3Scene.h:125
SO3::SScene::GetPhysicsWorld
SPhysicWorld * GetPhysicsWorld()
Definition
SO3Scene.cpp:1332
SO3::SSliderContraint::UseSpring
void UseSpring(bool state)
Definition
SO3SliderContraint.cpp:99
SO3::SSliderContraint::GetVelocity
Ogre::Real GetVelocity()
Definition
SO3SliderContraint.cpp:106
SO3::SSliderContraint::UseMotor
void UseMotor(bool state)
Definition
SO3SliderContraint.cpp:71
SO3::SSliderContraint::~SSliderContraint
~SSliderContraint()
Definition
SO3SliderContraint.cpp:30
SO3::SSliderContraint::SetSpring
void SetSpring(Ogre::Real springStrength, Ogre::Real springDamping)
Definition
SO3SliderContraint.cpp:93
SO3::SSliderContraint::SetSonBody
virtual void SetSonBody(SBody *body)
Definition
SO3SliderContraint.cpp:42
SO3::SSliderContraint::UseLimits
void UseLimits(bool state)
Definition
SO3SliderContraint.cpp:64
SO3::SSliderContraint::GetDistance
Ogre::Real GetDistance()
Definition
SO3SliderContraint.cpp:122
SO3::SSliderContraint::SetLimits
void SetLimits(Ogre::Real maxDist, Ogre::Real minDist)
Definition
SO3SliderContraint.cpp:84
SO3::SSliderContraint::SetMotorVelocity
void SetMotorVelocity(Ogre::Real velocity, Ogre::Real strength)
Definition
SO3SliderContraint.cpp:78
SO3::SSliderContraint::SetParentBody
virtual void SetParentBody(SBody *body)
Definition
SO3SliderContraint.cpp:35
SO3::SSliderContraint::GetForce
Ogre::Vector3 GetForce()
Definition
SO3SliderContraint.cpp:114
SO3::SSliderContraint::SetFriction
void SetFriction(Ogre::Real friction)
Definition
SO3SliderContraint.cpp:130
SPhysicContraint
Manage Physics Contraint. .
SO3
Definition
SO3DataScol.h:38
Generated by
1.9.8