T3DSceneClient.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "T3DSceneClient.h"
  23. //---------------------------------------------------
  24. // T3DSceneClient
  25. //---------------------------------------------------
  26. void T3DSceneClient::setSceneGroupName(const char * name)
  27. {
  28. _sceneGroupName = StringTable->insert(name);
  29. if (getOwner() != NULL)
  30. {
  31. if (_sceneGroup != NULL)
  32. _sceneGroup->RemoveClientObject(this);
  33. _sceneGroup = NULL;
  34. ValueWrapperInterface<T3DSceneComponent*> * iface = getInterface<ValueWrapperInterface<T3DSceneComponent*> >("sceneComponent", _sceneGroupName);
  35. if (iface != NULL)
  36. {
  37. _sceneGroup = iface->get();
  38. _sceneGroup->AddSceneClient(this);
  39. }
  40. }
  41. }
  42. bool T3DSceneClient::onComponentRegister(SimComponent * owner)
  43. {
  44. if (!Parent::onComponentRegister(owner))
  45. return false;
  46. // lookup scene group and add ourself
  47. setSceneGroupName(_sceneGroupName);
  48. if (_sceneGroupName != NULL && dStricmp(_sceneGroupName, "none") && _sceneGroup == NULL)
  49. // tried to add ourself to a scene group but failed, fail to add component
  50. return false;
  51. return true;
  52. }
  53. void T3DSceneClient::registerInterfaces(SimComponent * owner)
  54. {
  55. Parent::registerInterfaces(owner);
  56. registerCachedInterface("sceneClient", NULL, this, new ValueWrapperInterface<T3DSceneClient>());
  57. }
  58. //---------------------------------------------------
  59. // T3DSceneClient
  60. //---------------------------------------------------
  61. Box3F T3DSolidSceneClient::getWorldBox()
  62. {
  63. MatrixF mat = getTransform();
  64. Box3F box = _objectBox->get();
  65. mat.mul(box);
  66. return box;
  67. }
  68. const MatrixF & T3DSolidSceneClient::getTransform()
  69. {
  70. if (_transform != NULL)
  71. return _transform->getWorldMatrix();
  72. else if (getSceneGroup() != NULL)
  73. return getSceneGroup()->getTransform3D()->getWorldMatrix();
  74. else
  75. return MatrixF::smIdentity;
  76. }
  77. void T3DSolidSceneClient::setTransform3D(Transform3D * transform)
  78. {
  79. if (_transform != NULL)
  80. _transform->setDirtyListener(NULL);
  81. _transform = transform;
  82. _transform->setDirtyListener(this);
  83. OnTransformDirty();
  84. }
  85. void T3DSolidSceneClient::OnTransformDirty()
  86. {
  87. // TODO: need a way to skip this...a flag, but we don't want to add a bool just for that
  88. // reason we might want to skip it is if we have a renderable that orbits an object but always
  89. // stays within object box. Want to be able to use that info to skip object box updates.
  90. if (getSceneGroup() != NULL)
  91. getSceneGroup()->setDirtyObjectBox(true);
  92. }