30 #ifndef _WorldEntity_H__ 31 #define _WorldEntity_H__ 35 #ifdef ORXONOX_RELEASE 36 # include <OgreSceneNode.h> 38 #include <LinearMath/btMotionState.h> 39 #include <LinearMath/btAlignedAllocator.h> 77 BT_DECLARE_ALIGNED_ALLOCATOR();
101 {
return this->node_; }
108 static const Vector3
UP;
110 virtual void changedActivity(
void)
override;
111 virtual void changedVisibility(
void)
override;
114 {
return this->id_; }
119 virtual void setPosition(
const Vector3& position) = 0;
121 { this->setPosition(Vector3(x, y, z)); }
122 const Vector3& getPosition()
const;
123 const Vector3& getWorldPosition()
const;
125 void translate(
const Vector3& distance,
TransformSpace relativeTo = TransformSpace::Parent);
127 { this->translate(Vector3(x, y, z), relativeTo); }
130 {
return Vector3::ZERO; }
132 virtual void setOrientation(
const Quaternion& orientation) = 0;
134 { this->setOrientation(Quaternion(w, x, y, z)); }
136 { this->setOrientation(Quaternion(angle, axis)); }
138 { this->setOrientation(Quaternion(angle, axis)); }
139 const Quaternion& getOrientation()
const;
140 const Quaternion& getWorldOrientation()
const;
142 void rotate(
const Quaternion& rotation,
TransformSpace relativeTo = TransformSpace::Local);
143 inline void rotate(
const Vector3& axis,
const Degree& angle,
TransformSpace relativeTo = TransformSpace::Local)
144 { this->rotate(Quaternion(angle, axis), relativeTo); }
147 { this->rotate(Quaternion(angle, Vector3::UNIT_Y), relativeTo); }
149 { this->rotate(Quaternion(angle, Vector3::UNIT_X), relativeTo); }
151 { this->rotate(Quaternion(angle, Vector3::UNIT_Z), relativeTo); }
153 void lookAt(
const Vector3& target,
TransformSpace relativeTo = TransformSpace::Parent,
const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);
154 void setDirection(
const Vector3& direction,
TransformSpace relativeTo = TransformSpace::Local,
const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);
155 inline void setDirection(
float x,
float y,
float z,
TransformSpace relativeTo = TransformSpace::Local,
const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z)
156 { this->setDirection(Vector3(x, y, z), relativeTo, localDirectionVector); }
158 virtual void setScale3D(
const Vector3& scale);
160 { this->setScale3D(Vector3(x, y, z)); }
161 const Vector3& getScale3D()
const;
162 const Vector3& getWorldScale3D()
const;
165 { this->setScale3D(scale, scale, scale); }
167 { Vector3 scale = this->getScale3D();
return (scale.x == scale.y && scale.x == scale.z) ? scale.x : 1; }
168 float getWorldScale()
const;
171 { this->setScale3D(this->getScale3D() * scale); }
172 inline void scale3D(
float x,
float y,
float z)
173 { this->scale3D(Vector3(x, y, z)); }
175 { this->scale3D(scale, scale, scale); }
181 WorldEntity* getAttachedObject(
unsigned int index);
183 {
return this->children_; }
185 void attachOgreObject(Ogre::MovableObject*
object);
186 void attachOgreObject(Ogre::BillboardSet*
object);
187 void attachOgreObject(Ogre::Camera*
object);
188 void attachOgreObject(Ogre::Entity*
object);
189 void attachOgreObject(Ogre::ParticleSystem*
object);
191 void detachOgreObject(Ogre::MovableObject*
object);
192 void detachOgreObject(Ogre::BillboardSet*
object);
193 void detachOgreObject(Ogre::Camera*
object);
194 void detachOgreObject(Ogre::Entity*
object);
195 void detachOgreObject(Ogre::ParticleSystem*
object);
197 Ogre::MovableObject* detachOgreObject(
const Ogre::String& name);
202 {
if (this->parent_) { this->parent_->detach(
this); } }
204 {
return this->parent_; }
206 void attachNode(Ogre::SceneNode* node);
207 void detachNode(Ogre::SceneNode* node);
208 void attachToNode(Ogre::SceneNode* node);
209 void detachFromNode(Ogre::SceneNode* node);
212 { this->bDeleteWithParent_ = value; }
214 {
return this->bDeleteWithParent_; }
216 void notifyChildPropsChanged();
224 void registerVariables();
227 { this->lookAt(target); }
229 { this->setDirection(direction); }
231 { this->yaw(angle); }
233 { this->pitch(angle); }
235 { this->roll(angle); }
238 void networkcallback_parentChanged();
240 { this->setScale3D(this->getScale3D()); }
276 bool isStatic()
const {
return getCollisionType() == CollisionType::Static ; }
278 bool isKinematic()
const {
return getCollisionType() == CollisionType::Kinematic; }
280 bool isDynamic()
const {
return getCollisionType() == CollisionType::Dynamic ; }
283 bool addedToPhysicalWorld()
const;
285 void activatePhysics();
286 void deactivatePhysics();
290 {
return this->collisionType_; }
298 { this->mass_ = mass; recalculateMassProps(); }
301 {
return this->mass_; }
305 {
return this->mass_ + this->childrenMass_; }
315 {
return this->localInertia_; }
327 { this->restitution_ = restitution; internalSetPhysicsProps(); }
330 {
return this->restitution_; }
340 { this->angularFactor_ = angularFactor; internalSetPhysicsProps(); }
343 {
return this->angularFactor_; }
347 { this->linearDamping_ = linearDamping; internalSetPhysicsProps(); }
350 {
return this->linearDamping_; }
354 { this->angularDamping_ = angularDamping; internalSetPhysicsProps(); }
357 {
return this->angularDamping_; }
361 { this->friction_ = friction; internalSetPhysicsProps(); }
364 {
return this->friction_; }
377 { this->ccdMotionThreshold_ = ccdMotionThreshold; internalSetPhysicsProps(); }
380 {
return this->ccdMotionThreshold_; }
391 { this->ccdSweptSphereRadius_ = ccdSweptSphereRadius; internalSetPhysicsProps(); }
394 {
return this->ccdSweptSphereRadius_; }
400 void notifyCollisionShapeChanged();
401 void notifyChildMassChanged();
422 { this->bCollisionCallbackActive_ =
true; this->collisionCallbackActivityChanged(); }
425 { this->bCollisionCallbackActive_ =
false; this->collisionCallbackActivityChanged(); }
428 {
return this->bCollisionCallbackActive_; }
432 { this->bCollisionResponseActive_ = value; this->collisionResponseActivityChanged(); }
435 {
return this->bCollisionResponseActive_; }
447 virtual bool isCollisionTypeLegal(
CollisionType type)
const = 0;
453 void recalculateMassProps();
454 void internalSetPhysicsProps();
457 void notifyDetached();
460 void collisionTypeChanged();
461 void physicsActivityChanged();
462 void collisionCallbackActivityChanged();
463 void collisionResponseActivityChanged();
466 { this->setMass(this->mass_); }
469 { this->setRestitution(this->restitution_); }
472 { this->setAngularFactor(this->angularFactor_); }
475 { this->setLinearDamping(this->linearDamping_); }
478 { this->setAngularDamping(this->angularDamping_); }
481 { this->setFriction(this->friction_); }
484 { this->setCcdMotionThreshold(this->ccdMotionThreshold_); }
487 { this->setCcdSweptSphereRadius(this->ccdSweptSphereRadius_); }
493 bool bPhysicsActiveBeforeAttaching_;
511 #ifdef ORXONOX_RELEASE 513 {
return this->node_->getPosition(); }
515 {
return this->node_->getOrientation(); }
517 {
return this->node_->getScale(); }
The BaseObject is the parent of all classes representing an instance in the game. ...
Definition: BaseObject.h:63
static const Vector3 LEFT
Definition: WorldEntity.h:105
void translate(float x, float y, float z, TransformSpace relativeTo=TransformSpace::Parent)
Definition: WorldEntity.h:126
btRigidBody * physicalBody_
Bullet rigid body. Everything physical is applied to this instance.
Definition: WorldEntity.h:449
bool bVisibleMem_
Definition: WorldEntity.h:248
WorldEntity * parent_
Definition: WorldEntity.h:242
virtual bool collidesAgainst(WorldEntity *otherObject, const btCollisionShape *ownCollisionShape, btManifoldPoint &contactPoint)
Virtual function that gets called when this object collides with another.
Definition: WorldEntity.h:417
const btVector3 & getLocalInertia() const
Returns the diagonal elements of the inertia tensor when calculated in local coordinates.
Definition: WorldEntity.h:314
static const Vector3 RIGHT
Definition: WorldEntity.h:106
void setOrientation(const Vector3 &axis, const Degree &angle)
Definition: WorldEntity.h:137
btScalar ccdMotionThreshold_
Definition: WorldEntity.h:504
This class is the base class of all the Objects in the universe that need to be synchronised over the...
Definition: Synchronisable.h:142
btScalar restitution_
Definition: WorldEntity.h:498
btScalar ccdSweptSphereRadius_
Definition: WorldEntity.h:505
void setLinearDamping(float linearDamping)
Applies a mass independent damping. Velocities will simply diminish exponentially.
Definition: WorldEntity.h:346
btScalar friction_
Definition: WorldEntity.h:502
void attachToParent(WorldEntity *parent)
Definition: WorldEntity.h:199
std::string getID(void)
Definition: WorldEntity.h:113
void detachFromParent()
Definition: WorldEntity.h:201
btScalar angularFactor_
Definition: WorldEntity.h:499
btScalar angularDamping_
Definition: WorldEntity.h:501
std::set< WorldEntity * > children_
Definition: WorldEntity.h:244
::std::string string
Definition: gtest-port.h:756
CollisionType collisionTypeSynchronised_
Network synchronised variable for collisionType_.
Definition: WorldEntity.h:490
const std::set< WorldEntity * > & getAttachedObjects() const
Definition: WorldEntity.h:182
static const Vector3 BACK
Definition: WorldEntity.h:104
bool bCollisionResponseActive_
Tells whether the object should respond to collisions.
Definition: WorldEntity.h:507
virtual const Vector3 & getVelocity() const
Definition: WorldEntity.h:129
void scale3D(const Vector3 &scale)
Definition: WorldEntity.h:170
bool bActiveMem_
Definition: WorldEntity.h:247
void setFriction(float friction)
Applies friction to the object. Friction occurs when two objects collide.
Definition: WorldEntity.h:360
void pitch(const Degree &angle, TransformSpace relativeTo=TransformSpace::Local)
Definition: WorldEntity.h:148
void setScale3D(float x, float y, float z)
Definition: WorldEntity.h:159
void roll(const Degree &angle, TransformSpace relativeTo=TransformSpace::Local)
Definition: WorldEntity.h:150
void setCcdMotionThreshold(float ccdMotionThreshold)
Sets the motion threshold for continuous collision detection (CCD).
Definition: WorldEntity.h:376
void setCollisionResponse(bool value)
Enables or disables collision response (default is of course on)
Definition: WorldEntity.h:431
void massChanged()
Network callback workaround to call a function when the value changes.
Definition: WorldEntity.h:465
std::string id_
Used by the ScriptableController to identify objects.
Definition: WorldEntity.h:450
void scaleChanged()
Definition: WorldEntity.h:239
const Vector3 & getPosition() const
Definition: WorldEntity.cc:622
virtual void parentChanged()
Definition: WorldEntity.h:219
static const Vector3 UP
Definition: WorldEntity.h:108
float getAngularDamping() const
Returns the angular damping.
Definition: WorldEntity.h:356
void angularDampingChanged()
Network callback workaround to call a function when the value changes.
Definition: WorldEntity.h:477
void setDirection_xmlport(const Vector3 &direction)
Definition: WorldEntity.h:228
SUPER_FUNCTION(0, BaseObject, XMLPort, false)
The WorldEntity represents everything that can be put in a Scene at a certain location.
Definition: WorldEntity.h:72
float getCcdMotionThreshold() const
Returns the currently used motion threshold for CCD (0 means CCD is deactivated). ...
Definition: WorldEntity.h:379
float getScale() const
Definition: WorldEntity.h:166
float getRestitution() const
Returns the restitution parameter.
Definition: WorldEntity.h:329
bool bCollisionCallbackActive_
Definition: WorldEntity.h:506
bool bDeleteWithParent_
Definition: WorldEntity.h:245
void linearDampingChanged()
Network callback workaround to call a function when the value changes.
Definition: WorldEntity.h:474
void pitch_xmlport(const Degree &angle)
Definition: WorldEntity.h:232
Definition: WorldEntityCollisionShape.h:37
xmlelement
Definition: Super.h:519
btScalar mass_
Definition: WorldEntity.h:496
WorldEntityCollisionShape * collisionShape_
Attached collision shapes go here.
Definition: WorldEntity.h:495
void setOrientation(float w, float x, float y, float z)
Definition: WorldEntity.h:133
TransformSpace
Enumeration denoting the spaces which a transform can be relative to.
Definition: WorldEntity.h:84
void setID(std::string id)
Definition: WorldEntity.h:116
void angularFactorChanged()
Network callback workaround to call a function when the value changes.
Definition: WorldEntity.h:471
Declaration and implementation of several math-functions, typedefs of some Ogre::Math classes to the ...
btVector3 localInertia_
Definition: WorldEntity.h:497
bool isDynamic() const
Definition: WorldEntity.h:280
unsigned int parentID_
Definition: WorldEntity.h:243
void restitutionChanged()
Network callback workaround to call a function when the value changes.
Definition: WorldEntity.h:468
float getAngularFactor() const
Returns the angular factor.
Definition: WorldEntity.h:342
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
float getCcdSweptSphereRadius() const
Returns the currently used radius of the sphere for CCD.
Definition: WorldEntity.h:393
void scale3D(float x, float y, float z)
Definition: WorldEntity.h:172
void setScale(float scale)
Definition: WorldEntity.h:164
Mode
Definition: CorePrereqs.h:102
void roll_xmlport(const Degree &angle)
Definition: WorldEntity.h:234
void setDeleteWithParent(bool value)
Definition: WorldEntity.h:211
void yaw_xmlport(const Degree &angle)
Definition: WorldEntity.h:230
CollisionType
Denotes the possible types of physical objects in a Scene.
Definition: WorldEntity.h:265
Shared library macros, enums, constants and forward declarations for the orxonox library ...
btScalar childrenMass_
Sum of all the children's masses.
Definition: WorldEntity.h:503
Ogre::SceneNode * node_
Definition: WorldEntity.h:221
Declaration of BaseObject, the base class of all objects in Orxonox.
void scale(float scale)
Definition: WorldEntity.h:174
WorldEntity * getParent() const
Definition: WorldEntity.h:203
bool isKinematic() const
Definition: WorldEntity.h:278
void setMass(float mass)
Sets the mass of this object. Note that the total mass may be influenced by attached objects! ...
Definition: WorldEntity.h:297
static const Vector3 FRONT
Definition: WorldEntity.h:103
const Vector3 & getScale3D() const
Definition: WorldEntity.cc:632
#define _OrxonoxExport
Definition: OrxonoxPrereqs.h:60
bool bPhysicsActiveSynchronised_
Network synchronised variable for bPhysicsActive_.
Definition: WorldEntity.h:492
float getTotalMass() const
Returns the total mass of this object with all its attached children.
Definition: WorldEntity.h:304
void lookAt_xmlport(const Vector3 &target)
Definition: WorldEntity.h:226
btScalar linearDamping_
Definition: WorldEntity.h:500
Wrapper for bullet collision shape class btCollisionShape.
Definition: CollisionShape.h:57
void setOrientation(const Vector3 &axis, const Radian &angle)
Definition: WorldEntity.h:135
void setRestitution(float restitution)
Sets how much reaction is applied in a collision.
Definition: WorldEntity.h:326
void setCcdSweptSphereRadius(float ccdSweptSphereRadius)
Sets the radius of the sphere which is used for continuous collision detection (CCD).
Definition: WorldEntity.h:390
bool getDeleteWithParent() const
Definition: WorldEntity.h:213
void setAngularDamping(float angularDamping)
Applies a tensor independent rotation damping. Angular velocities will simply diminish exponentially...
Definition: WorldEntity.h:353
void attach(WorldEntity *object)
Attaches a child WorldEntity to this object.
Definition: WorldEntity.cc:395
void rotate(const Vector3 &axis, const Degree &angle, TransformSpace relativeTo=TransformSpace::Local)
Definition: WorldEntity.h:143
void setAngularFactor(float angularFactor)
Sets an artificial parameter that tells how much torque is applied when you apply a non-central force...
Definition: WorldEntity.h:339
void ccdSweptSphereRadiusChanged()
Network callback workaround to call a function when the value changes.
Definition: WorldEntity.h:486
bool hasPhysics() const
Tells whether the object has any connection to the Bullet physics engine. If hasPhysics() is false...
Definition: WorldEntity.h:274
float getMass() const
Returns the mass of this object without its children.
Definition: WorldEntity.h:300
void ccdMotionThresholdChanged()
Network callback workaround to call a function when the value changes.
Definition: WorldEntity.h:483
bool hasCollisionResponse()
Tells whether there could be a collision response.
Definition: WorldEntity.h:434
CollisionType collisionType_
Definition: WorldEntity.h:489
void setDirection(float x, float y, float z, TransformSpace relativeTo=TransformSpace::Local, const Vector3 &localDirectionVector=Vector3::NEGATIVE_UNIT_Z)
Definition: WorldEntity.h:155
virtual void changedScale()
Definition: WorldEntity.h:177
const Ogre::SceneNode * getNode() const
Definition: WorldEntity.h:100
bool isPhysicsActive() const
Tells whether physics has been activated (you can temporarily deactivate it)
Definition: WorldEntity.h:282
float getLinearDamping() const
Returns the linear damping.
Definition: WorldEntity.h:349
void disableCollisionCallback()
Disables the collidesAgainst(.) function.
Definition: WorldEntity.h:424
void enableCollisionCallback()
Enables the collidesAgainst(.) function. The object doesn't respond to collision otherwise! ...
Definition: WorldEntity.h:421
void yaw(const Degree &angle, TransformSpace relativeTo=TransformSpace::Local)
Definition: WorldEntity.h:146
const Quaternion & getOrientation() const
Definition: WorldEntity.cc:627
static const Vector3 DOWN
Definition: WorldEntity.h:107
CollisionType getCollisionType() const
Returns the CollisionType.
Definition: WorldEntity.h:289
void frictionChanged()
Network callback workaround to call a function when the value changes.
Definition: WorldEntity.h:480
bool isStatic() const
Definition: WorldEntity.h:276
float getFriction() const
Returns the amount of friction applied to the object.
Definition: WorldEntity.h:363
void setPosition(float x, float y, float z)
Definition: WorldEntity.h:120
bool bPhysicsActive_
Definition: WorldEntity.h:491
bool isCollisionCallbackActive() const
Tells whether there could be a collision callback via collidesAgainst(.)
Definition: WorldEntity.h:427