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