SO3Engine
SO3NodeScol.cpp
Go to the documentation of this file.
1
8// using scolSDK
28
29namespace SO3
30{
31
32SNode::SNode() : SData(""), type(SNode::NODE_TYPE_ID)
33{
34 // Forbiden (private)
35}
36
37SNode::SNode(SScene* parent, const std::string& nodeName, const bool& isRootNode) : SData(nodeName), currentScene(parent), type(SNode::NODE_TYPE_ID)
38{
39 nodeBody = 0;
40 staticGeometry = 0;
42 staticVisibility = true;
43 isForeGround = false;
44 isMouseClick = true;
45 mIsDirty = true;
46 mouseFlags = SO3_OBJECT_MOUSE_ENABLE;
47 mFlags = 0;
49 mPhysicsOverride = false;
50 mVisible = true;
51
52 initialPosition = Ogre::Vector3::ZERO;
53 initialOrientation = Ogre::Quaternion::IDENTITY;
54 initialScale = Ogre::Vector3::UNIT_SCALE;
55 autoTrackTargetNode = 0;
56
57 nodeFather = 0;
58 if (isRootNode)
59 {
60 O3SceneNode = currentScene->GetOgreScenePointer()->getRootSceneNode();
61 }
62 else
63 {
64 SNode* rootNode = currentScene->GetRootNode();
65 O3SceneNode = currentScene->GetOgreScenePointer()->createSceneNode(name);
66 AttachToParent(rootNode);
67 }
68
69// If our ogre is anterior to v1.7
70#if OGRE_VERSION < ((1 << 16) | (7 << 8) | 0)
71 // Bind our instance to Ogre::SceneNode.
72 O3SceneNode->setUserAny(Ogre::Any(this));
73#else
74 // Bind our instance to Ogre::SceneNode.
75 O3SceneNode->getUserObjectBindings().setUserAny("SNode", Ogre::Any(this));
76#endif
77}
78
79SNode::SNode(SScene* parent, const std::string& nodeName, const NodeType& nodeType) : SData(nodeName), currentScene(parent), type(nodeType)
80{
82 staticGeometry = 0;
83 nodeBody = 0;
84 staticVisibility = true;
85 isForeGround = false;
86 isMouseClick = true;
87 mouseFlags = SO3_OBJECT_MOUSE_ENABLE;
88 mFlags = 0;
89 mVisible = true;
90
91 initialPosition = Ogre::Vector3::ZERO;
92 initialOrientation = Ogre::Quaternion::IDENTITY;
93 initialScale = Ogre::Vector3::UNIT_SCALE;
94 autoTrackTargetNode = 0;
96
97 nodeFather = 0;
98 // Hack
99 if (type == SKELETON_TYPE_ID)
100 {
101 O3SceneNode = 0;
102 }
103 else
104 {
105 SNode* rootNode = currentScene->GetRootNode();
106 O3SceneNode = currentScene->GetOgreScenePointer()->createSceneNode(name);
107 AttachToParent(rootNode);
108
109 // If our ogre is anterior to v1.7
110 #if OGRE_VERSION < ((1 << 16) | (7 << 8) | 0)
111 // Bind our instance to Ogre::SceneNode.
112 O3SceneNode->setUserAny(Ogre::Any(this));
113 #else
114 // Bind our instance to Ogre::SceneNode.
115 O3SceneNode->getUserObjectBindings().setUserAny("SNode", Ogre::Any(this));
116 #endif
117 }
118}
119
121{
122 SetAsStaticGeometry(false);
123
124 // detach from parent.
126
127 // detach all children nodes before deleting this.
128 // sons are destroyed with Scol object callback
129 SNodeMap childNodeListCopy = childNodeList;
130 SNodeMap::iterator iChildNodeListCopy = childNodeListCopy.begin();
131 while (iChildNodeListCopy != childNodeListCopy.end())
132 {
133 iChildNodeListCopy->second->DetachFromParent();
134 iChildNodeListCopy++;
135 }
136
137 // Erase all anims
138 const SAnimMap animationListCopy = GetAnimations();
139 SAnimMap::const_iterator iAnimation = animationListCopy.begin();
140 while(iAnimation != animationListCopy.end())
141 {
142 DeleteAnimation(iAnimation->second);
143 iAnimation++;
144 }
145
146 if (O3SceneNode)
147 {
148 SetAutoTracking(false); // Suppress autotracking to avoid crash
149
150 // Do not destroy scene root node!!!
151 if (this != currentScene->GetRootNode())
152 {
153 currentScene->GetOgreScenePointer()->destroySceneNode(O3SceneNode);
154 O3SceneNode = 0;
155 }
156 }
157
158 //must be destroy by scol
159 assert(nodeBody == 0);
160 nodeBody = 0;
161}
162
164{
165 return O3SceneNode;
166}
167
168Ogre::MovableObject* SNode::GetMovableObjectPointer()
169{
170 return ogreMovableObject;
171}
172
173void SNode::SetFlags(const int& flags)
174{
175 mFlags = flags;
176}
177
179{
180 return mFlags;
181}
182
184{
185 return isForeGround;
186}
187
188void SNode::SetSceneNodeIsMouseForeground(const bool& mForeground)
189{
190 isForeGround = mForeground;
191}
192
194{
195 return isMouseClick;
196}
197
198void SNode::SetSceneNodeIsMouseClick(const bool& mClickable)
199{
200 isMouseClick = mClickable;
201}
202
204{
205 return mouseFlags;
206}
207
209{
210 mouseFlags = flags;
211}
212
214{
215 return nodeBody != 0;
216}
217
219{
220 return nodeBody;
221}
222
223// $BB TODO update the body shape scale on object scale change
224void SNode::UpdateNodeBody(const bool& bScale)
225{
226 //$BB add the new initial position to node
227 /*if(!currentScene->GetPhysicWorldEnable())
228 {
229 StoreInitialPRS();
230 }*/
231
232 //$BB setPositionOrientation make an update body in newton wrapper but we need to use it to keep the good PRS in body class
233 //$BB test with added setPositionOrientationFromNode
234
235 // we need to update all the parent hierarchy to get the correct global values.
236 if (O3SceneNode && mIsDirty)
237 {
238 O3SceneNode->_update(false, true);
239 SetDirty(false);
240 }
241
242 if(nodeBody!=NULL)
243 {
244 if(O3SceneNode && type == BONE_TYPE_ID)
245 {
246 SBone* bone = static_cast<SBone*>(this);
248
249 if (bScale)
251
252 if (IsAnimated())
253 {
254 nodeBody->SetVelocity(Ogre::Vector3::ZERO);
255 nodeBody->SetOmega(Ogre::Vector3::ZERO);
256 }
257 }
258 else
259 {
260 //O3SceneNode->_update(true, true);
262
263 if (bScale)
265 }
266 }
267
268 SNodeMap::iterator iNodeChildList = childNodeList.begin();
269 while (iNodeChildList != childNodeList.end())
270 {
271 iNodeChildList->second->UpdateNodeBody(bScale);
272 iNodeChildList++;
273 }
274}
275
277{
278 SNodeMap::const_iterator iNodeList = currentScene->GetNodeList().begin();
279 while (iNodeList != currentScene->GetNodeList().end())
280 {
281 SNode* currentNode = iNodeList->second;
282 if(currentScene->O3SceneManager->hasSceneNode(currentNode->name))
283 {
284 //Ogre::SceneNode* target = currentNode->getOgreSceneNodePointer()->getAutoTrackTarget();
285 SNode* target = currentNode->GetAutoTrackingTarget();
286 if(target)
287 {
288 if(target->GetName() == currentNode->GetName())
289 {
290 currentNode->SetAutoTracking(false);
291 }
292 }
293 }
294 iNodeList++;
295 }
296}
297
302
304{
305 return type;
306}
307
308void SNode::AttachToParent(SNode* newParentNode)
309{
310 //can't attach a node to himself!
311 if (newParentNode == this)
312 return;
313
314 // test if the new father is a child
315 // in this case the new parent is detached first
316 SNodeMap::iterator iNodeSearched = childNodeList.find(newParentNode->GetName());
317 if (iNodeSearched != childNodeList.end())
318 {
319 iNodeSearched->second->DetachFromParent();
320 }
321
323
324 if (nodeFather && nodeFather->GetNodeType() == SNode::BONE_TYPE_ID)
325 {
326 SBone* boneFather = static_cast <SBone*> (nodeFather);
327 boneFather->AttachToBone(this);
328 }
329
330 newParentNode->AddChildNode(this);
331 nodeFather = newParentNode;
332 SetDirty(true);
333
334 UpdateNodeBody(true);
335}
336
338{
339 if (nodeFather != 0)
340 {
341 if (nodeFather->GetNodeType() == SNode::BONE_TYPE_ID)
342 {
343 SBone* boneFather = static_cast <SBone*> (nodeFather);
344 boneFather->DetachFromBone(this);
345 }
346
347 nodeFather->RemoveChildNode(this);
348 nodeFather = 0;
349 }
350}
351
353{
354 return nodeFather;
355}
356
358{
359 return childNodeList;
360}
361
363{
364 return O3SceneNode->numChildren();
365}
366
368{
369 const SNodeMap childNodeListCopy = childNodeList;
370 SNodeMap::const_iterator iChildNodeList = childNodeListCopy.begin();
371 while (iChildNodeList != childNodeListCopy.end())
372 {
373 iChildNodeList->second->DetachFromParent();
374 iChildNodeList++;
375 }
376}
377
378void SNode::AddChildNode(SNode* newChild)
379{
380 string nodeName = newChild->GetName();
381 SNodeMap::iterator iNodeSearched = childNodeList.find(nodeName);
382 if (iNodeSearched == childNodeList.end())
383 {
384 Ogre::SceneNode* ogreNewChild = newChild->GetOgreSceneNodePointer();
385 if (ogreNewChild->getParentSceneNode() != O3SceneNode)
386 O3SceneNode->addChild(ogreNewChild);
387
388 childNodeList.insert(SNodeMap::value_type(nodeName, newChild));
389 }
390 else
391 {
392 // Node already exist in the handled nodes list.
393 OGRE_EXCEPT(Ogre::Exception::ERR_DUPLICATE_ITEM, "Can not add node named \""+ nodeName +"\", an element with the same name already exist!", "SNode::AddChildNode");
394 }
395}
396
397void SNode::RemoveChildNode(SNode* existingChild)
398{
399 string nodeName = existingChild->GetName();
400 SNodeMap::iterator iNodeSearched = childNodeList.find(nodeName);
401 if (iNodeSearched != childNodeList.end())
402 {
403 // Special case for skeleton for example.
404 if (O3SceneNode != 0)
405 {
406 try
407 {
408 O3SceneNode->removeChild(existingChild->GetOgreSceneNodePointer());
409 }
410 catch(Ogre::Exception &)
411 {
412 //must been in static geometry
413 }
414 }
415
416 childNodeList.erase(iNodeSearched);
417 }
418 else
419 {
420 // Node not found in the handled nodes list
421 OGRE_EXCEPT(Ogre::Exception::ERR_ITEM_NOT_FOUND, "Can not remove Node named \""+ nodeName +"\", element not found!", "SNode::RemoveChildNode");
422 }
423}
424
425void SNode::SetCastShadows(const bool& castShadows)
426{
427 OGRE_EXCEPT(Ogre::Exception::ERR_NOT_IMPLEMENTED, "This SNode object do not manage Shadow Casting!", "SNode::SetCastShadows");
428}
429
431{
432 OGRE_EXCEPT(Ogre::Exception::ERR_NOT_IMPLEMENTED, "This SNode object do not manage Shadow Casting!", "SNode::GetCastShadows");
433 return false;
434}
435
436void SNode::SetRenderingDistance(const float& distance)
437{
438 OGRE_EXCEPT(Ogre::Exception::ERR_NOT_IMPLEMENTED, "This SNode object do not manage Rendering distance!", "SNode::SetRenderingDistance");
439}
440
442{
443 OGRE_EXCEPT(Ogre::Exception::ERR_NOT_IMPLEMENTED, "This SNode object do not manage Rendering distance!", "SNode::GetRenderingDistance");
444 return 0.0;
445}
446
447Ogre::Vector3 SNode::GetBoundingBoxSize(const bool& childs)
448{
449 if (childs)
450 return GetSonsBoundingBox();
451
452 throw std::logic_error("SNode::GetBoundingBoxSize : This SNode object do not manage any bounding box!");
453 return Ogre::Vector3::ZERO;
454}
455
456Ogre::Vector3 SNode::GetBoundingBoxCenter(const bool& childs)
457{
458 throw std::logic_error("SNode::GetBoundingBoxSize : This SNode object do not manage any bounding box!");
459 return Ogre::Vector3::ZERO;
460}
461
462Ogre::Vector3 SNode::GetWorldBoundingBoxSize(const bool& childs)
463{
464 if (childs)
466
467 throw std::logic_error("SNode::GetWorldBoundingBoxSize : This SNode object do not manage any bounding box!");
468 return Ogre::Vector3::ZERO;
469}
470
471Ogre::Vector3 SNode::GetWorldBoundingBoxCenter(const bool& childs)
472{
473 throw std::logic_error("SNode::GetWorldBoundingBoxCenter : This SNode object do not manage any bounding box!");
474 return Ogre::Vector3::ZERO;
475}
476
478{
479 Ogre::Vector3 bbox(Ogre::Vector3::ZERO);
480 try
481 {
482 bbox = GetBoundingBoxSize();
483 }
484 catch (std::exception)
485 {
486 bbox = Ogre::Vector3::ZERO;
487 }
488
489 Ogre::Vector3 tbox(Ogre::Vector3::ZERO);
490
491 SNodeMap::iterator iChildNodeList = childNodeList.begin();
492 while (iChildNodeList != childNodeList.end())
493 {
494 tbox = iChildNodeList->second->GetSonsBoundingBox();
495 if (tbox.x > bbox.x)
496 bbox.x = tbox.x;
497 if (tbox.y > bbox.y)
498 bbox.y = tbox.y;
499 if (tbox.z > bbox.z)
500 bbox.z = tbox.z;
501
502 iChildNodeList++;
503 }
504
505 return bbox;
506}
507
509{
510 Ogre::Vector3 bbox(Ogre::Vector3::ZERO);
511 try
512 {
514 }
515 catch (std::exception)
516 {
517 bbox = Ogre::Vector3::ZERO;
518 }
519
520 Ogre::Vector3 tbox(Ogre::Vector3::ZERO);
521
522 SNodeMap::iterator iChildNodeList = childNodeList.begin();
523 while (iChildNodeList != childNodeList.end())
524 {
525 tbox = iChildNodeList->second->GetSonsWorldBoundingBox();
526 if (tbox.x > bbox.x)
527 bbox.x = tbox.x;
528 if (tbox.y > bbox.y)
529 bbox.y = tbox.y;
530 if (tbox.z > bbox.z)
531 bbox.z = tbox.z;
532
533 iChildNodeList++;
534 }
535
536 return bbox;
537}
539{
540 return O3SceneNode->_getFullTransform();
541}
542
543Ogre::Vector3 SNode::GetPosition()
544{
545 return O3SceneNode->getPosition();
546}
547
548void SNode::SetPosition(const Ogre::Vector3& pos)
549{
550 if (GetParentScene()->GetRootNode() == this)
551 return;
552
553 //TODO correct this in Ogre
554 //Big hack to avoid the camera to be placed at 0 0 0 to prevent a rectangle2D bug
555 if (type == SNode::CAMERA_TYPE_ID && pos.x == 0.0 && pos.y == 0.0 && pos.z == 0.0)
556 {
557 O3SceneNode->setPosition(Ogre::Vector3(0, 0.0, 0.15));
558 }
559 else
560 {
561 if (nodeFather && nodeFather->GetNodeType()==SNode::BONE_TYPE_ID)
562 {
563 if (ogreMovableObject != 0)
564 {
565 SBone* boneFather = static_cast <SBone*> (nodeFather);
566 boneFather->DetachFromBone(this);
567 boneFather->GetOgreSceneNodePointer()->setPosition(pos);
568 boneFather->AttachToBone(this);
569 }
570 }
571 else
572 {
573 O3SceneNode->setPosition(pos);
574 }
575 }
576
577 SetDirty(true);
578 UpdateNodeBody(false);
579}
580
581Ogre::Quaternion SNode::GetOrientation()
582{
583 if (GetNodeType() == SNode::LIGHT_TYPE_ID) // keep old Ogre light orientation
584 return O3SceneNode->getOrientation() * Ogre::Quaternion(0.0f, 0.0f, 1.0f, 0.0f);
585 else
586 return O3SceneNode->getOrientation();
587}
588
589void SNode::SetOrientation(const Ogre::Quaternion& quat)
590{
591 if (GetParentScene()->GetRootNode() == this)
592 return;
593
594 if (nodeFather && nodeFather->GetNodeType()==SNode::BONE_TYPE_ID)
595 {
596 if (ogreMovableObject != 0)
597 {
598 SBone* boneFather = static_cast <SBone*> (nodeFather);
599 boneFather->DetachFromBone(this);
600 boneFather->GetOgreSceneNodePointer()->setOrientation(quat);
601 boneFather->AttachToBone(this);
602 }
603 }
604 else if (GetNodeType() == SNode::LIGHT_TYPE_ID) // keep old Ogre light orientation
605 {
606 O3SceneNode->setOrientation(quat * Ogre::Quaternion(0.0f, 0.0f, 1.0f, 0.0f));
607 }
608 else
609 {
610 O3SceneNode->setOrientation(quat);
611 }
612
613 SetDirty(true);
614 UpdateNodeBody(false);
615}
616
617void SNode::AddOrientation(const Ogre::Quaternion& quat)
618{
619 Ogre::Quaternion tmpQuat(quat);
620 tmpQuat.normalise();
621 if (tmpQuat != Ogre::Quaternion::ZERO)
622 SetOrientation(GetOrientation() * tmpQuat);
623}
624
625Ogre::Vector3 SNode::GetScale()
626{
627 return O3SceneNode->getScale();
628}
629
630void SNode::SetScale(const Ogre::Vector3& scale)
631{
632 if (GetParentScene()->GetRootNode() == this)
633 return;
634
635 Ogre::Vector3 nscale = scale;
636 if (fabs(nscale.x) < 0.000001f)
637 nscale.x = 0.000001f;
638 if (fabs(nscale.y) < 0.000001f)
639 nscale.y = 0.00001f;
640 if (fabs(nscale.z) < 0.000001f)
641 nscale.z = 0.000001f;
642
643 O3SceneNode->setScale(nscale);
644
645 SetDirty(true);
646 UpdateNodeBody(true);
647}
648
650{
651 if (mIsDirty)
652 {
653 O3SceneNode->_update(false, true);
654 SetDirty(false);
655 }
656
657 return O3SceneNode->_getDerivedPosition();
658}
659
660void SNode::SetGlobalPosition(const Ogre::Vector3& pos, bool updateBody)
661{
662 if (GetParentScene()->GetRootNode() == this)
663 return;
664
665 if (nodeFather && nodeFather->GetNodeType()==SNode::BONE_TYPE_ID)
666 {
667 if (ogreMovableObject != 0)
668 {
669 SBone* boneFather = static_cast <SBone*> (nodeFather);
670
671 if (boneFather->IsDirty())
672 {
673 boneFather->GetParentSceneNode()->GetOgreSceneNodePointer()->_update(false, true);
674 boneFather->SetDirty(false);
675 }
676
677 boneFather->DetachFromBone(this);
678 boneFather->GetParentSceneNode()->GetOgreSceneNodePointer()->setPosition(boneFather->GetParentSceneNode()->GetGlobalOrientation().Inverse() * (pos - boneFather->GetParentSceneNode()->GetGlobalPosition() / boneFather->GetParentSceneNode()->GetGlobalScale()));
679 boneFather->AttachToBone(this);
680 }
681 }
682 else
683 {
684 Ogre::Node* m_nodeParent = O3SceneNode->getParent();
685 if (m_nodeParent)
686 {
687 if (nodeFather->IsDirty())
688 {
689 m_nodeParent->_update(false, true);
690 nodeFather->SetDirty(false);
691 }
692
693 Ogre::Vector3 gscale = m_nodeParent->_getDerivedScale();
694 //if this is a bad scale we ignore the set position
695 if (gscale.x == 0.0f || gscale.y == 0.0f || gscale.z == 0.0f)
696 return;
697 O3SceneNode->setPosition((m_nodeParent->_getDerivedOrientation().Inverse() * (pos - m_nodeParent->_getDerivedPosition()) / gscale));
698 }
699 else
700 O3SceneNode->setPosition(pos);
701 }
702
703 SetDirty(true);
704
705 if (updateBody)
706 UpdateNodeBody(false);
707}
708
710{
711 if (mIsDirty)
712 {
713 O3SceneNode->_update(false, true);
714 SetDirty(false);
715 }
716
717 if (GetNodeType() == SNode::LIGHT_TYPE_ID) // keep old Ogre light orientation
718 return O3SceneNode->_getDerivedOrientation() * Ogre::Quaternion(0.0f, 0.0f, 1.0f, 0.0f);
719 else
720 return O3SceneNode->_getDerivedOrientation();
721}
722
723void SNode::SetGlobalOrientation(const Ogre::Quaternion& quat, bool updateBody)
724{
725 if (GetParentScene()->GetRootNode() == this)
726 return;
727
728 if (nodeFather && nodeFather->GetNodeType()==SNode::BONE_TYPE_ID)
729 {
730 if (ogreMovableObject != 0)
731 {
732 SBone* boneFather = static_cast <SBone*> (nodeFather);
733 boneFather->DetachFromBone(this);
734
735 if (boneFather->IsDirty())
736 {
737 boneFather->GetParentSceneNode()->GetOgreSceneNodePointer()->_update(false, true);
738 boneFather->SetDirty(false);
739 }
740
741 boneFather->GetParentSceneNode()->GetOgreSceneNodePointer()->setOrientation(boneFather->GetParentSceneNode()->GetGlobalOrientation().Inverse() * quat);
742 boneFather->AttachToBone(this);
743 }
744 }
745 if (GetNodeType() == SNode::LIGHT_TYPE_ID) // keep old Ogre light orientation
746 {
747 Ogre::Node* m_nodeParent = O3SceneNode->getParent();
748 if (m_nodeParent)
749 {
750 if (nodeFather->IsDirty())
751 {
752 m_nodeParent->_update(false, true);
753 nodeFather->SetDirty(false);
754 }
755
756 O3SceneNode->setOrientation((m_nodeParent->_getDerivedOrientation()).Inverse() * quat * Ogre::Quaternion(0.0f, 0.0f, 1.0f, 0.0f));
757 }
758 else
759 O3SceneNode->setOrientation(quat * Ogre::Quaternion(0.0f, 0.0f, 1.0f, 0.0f));
760 }
761 else
762 {
763 Ogre::Node* m_nodeParent = O3SceneNode->getParent();
764 if (m_nodeParent)
765 {
766 if (nodeFather->IsDirty())
767 {
768 m_nodeParent->_update(false, true);
769 nodeFather->SetDirty(false);
770 }
771
772 O3SceneNode->setOrientation((m_nodeParent->_getDerivedOrientation()).Inverse() * quat);
773 }
774 else
775 O3SceneNode->setOrientation(quat);
776 }
777
778 SetDirty(true);
779
780 if (updateBody)
781 UpdateNodeBody(false);
782}
783
785{
786 if (mIsDirty)
787 {
788 O3SceneNode->_update(false, true);
789 SetDirty(false);
790 }
791
792 return O3SceneNode->_getDerivedScale();
793}
794
795void SNode::SetGlobalScale(const Ogre::Vector3& scale, bool updateBody)
796{
797 if (GetParentScene()->GetRootNode() == this)
798 return;
799
800 Ogre::Vector3 nscale = scale;
801 if (fabs(nscale.x) < 0.000001f)
802 nscale.x = 0.000001f;
803 if (fabs(nscale.y) < 0.000001f)
804 nscale.y = 0.00001f;
805 if (fabs(nscale.z) < 0.000001f)
806 nscale.z = 0.000001f;
807
808 Ogre::Node* m_nodeParent = O3SceneNode->getParent();
809 if (m_nodeParent)
810 {
811 if (nodeFather->IsDirty())
812 {
813 m_nodeParent->_update(false, true);
814 nodeFather->SetDirty(false);
815 }
816
817 Ogre::Vector3 gscale = m_nodeParent->_getDerivedScale();
818 //if this is a bad scale we ignore the set position
819 if (gscale.x == 0.0f || gscale.y == 0.0f || gscale.z == 0.0f)
820 return;
821
822 O3SceneNode->setScale(nscale / gscale);
823 }
824 else
825 O3SceneNode->setScale(nscale);
826
827 SetDirty(true);
828
829 if (updateBody)
830 UpdateNodeBody(true);
831}
832
834{
835 return O3SceneNode->getShowBoundingBox();
836}
837
838void SNode::SetShowBoundingBox(const bool& showBounding)
839{
840 O3SceneNode->showBoundingBox(showBounding);
841}
842
843void SNode::SetAutoTracking(const bool& autoTrack, SNode* targetNode, const Ogre::Vector3& localDirectionVector, const Ogre::Vector3& offset)
844{
845 autoTrackTargetNode = targetNode;
846 if (autoTrackTargetNode != 0)
847 O3SceneNode->setAutoTracking(autoTrack, targetNode->GetOgreSceneNodePointer());
848 else
849 O3SceneNode->setAutoTracking(autoTrack);
850}
851
853{
854 return autoTrackTargetNode;
855}
856
857void SNode::Pitch(const float& radianAngle, const SNode::NodeTransformSpace& relativeTo)
858{
859 O3SceneNode->pitch(Ogre::Radian(radianAngle), static_cast <Ogre::Node::TransformSpace> (static_cast<int>(relativeTo)));
860 SetDirty(true);
861 UpdateNodeBody(false);
862}
863
864void SNode::Yaw(const float& radianAngle, const SNode::NodeTransformSpace& relativeTo)
865{
866 O3SceneNode->yaw(Ogre::Radian(radianAngle), static_cast <Ogre::Node::TransformSpace> (static_cast<int>(relativeTo)));
867 SetDirty(true);
868 UpdateNodeBody(false);
869}
870
871void SNode::Roll(const float& radianAngle, const SNode::NodeTransformSpace& relativeTo)
872{
873 O3SceneNode->roll(Ogre::Radian(radianAngle), static_cast <Ogre::Node::TransformSpace> (static_cast<int>(relativeTo)));
874 SetDirty(true);
875 UpdateNodeBody(false);
876}
877
878void SNode::Rotate(const Ogre::Vector3& axis, const float& radianAngle, const SNode::NodeTransformSpace& relativeTo)
879{
880 O3SceneNode->rotate(axis, Ogre::Radian(radianAngle), static_cast <Ogre::Node::TransformSpace> (static_cast<int>(relativeTo)));
881 SetDirty(true);
882 UpdateNodeBody(false);
883}
884
885void SNode::Translate(const Ogre::Vector3& d, const SNode::NodeTransformSpace& relativeTo)
886{
887 O3SceneNode->translate(d, static_cast <Ogre::Node::TransformSpace> (static_cast<int>(relativeTo)));
888 SetDirty(true);
889 UpdateNodeBody(false);
890}
891
892void SNode::SetDirection(const Ogre::Vector3& vec, const SNode::NodeTransformSpace& relativeTo, const Ogre::Vector3& localDirectionVector)
893{
894 O3SceneNode->setDirection(vec, static_cast <Ogre::Node::TransformSpace> (static_cast<int>(relativeTo)), localDirectionVector);
895 SetDirty(true);
896 UpdateNodeBody(false);
897}
898
899Ogre::Vector3 SNode::GetDirection(bool derived, Ogre::Vector3 axis)
900{
901 if (derived)
902 return O3SceneNode->_getDerivedOrientation() * axis;
903 else
904 return O3SceneNode->getOrientation() * axis;
905}
906
907void SNode::LookAt(const Ogre::Vector3& targetPoint, const SNode::NodeTransformSpace& relativeTo, const Ogre::Vector3& localDirectionVector)
908{
909 O3SceneNode->lookAt(targetPoint, static_cast <Ogre::Node::TransformSpace> (static_cast<int>(relativeTo)), localDirectionVector);
910 SetDirty(true);
911 UpdateNodeBody(false);
912}
913
915{
916 return mVisible;
917
918 //SNode* father = nodeFather;
919 //Ogre::StaticGeometry* staticGeom = staticGeometry;
920 //while ((father != 0) && (staticGeom == 0))
921 //{
922 // staticGeom = father->GetStaticGeometry();
923 // father = father->GetParentSceneNode();
924 //}
925 //
926 //if (staticGeom != 0)
927 // result = staticGeom->isVisible();
928 //else if (O3SceneNode->numAttachedObjects() != 0)
929 // result = O3SceneNode->getAttachedObject(0)->isVisible();
930 //
931 //return result;
932}
933
934void SNode::SetVisible(const bool& visible, const bool& cascade)
935{
936 mVisible = visible;
937
938 // look for static geometry in parents
939 SNode* father = nodeFather;
940 Ogre::StaticGeometry* staticGeom = staticGeometry;
941 while ((father != 0) && (staticGeom == 0))
942 {
943 staticGeom = father->GetStaticGeometry();
944 father = father->GetParentSceneNode();
945 }
946
947 staticVisibility = visible;
948
949 if (staticGeom != 0)
950 staticGeom->setVisible(visible);
951 else
952 O3SceneNode->setVisible(visible, false);
953
955 {
956 SLight* light = static_cast<SLight*>(this);
957 light->SetVisible(visible);
958 }
959
960 if (cascade)
961 {
962 SNodeMap::iterator iChildNodeList = childNodeList.begin();
963 while (iChildNodeList != childNodeList.end())
964 {
965 iChildNodeList->second->SetVisible(visible, cascade);
966 iChildNodeList++;
967 }
968 }
969}
970
972{
973 initialPosition = O3SceneNode->getPosition();
974 initialOrientation = O3SceneNode->getOrientation();
975 initialScale = O3SceneNode->getScale();
976}
977
979{
980 O3SceneNode->setPosition(initialPosition);
981 O3SceneNode->setOrientation(initialOrientation);
982 O3SceneNode->setScale(initialScale);
983
984 UpdateNodeBody(true);
985}
986
988{
989 // TODO: with 1.7?
990 OGRE_EXCEPT(Ogre::Exception::ERR_NOT_IMPLEMENTED, "Not implemented in Ogre 1.6!", "SNode::ResetToInitialPosition");
991}
992
994{
995 O3SceneNode->resetOrientation();
996 SetDirty(true);
997}
998
1000{
1001 // TODO: with 1.7?
1002 OGRE_EXCEPT(Ogre::Exception::ERR_NOT_IMPLEMENTED, "Not implemented in Ogre 1.6!", "SNode::ResetToInitialScale");
1003}
1004
1006{
1007 if (nodeBody)
1008 nodeBody->Reset();
1009 else
1010 {
1011 if (type == SNode::ENTITY_TYPE_ID)
1012 {
1013 SEntity* curEntity = static_cast<SEntity*>(this);
1014 SSkeleton* skeleton = curEntity->GetSkeleton();
1015 if (skeleton)
1016 {
1017 SBoneMap rootBoneList = skeleton->GetRootBones();
1018 SBoneMap::iterator iRootBones = rootBoneList.begin();
1019 while (iRootBones != rootBoneList.end())
1020 {
1021 iRootBones->second->ResetNode();
1022 iRootBones++;
1023 }
1024 }
1025 }
1026
1027 SNodeMap::iterator iChildNodeList = childNodeList.begin();
1028 while (iChildNodeList != childNodeList.end())
1029 {
1030 iChildNodeList->second->ResetNode();
1031 iChildNodeList++;
1032 }
1033 }
1034}
1035
1037{
1038 return O3SceneNode->getInitialPosition();
1039}
1040
1042{
1043 return O3SceneNode->getInitialOrientation();
1044}
1045
1047{
1048 return O3SceneNode->getInitialScale();
1049}
1050
1051SNodeAnimation* SNode::CreateNodeAnimation(const std::string& animationName, const float& animationLength)
1052{
1053 SNodeAnimation* animation = new SNodeAnimation(GetParentScene(), animationName, this, animationCounter++, animationLength);
1054 AddAnimation(animation);
1055 return animation;
1056}
1057
1058void SNode::DeleteAnimation(SAnim* existingAnimation)
1059{
1060 // Verify that anim instance is in handled by this SNode instance.
1061 assert(existingAnimation != 0);
1062 if(GetAnimation(existingAnimation->GetName()) != existingAnimation)
1063 OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS, "Cannot destroy an animation that is not handled by this node", "SNode::DeleteAnimation");
1064
1065 currentScene->RemoveAnimation(existingAnimation);
1066 RemoveAnimation(existingAnimation);
1067 SO3_SAFE_DELETE(existingAnimation);
1068}
1069
1071{
1072 return animationList.size();
1073}
1074
1075SAnim* SNode::GetAnimation(const std::string& animationName)
1076{
1077 SAnimMap::iterator iAnimationSearched = animationList.find(animationName);
1078 if (iAnimationSearched != animationList.end())
1079 return iAnimationSearched->second;
1080 else
1081 return 0;
1082}
1083
1084SAnim* SNode::GetAnimation(const unsigned short& animationIndex)
1085{
1086 SAnimIndexMap::iterator iAnimationSearched = animationListByIndex.find(animationIndex);
1087 if (iAnimationSearched != animationListByIndex.end())
1088 return iAnimationSearched->second;
1089 else
1090 return 0;
1091}
1092
1094{
1095 return animationList;
1096}
1097
1099{
1100 bool animated = false;
1101 SAnimMap animList;
1102
1103 if (type == SNode::BONE_TYPE_ID)
1104 {
1105 SBone* bone = static_cast<SBone*>(this);
1106 animList = bone->GetSkeleton()->GetAnimations();
1107 }
1108 else
1109 animList = animationList;
1110
1111 if(animList.size() > 0)
1112 {
1113 SAnimMap::const_iterator iAnimList = animList.begin();
1114 while(iAnimList != animList.end() && !animated)
1115 {
1116 SAnim* curAnim = iAnimList->second;
1117 if (curAnim->GetEnable())
1118 animated = true;
1119
1120 iAnimList++;
1121 }
1122 }
1123
1124 return animated;
1125}
1126
1127void SNode::AddAnimation(SAnim* existingAnimation)
1128{
1129 string animationName = existingAnimation->GetName();
1130 SAnimMap::iterator iAnimationSearched = animationList.find(animationName);
1131 if (iAnimationSearched == animationList.end())
1132 {
1133 animationList.insert(SAnimMap::value_type(animationName, existingAnimation));
1134 animationListByIndex.insert(SAnimIndexMap::value_type(existingAnimation->GetIndex(), existingAnimation));
1135 }
1136 else
1137 {
1138 // Animation already exist in the handled animations list.
1139 OGRE_EXCEPT(Ogre::Exception::ERR_DUPLICATE_ITEM, "Can not add animation named \""+ animationName +"\", an element with the same name already exist!", "SNode::AddAnimation");
1140 }
1141
1142 //also add in scene animation list for update
1143 currentScene->AddAnimation(existingAnimation);
1144}
1145
1146void SNode::RemoveAnimation(SAnim* existingAnimation)
1147{
1148 RemoveAnimation(existingAnimation->GetName());
1149 //GetParentScene()->RemoveAnimation(existingAnimation->GetName());
1150}
1151
1152void SNode::RemoveAnimation(const std::string& animationName)
1153{
1154 SAnimMap::iterator iAnimationSearched = animationList.find(animationName);
1155 if (iAnimationSearched != animationList.end())
1156 {
1157 SAnim* findedAnimation = iAnimationSearched->second;
1158 animationList.erase(iAnimationSearched);
1159
1160 // Delete from index map too
1161 SAnimIndexMap::iterator iAnimationIndexSearched = animationListByIndex.find(findedAnimation->GetIndex());
1162 animationListByIndex.erase(iAnimationIndexSearched);
1163 }
1164 else
1165 {
1166 // Animation not found in the handled animations list
1167 OGRE_EXCEPT(Ogre::Exception::ERR_ITEM_NOT_FOUND, "Can not remove Animation named \""+ animationName +"\", element not found!", "SNode::RemoveAnimation");
1168 }
1169}
1170
1171Ogre::Vector3 SNode::GetPositionFromNode(SNode* nodeRef)
1172{
1173 Ogre::Matrix4 mat;
1174
1175 if (mIsDirty)
1176 {
1177 O3SceneNode->_update(true, true);
1178 SetDirty(false);
1179 }
1180
1181 mat = nodeRef->GetTransformationMatrix().inverse() * GetTransformationMatrix();
1182
1183 return mat.getTrans();
1184}
1185
1186Ogre::Quaternion SNode::GetOrientationFromNode(SNode* nodeRef)
1187{
1188 Ogre::Matrix4 mat;
1189
1190 if (mIsDirty)
1191 {
1192 O3SceneNode->_update(true, true);
1193 SetDirty(false);
1194 }
1195
1196 mat = nodeRef->GetTransformationMatrix().inverse() * GetTransformationMatrix();
1197 return Ogre::Quaternion(mat.linear());
1198}
1199
1200Ogre::Vector3 SNode::GetScaleFromNode(SNode* nodeRef)
1201{
1202 Ogre::Vector3 scaleParent;
1203 Ogre::Vector3 scaleResult(1.0,1.0,1.0);
1204
1205 scaleParent = nodeRef->GetGlobalScale();
1206
1207 if(scaleParent.x != 0.0 && scaleParent.y != 0.0 && scaleParent.z != 0.0)
1208 scaleResult = GetGlobalScale() / scaleParent;
1209
1210 return scaleResult;
1211}
1212
1213void SNode::SetInheritOrientation(const bool& state)
1214{
1215 O3SceneNode->setInheritOrientation(state);
1216}
1217
1219{
1220 return O3SceneNode->getInheritOrientation();
1221}
1222
1224{
1225 O3SceneNode->resetOrientation();
1226 SetDirty(true);
1227}
1228
1230{
1231 SO3_SAFE_DELETE(nodeBody);
1232}
1233
1234SBody* SNode::CreateBoxBody(const Ogre::Vector3& size)
1235{
1236 // test if the vector is ok, return if not
1237 if ((size.x == 0.0f) || (size.y == 0.0f) || (size.z == 0.0f))
1238 return 0;
1239
1240 SShapeBox* shape = new SShapeBox(GetName() + "body_box", this, size);
1241 SBody* body = new SBody(this, shape);
1242 nodeBody = body;
1244 body->SetScale(GetGlobalScale());
1245
1246 return nodeBody;
1247}
1248
1249SBody* SNode::CreateBoxBody(const Ogre::Vector3& size, const Ogre::Vector3& offset, const Ogre::Quaternion& quat)
1250{
1251 // test if the vector is ok, return if not
1252 if ((size.x == 0.0f) || (size.y == 0.0f) || (size.z == 0.0f))
1253 return 0;
1254
1255 SShapeBox* shape = new SShapeBox(GetName() + "body_box", this, size, offset, quat);
1256 SBody* body = new SBody(this, shape);
1257 nodeBody = body;
1259 body->SetScale(GetGlobalScale());
1260
1261 return nodeBody;
1262}
1263
1264SBody* SNode::CreateConeBody(const Ogre::Real& radius, const Ogre::Real& height)
1265{
1266 // test if the height or radius is ok, return if not
1267 if ((height == 0.0f) || (radius == 0.0f))
1268 return 0;
1269
1270 SShapeCone* shape = new SShapeCone(GetName() + "body_cone", this, radius, height);
1271 SBody* body = new SBody(this, shape);
1272 nodeBody = body;
1274 body->SetScale(GetGlobalScale());
1275
1276 return nodeBody;
1277}
1278
1279SBody* SNode::CreateConeBody(const Ogre::Real& radius, const Ogre::Real& height, const Ogre::Vector3& offset, const Ogre::Quaternion& quat)
1280{
1281 // test if the height or radius is ok, return if not
1282 if ((height == 0.0f) || (radius == 0.0f))
1283 return 0;
1284
1285 SShapeCone* shape = new SShapeCone(GetName() + "body_cone", this, radius, height, offset, quat);
1286 SBody* body = new SBody(this, shape);
1287 nodeBody = body;
1289 body->SetScale(GetGlobalScale());
1290
1291 return nodeBody;
1292}
1293
1294SBody* SNode::CreateEllipsoidBody(const Ogre::Vector3& size)
1295{
1296 // test if the vector is ok, return if not
1297 if ((size.x == 0.0f) || (size.y == 0.0f) || (size.z == 0.0f))
1298 return 0;
1299
1300 SShapeEllipsoid* shape = new SShapeEllipsoid(GetName() + "body_ellipsoid", this, size);
1301 SBody* body = new SBody(this, shape);
1302 nodeBody = body;
1304 body->SetScale(GetGlobalScale());
1305
1306 return nodeBody;
1307}
1308
1309SBody* SNode::CreateEllipsoidBody(const Ogre::Vector3& size, const Ogre::Vector3& offset, const Ogre::Quaternion& quat)
1310{
1311 // test if the vector is ok, return if not
1312 if ((size.x == 0.0f) || (size.y == 0.0f) || (size.z == 0.0f))
1313 return 0;
1314
1315 SShapeEllipsoid* shape = new SShapeEllipsoid(GetName() + "body_ellipsoid", this, size, offset, quat);
1316 SBody* body = new SBody(this, shape);
1317 nodeBody = body;
1319 body->SetScale(GetGlobalScale());
1320
1321 return nodeBody;
1322}
1323
1324SBody* SNode::CreateCapsuleBody(const Ogre::Real& radius, const Ogre::Real& height)
1325{
1326 // test if the height or radius is ok, return if not
1327 if ((height == 0.0f) || (radius == 0.0f))
1328 return 0;
1329
1330 SShapeCapsule* shape = new SShapeCapsule(GetName() + "body_capsule", this, radius, height);
1331 SBody* body = new SBody(this, shape);
1332 nodeBody = body;
1334 body->SetScale(GetGlobalScale());
1335
1336 return nodeBody;
1337}
1338
1339SBody* SNode::CreateCapsuleBody(const Ogre::Real& radius, const Ogre::Real& height, const Ogre::Vector3& offset, const Ogre::Quaternion& quat)
1340{
1341 // test if the height or radius is ok, return if not
1342 if ((height == 0.0f) || (radius == 0.0f))
1343 return 0;
1344
1345 SShapeCapsule* shape = new SShapeCapsule(GetName() + "body_capsule", this, radius, height, offset, quat);
1346 SBody* body = new SBody(this, shape);
1347 nodeBody = body;
1349 body->SetScale(GetGlobalScale());
1350
1351 return nodeBody;
1352}
1353
1354SBody* SNode::CreateCylinderBody(const Ogre::Real& radius, const Ogre::Real& height)
1355{
1356 // test if the height or radius is ok, return if not
1357 if ((height == 0.0f) || (radius == 0.0f))
1358 return 0;
1359
1360 SShapeCylinder* shape = new SShapeCylinder(GetName() + "body_cylinder", this, radius, height);
1361 SBody* body = new SBody(this, shape);
1362 nodeBody = body;
1364 body->SetScale(GetGlobalScale());
1365
1366 return nodeBody;
1367}
1368
1369SBody* SNode::CreateCylinderBody(const Ogre::Real& radius, const Ogre::Real& height, const Ogre::Vector3& offset, const Ogre::Quaternion& quat)
1370{
1371 // test if the height or radius is ok, return if not
1372 if ((height == 0.0f) || (radius == 0.0f))
1373 return 0;
1374
1375 SShapeCylinder* shape = new SShapeCylinder(GetName() + "body_cylinder", this, radius, height, offset, quat);
1376 SBody* body = new SBody(this, shape);
1377 nodeBody = body;
1379 body->SetScale(GetGlobalScale());
1380
1381 return nodeBody;
1382}
1383
1384SBody* SNode::CreateChamferCylinderBody(const Ogre::Real& radius, const Ogre::Real& height)
1385{
1386 // test if the height or radius is ok, return if not
1387 if ((height == 0.0f) || (radius == 0.0f))
1388 return 0;
1389
1390 SShapeChamferCylinder* shape = new SShapeChamferCylinder(GetName() + "body_chamfercylinder", this, radius, height);
1391 SBody* body = new SBody(this, shape);
1392 nodeBody = body;
1394 body->SetScale(GetGlobalScale());
1395
1396 return nodeBody;
1397}
1398
1399SBody* SNode::CreateChamferCylinderBody(const Ogre::Real& radius, const Ogre::Real& height, const Ogre::Vector3& offset, const Ogre::Quaternion& quat)
1400{
1401 // test if the height or radius is ok, return if not
1402 if ((height == 0.0f) || (radius == 0.0f))
1403 return 0;
1404
1405 SShapeChamferCylinder* shape = new SShapeChamferCylinder(GetName() + "body_chamfercylinder", this, radius, height, offset, quat);
1406 SBody* body = new SBody(this, shape);
1407 nodeBody = body;
1409 body->SetScale(GetGlobalScale());
1410
1411 return nodeBody;
1412}
1413
1414SBody* SNode::CreatePyramidBody(const Ogre::Vector3& size)
1415{
1416 // test if the vector is ok, return if not
1417 if ((size.x == 0.0f) || (size.y == 0.0f) || (size.z == 0.0f))
1418 return 0;
1419
1420 SShapePyramid* shape = new SShapePyramid(GetName() + "body_pyramid", this, size);
1421 SBody* body = new SBody(this, shape);
1422 nodeBody = body;
1424 body->SetScale(GetGlobalScale());
1425
1426 return nodeBody;
1427}
1428
1429SBody* SNode::CreatePyramidBody(const Ogre::Vector3& size, const Ogre::Vector3& offset, const Ogre::Quaternion& quat)
1430{
1431 // test if the vector is ok, return if not
1432 if ((size.x == 0.0f) || (size.y == 0.0f) || (size.z == 0.0f))
1433 return 0;
1434
1435 SShapePyramid* shape = new SShapePyramid(GetName() + "body_pyramid", this, size, offset, quat);
1436 SBody* body = new SBody(this, shape);
1437 nodeBody = body;
1439 body->SetScale(GetGlobalScale());
1440
1441 return nodeBody;
1442}
1443
1444SBody* SNode::CreateConvexHullBody(const Ogre::Real& tolerance)
1445{
1447 {
1448 //check if the object is a triangle list object
1449 SEntity* entity = static_cast<SEntity*> (this);
1450 Ogre::MeshPtr mesh = entity->getOgreEntityPointer()->getMesh();
1451
1452 if (!mesh)
1453 return 0;
1454
1455 bool isTriangleList = false;
1456 size_t sub = mesh->getNumSubMeshes();
1457 for (size_t cs = 0; cs < sub && !isTriangleList; cs++)
1458 {
1459 Ogre::SubMesh* sub_mesh = mesh->getSubMesh(cs);
1460 isTriangleList = (sub_mesh->operationType == Ogre::RenderOperation::OT_TRIANGLE_LIST) ? true : false;
1461 }
1462
1463 if (!isTriangleList)
1464 return 0;
1465
1466 // test if the mesh is convex, return if not
1467 Ogre::Vector3 convexTest = entity->GetBoundingBoxSize();
1468 if ((convexTest.x == 0.0f) || (convexTest.y == 0.0f) || (convexTest.z == 0.0f))
1469 return 0;
1470
1471 SShapeConvexHull* shape = 0;
1472
1473 shape = new SShapeConvexHull(GetName() + "body_convex", entity, tolerance);
1474
1475 SBody* body = new SBody(this, shape);
1476 nodeBody = body;
1478 body->SetScale(GetGlobalScale());
1479
1480 return nodeBody;
1481 }
1482
1483 return 0;
1484}
1485
1486SBody* SNode::CreateConcaveHullBody(const Ogre::Real& tolerance)
1487{
1489 {
1490 //check if the object is a triangle list object
1491 SEntity* entity = static_cast<SEntity*> (this);
1492 Ogre::MeshPtr mesh = entity->getOgreEntityPointer()->getMesh();
1493
1494 if (!mesh)
1495 return 0;
1496
1497 bool isTriangleList = false;
1498 size_t sub = mesh->getNumSubMeshes();
1499 for (size_t cs = 0; cs < sub && !isTriangleList; cs++)
1500 {
1501 Ogre::SubMesh* sub_mesh = mesh->getSubMesh(cs);
1502 isTriangleList = (sub_mesh->operationType == Ogre::RenderOperation::OT_TRIANGLE_LIST) ? true : false;
1503 }
1504
1505 if (!isTriangleList)
1506 return 0;
1507
1508 // test if the mesh is convex, return if not
1509 Ogre::Vector3 convexTest = entity->GetBoundingBoxSize();
1510 if ((convexTest.x == 0.0f) || (convexTest.y == 0.0f) || (convexTest.z == 0.0f))
1511 return 0;
1512
1513 SShapeConcaveHull* shape = 0;
1514
1515 shape = new SShapeConcaveHull(GetName() + "body_convex", entity, tolerance);
1516
1517 SBody* body = new SBody(this, shape);
1518 nodeBody = body;
1520 body->SetScale(GetGlobalScale());
1521
1522 return nodeBody;
1523 }
1524
1525 return 0;
1526}
1527
1528SBody* SNode::CreateTreeBody(const bool& optimize)
1529{
1530 //check if the object is a triangle list object
1531 if ((GetNodeType() == SNode::ENTITY_TYPE_ID)/* && (staticGeometry == 0)*/)
1532 {
1533 SEntity* entity = static_cast<SEntity*> (this);
1534 if (!entity->getOgreEntityPointer())
1535 return 0;
1536
1537 Ogre::MeshPtr mesh = entity->getOgreEntityPointer()->getMesh();
1538
1539 if (!mesh)
1540 return 0;
1541
1542 bool isTriangleList = false;
1543 size_t sub = mesh->getNumSubMeshes();
1544 for (size_t cs = 0; cs < sub && !isTriangleList; cs++)
1545 {
1546 Ogre::SubMesh* sub_mesh = mesh->getSubMesh(cs);
1547 isTriangleList = (sub_mesh->operationType == Ogre::RenderOperation::OT_TRIANGLE_LIST) ? true : false;
1548 }
1549
1550 if (!isTriangleList)
1551 return 0;
1552
1553 SShapeTree* shape = new SShapeTree(GetName() + "body_tree", entity, optimize);
1554 SBody* body = new SBody(this, shape);
1555 nodeBody = body;
1557 body->SetScale(GetGlobalScale());
1558
1559 return nodeBody;
1560 }
1561 /*
1562 else if (staticGeometry != 0)
1563 {
1564 //TODO
1565 return 0;
1566
1567 //SShapeTree* shape = new SShapeTree(GetName() + "body_tree", entity, optimize);
1568 //SBody* body = new SBody(this, shape);
1569 //nodeBody = body;
1570 //StoreInitialPRS();
1571 //body->SetScale(GetGlobalScale());
1572 //
1573 //return nodeBody;
1574 }*/
1575
1576 return 0;
1577}
1578
1580{
1581 if (nodeFather)
1582 {
1583 try
1584 {
1585 nodeFather->GetOgreSceneNodePointer()->addChild(O3SceneNode);
1586 }
1587 catch(Ogre::Exception &)
1588 {
1589 // should not happen
1590 }
1591 }
1592
1593 SNodeMap::iterator iChildNodeList = childNodeList.begin();
1594 while (iChildNodeList != childNodeList.end())
1595 {
1596 iChildNodeList->second->RestoreStaticGraph();
1597 iChildNodeList++;
1598 }
1599}
1600
1601void SNode::SetAsStaticGeometry(const bool& state)
1602{
1603 if (staticGeometry != 0)
1604 {
1605 currentScene->GetOgreScenePointer()->destroyStaticGeometry(GetName());
1606 staticGeometry = 0;
1608
1609 O3SceneNode->setVisible(staticVisibility, true);
1610 }
1611
1612 if (state)
1613 {
1614 // look for static geometry mode in fathers node
1615 SNode* father = nodeFather;
1616 bool alreadySet = false;
1617
1618 while ((father != 0) && !alreadySet)
1619 {
1620 if (father->GetAsStaticGeometry() != 0)
1621 alreadySet = true;
1622
1623 father = father->GetParentSceneNode();
1624 }
1625
1626 if (!alreadySet)
1627 {
1628 // remove static geometry on sons for sons
1629 SNodeMap::iterator iChildNodeList = childNodeList.begin();
1630 while (iChildNodeList != childNodeList.end())
1631 {
1632 iChildNodeList->second->SetAsStaticGeometry(false);
1633 iChildNodeList++;
1634 }
1635
1636 staticGeometry = currentScene->GetOgreScenePointer()->createStaticGeometry(GetName());
1637 staticGeometry->destroy();
1638 staticGeometry->addSceneNode(O3SceneNode);
1639
1641 {
1642 SEntity* entity = static_cast<SEntity*> (this);
1643 staticGeometry->setCastShadows(entity->GetCastShadows());
1644 }
1645 else
1646 {
1647 staticGeometry->setCastShadows(true);
1648 }
1649
1650 staticGeometry->build();
1651 staticGeometry->setVisible(staticVisibility);
1652
1653 O3SceneNode->setVisible(false, true);
1654
1655 if (nodeFather)
1656 nodeFather->GetOgreSceneNodePointer()->removeChild(O3SceneNode);
1657 }
1658 }
1659}
1660
1662{
1663 if (staticGeometry != 0)
1664 return true;
1665
1666 return false;
1667}
1668
1669Ogre::StaticGeometry* SNode::GetStaticGeometry()
1670{
1671 return staticGeometry;
1672}
1673
1675{
1676 return mIsDirty;
1677}
1678
1679void SNode::SetDirty(bool state)
1680{
1681 mIsDirty = state;
1682
1683 if (state)
1684 {
1685 SNodeMap::iterator iChildNodeList = childNodeList.begin();
1686 while (iChildNodeList != childNodeList.end())
1687 {
1688 iChildNodeList->second->SetDirty(state);
1689 iChildNodeList++;
1690 }
1691 }
1692}
1693
1695{
1696 if (nodeBody && nodeBody->GetMass() > 0.0f)
1698 else
1699 {
1700 //update body with 0 mass
1701 if (nodeBody != NULL)
1702 {
1703 if (O3SceneNode && type == BONE_TYPE_ID)
1704 {
1705 SBone* bone = static_cast<SBone*>(this);
1707
1708 if (IsAnimated())
1709 {
1710 nodeBody->SetVelocity(Ogre::Vector3::ZERO);
1711 nodeBody->SetOmega(Ogre::Vector3::ZERO);
1712 }
1713 }
1714 else
1715 {
1717 }
1718 }
1719
1720 if (type == SNode::ENTITY_TYPE_ID)
1721 {
1722 SEntity* curEntity = static_cast<SEntity*>(this);
1723 SSkeleton* skeleton = curEntity->GetSkeleton();
1724 if (skeleton)
1725 {
1726 SBoneMap rootBoneList = skeleton->GetRootBones();
1727 SBoneMap::iterator iRootBones = rootBoneList.begin();
1728 while (iRootBones != rootBoneList.end())
1729 {
1730 iRootBones->second->UpdateNodeFromBody();
1731 iRootBones++;
1732 }
1733 }
1734 }
1735
1736 SNodeMap::iterator iChildNodeList = childNodeList.begin();
1737 while (iChildNodeList != childNodeList.end())
1738 {
1739 iChildNodeList->second->UpdateNodeFromBody();
1740 iChildNodeList++;
1741 }
1742 }
1743}
1744
1746{
1747 mPhysicsOverride = state;
1748}
1749
1750
1752{
1753 return mPhysicsOverride;
1754}
1755
1756}
unsigned short GetIndex()
Definition SO3Anim.cpp:130
virtual bool GetEnable()
Definition SO3Anim.cpp:302
void SetScale(const Ogre::Vector3 &mDerivedScale)
Definition SO3Body.cpp:610
OgreNewt::Body * getOgreNewtBodyPointer()
Definition SO3Body.cpp:340
Ogre::Real GetMass()
Definition SO3Body.cpp:423
void Reset()
Definition SO3Body.cpp:116
void SetVelocity(const Ogre::Vector3 &velocity)
Definition SO3Body.cpp:629
void UpdatePositionOrientation()
Definition SO3Body.cpp:598
void BodyUpdateCallback(OgreNewt::Body *body)
Definition SO3Body.cpp:166
void SetOmega(const Ogre::Vector3 &omega)
Definition SO3Body.cpp:532
SSkeleton * GetSkeleton()
Definition SO3Bone.cpp:78
void AttachToBone(Ogre::MovableObject *ogreObject)
Definition SO3Bone.cpp:538
void DetachFromBone(Ogre::MovableObject *ogreObject)
Definition SO3Bone.cpp:550
virtual Ogre::Quaternion GetGlobalOrientation()
Definition SO3Bone.cpp:256
virtual Ogre::Vector3 GetGlobalPosition()
Definition SO3Bone.cpp:238
virtual Ogre::Vector3 GetGlobalScale()
Definition SO3Bone.cpp:275
std::string GetName() const
std::string name
Definition SO3DataScol.h:44
SSkeleton * GetSkeleton()
virtual Ogre::Vector3 GetBoundingBoxSize(const bool &childs=false)
virtual bool GetCastShadows()
Ogre::Entity * getOgreEntityPointer()
void SetVisible(const bool &isVisible)
Definition SO3Light.cpp:149
virtual Ogre::Quaternion GetGlobalOrientation()
SBody * CreateCapsuleBody(const Ogre::Real &radius, const Ogre::Real &height)
const SNodeMap GetChildrenNodes() const
bool GetPhysicsOverride()
void AddAnimation(SAnim *existingAnimation)
Ogre::Vector3 GetSonsWorldBoundingBox()
void UpdateNodeBody(const bool &bScale)
SBody * CreateCylinderBody(const Ogre::Real &radius, const Ogre::Real &height)
void SetFlags(const int &flags)
bool GetSceneNodeHasBody()
bool GetSceneNodeIsMouseClick()
void SetAutoTracking(const bool &autoTrack, SNode *targetNode=0, const Ogre::Vector3 &localDirectionVector=Ogre::Vector3::NEGATIVE_UNIT_Z, const Ogre::Vector3 &offset=Ogre::Vector3::ZERO)
void RestoreStaticGraph()
SScene * currentScene
Definition SO3NodeScol.h:68
virtual void SetInheritOrientation(const bool &state)
size_t GetNumAnimations()
virtual Ogre::Vector3 GetPosition()
void SetDirection(const Ogre::Vector3 &vec, const SNode::NodeTransformSpace &relativeTo=SNode::SO3_LOCAL_TS, const Ogre::Vector3 &localDirectionVector=Ogre::Vector3::NEGATIVE_UNIT_Z)
Ogre::SceneNode * O3SceneNode
Definition SO3NodeScol.h:69
Ogre::Quaternion GetOrientationFromNode(SNode *nodeRef)
virtual Ogre::Vector3 GetBoundingBoxCenter(const bool &childs=false)
Ogre::Vector3 initialPosition
Definition SO3NodeScol.h:75
bool GetVisible()
virtual void Yaw(const float &radianAngle, const SNode::NodeTransformSpace &relativeTo=SNode::SO3_LOCAL_TS)
virtual void SetScale(const Ogre::Vector3 &scale)
void UpdateNodeFromBody()
void RemoveAnimation(SAnim *existingAnimation)
void LookAt(const Ogre::Vector3 &targetPoint, const SNode::NodeTransformSpace &relativeTo, const Ogre::Vector3 &localDirectionVector=Ogre::Vector3::NEGATIVE_UNIT_Z)
SScene * GetParentScene()
virtual void SetGlobalPosition(const Ogre::Vector3 &pos, bool updateBody=true)
virtual Ogre::Vector3 GetScale()
virtual bool GetInheritOrientation()
void SetSceneNodeIsMouseForeground(const bool &mForeground)
NodeType GetNodeType()
SBody * CreateConcaveHullBody(const Ogre::Real &tolerance)
virtual void SetGlobalOrientation(const Ogre::Quaternion &quat, bool updateBody=true)
virtual float GetRenderingDistance()
SNodeAnimation * CreateNodeAnimation(const std::string &animationName, const float &animationLength)
virtual void SetRenderingDistance(const float &distance)
void SetDirty(bool state)
SBody * CreateConvexHullBody(const Ogre::Real &tolerance)
SBody * CreateEllipsoidBody(const Ogre::Vector3 &size)
virtual void Pitch(const float &radianAngle, const SNode::NodeTransformSpace &relativeTo=SNode::SO3_LOCAL_TS)
void ResetToInitialScale()
virtual void AddOrientation(const Ogre::Quaternion &quat)
void SetAsStaticGeometry(const bool &state)
int GetSceneNodeMouseFlags()
void SetSceneNodeIsMouseClick(const bool &mClickable)
virtual void SetCastShadows(const bool &castShadows)
virtual void SetGlobalScale(const Ogre::Vector3 &scale, bool updateBody=true)
void DetachFromParent()
void SetShowBoundingBox(const bool &showBounding)
Ogre::Vector3 GetScaleFromNode(SNode *nodeRef)
virtual void SetOrientation(const Ogre::Quaternion &quat)
SBody * GetSceneNodeBody()
Ogre::Vector3 GetPositionFromNode(SNode *nodeRef)
SBody * CreateTreeBody(const bool &optimize)
void DeleteBody()
virtual void SetPosition(const Ogre::Vector3 &pos)
virtual Ogre::Vector3 GetWorldBoundingBoxSize(const bool &childs=false)
SBody * CreateChamferCylinderBody(const Ogre::Real &radius, const Ogre::Real &height)
void DetachAllChildren()
virtual void ResetOrientation()
virtual Ogre::Vector3 GetGlobalPosition()
unsigned short animationCounter
Definition SO3NodeScol.h:72
virtual Ogre::Quaternion GetInitialOrientation()
bool GetAsStaticGeometry()
virtual Ogre::Vector3 GetInitialScale()
SBody * CreatePyramidBody(const Ogre::Vector3 &size)
Ogre::StaticGeometry * GetStaticGeometry()
Ogre::MovableObject * GetMovableObjectPointer()
virtual void Roll(const float &radianAngle, const SNode::NodeTransformSpace &relativeTo=SNode::SO3_LOCAL_TS)
bool GetShowBoundingBox()
virtual Ogre::Vector3 GetGlobalScale()
SAnim * GetAnimation(const std::string &animationName)
Ogre::MovableObject * ogreMovableObject
Definition SO3NodeScol.h:70
virtual Ogre::Quaternion GetOrientation()
void SetSceneNodeMouseFlags(const int &flags)
Ogre::Vector3 GetDirection(bool derived=false, Ogre::Vector3 axis=Ogre::Vector3::NEGATIVE_UNIT_Z)
virtual void StoreInitialPRS()
SBody * CreateBoxBody(const Ogre::Vector3 &boxsetting)
virtual void ResetToInitialOrientation()
void ResetToInitialPosition()
void SetPhysicsOverride(bool state)
virtual bool GetCastShadows()
bool IsAnimated()
virtual void Rotate(const Ogre::Vector3 &axis, const float &radianAngle, const SNode::NodeTransformSpace &relativeTo=SNode::SO3_LOCAL_TS)
virtual Ogre::Vector3 GetBoundingBoxSize(const bool &childs=false)
void DeleteAnimation(SAnim *existingAnimation)
void SetVisible(const bool &visible, const bool &cascade=true)
virtual ~SNode()
virtual int GetNumChildren()
virtual Ogre::Vector3 GetInitialPosition()
virtual Ogre::Matrix4 GetTransformationMatrix()
Ogre::Quaternion initialOrientation
Definition SO3NodeScol.h:76
virtual Ogre::Vector3 GetWorldBoundingBoxCenter(const bool &childs=false)
SNode * GetParentSceneNode()
SAnimMap GetAnimations() const
SBody * CreateConeBody(const Ogre::Real &radius, const Ogre::Real &height)
bool GetSceneNodeIsMouseForeground()
virtual void Translate(const Ogre::Vector3 &d, const SNode::NodeTransformSpace &relativeTo=SNode::SO3_PARENT_TS)
Ogre::Vector3 initialScale
Definition SO3NodeScol.h:77
SNode * GetAutoTrackingTarget()
virtual void ResetToInitialPRS()
void DisableAutoTarget()
Ogre::SceneNode * GetOgreSceneNodePointer()
void AttachToParent(SNode *newParentNode)
SBody * nodeBody
Definition SO3NodeScol.h:71
Ogre::Vector3 GetSonsBoundingBox()
void AddAnimation(SAnim *existingAnimation)
Ogre::SceneManager * O3SceneManager
Definition SO3Scene.h:127
const SNodeMap & GetNodeList() const
Definition SO3Scene.cpp:588
Ogre::SceneManager * GetOgreScenePointer()
Definition SO3Scene.cpp:449
SNode * GetRootNode()
Definition SO3Scene.cpp:454
void RemoveAnimation(SAnim *existingAnimation)
SBoneMap GetRootBones()
std::unordered_map< std::string, SBone * > SBoneMap
std::unordered_map< std::string, SNode * > SNodeMap
std::unordered_map< std::string, SAnim * > SAnimMap
STBI_EXTERN unsigned long flags
Definition stb_image.h:1182