mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-12 15:14:35 +00:00
Engine directory for ticket #1
This commit is contained in:
parent
352279af7a
commit
7dbfe6994d
3795 changed files with 1363358 additions and 0 deletions
107
Engine/source/T3D/sceneComponent/T3DSceneClient.cpp
Normal file
107
Engine/source/T3D/sceneComponent/T3DSceneClient.cpp
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "T3DSceneClient.h"
|
||||
|
||||
//---------------------------------------------------
|
||||
// T3DSceneClient
|
||||
//---------------------------------------------------
|
||||
|
||||
void T3DSceneClient::setSceneGroupName(const char * name)
|
||||
{
|
||||
_sceneGroupName = StringTable->insert(name);
|
||||
if (getOwner() != NULL)
|
||||
{
|
||||
if (_sceneGroup != NULL)
|
||||
_sceneGroup->RemoveClientObject(this);
|
||||
_sceneGroup = NULL;
|
||||
|
||||
ValueWrapperInterface<T3DSceneComponent*> * iface = getInterface<ValueWrapperInterface<T3DSceneComponent*> >("sceneComponent", _sceneGroupName);
|
||||
if (iface != NULL)
|
||||
{
|
||||
_sceneGroup = iface->get();
|
||||
_sceneGroup->AddSceneClient(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool T3DSceneClient::onComponentRegister(SimComponent * owner)
|
||||
{
|
||||
if (!Parent::onComponentRegister(owner))
|
||||
return false;
|
||||
|
||||
// lookup scene group and add ourself
|
||||
setSceneGroupName(_sceneGroupName);
|
||||
|
||||
if (_sceneGroupName != NULL && dStricmp(_sceneGroupName, "none") && _sceneGroup == NULL)
|
||||
// tried to add ourself to a scene group but failed, fail to add component
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void T3DSceneClient::registerInterfaces(SimComponent * owner)
|
||||
{
|
||||
Parent::registerInterfaces(owner);
|
||||
registerCachedInterface("sceneClient", NULL, this, new ValueWrapperInterface<T3DSceneClient>());
|
||||
}
|
||||
|
||||
//---------------------------------------------------
|
||||
// T3DSceneClient
|
||||
//---------------------------------------------------
|
||||
|
||||
Box3F T3DSolidSceneClient::getWorldBox()
|
||||
{
|
||||
MatrixF mat = getTransform();
|
||||
Box3F box = _objectBox->get();
|
||||
mat.mul(box);
|
||||
return box;
|
||||
}
|
||||
|
||||
const MatrixF & T3DSolidSceneClient::getTransform()
|
||||
{
|
||||
if (_transform != NULL)
|
||||
return _transform->getWorldMatrix();
|
||||
else if (getSceneGroup() != NULL)
|
||||
return getSceneGroup()->getTransform3D()->getWorldMatrix();
|
||||
else
|
||||
return MatrixF::smIdentity;
|
||||
}
|
||||
|
||||
void T3DSolidSceneClient::setTransform3D(Transform3D * transform)
|
||||
{
|
||||
if (_transform != NULL)
|
||||
_transform->setDirtyListener(NULL);
|
||||
_transform = transform;
|
||||
|
||||
_transform->setDirtyListener(this);
|
||||
OnTransformDirty();
|
||||
}
|
||||
|
||||
void T3DSolidSceneClient::OnTransformDirty()
|
||||
{
|
||||
// TODO: need a way to skip this...a flag, but we don't want to add a bool just for that
|
||||
// reason we might want to skip it is if we have a renderable that orbits an object but always
|
||||
// stays within object box. Want to be able to use that info to skip object box updates.
|
||||
if (getSceneGroup() != NULL)
|
||||
getSceneGroup()->setDirtyObjectBox(true);
|
||||
}
|
||||
93
Engine/source/T3D/sceneComponent/T3DSceneClient.h
Normal file
93
Engine/source/T3D/sceneComponent/T3DSceneClient.h
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _T3DSCENECLIENT_H_
|
||||
#define _T3DSCENECLIENT_H_
|
||||
|
||||
#include "component/simComponent.h"
|
||||
#include "T3DSceneComponent.h"
|
||||
|
||||
class T3DSceneClient : public SimComponent
|
||||
{
|
||||
typedef SimComponent Parent;
|
||||
|
||||
public:
|
||||
T3DSceneClient()
|
||||
{
|
||||
_nextClient = NULL;
|
||||
_sceneGroup = NULL;
|
||||
_sceneGroupName = NULL;
|
||||
_sceneClientName = NULL;
|
||||
}
|
||||
|
||||
T3DSceneClient * getNextSceneClient() { return _nextClient; }
|
||||
// TODO: internal
|
||||
void setNextSceneClient(T3DSceneClient * client) { _nextClient = client; }
|
||||
|
||||
T3DSceneComponent * getSceneGroup() { return _sceneGroup; }
|
||||
|
||||
StringTableEntry getSceneGroupName() { return _sceneGroupName; }
|
||||
void setSceneGroupName(const char * name);
|
||||
|
||||
StringTableEntry getSceneClientName() { return _sceneClientName; }
|
||||
void setSceneClientName(const char * name) { _sceneClientName = StringTable->insert(name); }
|
||||
|
||||
protected:
|
||||
|
||||
bool onComponentRegister(SimComponent * owner);
|
||||
void registerInterfaces(SimComponent * owner);
|
||||
|
||||
T3DSceneClient * _nextClient;
|
||||
T3DSceneComponent * _sceneGroup;
|
||||
StringTableEntry _sceneGroupName;
|
||||
StringTableEntry _sceneClientName;
|
||||
};
|
||||
|
||||
class T3DSolidSceneClient : public T3DSceneClient, public ISolid3D, public Transform3D::IDirtyListener
|
||||
{
|
||||
public:
|
||||
|
||||
T3DSolidSceneClient()
|
||||
{
|
||||
_transform = NULL;
|
||||
_objectBox = new ValueWrapperInterface<Box3F>();
|
||||
}
|
||||
|
||||
Box3F getObjectBox() { return _objectBox->get(); }
|
||||
void setObjectBox(const Box3F & box) { _objectBox->set(box); }
|
||||
Box3F getWorldBox();
|
||||
const MatrixF & getTransform();
|
||||
Transform3D * getTransform3D() { return _transform; }
|
||||
|
||||
void OnTransformDirty();
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
// TODO: internal
|
||||
void setTransform3D(Transform3D * transform);
|
||||
|
||||
Transform3D * _transform;
|
||||
ValueWrapperInterface<Box3F> * _objectBox;
|
||||
};
|
||||
|
||||
#endif // #ifndef _T3DSCENECLIENT_H_
|
||||
289
Engine/source/T3D/sceneComponent/T3DSceneComponent.cpp
Normal file
289
Engine/source/T3D/sceneComponent/T3DSceneComponent.cpp
Normal file
|
|
@ -0,0 +1,289 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "T3DSceneComponent.h"
|
||||
#include "T3DSceneClient.h"
|
||||
|
||||
void T3DSceneComponent::setSceneGroup(const char * sceneGroup)
|
||||
{
|
||||
AssertFatal(getOwner()==NULL, "Changing scene group name after registration will have no effect.");
|
||||
if (sceneGroup == NULL)
|
||||
sceneGroup = StringTable->insert("");
|
||||
_sceneGroup = StringTable->insert(sceneGroup);
|
||||
}
|
||||
|
||||
void T3DSceneComponent::setParentTransformName(const char * name)
|
||||
{
|
||||
_parentTransformName = StringTable->insert(name);
|
||||
if (getOwner() != NULL)
|
||||
{
|
||||
Transform3D * old = _transform->getParentTransform();
|
||||
ValueWrapperInterface<Transform3D*> * iface = NULL;
|
||||
if (_parentTransformName != NULL)
|
||||
iface = getInterface<ValueWrapperInterface<Transform3D*> >("transform3D", _parentTransformName);
|
||||
_transform->setParentTransform(iface == NULL ? NULL : iface->get());
|
||||
if (_transform->getParentTransform() != old)
|
||||
setDirtyWorldBox(true);
|
||||
}
|
||||
}
|
||||
|
||||
void T3DSceneComponent::setObjectType(U32 objectTypeMask)
|
||||
{
|
||||
_objectType = objectTypeMask;
|
||||
setUseOwnerObjectType(true);
|
||||
}
|
||||
|
||||
void T3DSceneComponent::setDirtyObjectBox(bool val)
|
||||
{
|
||||
_SetFlag(T3DSceneComponent::DirtyObjectBox, val);
|
||||
if (val && !isObjectBoxLocked())
|
||||
_ComputeObjectBox();
|
||||
}
|
||||
|
||||
void T3DSceneComponent::setDirtyWorldBox(bool val)
|
||||
{
|
||||
_SetFlag(T3DSceneComponent::DirtyWorldBox, val);
|
||||
if (val && !isWorldBoxLocked())
|
||||
_UpdateWorldBox();
|
||||
}
|
||||
|
||||
void T3DSceneComponent::setObjectBoxLocked(bool val)
|
||||
{
|
||||
_SetFlag(T3DSceneComponent::LockObjectBox, val);
|
||||
if (!val && isDirtyObjectBox())
|
||||
_ComputeObjectBox();
|
||||
}
|
||||
|
||||
void T3DSceneComponent::setWorldBoxLocked(bool val)
|
||||
{
|
||||
_SetFlag(T3DSceneComponent::LockWorldBox, val);
|
||||
if (!val && isDirtyWorldBox())
|
||||
_UpdateWorldBox();
|
||||
}
|
||||
|
||||
void T3DSceneComponent::setPosition(const Point3F & pos)
|
||||
{
|
||||
_transform->setPosition(pos);
|
||||
setDirtyWorldBox(true);
|
||||
}
|
||||
|
||||
void T3DSceneComponent::setRotation(const QuatF & rotation)
|
||||
{
|
||||
_transform->setRotation(rotation);
|
||||
setDirtyWorldBox(true);
|
||||
}
|
||||
|
||||
void T3DSceneComponent::setScale(const Point3F & scale)
|
||||
{
|
||||
_transform->setScale (scale);
|
||||
Parent::setScale(scale);
|
||||
setDirtyWorldBox(true);
|
||||
}
|
||||
|
||||
void T3DSceneComponent::setTransform3D(Transform3D * transform)
|
||||
{
|
||||
if (transform == NULL)
|
||||
// never let it be null
|
||||
return;
|
||||
if (_transform != NULL)
|
||||
delete _transform;
|
||||
_transform = transform;
|
||||
_transform->setDirtyListener(this);
|
||||
}
|
||||
|
||||
void T3DSceneComponent::setTransform(const MatrixF & mat)
|
||||
{
|
||||
_transform->setLocalMatrix(mat);
|
||||
Parent::setTransform(mat);
|
||||
setDirtyWorldBox(true);
|
||||
}
|
||||
|
||||
Box3F T3DSceneComponent::getObjectBox()
|
||||
{
|
||||
if (DirtyObjectBox && !LockObjectBox)
|
||||
_ComputeObjectBox();
|
||||
|
||||
return _objectBox->get();
|
||||
}
|
||||
|
||||
Box3F T3DSceneComponent::getWorldBox()
|
||||
{
|
||||
if (DirtyWorldBox && !LockWorldBox)
|
||||
_UpdateWorldBox();
|
||||
|
||||
MatrixF mat = getTransform3D()->getWorldMatrix();
|
||||
Box3F box = getObjectBox();
|
||||
|
||||
mat.mul(box);
|
||||
return box;
|
||||
}
|
||||
|
||||
void T3DSceneComponent::Render()
|
||||
{
|
||||
if (_sceneClientList == NULL)
|
||||
return;
|
||||
|
||||
PROFILE_SCOPE(T3DSceneComponent_Render);
|
||||
|
||||
GFX->multWorld(_transform->getWorldMatrix());
|
||||
|
||||
if (doRenderObjectBounds())
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
if (doRenderWorldBounds())
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
for (T3DSceneClient * walk = _sceneClientList; walk != NULL; walk = walk->getNextSceneClient())
|
||||
{
|
||||
IRenderable3D * render = dynamic_cast<IRenderable3D*>(walk);
|
||||
if (render != NULL)
|
||||
render->Render();
|
||||
}
|
||||
|
||||
GFX->popWorldMatrix();
|
||||
}
|
||||
|
||||
void T3DSceneComponent::AddSceneClient(T3DSceneClient * sceneClient)
|
||||
{
|
||||
AssertFatal(sceneClient,"Cannot add a NULL scene client");
|
||||
|
||||
// add to the front of the list
|
||||
sceneClient->setNextSceneClient(_sceneClientList);
|
||||
_sceneClientList = sceneClient;
|
||||
|
||||
// extend object box
|
||||
ISolid3D * solid = dynamic_cast<ISolid3D*>(sceneClient);
|
||||
if (solid != NULL)
|
||||
{
|
||||
if (isObjectBoxLocked())
|
||||
setDirtyObjectBox(true);
|
||||
else
|
||||
{
|
||||
Box3F box = solid->getObjectBox();
|
||||
if (solid->getTransform3D() != NULL)
|
||||
{
|
||||
MatrixF mat;
|
||||
solid->getTransform3D()->getObjectMatrix(mat, true);
|
||||
mat.mul(box);
|
||||
}
|
||||
box.extend(_objectBox->get().min);
|
||||
box.extend(_objectBox->get().max);
|
||||
_objectBox->set(box);
|
||||
}
|
||||
|
||||
// policy is that we become parent transform
|
||||
if (solid->getTransform3D() != NULL && solid->getTransform3D()->isChildOf(_transform, true))
|
||||
solid->getTransform3D()->setParentTransform(_transform);
|
||||
}
|
||||
}
|
||||
|
||||
void T3DSceneComponent::RemoveClientObject(T3DSceneClient * sceneClient)
|
||||
{
|
||||
AssertFatal(sceneClient != NULL, "Removing null scene client");
|
||||
if (sceneClient == NULL)
|
||||
return;
|
||||
if (_sceneClientList == sceneClient)
|
||||
_sceneClientList = _sceneClientList->getNextSceneClient();
|
||||
else
|
||||
{
|
||||
T3DSceneClient * walk = _sceneClientList;
|
||||
while (walk->getNextSceneClient() != sceneClient && walk != NULL)
|
||||
walk = walk->getNextSceneClient();
|
||||
if (walk != NULL)
|
||||
walk->setNextSceneClient(sceneClient->getNextSceneClient());
|
||||
}
|
||||
|
||||
if (dynamic_cast<ISolid3D*>(sceneClient))
|
||||
setDirtyObjectBox(true);
|
||||
}
|
||||
|
||||
bool T3DSceneComponent::onComponentRegister(SimComponent * owner)
|
||||
{
|
||||
if (!Parent::onComponentRegister(owner) || !registerObject())
|
||||
return false;
|
||||
|
||||
// Note: was added to scene graph in register object
|
||||
|
||||
setTransform3D(_transform);
|
||||
setParentTransformName(_parentTransformName);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void T3DSceneComponent::onComponentUnRegister()
|
||||
{
|
||||
_sceneClientList = NULL;
|
||||
Parent::onComponentUnRegister();
|
||||
}
|
||||
|
||||
void T3DSceneComponent::registerInterfaces(SimComponent * owner)
|
||||
{
|
||||
Parent::registerInterfaces(owner);
|
||||
|
||||
// TODO: need to figure out the best way to wrap these
|
||||
// we don't need to track these interfaces ourselves -- just create them here
|
||||
ComponentInterface * sceneComponent = new ComponentInterface();
|
||||
ValueWrapperInterface<Transform3D*> * transform = new ValueWrapperInterface<Transform3D*>(_transform);
|
||||
|
||||
registerCachedInterface("sceneComponent", _sceneGroup, owner, sceneComponent);
|
||||
registerCachedInterface("transform3D", _sceneGroup, owner, transform);
|
||||
registerCachedInterface("box", _sceneGroup, this, _objectBox);
|
||||
}
|
||||
|
||||
void T3DSceneComponent::_ComputeObjectBox()
|
||||
{
|
||||
_objectBox->set(Box3F(10E30f, 10E30f, 10E30f, -10E30f, -10E30f, -10E30f));
|
||||
bool gotone = false;
|
||||
for (T3DSceneClient * walk = _sceneClientList; walk != NULL; walk = walk->getNextSceneClient())
|
||||
{
|
||||
ISolid3D * solid = dynamic_cast<ISolid3D*>(walk);
|
||||
if (solid == NULL)
|
||||
continue;
|
||||
|
||||
Box3F box = solid->getObjectBox();
|
||||
if (solid->getTransform3D() != NULL)
|
||||
{
|
||||
MatrixF mat;
|
||||
solid->getTransform3D()->getObjectMatrix(mat, true);
|
||||
mat.mul(box);
|
||||
}
|
||||
box.extend(_objectBox->get().min);
|
||||
box.extend(_objectBox->get().max);
|
||||
_objectBox->set(box);
|
||||
gotone = true;
|
||||
}
|
||||
if (!gotone)
|
||||
_objectBox->set(Box3F());
|
||||
|
||||
setDirtyObjectBox(false);
|
||||
setDirtyWorldBox(true);
|
||||
}
|
||||
|
||||
void T3DSceneComponent::_UpdateWorldBox()
|
||||
{
|
||||
setDirtyWorldBox(false);
|
||||
// TODO:
|
||||
// T3DSceneGraph.Instance.UpdateObject(this);
|
||||
}
|
||||
178
Engine/source/T3D/sceneComponent/T3DSceneComponent.h
Normal file
178
Engine/source/T3D/sceneComponent/T3DSceneComponent.h
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _T3DSCENECOMPONENT_H_
|
||||
#define _T3DSCENECOMPONENT_H_
|
||||
|
||||
#include "T3DTransform.h"
|
||||
#include "component/simComponent.h"
|
||||
#include "sceneGraph/sceneobject.h"
|
||||
|
||||
class T3DSceneClient;
|
||||
|
||||
class IRenderable3D
|
||||
{
|
||||
public:
|
||||
// TODO: what parameters to use?
|
||||
virtual void Render() = 0;
|
||||
};
|
||||
|
||||
class ISolid3D
|
||||
{
|
||||
public:
|
||||
virtual Box3F getObjectBox() = 0;
|
||||
virtual Transform3D * getTransform3D() = 0;
|
||||
};
|
||||
|
||||
class T3DSceneComponent : public SceneObject, public Transform3D::IDirtyListener
|
||||
{
|
||||
typedef SceneObject Parent;
|
||||
|
||||
public:
|
||||
|
||||
T3DSceneComponent()
|
||||
{
|
||||
_transform = new Transform3DInPlace();
|
||||
_objectBox = new ValueWrapperInterface<Box3F>();
|
||||
_flags = T3DSceneComponent::Visible | T3DSceneComponent::DirtyObjectBox | T3DSceneComponent::DirtyWorldBox | T3DSceneComponent::UseOwnerObjectType;
|
||||
_visibilityLevel = 1.0f;
|
||||
_objectType = 0;
|
||||
_sceneGroup = NULL;
|
||||
_parentTransformName = NULL;
|
||||
setSceneGroup(NULL);
|
||||
}
|
||||
|
||||
StringTableEntry getSceneGroup() const { return _sceneGroup; }
|
||||
void setSceneGroup(const char * sceneGroup);
|
||||
|
||||
StringTableEntry getParentTransformName() const { return _parentTransformName; }
|
||||
void setParentTransformName(const char * name);
|
||||
|
||||
U32 getObjectType() const { return _objectType; } // TODO: use owner if useowner set
|
||||
void setObjectType(U32 objectTypeMask);
|
||||
|
||||
void setUseOwnerObjectType(bool val) { _SetFlag(T3DSceneComponent::UseOwnerObjectType, val); }
|
||||
bool useOwnerObjectType() const { return _TestFlag(T3DSceneComponent::UseOwnerObjectType); }
|
||||
|
||||
bool isDirtyObjectBox() const { return _TestFlag(T3DSceneComponent::DirtyObjectBox); }
|
||||
void setDirtyObjectBox(bool val);
|
||||
|
||||
bool isDirtyWorldBox() const { return _TestFlag(T3DSceneComponent::DirtyWorldBox); }
|
||||
void setDirtyWorldBox(bool val);
|
||||
|
||||
bool isObjectBoxLocked() const { return _TestFlag(T3DSceneComponent::LockObjectBox); }
|
||||
void setObjectBoxLocked(bool val);
|
||||
|
||||
bool isWorldBoxLocked() const { return _TestFlag(T3DSceneComponent::LockWorldBox); }
|
||||
void setWorldBoxLocked(bool val);
|
||||
|
||||
bool doRenderObjectBounds() const { return _TestFlag(T3DSceneComponent::RenderObjectBounds); }
|
||||
void setRenderObjectBounds(bool val) { _SetFlag(T3DSceneComponent::RenderObjectBounds, val); }
|
||||
|
||||
bool doRenderWorldBounds() const { return _TestFlag(T3DSceneComponent::RenderWorldBounds); }
|
||||
void setRenderWorldBounds(bool val) { _SetFlag(T3DSceneComponent::RenderWorldBounds, val); }
|
||||
|
||||
bool doRenderSubBounds() const { return _TestFlag(T3DSceneComponent::RenderSubBounds); }
|
||||
void setRenderSubBounds(bool val) { _SetFlag(T3DSceneComponent::RenderSubBounds, val); }
|
||||
|
||||
bool isVisible() const { return _TestFlag(T3DSceneComponent::Visible); }
|
||||
void setVisible(bool val) { _SetFlag(T3DSceneComponent::Visible, val); }
|
||||
|
||||
float getVisibilityLevel() const { return _visibilityLevel; }
|
||||
void setVisibilityLevel(float val) { _visibilityLevel = val; }
|
||||
|
||||
Point3F getPosition() const { return _transform->getPosition(); }
|
||||
void setPosition(const Point3F & pos);
|
||||
|
||||
QuatF getRotation() const { return _transform->getRotation(); }
|
||||
void setRotation(const QuatF & rotation);
|
||||
|
||||
Point3F getScale() const { return _transform->getScale(); }
|
||||
void setScale(const Point3F & scale);
|
||||
|
||||
Transform3D * getTransform3D(){ return _transform; }
|
||||
|
||||
void setTransform(const MatrixF & mat);
|
||||
|
||||
Box3F getObjectBox();
|
||||
Box3F getWorldBox();
|
||||
|
||||
T3DSceneClient * getSceneClientList() const { return _sceneClientList; }
|
||||
|
||||
void Render();
|
||||
|
||||
void AddSceneClient(T3DSceneClient * sceneClient);
|
||||
void RemoveClientObject(T3DSceneClient * sceneClient);
|
||||
|
||||
void OnTransformDirty() { setDirtyWorldBox(true); }
|
||||
|
||||
protected:
|
||||
|
||||
bool onComponentRegister(SimComponent * owner);
|
||||
void onComponentUnRegister();
|
||||
|
||||
void registerInterfaces(SimComponent * owner);
|
||||
|
||||
void _ComputeObjectBox();
|
||||
void _UpdateWorldBox();
|
||||
void setTransform3D(Transform3D * transform);
|
||||
|
||||
bool _TestFlag(U32 test) const
|
||||
{
|
||||
return (_flags & test) != T3DSceneComponent::None;
|
||||
}
|
||||
|
||||
void _SetFlag(U32 test, bool value)
|
||||
{
|
||||
if (value)
|
||||
_flags |= test;
|
||||
else
|
||||
_flags &= ~test;
|
||||
}
|
||||
|
||||
enum SceneFlags
|
||||
{
|
||||
None = 0,
|
||||
Visible = 1 << 0,
|
||||
DirtyObjectBox = 1 << 1,
|
||||
DirtyWorldBox = 1 << 2,
|
||||
LockObjectBox = 1 << 3,
|
||||
LockWorldBox = 1 << 4,
|
||||
UseOwnerObjectType = 1 << 5,
|
||||
RenderDebug = 1 << 6,
|
||||
RenderObjectBounds = 1 << 7,
|
||||
RenderWorldBounds = 1 << 8,
|
||||
RenderSubBounds = 1 << 9,
|
||||
LastFlag = 1 << 9
|
||||
};
|
||||
|
||||
Transform3D * _transform;
|
||||
T3DSceneClient * _sceneClientList;
|
||||
ValueWrapperInterface<Box3F> * _objectBox;
|
||||
U32 _flags;
|
||||
float _visibilityLevel;
|
||||
U32 _objectType;
|
||||
StringTableEntry _sceneGroup;
|
||||
StringTableEntry _parentTransformName ;
|
||||
};
|
||||
|
||||
#endif // #ifndef _T3DSCENECOMPONENT_H_
|
||||
386
Engine/source/T3D/sceneComponent/T3DTransform.cpp
Normal file
386
Engine/source/T3D/sceneComponent/T3DTransform.cpp
Normal file
|
|
@ -0,0 +1,386 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "T3DTransform.h"
|
||||
#include "math/mPoint.h"
|
||||
#include "math/mQuat.h"
|
||||
|
||||
//---------------------------------------------------------
|
||||
// T3DTransform
|
||||
//---------------------------------------------------------
|
||||
|
||||
void Transform3D::setParentTransform(Transform3D * parent)
|
||||
{
|
||||
if (_parentTransform == parent)
|
||||
return;
|
||||
_flags |= Transform3D::ParentDirty;
|
||||
_parentTransform = parent;
|
||||
if (_dirtyListener != NULL)
|
||||
_dirtyListener->onTransformDirty();
|
||||
}
|
||||
|
||||
bool Transform3D::hasObjectScale() const
|
||||
{
|
||||
if (hasLocalScale())
|
||||
return true;
|
||||
|
||||
// check all parent transforms except last for scale
|
||||
Transform3D * walk = _parentTransform;
|
||||
while (walk != NULL && walk->_parentTransform != NULL)
|
||||
{
|
||||
if (walk->hasLocalScale())
|
||||
return true;
|
||||
walk = walk->getParentTransform();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Transform3D::hasWorldScale() const
|
||||
{
|
||||
if (hasLocalScale())
|
||||
return true;
|
||||
|
||||
// check all parent transforms for scale
|
||||
Transform3D * walk = _parentTransform;
|
||||
while (walk != NULL)
|
||||
{
|
||||
if (walk->hasLocalScale())
|
||||
return true;
|
||||
walk = walk->getParentTransform();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Transform3D::setWorldMatrix(const MatrixF & world)
|
||||
{
|
||||
if (_parentTransform != NULL)
|
||||
{
|
||||
MatrixF parentMatrix;
|
||||
_parentTransform->getWorldMatrix(parentMatrix, true);
|
||||
MatrixF parentMatrixInv = parentMatrix;
|
||||
parentMatrixInv.inverse();
|
||||
MatrixF localMat;
|
||||
localMat = parentMatrixInv * world;
|
||||
setLocalMatrix(localMat);
|
||||
}
|
||||
else
|
||||
setLocalMatrix(world);
|
||||
}
|
||||
|
||||
void Transform3D::setObjectMatrix(const MatrixF & objMatrix)
|
||||
{
|
||||
if (_parentTransform != NULL)
|
||||
{
|
||||
MatrixF parentMatrix;
|
||||
_parentTransform->getObjectMatrix(parentMatrix, true);
|
||||
MatrixF parentMatrixInv = parentMatrix;
|
||||
parentMatrixInv.inverse();
|
||||
MatrixF localMat;
|
||||
localMat = parentMatrixInv * objMatrix;
|
||||
setLocalMatrix(localMat);
|
||||
}
|
||||
else
|
||||
setLocalMatrix(objMatrix);
|
||||
}
|
||||
|
||||
bool Transform3D::isChildOf(Transform3D * parent, bool recursive) const
|
||||
{
|
||||
if (_parentTransform != NULL)
|
||||
{
|
||||
if (_parentTransform == parent)
|
||||
return true;
|
||||
else if (recursive)
|
||||
return _parentTransform->isChildOf(parent, true);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// Transform3DInPlace
|
||||
//---------------------------------------------------------
|
||||
|
||||
Point3F Transform3DInPlace::getPosition() const
|
||||
{
|
||||
return _position;
|
||||
}
|
||||
|
||||
void Transform3DInPlace::setPosition(const Point3F & position)
|
||||
{
|
||||
_position = position;
|
||||
_flags |= Transform3D::LocalPositionDirty;
|
||||
if (_dirtyListener != NULL)
|
||||
_dirtyListener->onTransformDirty();
|
||||
}
|
||||
|
||||
QuatF Transform3DInPlace::getRotation() const
|
||||
{
|
||||
return _rotation;
|
||||
}
|
||||
|
||||
void Transform3DInPlace::setRotation(const QuatF & rotation)
|
||||
{
|
||||
_rotation = rotation;
|
||||
_flags |= Transform3D::LocalRotationDirty;
|
||||
if (_dirtyListener != NULL)
|
||||
_dirtyListener->onTransformDirty();
|
||||
}
|
||||
|
||||
Point3F Transform3DInPlace::getScale() const
|
||||
{
|
||||
return _scale;
|
||||
}
|
||||
|
||||
void Transform3DInPlace::setScale(const Point3F & scale)
|
||||
{
|
||||
_scale = scale;
|
||||
_flags |= Transform3D::LocalScaleDirty;
|
||||
if (_dirtyListener != NULL)
|
||||
_dirtyListener->onTransformDirty();
|
||||
}
|
||||
|
||||
void Transform3DInPlace::getWorldMatrix(MatrixF & worldMat, bool includeLocalScale) const
|
||||
{
|
||||
if (_parentTransform == NULL)
|
||||
getLocalMatrix(worldMat, includeLocalScale);
|
||||
else
|
||||
{
|
||||
MatrixF localMat, parentMat;
|
||||
getLocalMatrix(localMat, includeLocalScale);
|
||||
_parentTransform->getWorldMatrix(parentMat, true);
|
||||
worldMat = parentMat * localMat;
|
||||
}
|
||||
}
|
||||
|
||||
void Transform3DInPlace::getObjectMatrix(MatrixF & objectMat, bool includeLocalScale) const
|
||||
{
|
||||
if (_parentTransform == NULL)
|
||||
objectMat = MatrixF::smIdentity;
|
||||
else if (_parentTransform->getParentTransform() == NULL)
|
||||
getLocalMatrix(objectMat, includeLocalScale);
|
||||
else
|
||||
{
|
||||
MatrixF localMat, parentMat;
|
||||
getLocalMatrix(localMat, includeLocalScale);
|
||||
_parentTransform->getObjectMatrix(parentMat, true);
|
||||
objectMat = parentMat * localMat;
|
||||
}
|
||||
}
|
||||
|
||||
void Transform3DInPlace::getLocalMatrix(MatrixF & localMat, bool includeLocalScale) const
|
||||
{
|
||||
_rotation.setMatrix(&localMat);
|
||||
localMat.setColumn(3,_position);
|
||||
if (includeLocalScale)
|
||||
localMat.scale(_scale);
|
||||
}
|
||||
|
||||
void Transform3DInPlace::setLocalMatrix(const MatrixF & localMat)
|
||||
{
|
||||
_rotation.set(localMat);
|
||||
_position = localMat.getPosition();
|
||||
_scale = localMat.getScale();
|
||||
_flags |= Transform3D::LocalScaleDirty | Transform3D::LocalRotationDirty | Transform3D::LocalPositionDirty;
|
||||
if (_dirtyListener != NULL)
|
||||
_dirtyListener->onTransformDirty();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// TSTransform3D
|
||||
//---------------------------------------------------------
|
||||
|
||||
TSTransform3D::TSTransform3D(TSShapeInstance * si, S32 nodeIndex)
|
||||
{
|
||||
_shapeInstance = si;
|
||||
_nodeIndex = nodeIndex;
|
||||
AssertFatal(_nodeIndex >= 0 && _nodeIndex < _shapeInstance->mNodeTransforms.size(), "TSTransform3D nodeIndex out of range");
|
||||
}
|
||||
|
||||
Point3F TSTransform3D::getPosition() const
|
||||
{
|
||||
if (!doHandleLocal())
|
||||
{
|
||||
MatrixF mat;
|
||||
return getTSLocal(mat).getPosition();
|
||||
}
|
||||
return _position;
|
||||
}
|
||||
|
||||
void TSTransform3D::setPosition(const Point3F & position)
|
||||
{
|
||||
setHandleLocal(true);
|
||||
_position = position;
|
||||
_flags |= Transform3D::LocalPositionDirty;
|
||||
if (_dirtyListener != NULL)
|
||||
_dirtyListener->onTransformDirty();
|
||||
}
|
||||
|
||||
QuatF TSTransform3D::getRotation() const
|
||||
{
|
||||
if (!doHandleLocal())
|
||||
{
|
||||
MatrixF mat;
|
||||
return QuatF(getTSLocal(mat));
|
||||
}
|
||||
return _rotation;
|
||||
}
|
||||
void TSTransform3D::setRotation(const QuatF & rotation)
|
||||
{
|
||||
setHandleLocal(true);
|
||||
_rotation = rotation;
|
||||
_flags |= Transform3D::LocalRotationDirty;
|
||||
if (_dirtyListener != NULL)
|
||||
_dirtyListener->onTransformDirty();
|
||||
}
|
||||
|
||||
Point3F TSTransform3D::getScale() const
|
||||
{
|
||||
if (!doHandleLocal())
|
||||
{
|
||||
MatrixF mat;
|
||||
return getTSLocal(mat).getScale();
|
||||
}
|
||||
return _scale;
|
||||
}
|
||||
void TSTransform3D::setScale(const Point3F & scale)
|
||||
{
|
||||
setHandleLocal(true);
|
||||
_scale = scale;
|
||||
_flags |= Transform3D::LocalScaleDirty;
|
||||
if (_dirtyListener != NULL)
|
||||
_dirtyListener->onTransformDirty();
|
||||
}
|
||||
|
||||
void TSTransform3D::getWorldMatrix(MatrixF & worldMat, bool includeLocalScale) const
|
||||
{
|
||||
_shapeInstance->animate();
|
||||
if (_parentTransform == NULL)
|
||||
{
|
||||
worldMat = _shapeInstance->mNodeTransforms[_nodeIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
MatrixF parentMat;
|
||||
_parentTransform->getWorldMatrix(parentMat, true);
|
||||
worldMat = parentMat * _shapeInstance->mNodeTransforms[_nodeIndex];
|
||||
}
|
||||
}
|
||||
|
||||
void TSTransform3D::getObjectMatrix(MatrixF & objectMat, bool includeLocalScale) const
|
||||
{
|
||||
if (_parentTransform == NULL)
|
||||
objectMat = MatrixF::smIdentity;
|
||||
else if (_parentTransform->getParentTransform() == NULL)
|
||||
{
|
||||
_shapeInstance->animate();
|
||||
objectMat = _shapeInstance->mNodeTransforms[_nodeIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
_shapeInstance->animate();
|
||||
|
||||
MatrixF parentMat;
|
||||
_parentTransform->getObjectMatrix(parentMat, true);
|
||||
objectMat = parentMat * _shapeInstance->mNodeTransforms[_nodeIndex];
|
||||
}
|
||||
}
|
||||
|
||||
void TSTransform3D::getLocalMatrix(MatrixF & localMat, bool includeLocalScale) const
|
||||
{
|
||||
if (doHandleLocal())
|
||||
{
|
||||
_rotation.setMatrix(&localMat);
|
||||
localMat.setPosition(_position);
|
||||
if (includeLocalScale)
|
||||
localMat.scale(_scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
_shapeInstance->animate();
|
||||
localMat = _shapeInstance->mNodeTransforms[_nodeIndex];
|
||||
if (!includeLocalScale && (_flags & Transform3D::LocalHasScale) != Transform3D::None)
|
||||
{
|
||||
// reverse any scale on matrix -- this is a inconvenient, but not a common case
|
||||
Point3F scale = localMat.getScale();
|
||||
scale.x = 1.0f / scale.x;
|
||||
scale.y = 1.0f / scale.y;
|
||||
scale.z = 1.0f / scale.z;
|
||||
localMat.scale(scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TSTransform3D::setLocalMatrix(const MatrixF & localMatrix)
|
||||
{
|
||||
setHandleLocal(true);
|
||||
_position = localMatrix.getPosition();
|
||||
_rotation.set(localMatrix);
|
||||
_scale = localMatrix.getScale();
|
||||
_flags |= Transform3D::LocalScaleDirty | Transform3D::LocalRotationDirty | Transform3D::LocalPositionDirty;
|
||||
if (_dirtyListener != NULL)
|
||||
_dirtyListener->onTransformDirty();
|
||||
}
|
||||
|
||||
MatrixF & TSTransform3D::getTSLocal(MatrixF & mat) const
|
||||
{
|
||||
_shapeInstance->animate();
|
||||
|
||||
// if node has no parent, easy enough to just grab the matrix of the node
|
||||
int parentIdx = _shapeInstance->getShape()->nodes[_nodeIndex].parentIndex;
|
||||
if (parentIdx < 0)
|
||||
{
|
||||
return _shapeInstance->mNodeTransforms[_nodeIndex];
|
||||
}
|
||||
|
||||
// has parent, local is transform from this node to parent so get local matrix the hard way
|
||||
MatrixF parentMat = _shapeInstance->mNodeTransforms[parentIdx];
|
||||
parentMat.inverse();
|
||||
mat = parentMat * _shapeInstance->mNodeTransforms[_nodeIndex];
|
||||
return mat;
|
||||
}
|
||||
|
||||
void TSTransform3D::setHandleLocal(bool handleLocal)
|
||||
{
|
||||
if (handleLocal == doHandleLocal())
|
||||
return;
|
||||
|
||||
if (handleLocal)
|
||||
{
|
||||
_position = getPosition();
|
||||
_rotation = getRotation();
|
||||
_scale = getScale();
|
||||
_shapeInstance->setNodeAnimationState(_nodeIndex, 0, this);
|
||||
}
|
||||
else
|
||||
_shapeInstance->setNodeAnimationState(_nodeIndex, 0);
|
||||
_flags ^= TSTransform3D::HandleLocal;
|
||||
}
|
||||
|
||||
void TSTransform3D::setNodeTransform(TSShapeInstance * si, S32 nodeIndex, MatrixF & localTransform)
|
||||
{
|
||||
AssertFatal(si == _shapeInstance,"TSTransform3D hooked up to wrong shape.");
|
||||
getLocalMatrix(localTransform, true);
|
||||
}
|
||||
218
Engine/source/T3D/sceneComponent/T3DTransform.h
Normal file
218
Engine/source/T3D/sceneComponent/T3DTransform.h
Normal file
|
|
@ -0,0 +1,218 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _T3DTRANSFORM_H_
|
||||
#define _T3DTRANSFORM_H_
|
||||
|
||||
#include "ts/tsShapeInstance.h"
|
||||
#include "math/mMatrix.h"
|
||||
|
||||
//---------------------------------------------------------
|
||||
// T3DTransform
|
||||
//---------------------------------------------------------
|
||||
|
||||
class Transform3D
|
||||
{
|
||||
public:
|
||||
|
||||
class IDirtyListener
|
||||
{
|
||||
public:
|
||||
virtual void onTransformDirty() = 0;
|
||||
};
|
||||
|
||||
// local/object/world matrix access
|
||||
|
||||
void setWorldMatrix(const MatrixF & world);
|
||||
void setObjectMatrix(const MatrixF & objMatrix);
|
||||
virtual void setLocalMatrix(const MatrixF & localMatrix) = 0;
|
||||
|
||||
virtual void getWorldMatrix(MatrixF & worldMatrix, bool includeLocalScale) const = 0;
|
||||
virtual void getObjectMatrix(MatrixF & objectMatrix, bool includeLocalScale) const = 0;
|
||||
virtual void getLocalMatrix(MatrixF & localMatrix, bool includeLocalScale) const = 0;
|
||||
|
||||
MatrixF getWorldMatrix() const
|
||||
{
|
||||
MatrixF world;
|
||||
getWorldMatrix(world, true);
|
||||
return world;
|
||||
}
|
||||
|
||||
MatrixF getObjectMatrix() const
|
||||
{
|
||||
MatrixF objMatrix;
|
||||
getObjectMatrix(objMatrix, true);
|
||||
return objMatrix;
|
||||
}
|
||||
|
||||
MatrixF getLocalMatrix() const
|
||||
{
|
||||
MatrixF loc;
|
||||
getLocalMatrix(loc, true);
|
||||
return loc;
|
||||
}
|
||||
|
||||
// local position/rotation/scale
|
||||
|
||||
virtual Point3F getPosition() const = 0;
|
||||
virtual void setPosition(const Point3F & position) = 0;
|
||||
|
||||
virtual QuatF getRotation() const = 0;
|
||||
virtual void setRotation(const QuatF & rotation) = 0;
|
||||
|
||||
virtual Point3F getScale() const = 0;
|
||||
virtual void setScale(const Point3F & scale) = 0;
|
||||
|
||||
// scale tests
|
||||
|
||||
bool hasLocalScale() const
|
||||
{
|
||||
return (_flags & Transform3D::LocalHasScale) != Transform3D::None;
|
||||
}
|
||||
|
||||
bool hasObjectScale() const;
|
||||
bool hasWorldScale() const;
|
||||
|
||||
// parent/child methods
|
||||
|
||||
Transform3D * getParentTransform() const
|
||||
{
|
||||
return _parentTransform;
|
||||
}
|
||||
|
||||
void setParentTransform(Transform3D * parent);
|
||||
|
||||
IDirtyListener * getDirtyListener() const
|
||||
{
|
||||
return _dirtyListener;
|
||||
}
|
||||
|
||||
void setDirtyListener(IDirtyListener * dirtyListener)
|
||||
{
|
||||
_dirtyListener = dirtyListener;
|
||||
}
|
||||
|
||||
bool isChildOf(Transform3D * parent, bool recursive) const;
|
||||
|
||||
protected:
|
||||
|
||||
enum TransformFlags
|
||||
{
|
||||
None = 0,
|
||||
LocalHasScale = 1 << 0,
|
||||
LocalPositionDirty = 1 << 1,
|
||||
LocalRotationDirty = 1 << 2,
|
||||
LocalScaleDirty = 1 << 3,
|
||||
LocalDirty = LocalPositionDirty | LocalRotationDirty | LocalScaleDirty,
|
||||
ParentDirty = 1 << 4,
|
||||
LastFlag = 1 << 4
|
||||
};
|
||||
|
||||
Transform3D * _parentTransform;
|
||||
IDirtyListener * _dirtyListener;
|
||||
U32 _flags;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------
|
||||
// Transform3DInPlace
|
||||
//---------------------------------------------------------
|
||||
|
||||
class Transform3DInPlace : public Transform3D
|
||||
{
|
||||
public:
|
||||
|
||||
Transform3DInPlace() : _position(0,0,0), _rotation(0,0,0,1), _scale(1,1,1)
|
||||
{
|
||||
}
|
||||
|
||||
Point3F getPosition() const;
|
||||
void setPosition(const Point3F & position);
|
||||
|
||||
QuatF getRotation() const;
|
||||
void setRotation(const QuatF & rotation);
|
||||
|
||||
Point3F getScale() const;
|
||||
void setScale(const Point3F & scale);
|
||||
|
||||
void getWorldMatrix(MatrixF & worldMat, bool includeLocalScale) const;
|
||||
void getObjectMatrix(MatrixF & objectMat, bool includeLocalScale) const;
|
||||
void getLocalMatrix(MatrixF & localMat, bool includeLocalScale) const;
|
||||
void setLocalMatrix(const MatrixF & localMat);
|
||||
|
||||
protected:
|
||||
|
||||
Point3F _position;
|
||||
QuatF _rotation;
|
||||
Point3F _scale;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------
|
||||
// TSTransform3D
|
||||
//---------------------------------------------------------
|
||||
|
||||
class TSTransform3D : public Transform3D, public TSCallback
|
||||
{
|
||||
public:
|
||||
TSTransform3D(TSShapeInstance * si, S32 nodeIndex);
|
||||
|
||||
Point3F getPosition() const;
|
||||
void setPosition(const Point3F & position);
|
||||
|
||||
QuatF getRotation() const;
|
||||
void setRotation(const QuatF & rotation);
|
||||
|
||||
Point3F getScale() const;
|
||||
void setScale(const Point3F & scale);
|
||||
|
||||
void getWorldMatrix(MatrixF & worldMat, bool includeLocalScale) const;
|
||||
void getObjectMatrix(MatrixF & objectMat, bool includeLocalScale) const;
|
||||
void getLocalMatrix(MatrixF & localMat, bool includeLocalScale) const;
|
||||
void setLocalMatrix(const MatrixF & localMatrix);
|
||||
|
||||
// Define TSCallback interface
|
||||
void setNodeTransform(TSShapeInstance * si, S32 nodeIndex, MatrixF & localTransform);
|
||||
|
||||
protected:
|
||||
|
||||
enum TSTransformFlags
|
||||
{
|
||||
HandleLocal = Transform3D::LastFlag << 1,
|
||||
LastFlag = Transform3D::LastFlag << 1
|
||||
};
|
||||
|
||||
bool doHandleLocal() const
|
||||
{
|
||||
return (_flags & (TransformFlags)TSTransform3D::HandleLocal) != Transform3D::None;
|
||||
}
|
||||
|
||||
void setHandleLocal(bool handleLocal);
|
||||
MatrixF & getTSLocal(MatrixF & mat) const;
|
||||
|
||||
TSShapeInstance * _shapeInstance;
|
||||
int _nodeIndex;
|
||||
|
||||
Point3F _position;
|
||||
QuatF _rotation;
|
||||
Point3F _scale;
|
||||
};
|
||||
|
||||
#endif // _T3DTRANSFORM_H_
|
||||
Loading…
Add table
Add a link
Reference in a new issue