Project

General

Profile

SO3Engine
SO3ShapeCapsule.cpp
Go to the documentation of this file.
1
12
13namespace SO3
14{
15
16SShapeCapsule::SShapeCapsule() : SShape("", SShape::SO3_NULL_COLLISION)
17{
18 // Forbiden, private.
19}
20
21SShapeCapsule::SShapeCapsule(const std::string& shapeName, SNode* node, const Ogre::Real& radius, const Ogre::Real& height) : SShape(shapeName, SShape::SO3_CAPSULE_COLLISION)
22{
23 Ogre::Vector3 poffset = Ogre::Vector3::ZERO;
24 if ((node != 0) && node->GetNodeType() == SNode::ENTITY_TYPE_ID)
25 {
26 SEntity* entity = static_cast<SEntity*> (node);
27 poffset = entity->getOgreEntityPointer()->getBoundingBox().getCenter();
28 }
29
30#ifdef USE_COLLISION_NOSCALE
31 Ogre::Vector3 scale = node->GetGlobalScale();
32 mComputedOffset = poffset * scale;
33 mRadius = std::max(radius, 0.0001f) * scale.x;
34 mHeight = std::max(height, 0.0001f) * scale.y;
35#else
36 mComputedOffset = poffset;
37 mRadius = std::max(radius, 0.0001f);
38 mHeight = std::max(height, 0.0001f);
39#endif
40
41 mBaseRotation = Ogre::Quaternion(sqrt(0.5f), 0.0f, 0.0f, sqrt(0.5f));
43}
44
45SShapeCapsule::SShapeCapsule(const std::string& shapeName, SNode* node, const Ogre::Real& radius, const Ogre::Real& height, const Ogre::Vector3& offset, const Ogre::Quaternion& quat) : SShape(shapeName, SShape::SO3_CAPSULE_COLLISION)
46{
47 Ogre::Vector3 poffset = Ogre::Vector3::ZERO;
48 if ((node != 0) && node->GetNodeType() == SNode::ENTITY_TYPE_ID)
49 {
50 SEntity* entity = static_cast<SEntity*> (node);
51 poffset = entity->getOgreEntityPointer()->getBoundingBox().getCenter();
52 }
53
54 mBaseOffset = offset;
55#ifdef USE_COLLISION_NOSCALE
56 Ogre::Vector3 scale = node->GetGlobalScale();
57 mComputedOffset = (poffset + offset) * scale;
58 mRadius = std::max(radius, 0.0001f) * scale.x;
59 mHeight = std::max(height, 0.0001f) * scale.y;
60#else
61 mComputedOffset = poffset + offset;
62 mRadius = std::max(radius, 0.0001f);
63 mHeight = std::max(height, 0.0001f);
64#endif
65 mBaseRotation = Ogre::Quaternion(sqrt(0.5f), 0.0f, 0.0f, sqrt(0.5f)) * quat;
66
68}
69
73
75{
76 return mRadius;
77}
78
80{
81 return mHeight;
82}
83
84}
Ogre::Entity * getOgreEntityPointer()
SScene * GetParentScene()
NodeType GetNodeType()
virtual Ogre::Vector3 GetGlobalScale()
OgreNewt::World * GetPhysicWorld()
SPhysicWorld * GetPhysicsWorld()
Ogre::Vector3 mComputedOffset
Definition SO3Shape.h:70
OgreNewt::CollisionPtr mCollisionPtr
Definition SO3Shape.h:66
Ogre::Vector3 mBaseOffset
Definition SO3Shape.h:68
Ogre::Quaternion mBaseRotation
Definition SO3Shape.h:67
Manage physics shape .
Collision * CollisionPtr