Project

General

Profile

SO3Engine
SO3ShapeEllipsoid.cpp
Go to the documentation of this file.
1
12
13namespace SO3
14{
15
16SShapeEllipsoid::SShapeEllipsoid() : SShape("", SShape::SO3_NULL_COLLISION)
17{
18 // Forbiden, private.
19}
20
21SShapeEllipsoid::SShapeEllipsoid(const std::string& shapeName, SNode* node, const Ogre::Vector3& size) : SShape(shapeName, SShape::SO3_ELLIPSOID_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 mSize = Ogre::Vector3(std::max(size.x, 0.0001f), std::max(size.y, 0.0001f), std::max(size.z, 0.0001f));
30
31#ifdef USE_COLLISION_NOSCALE
32 Ogre::Vector3 scale = node->GetGlobalScale();
33 mSize = mSize * scale;
34 mComputedOffset = poffset * scale;
35 float radius = std::min(std::min(mSize.x, mSize.y), mSize.z);
36 mBaseScale = Ogre::Vector3(mSize.x / radius, mSize.y / radius, mSize.z / radius);
37#else
38 mComputedOffset = poffset;
39 float radius = std::min(std::min(mSize.x, mSize.y), mSize.z);
40 mBaseScale = Ogre::Vector3(mSize.x / radius, mSize.y / radius, mSize.z / radius);
41#endif
42
44}
45
46SShapeEllipsoid::SShapeEllipsoid(const std::string& shapeName, SNode* node, const Ogre::Vector3& size, const Ogre::Vector3& offset, const Ogre::Quaternion& quat) : SShape(shapeName, SShape::SO3_ELLIPSOID_COLLISION)
47{
48 Ogre::Vector3 poffset = Ogre::Vector3::ZERO;
49 if ((node != 0) && node->GetNodeType() == SNode::ENTITY_TYPE_ID)
50 {
51 SEntity* entity = static_cast<SEntity*> (node);
52 poffset = entity->getOgreEntityPointer()->getBoundingBox().getCenter();
53 }
54 mSize = Ogre::Vector3(std::max(size.x, 0.0001f), std::max(size.y, 0.0001f), std::max(size.z, 0.0001f));
55
56 mBaseOffset = offset;
57#ifdef USE_COLLISION_NOSCALE
58 Ogre::Vector3 scale = node->GetGlobalScale();
59 mSize = mSize * scale;
60 mComputedOffset = (poffset + offset) * scale;
61 float radius = std::min(std::min(mSize.x, mSize.y), mSize.z);
62 mBaseScale = Ogre::Vector3(mSize.x / radius, mSize.y / radius, mSize.z / radius);
63#else
64 mComputedOffset = poffset + offset;
65 float radius = std::min(std::min(mSize.x, mSize.y), mSize.z);
66 mBaseScale = Ogre::Vector3(mSize.x / radius, mSize.y / radius, mSize.z / radius);
67#endif
68 mBaseRotation = quat;
69
71}
72
76
78{
79 return mSize;
80}
81
82}
Ogre::Entity * getOgreEntityPointer()
SScene * GetParentScene()
NodeType GetNodeType()
virtual Ogre::Vector3 GetGlobalScale()
OgreNewt::World * GetPhysicWorld()
SPhysicWorld * GetPhysicsWorld()
Ogre::Vector3 mBaseScale
Definition SO3Shape.h:69
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