Project

General

Profile

SO3Engine
SO3ShapeCylinder.cpp
Go to the documentation of this file.
1
12
13namespace SO3
14{
15
16SShapeCylinder::SShapeCylinder() : SShape("", SShape::SO3_NULL_COLLISION)
17{
18 // Forbiden, private.
19}
20
21SShapeCylinder::SShapeCylinder(const std::string& shapeName, SNode* node, const Ogre::Real& radius, const Ogre::Real& height) : SShape(shapeName, SShape::SO3_CYLINDER_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#ifdef USE_COLLISION_NOSCALE
30 Ogre::Vector3 scale = node->GetGlobalScale();
31 mComputedOffset = poffset * scale;
32 mRadius = std::max(radius, 0.0001f) * scale.x;
33 mHeight = std::max(height, 0.0001f) * scale.y;
34#else
35 mComputedOffset = poffset;
36 mRadius = std::max(radius, 0.0001f);
37 mHeight = std::max(height, 0.0001f);
38#endif
39
40 mBaseRotation = Ogre::Quaternion(sqrt(0.5f), 0.0f, 0.0f, sqrt(0.5f));
42}
43
44SShapeCylinder::SShapeCylinder(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_CYLINDER_COLLISION)
45{
46 Ogre::Vector3 poffset = Ogre::Vector3::ZERO;
47 if ((node != 0) && node->GetNodeType() == SNode::ENTITY_TYPE_ID)
48 {
49 SEntity* entity = static_cast<SEntity*> (node);
50 poffset = entity->getOgreEntityPointer()->getBoundingBox().getCenter();
51 }
52
53 mBaseOffset = offset;
54#ifdef USE_COLLISION_NOSCALE
55 Ogre::Vector3 scale = node->GetGlobalScale();
56 mComputedOffset = (poffset + offset) * scale;
57 mRadius = std::max(radius, 0.0001f) * scale.x;
58 mHeight = std::max(height, 0.0001f) * scale.y;
59#else
60 mComputedOffset = poffset + offset;
61 mRadius = std::max(radius, 0.0001f);
62 mHeight = std::max(height, 0.0001f);
63#endif
64
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