00001
00008
00009 #include "../ScolPack/SO3SCOL.h"
00010 #include "SO3NodeScol.h"
00011 #include "SO3Entity.h"
00012 #include "SO3Scene.h"
00013
00014 #include "../SO3SceneGraph/SO3Bone.h"
00015 #include "../SO3Animation/SO3NodeAnimation.h"
00016
00017 #include "../SO3PhysicGraph/SO3Body.h"
00018 #include "../SO3PhysicGraph/SO3Shape.h"
00019 #include "../SO3PhysicGraph/SO3ShapeBox.h"
00020 #include "../SO3PhysicGraph/SO3ShapeCone.h"
00021 #include "../SO3PhysicGraph/SO3ShapeEllipsoid.h"
00022 #include "../SO3PhysicGraph/SO3ShapeCapsule.h"
00023 #include "../SO3PhysicGraph/SO3ShapeCylinder.h"
00024 #include "../SO3PhysicGraph/SO3ShapeChamferCylinder.h"
00025 #include "../SO3PhysicGraph/SO3ShapePyramid.h"
00026 #include "../SO3PhysicGraph/SO3ShapeConvexHull.h"
00027 #include "../SO3PhysicGraph/SO3ShapeTree.h"
00028
00029 namespace SO3
00030 {
00031
00032 SNode::SNode() : SData(""), type(SNode::NODE_TYPE_ID)
00033 {
00034
00035 }
00036
00037 SNode::SNode(SScene* parent, std::string nodeName, bool isRootNode) : SData(nodeName), currentScene(parent), type(SNode::NODE_TYPE_ID)
00038 {
00039 nodeBody = 0;
00040 ogreMovableObject = 0;
00041 isForeGround = false;
00042 isMouseClick = true;
00043 mouseFlags = SO3_OBJECT_MOUSE_ENABLE;
00044 animationCounter = 0;
00045
00046 initialPosition = Ogre::Vector3::ZERO;
00047 initialOrientation = Ogre::Quaternion::IDENTITY;
00048 initialScale = Ogre::Vector3::UNIT_SCALE;
00049 autoTrackTargetNode = 0;
00050
00051 nodeFather = 0;
00052 if (isRootNode)
00053 {
00054 O3SceneNode = currentScene->GetOgreScenePointer()->getRootSceneNode();
00055 }
00056 else
00057 {
00058 SNode* rootNode = currentScene->GetRootNode();
00059 O3SceneNode = rootNode->GetOgreSceneNodePointer()->createChildSceneNode(name);
00060 AttachToParent(rootNode);
00061 }
00062
00063
00064 #if OGRE_VERSION < ((1 << 16) | (7 << 8) | 0)
00065
00066 O3SceneNode->setUserAny(Ogre::Any(this));
00067 #else
00068
00069 O3SceneNode->getUserObjectBindings().setUserAny("SNode", Ogre::Any(this));
00070 #endif
00071 }
00072
00073 SNode::SNode(SScene* parent, std::string nodeName, NodeType nodeType) : SData(nodeName), currentScene(parent), type(nodeType)
00074 {
00075 ogreMovableObject = 0;
00076 nodeBody = 0;
00077 isForeGround = false;
00078 isMouseClick = true;
00079 mouseFlags = SO3_OBJECT_MOUSE_ENABLE;
00080
00081 initialPosition = Ogre::Vector3::ZERO;
00082 initialOrientation = Ogre::Quaternion::IDENTITY;
00083 initialScale = Ogre::Vector3::UNIT_SCALE;
00084 autoTrackTargetNode = 0;
00085 animationCounter = 0;
00086
00087 nodeFather = 0;
00088
00089 if (type == SKELETON_TYPE_ID)
00090 {
00091 O3SceneNode = 0;
00092 }
00093 else
00094 {
00095 SNode* rootNode = currentScene->GetRootNode();
00096 O3SceneNode = rootNode->GetOgreSceneNodePointer()->createChildSceneNode(name);
00097 AttachToParent(rootNode);
00098
00099
00100 #if OGRE_VERSION < ((1 << 16) | (7 << 8) | 0)
00101
00102 O3SceneNode->setUserAny(Ogre::Any(this));
00103 #else
00104
00105 O3SceneNode->getUserObjectBindings().setUserAny("SNode", Ogre::Any(this));
00106 #endif
00107 }
00108 }
00109
00110 SNode::~SNode()
00111 {
00112
00113 DetachFromParent();
00114
00115
00116
00117 SNodeMap childNodeListCopy = childNodeList;
00118 SNodeMap::iterator iChildNodeListCopy = childNodeListCopy.begin();
00119 while (iChildNodeListCopy != childNodeListCopy.end())
00120 {
00121 iChildNodeListCopy->second->DetachFromParent();
00122 iChildNodeListCopy++;
00123 }
00124
00125
00126 SAnimMap animationListCopy = GetAnimations();
00127 SAnimMap::iterator iAnimation = animationListCopy.begin();
00128 while(iAnimation != animationListCopy.end())
00129 {
00130 DeleteAnimation(iAnimation->second);
00131 iAnimation++;
00132 }
00133
00134 if (O3SceneNode)
00135 {
00136 SetAutoTracking(false);
00137
00138
00139 if (this != currentScene->GetRootNode())
00140 {
00141 currentScene->GetOgreScenePointer()->destroySceneNode(O3SceneNode);
00142 O3SceneNode = 0;
00143 }
00144 }
00145
00146
00147
00148 }
00149
00150 Ogre::SceneNode* SNode::GetOgreSceneNodePointer()
00151 {
00152 return O3SceneNode;
00153 }
00154
00155 Ogre::MovableObject* SNode::GetMovableObjectPointer()
00156 {
00157 return ogreMovableObject;
00158 }
00159
00160 bool SNode::getSceneNodeIsMouseForeground()
00161 {
00162 return this->isForeGround;
00163 }
00164
00165 void SNode::setSceneNodeIsMouseForeground(bool mForeground)
00166 {
00167 isForeGround = mForeground;
00168 }
00169
00170 bool SNode::getSceneNodeIsMouseClick()
00171 {
00172 return isMouseClick;
00173 }
00174
00175 void SNode::setSceneNodeIsMouseClick(bool mClickable)
00176 {
00177 isMouseClick = mClickable;
00178 }
00179
00180 int SNode::getSceneNodeMouseFlags()
00181 {
00182 return mouseFlags;
00183 }
00184
00185 void SNode::setSceneNodeMouseFlags(int flags)
00186 {
00187 mouseFlags = flags;
00188 }
00189
00190 bool SNode::getSceneNodeHasBody()
00191 {
00192 return nodeBody != 0;
00193 }
00194
00195 SBody* SNode::getSceneNodeBody()
00196 {
00197 return nodeBody;
00198 }
00199
00200
00201 void SNode::UpdateNodeBody(bool bScale)
00202 {
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 if(nodeBody!=NULL)
00213 nodeBody->UpdatePositionOrientation();
00214
00215
00216
00217
00218
00219
00220 SNodeMap::iterator iNodeChildList = childNodeList.begin();
00221 while (iNodeChildList != childNodeList.end())
00222 {
00223 iNodeChildList->second->UpdateNodeBody(bScale);
00224 iNodeChildList++;
00225 }
00226
00227 }
00228
00229 void SNode::disableAutoTarget()
00230 {
00231 SNodeMap::const_iterator iNodeList = currentScene->GetNodeList().begin();
00232 while (iNodeList != currentScene->GetNodeList().end())
00233 {
00234 SNode* currentNode = iNodeList->second;
00235 if(currentScene->O3SceneManager->hasSceneNode(currentNode->name))
00236 {
00237
00238 SNode* target = currentNode->GetAutoTrackingTarget();
00239 if(target)
00240 {
00241 if(target->GetName() == currentNode->GetName())
00242 {
00243 currentNode->SetAutoTracking(false);
00244 }
00245 }
00246 }
00247 iNodeList++;
00248 }
00249 }
00250
00251 SScene* SNode::GetParentScene()
00252 {
00253 return currentScene;
00254 }
00255
00256 SNode::NodeType SNode::GetNodeType()
00257 {
00258 return type;
00259 }
00260
00261 void SNode::AttachToParent(SNode* newParentNode)
00262 {
00263 DetachFromParent();
00264
00265 if (nodeFather != 0)
00266 {
00267 if (nodeFather->GetNodeType() == SNode::BONE_TYPE_ID)
00268 {
00269 SBone* boneFather = static_cast <SBone*> (nodeFather);
00270 boneFather->AttachToBone(this);
00271 }
00272 }
00273
00274 newParentNode->AddChildNode(this);
00275 nodeFather = newParentNode;
00276
00277 UpdateNodeBody(false);
00278 }
00279
00280 void SNode::DetachFromParent()
00281 {
00282 if (nodeFather != 0)
00283 {
00284 if (nodeFather->GetNodeType() == SNode::BONE_TYPE_ID)
00285 {
00286 SBone* boneFather = static_cast <SBone*> (nodeFather);
00287 boneFather->DetachFromBone(this);
00288 }
00289
00290 nodeFather->RemoveChildNode(this);
00291 nodeFather = 0;
00292 }
00293 }
00294
00295 SNode* SNode::GetParentSceneNode()
00296 {
00297 return nodeFather;
00298 }
00299
00300 const SNodeMap SNode::GetChildrenNodes() const
00301 {
00302 return childNodeList;
00303 }
00304
00305 int SNode::GetNumChildren()
00306 {
00307 return O3SceneNode->numChildren();
00308 }
00309
00310 void SNode::DetachAllChildren()
00311 {
00312 const SNodeMap childNodeListCopy = childNodeList;
00313 SNodeMap::const_iterator iChildNodeList = childNodeListCopy.begin();
00314 while (iChildNodeList != childNodeListCopy.end())
00315 {
00316 iChildNodeList->second->DetachFromParent();
00317 iChildNodeList++;
00318 }
00319 }
00320
00321 void SNode::AddChildNode(SNode* newChild)
00322 {
00323 string nodeName = newChild->GetName();
00324 SNodeMap::iterator iNodeSearched = childNodeList.find(nodeName);
00325 if (iNodeSearched == childNodeList.end())
00326 {
00327 Ogre::SceneNode* ogreNewChild = newChild->GetOgreSceneNodePointer();
00328 if (ogreNewChild->getParentSceneNode() != O3SceneNode)
00329 O3SceneNode->addChild(ogreNewChild);
00330
00331 childNodeList.insert(SNodeMap::value_type(nodeName, newChild));
00332 }
00333 else
00334 {
00335
00336 OGRE_EXCEPT(Ogre::Exception::ERR_DUPLICATE_ITEM, "Can not add node named \""+ nodeName +"\", an element with the same name already exist!", "SNode::AddChildNode");
00337 }
00338 }
00339
00340 void SNode::RemoveChildNode(SNode* existingChild)
00341 {
00342 string nodeName = existingChild->GetName();
00343 SNodeMap::iterator iNodeSearched = childNodeList.find(nodeName);
00344 if (iNodeSearched != childNodeList.end())
00345 {
00346
00347 if (O3SceneNode != 0)
00348 O3SceneNode->removeChild(existingChild->GetOgreSceneNodePointer());
00349
00350 childNodeList.erase(iNodeSearched);
00351 }
00352 else
00353 {
00354
00355 OGRE_EXCEPT(Ogre::Exception::ERR_ITEM_NOT_FOUND, "Can not remove Node named \""+ nodeName +"\", element not found!", "SNode::RemoveChildNode");
00356 }
00357 }
00358
00359 void SNode::SetCastShadows(bool castShadows)
00360 {
00361 OGRE_EXCEPT(Ogre::Exception::ERR_NOT_IMPLEMENTED, "This SNode object do not manage Shadow Casting!", "SNode::SetCastShadows");
00362 }
00363
00364 bool SNode::GetCastShadows()
00365 {
00366 OGRE_EXCEPT(Ogre::Exception::ERR_NOT_IMPLEMENTED, "This SNode object do not manage Shadow Casting!", "SNode::GetCastShadows");
00367 return false;
00368 }
00369
00370 void SNode::SetRenderingDistance(float distance)
00371 {
00372 OGRE_EXCEPT(Ogre::Exception::ERR_NOT_IMPLEMENTED, "This SNode object do not manage Rendering distance!", "SNode::SetRenderingDistance");
00373 }
00374
00375 float SNode::GetRenderingDistance()
00376 {
00377 OGRE_EXCEPT(Ogre::Exception::ERR_NOT_IMPLEMENTED, "This SNode object do not manage Rendering distance!", "SNode::GetRenderingDistance");
00378 return 0.0;
00379 }
00380
00381 Ogre::Vector3 SNode::GetBoundingBoxSize(bool childs)
00382 {
00383 if (childs)
00384 return GetSonsBoundingBox();
00385
00386 throw std::logic_error("SNode::GetBoundingBoxSize : This SNode object do not manage any bounding box!");
00387 return Ogre::Vector3::ZERO;
00388 }
00389
00390 Ogre::Vector3 SNode::GetBoundingBoxCenter(bool childs)
00391 {
00392 throw std::logic_error("SNode::GetBoundingBoxSize : This SNode object do not manage any bounding box!");
00393 return Ogre::Vector3::ZERO;
00394 }
00395
00396 Ogre::Vector3 SNode::GetSonsBoundingBox()
00397 {
00398 Ogre::Vector3 bbox(Ogre::Vector3::ZERO);
00399 try
00400 {
00401 bbox = GetBoundingBoxSize();
00402 }
00403 catch (std::exception)
00404 {
00405 bbox = Ogre::Vector3::ZERO;
00406 }
00407
00408 Ogre::Vector3 tbox(Ogre::Vector3::ZERO);
00409
00410 SNodeMap::iterator iChildNodeList = childNodeList.begin();
00411 while (iChildNodeList != childNodeList.end())
00412 {
00413 tbox = iChildNodeList->second->GetSonsBoundingBox();
00414 if (tbox.x > bbox.x)
00415 bbox.x = tbox.x;
00416 if (tbox.y > bbox.y)
00417 bbox.y = tbox.y;
00418 if (tbox.z > bbox.z)
00419 bbox.z = tbox.z;
00420
00421 iChildNodeList++;
00422 }
00423
00424 return bbox;
00425 }
00426
00427 Ogre::Matrix4 SNode::GetTransformationMatrix()
00428 {
00429 return O3SceneNode->_getFullTransform();
00430 }
00431
00432 Ogre::Vector3 SNode::GetPosition()
00433 {
00434 return O3SceneNode->getPosition();
00435 }
00436
00437 void SNode::SetPosition(Ogre::Vector3 pos)
00438 {
00439 if (nodeFather->GetNodeType()==SNode::BONE_TYPE_ID)
00440 {
00441 if (ogreMovableObject != 0)
00442 {
00443 SBone* boneFather = static_cast <SBone*> (nodeFather);
00444 boneFather->DetachFromBone(this);
00445 boneFather->GetOgreSceneNodePointer()->setPosition(pos);
00446 boneFather->AttachToBone(this);
00447 }
00448 }
00449 else
00450 {
00451 O3SceneNode->setPosition(pos);
00452 UpdateNodeBody(false);
00453 }
00454 }
00455
00456 Ogre::Quaternion SNode::GetOrientation()
00457 {
00458 return O3SceneNode->getOrientation();
00459 }
00460
00461 void SNode::SetOrientation(Ogre::Quaternion quat)
00462 {
00463 if (nodeFather->GetNodeType()==SNode::BONE_TYPE_ID)
00464 {
00465 if (ogreMovableObject != 0)
00466 {
00467 SBone* boneFather = static_cast <SBone*> (nodeFather);
00468 boneFather->DetachFromBone(this);
00469 boneFather->GetOgreSceneNodePointer()->setOrientation(quat);
00470 boneFather->AttachToBone(this);
00471 }
00472 }
00473 else
00474 {
00475 O3SceneNode->setOrientation(quat);
00476 UpdateNodeBody(false);
00477 }
00478 }
00479
00480 void SNode::AddOrientation(Ogre::Quaternion quat)
00481 {
00482 quat.normalise();
00483
00484 if (quat != Ogre::Quaternion::ZERO)
00485 {
00486 Ogre::Quaternion oldQuat = GetOrientation();
00487 Ogre::Quaternion resultQuat = oldQuat * quat;
00488
00489 SetOrientation(resultQuat);
00490 }
00491 }
00492
00493 Ogre::Vector3 SNode::GetScale()
00494 {
00495 return O3SceneNode->getScale();
00496 }
00497
00498 void SNode::SetScale(Ogre::Vector3 scale)
00499 {
00500 O3SceneNode->setScale(scale);
00501 UpdateNodeBody(false);
00502 }
00503
00504 Ogre::Vector3 SNode::GetGlobalPosition()
00505 {
00506 O3SceneNode->_update(false, true);
00507 return O3SceneNode->_getDerivedPosition();
00508 }
00509
00510 void SNode::SetGlobalPosition(Ogre::Vector3 pos)
00511 {
00512 if (nodeFather->GetNodeType()==SNode::BONE_TYPE_ID)
00513 {
00514 if (ogreMovableObject != 0)
00515 {
00516 SBone* boneFather = static_cast <SBone*> (nodeFather);
00517 boneFather->DetachFromBone(this);
00518 boneFather->GetParentSceneNode()->GetOgreSceneNodePointer()->setPosition(boneFather->GetParentSceneNode()->GetGlobalOrientation().Inverse() * (pos - boneFather->GetParentSceneNode()->GetGlobalPosition() / boneFather->GetParentSceneNode()->GetGlobalScale()));
00519 boneFather->AttachToBone(this);
00520 }
00521 }
00522 else
00523 {
00524 Ogre::Node* m_nodeParent = O3SceneNode->getParent();
00525 if (m_nodeParent)
00526 O3SceneNode->setPosition((m_nodeParent->_getDerivedOrientation().Inverse() * (pos - m_nodeParent->_getDerivedPosition()) / m_nodeParent->_getDerivedScale()));
00527 else
00528 O3SceneNode->setPosition(pos);
00529 UpdateNodeBody(false);
00530 }
00531 }
00532
00533 Ogre::Quaternion SNode::GetGlobalOrientation()
00534 {
00535 O3SceneNode->_update(false, true);
00536 return O3SceneNode->_getDerivedOrientation();
00537 }
00538
00539 void SNode::SetGlobalOrientation(Ogre::Quaternion quat)
00540 {
00541 if (nodeFather->GetNodeType()==SNode::BONE_TYPE_ID)
00542 {
00543 if (ogreMovableObject != 0)
00544 {
00545 SBone* boneFather = static_cast <SBone*> (nodeFather);
00546 boneFather->DetachFromBone(this);
00547 boneFather->GetParentSceneNode()->GetOgreSceneNodePointer()->setOrientation(boneFather->GetParentSceneNode()->GetGlobalOrientation().Inverse() * quat);
00548 boneFather->AttachToBone(this);
00549 }
00550 }
00551 else
00552 {
00553 Ogre::Node* m_nodeParent = O3SceneNode->getParent();
00554 if (m_nodeParent)
00555 O3SceneNode->setOrientation((m_nodeParent->_getDerivedOrientation()).Inverse() * quat);
00556 else
00557 O3SceneNode->setOrientation(quat);
00558 UpdateNodeBody(false);
00559 }
00560 }
00561
00562 Ogre::Vector3 SNode::GetGlobalScale()
00563 {
00564 O3SceneNode->_update(false, true);
00565 return O3SceneNode->_getDerivedScale();
00566 }
00567
00568 void SNode::SetGlobalScale(Ogre::Vector3 scale)
00569 {
00570 Ogre::Node* m_nodeParent = O3SceneNode->getParent();
00571 if (m_nodeParent)
00572 O3SceneNode->setScale(scale / m_nodeParent->_getDerivedScale());
00573 else
00574 O3SceneNode->setScale(scale);
00575 UpdateNodeBody(false);
00576 }
00577
00578 bool SNode::GetShowBoundingBox()
00579 {
00580 return O3SceneNode->getShowBoundingBox();
00581 }
00582
00583 void SNode::SetShowBoundingBox(bool showBounding)
00584 {
00585 O3SceneNode->showBoundingBox(showBounding);
00586 }
00587
00588 void SNode::SetAutoTracking(bool autoTrack, SNode* targetNode, Ogre::Vector3 localDirectionVector, Ogre::Vector3 offset)
00589 {
00590 autoTrackTargetNode = targetNode;
00591
00592 if (autoTrackTargetNode != 0)
00593 O3SceneNode->setAutoTracking(autoTrack, targetNode->GetOgreSceneNodePointer());
00594 else
00595 O3SceneNode->setAutoTracking(autoTrack);
00596 }
00597
00598 SNode* SNode::GetAutoTrackingTarget()
00599 {
00600 return autoTrackTargetNode;
00601 }
00602
00603 void SNode::Pitch(float radianAngle, SNode::NodeTransformSpace relativeTo)
00604 {
00605 O3SceneNode->pitch(Ogre::Radian(radianAngle), static_cast <Ogre::Node::TransformSpace> (static_cast<int>(relativeTo)));
00606 UpdateNodeBody(false);
00607 }
00608
00609 void SNode::Yaw(float radianAngle, SNode::NodeTransformSpace relativeTo)
00610 {
00611 O3SceneNode->yaw(Ogre::Radian(radianAngle), static_cast <Ogre::Node::TransformSpace> (static_cast<int>(relativeTo)));
00612 UpdateNodeBody(false);
00613 }
00614
00615 void SNode::Roll(float radianAngle, SNode::NodeTransformSpace relativeTo)
00616 {
00617 O3SceneNode->roll(Ogre::Radian(radianAngle), static_cast <Ogre::Node::TransformSpace> (static_cast<int>(relativeTo)));
00618 UpdateNodeBody(false);
00619 }
00620
00621 void SNode::Rotate(Ogre::Vector3 axis, float radianAngle, SNode::NodeTransformSpace relativeTo)
00622 {
00623 O3SceneNode->rotate(axis, Ogre::Radian(radianAngle), static_cast <Ogre::Node::TransformSpace> (static_cast<int>(relativeTo)));
00624 UpdateNodeBody(false);
00625 }
00626
00627 void SNode::Translate(Ogre::Vector3 d, SNode::NodeTransformSpace relativeTo)
00628 {
00629 O3SceneNode->translate(d, static_cast <Ogre::Node::TransformSpace> (static_cast<int>(relativeTo)));
00630 UpdateNodeBody(false);
00631 }
00632
00633 void SNode::SetDirection(Ogre::Vector3 vec, SNode::NodeTransformSpace relativeTo, Ogre::Vector3 localDirectionVector)
00634 {
00635 O3SceneNode->setDirection(vec, static_cast <Ogre::Node::TransformSpace> (static_cast<int>(relativeTo)), localDirectionVector);
00636 UpdateNodeBody(false);
00637 }
00638
00639 void SNode::LookAt(Ogre::Vector3 targetPoint, SNode::NodeTransformSpace relativeTo, Ogre::Vector3 localDirectionVector)
00640 {
00641 O3SceneNode->lookAt(targetPoint, static_cast <Ogre::Node::TransformSpace> (static_cast<int>(relativeTo)), localDirectionVector);
00642 UpdateNodeBody(false);
00643 }
00644
00645 bool SNode::GetVisible()
00646 {
00647 bool result = false ;
00648 if(O3SceneNode->numAttachedObjects() != 0)
00649 result = O3SceneNode->getAttachedObject(0)->isVisible();
00650
00651 return result;
00652 }
00653
00654 void SNode::SetVisible(bool visible, bool cascade)
00655 {
00656 O3SceneNode->setVisible(visible, cascade);
00657 }
00658
00659 void SNode::StoreInitialPRS()
00660 {
00661 O3SceneNode->_update(false, true);
00662 initialPosition = O3SceneNode->_getDerivedPosition();
00663 initialOrientation = O3SceneNode->_getDerivedOrientation();
00664 initialScale = O3SceneNode->_getDerivedScale();
00665 }
00666
00667 void SNode::ResetToInitialPRS()
00668 {
00669 O3SceneNode->_setDerivedPosition(initialPosition);
00670 O3SceneNode->_setDerivedOrientation(initialOrientation);
00671 SetGlobalScale(initialScale);
00672 }
00673
00674 void SNode::ResetToInitialPosition()
00675 {
00676
00677 OGRE_EXCEPT(Ogre::Exception::ERR_NOT_IMPLEMENTED, "Not implemented in Ogre 1.6!", "SNode::ResetToInitialPosition");
00678 }
00679
00680 void SNode::ResetToInitialOrientation()
00681 {
00682 O3SceneNode->resetOrientation();
00683 }
00684
00685 void SNode::ResetToInitialScale()
00686 {
00687
00688 OGRE_EXCEPT(Ogre::Exception::ERR_NOT_IMPLEMENTED, "Not implemented in Ogre 1.6!", "SNode::ResetToInitialScale");
00689 }
00690
00691 Ogre::Vector3 SNode::GetInitialPosition()
00692 {
00693 return O3SceneNode->getInitialPosition();
00694 }
00695
00696 Ogre::Quaternion SNode::GetInitialOrientation()
00697 {
00698 return O3SceneNode->getInitialOrientation();
00699 }
00700
00701 Ogre::Vector3 SNode::GetInitialScale()
00702 {
00703 return O3SceneNode->getInitialScale();
00704 }
00705
00706 SNodeAnimation* SNode::CreateNodeAnimation(std::string animationName, float animationLength)
00707 {
00708 SNodeAnimation* animation = new SNodeAnimation(GetParentScene(), animationName, this, animationCounter++, animationLength);
00709 AddAnimation(animation);
00710 return animation;
00711 }
00712
00713 void SNode::DeleteAnimation(SAnim* existingAnimation)
00714 {
00715
00716 assert(existingAnimation != 0);
00717 if(GetAnimation(existingAnimation->GetName()) != existingAnimation)
00718 OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS, "Cannot destroy an animation that is not handled by this node", "SNode::DeleteAnimation");
00719
00720 RemoveAnimation(existingAnimation);
00721 SAFE_DELETE(existingAnimation);
00722 }
00723
00724 unsigned short SNode::GetNumAnimations()
00725 {
00726 return animationList.size();
00727 }
00728
00729 SAnim* SNode::GetAnimation(std::string animationName)
00730 {
00731 SAnimMap::iterator iAnimationSearched = animationList.find(animationName);
00732 if (iAnimationSearched != animationList.end())
00733 return iAnimationSearched->second;
00734 else
00735 return 0;
00736 }
00737
00738 SAnim* SNode::GetAnimation(unsigned short animationIndex)
00739 {
00740 SAnimIndexMap::iterator iAnimationSearched = animationListByIndex.find(animationIndex);
00741 if (iAnimationSearched != animationListByIndex.end())
00742 return iAnimationSearched->second;
00743 else
00744 return 0;
00745 }
00746
00747 SAnimMap SNode::GetAnimations() const
00748 {
00749 return animationList;
00750 }
00751
00752 void SNode::AddAnimation(SAnim* existingAnimation)
00753 {
00754 string animationName = existingAnimation->GetName();
00755 SAnimMap::iterator iAnimationSearched = animationList.find(animationName);
00756 if (iAnimationSearched == animationList.end())
00757 {
00758 animationList.insert(SAnimMap::value_type(animationName, existingAnimation));
00759 animationListByIndex.insert(SAnimIndexMap::value_type(existingAnimation->GetIndex(), existingAnimation));
00760 }
00761 else
00762 {
00763
00764 OGRE_EXCEPT(Ogre::Exception::ERR_DUPLICATE_ITEM, "Can not add animation named \""+ animationName +"\", an element with the same name already exist!", "SNode::AddAnimation");
00765 }
00766
00767
00768
00769 }
00770
00771 void SNode::RemoveAnimation(SAnim* existingAnimation)
00772 {
00773 RemoveAnimation(existingAnimation->GetName());
00774
00775 }
00776
00777 void SNode::RemoveAnimation(std::string animationName)
00778 {
00779 SAnimMap::iterator iAnimationSearched = animationList.find(animationName);
00780 if (iAnimationSearched != animationList.end())
00781 {
00782 SAnim* findedAnimation = iAnimationSearched->second;
00783 animationList.erase(iAnimationSearched);
00784
00785
00786 SAnimIndexMap::iterator iAnimationIndexSearched = animationListByIndex.find(findedAnimation->GetIndex());
00787 animationListByIndex.erase(iAnimationIndexSearched);
00788 }
00789 else
00790 {
00791
00792 OGRE_EXCEPT(Ogre::Exception::ERR_ITEM_NOT_FOUND, "Can not remove Animation named \""+ animationName +"\", element not found!", "SNode::RemoveAnimation");
00793 }
00794 }
00795
00796 Ogre::Vector3 SNode::GetPositionFromNode(SNode* nodeRef)
00797 {
00798 Ogre::Matrix4 mat;
00799
00800 O3SceneNode->_update(true, true);
00801 mat = nodeRef->GetTransformationMatrix().inverse() * GetTransformationMatrix();
00802
00803 return mat.getTrans();
00804 }
00805
00806 Ogre::Quaternion SNode::GetOrientationFromNode(SNode* nodeRef)
00807 {
00808 Ogre::Matrix4 mat;
00809
00810 O3SceneNode->_update(true, true);
00811 mat = nodeRef->GetTransformationMatrix().inverse() * GetTransformationMatrix();
00812
00813 return mat.extractQuaternion();
00814 }
00815
00816 Ogre::Vector3 SNode::GetScaleFromNode(SNode* nodeRef)
00817 {
00818 Ogre::Vector3 scaleParent;
00819 Ogre::Vector3 scaleResult(1.0,1.0,1.0);
00820
00821 scaleParent = nodeRef->GetGlobalScale();
00822
00823 if(scaleParent.x != 0.0 && scaleParent.y != 0.0 && scaleParent.z != 0.0)
00824 scaleResult = GetGlobalScale() / scaleParent;
00825
00826 return scaleResult;
00827 }
00828
00829 void SNode::SetInheritOrientation(bool state)
00830 {
00831 O3SceneNode->setInheritOrientation(state);
00832 }
00833
00834 bool SNode::GetInheritOrientation()
00835 {
00836 return O3SceneNode->getInheritOrientation();
00837 }
00838
00839 void SNode::ResetOrientation()
00840 {
00841 O3SceneNode->resetOrientation();
00842 }
00843
00844 void SNode::DeleteBody()
00845 {
00846 SAFE_DELETE(nodeBody);
00847 }
00848
00849 SBody* SNode::CreateBoxBody(Ogre::Vector3 size)
00850 {
00851 SShapeBox* shape = new SShapeBox(GetName() + "body_box", this, size);
00852 SBody* body = new SBody(this, shape);
00853 nodeBody = body;
00854 StoreInitialPRS();
00855
00856 return nodeBody;
00857 }
00858
00859 SBody* SNode::CreateConeBody(Ogre::Real radius, Ogre::Real height)
00860 {
00861 SShapeCone* shape = new SShapeCone(GetName() + "body_cone", this, radius, height);
00862 SBody* body = new SBody(this, shape);
00863 nodeBody = body;
00864 StoreInitialPRS();
00865
00866 return nodeBody;
00867 }
00868
00869 SBody* SNode::CreateEllipsoidBody(Ogre::Vector3 size)
00870 {
00871 SShapeEllipsoid* shape = new SShapeEllipsoid(GetName() + "body_ellipsoid", this, size);
00872 SBody* body = new SBody(this, shape);
00873 nodeBody = body;
00874 StoreInitialPRS();
00875
00876 return nodeBody;
00877 }
00878
00879 SBody* SNode::CreateCapsuleBody(Ogre::Real radius, Ogre::Real height)
00880 {
00881 SShapeCapsule* shape = new SShapeCapsule(GetName() + "body_capsule", this, radius, height);
00882 SBody* body = new SBody(this, shape);
00883 nodeBody = body;
00884 StoreInitialPRS();
00885
00886 return nodeBody;
00887 }
00888
00889 SBody* SNode::CreateCylinderBody(Ogre::Real radius, Ogre::Real height)
00890 {
00891 SShapeCylinder* shape = new SShapeCylinder(GetName() + "body_cylinder", this, radius, height);
00892 SBody* body = new SBody(this, shape);
00893 nodeBody = body;
00894 StoreInitialPRS();
00895
00896 return nodeBody;
00897 }
00898
00899 SBody* SNode::CreateChamferCylinderBody(Ogre::Real radius, Ogre::Real height)
00900 {
00901 SShapeChamferCylinder* shape = new SShapeChamferCylinder(GetName() + "body_chamfercylinder", this, radius, height);
00902 SBody* body = new SBody(this, shape);
00903 nodeBody = body;
00904 StoreInitialPRS();
00905
00906 return nodeBody;
00907 }
00908
00909 SBody* SNode::CreatePyramidBody(Ogre::Vector3 size)
00910 {
00911 SShapePyramid* shape = new SShapePyramid(GetName() + "body_pyramid", this, size);
00912 SBody* body = new SBody(this, shape);
00913 nodeBody = body;
00914 StoreInitialPRS();
00915
00916 return nodeBody;
00917 }
00918
00919 SBody* SNode::CreateConvexHullBody(Ogre::Real tolerance)
00920 {
00921 if (GetNodeType() == SNode::ENTITY_TYPE_ID)
00922 {
00923 SEntity* entity = static_cast<SEntity*> (this);
00924
00925
00926 Ogre::Vector3 convexTest = entity->GetBoundingBoxSize();
00927 if ((convexTest.x == 0.0f) || (convexTest.y == 0.0f) || (convexTest.z == 0.0f))
00928 return 0;
00929
00930 SShapeConvexHull* shape = 0;
00931
00932 shape = new SShapeConvexHull(GetName() + "body_convex", entity, tolerance);
00933
00934 SBody* body = new SBody(this, shape);
00935 nodeBody = body;
00936 StoreInitialPRS();
00937
00938 return nodeBody;
00939 }
00940
00941 return 0;
00942 }
00943
00944 SBody* SNode::CreateTreeBody(bool optimize)
00945 {
00946 if (GetNodeType() == SNode::ENTITY_TYPE_ID)
00947 {
00948 SEntity* entity = static_cast<SEntity*> (this);
00949 SShapeTree* shape = new SShapeTree(GetName() + "body_tree", entity, optimize);
00950 SBody* body = new SBody(this, shape);
00951 nodeBody = body;
00952 StoreInitialPRS();
00953
00954 return nodeBody;
00955 }
00956
00957 return 0;
00958 }
00959
00960 }