1 /************************************************************************
2 This file is part of NE.
4 NE is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 NE is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with NE. If not, see <http://www.gnu.org/licenses/>.
16 ************************************************************************/
23 #include <ode/odecpp.h>
24 #include <ode/odecpp_collision.h>
30 : m_gravity_mag(0), m_geom(0), m_static(false), m_colfunc(0)
32 m_body
= new dBody(World::Instance()->getWorld()->id());
40 int Object::collide(Object
* o
)
48 return m_colfunc(this,o
);
52 void Object::apply_matrix()
54 const dReal
*pos
= m_body
->getPosition();
55 const dReal
*rot
= m_body
->getRotation();
57 static GLfloat matrix
[16];
75 glMultMatrixf (matrix
);
78 void Object::init_geom()
82 m_geom
->setData(this);
83 m_geom
->setBody(m_body
->id());
87 void Object::setStatic(bool is_static
)
95 m_geom
->setBody(m_body
->id());
99 bool Object::applyGravity(const Vec3f
&grav
)
101 m_body
->addForce(grav
.x(), grav
.y(), grav
.z());
103 float mag
= grav
.length();
105 if (m_gravity_mag
< mag
)
116 std::string
&Object::serialize()
118 std::stringstream stream
;
120 const dReal
*p
= getPosition();
123 stream
<< p
[0] << ' ' << p
[1] << ' ' << p
[2] << ' ';
128 stream
<< p
[0] << ' ' << p
[1] << ' ' << p
[2] << ' ' << p
[3] << ' ';
130 static std::string out
= stream
.str();
134 void Object::unserialize(std::string
&s
)
136 std::stringstream
stream(s
);
138 while (stream
>> str
)
143 stream
>> x
>> y
>> z
;
146 else if (str
== "quat:")
149 stream
>> q
[0] >> q
[1] >> q
[2] >> q
[3];
155 void Object::setPosition(dReal x
, dReal y
, dReal z
)
158 m_geom
->setPosition(x
,y
,z
);
160 m_body
->setPosition(x
,y
,z
);
162 const dReal
*Object::getPosition()
165 return m_geom
->getPosition();
167 return m_body
->getPosition();
170 void Object::setRotation(const dMatrix3 r
)
173 m_geom
->setRotation(r
);
175 m_body
->setRotation(r
);
177 const dReal
*Object::getRotation()
180 return m_geom
->getRotation();
182 return m_body
->getRotation();
185 void Object::setQuaternion(const dQuaternion q
)
188 m_geom
->setQuaternion(q
);
190 m_body
->setQuaternion(q
);
192 const dReal
*Object::getQuaternion()
197 m_geom
->getQuaternion(q
);
201 return m_body
->getQuaternion();