T3DSceneComponent.h
Engine/source/T3D/sceneComponent/T3DSceneComponent.h
Classes:
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#ifndef _T3DSCENECOMPONENT_H_ 25#define _T3DSCENECOMPONENT_H_ 26 27#include "T3DTransform.h" 28#include "component/simComponent.h" 29#include "sceneGraph/sceneobject.h" 30 31class T3DSceneClient; 32 33class IRenderable3D 34{ 35public: 36 // TODO: what parameters to use? 37 virtual void Render() = 0; 38}; 39 40class ISolid3D 41{ 42public: 43 virtual Box3F getObjectBox() = 0; 44 virtual Transform3D * getTransform3D() = 0; 45}; 46 47class T3DSceneComponent : public SceneObject, public Transform3D::IDirtyListener 48{ 49 typedef SceneObject Parent; 50 51public: 52 53 T3DSceneComponent() 54 { 55 _transform = new Transform3DInPlace(); 56 _objectBox = new ValueWrapperInterface<Box3F>(); 57 _flags = T3DSceneComponent::Visible | T3DSceneComponent::DirtyObjectBox | T3DSceneComponent::DirtyWorldBox | T3DSceneComponent::UseOwnerObjectType; 58 _visibilityLevel = 1.0f; 59 _objectType = 0; 60 _sceneGroup = NULL; 61 _parentTransformName = NULL; 62 setSceneGroup(NULL); 63 } 64 65 StringTableEntry getSceneGroup() const { return _sceneGroup; } 66 void setSceneGroup(const char * sceneGroup); 67 68 StringTableEntry getParentTransformName() const { return _parentTransformName; } 69 void setParentTransformName(const char * name); 70 71 U32 getObjectType() const { return _objectType; } // TODO: use owner if useowner set 72 void setObjectType(U32 objectTypeMask); 73 74 void setUseOwnerObjectType(bool val) { _SetFlag(T3DSceneComponent::UseOwnerObjectType, val); } 75 bool useOwnerObjectType() const { return _TestFlag(T3DSceneComponent::UseOwnerObjectType); } 76 77 bool isDirtyObjectBox() const { return _TestFlag(T3DSceneComponent::DirtyObjectBox); } 78 void setDirtyObjectBox(bool val); 79 80 bool isDirtyWorldBox() const { return _TestFlag(T3DSceneComponent::DirtyWorldBox); } 81 void setDirtyWorldBox(bool val); 82 83 bool isObjectBoxLocked() const { return _TestFlag(T3DSceneComponent::LockObjectBox); } 84 void setObjectBoxLocked(bool val); 85 86 bool isWorldBoxLocked() const { return _TestFlag(T3DSceneComponent::LockWorldBox); } 87 void setWorldBoxLocked(bool val); 88 89 bool doRenderObjectBounds() const { return _TestFlag(T3DSceneComponent::RenderObjectBounds); } 90 void setRenderObjectBounds(bool val) { _SetFlag(T3DSceneComponent::RenderObjectBounds, val); } 91 92 bool doRenderWorldBounds() const { return _TestFlag(T3DSceneComponent::RenderWorldBounds); } 93 void setRenderWorldBounds(bool val) { _SetFlag(T3DSceneComponent::RenderWorldBounds, val); } 94 95 bool doRenderSubBounds() const { return _TestFlag(T3DSceneComponent::RenderSubBounds); } 96 void setRenderSubBounds(bool val) { _SetFlag(T3DSceneComponent::RenderSubBounds, val); } 97 98 bool isVisible() const { return _TestFlag(T3DSceneComponent::Visible); } 99 void setVisible(bool val) { _SetFlag(T3DSceneComponent::Visible, val); } 100 101 float getVisibilityLevel() const { return _visibilityLevel; } 102 void setVisibilityLevel(float val) { _visibilityLevel = val; } 103 104 Point3F getPosition() const { return _transform->getPosition(); } 105 void setPosition(const Point3F & pos); 106 107 QuatF getRotation() const { return _transform->getRotation(); } 108 void setRotation(const QuatF & rotation); 109 110 Point3F getScale() const { return _transform->getScale(); } 111 void setScale(const Point3F & scale); 112 113 Transform3D * getTransform3D(){ return _transform; } 114 115 void setTransform(const MatrixF & mat); 116 117 Box3F getObjectBox(); 118 Box3F getWorldBox(); 119 120 T3DSceneClient * getSceneClientList() const { return _sceneClientList; } 121 122 void Render(); 123 124 void AddSceneClient(T3DSceneClient * sceneClient); 125 void RemoveClientObject(T3DSceneClient * sceneClient); 126 127 void OnTransformDirty() { setDirtyWorldBox(true); } 128 129protected: 130 131 bool onComponentRegister(SimComponent * owner); 132 void onComponentUnRegister(); 133 134 void registerInterfaces(SimComponent * owner); 135 136 void _ComputeObjectBox(); 137 void _UpdateWorldBox(); 138 void setTransform3D(Transform3D * transform); 139 140 bool _TestFlag(U32 test) const 141 { 142 return (_flags & test) != T3DSceneComponent::None; 143 } 144 145 void _SetFlag(U32 test, bool value) 146 { 147 if (value) 148 _flags |= test; 149 else 150 _flags &= ~test; 151 } 152 153 enum SceneFlags 154 { 155 None = 0, 156 Visible = 1 << 0, 157 DirtyObjectBox = 1 << 1, 158 DirtyWorldBox = 1 << 2, 159 LockObjectBox = 1 << 3, 160 LockWorldBox = 1 << 4, 161 UseOwnerObjectType = 1 << 5, 162 RenderDebug = 1 << 6, 163 RenderObjectBounds = 1 << 7, 164 RenderWorldBounds = 1 << 8, 165 RenderSubBounds = 1 << 9, 166 LastFlag = 1 << 9 167 }; 168 169 Transform3D * _transform; 170 T3DSceneClient * _sceneClientList; 171 ValueWrapperInterface<Box3F> * _objectBox; 172 U32 _flags; 173 float _visibilityLevel; 174 U32 _objectType; 175 StringTableEntry _sceneGroup; 176 StringTableEntry _parentTransformName ; 177}; 178 179#endif // #ifndef _T3DSCENECOMPONENT_H_ 180