Skip to content

Commit

Permalink
Added ability to set world position and rotation to SceneObjects
Browse files Browse the repository at this point in the history
  • Loading branch information
BearishSun committed Jul 5, 2014
1 parent 7912eda commit 2e6a197
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 11 deletions.
16 changes: 13 additions & 3 deletions BansheeCore/Include/BsSceneObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,22 @@ namespace BansheeEngine
/************************************************************************/
public:
/**
* @brief Sets local position of the object.
* @brief Sets the local position of the object.
*/
void setPosition(const Vector3& position);

/**
* @brief Gets local position of the object.
* @brief Gets the local position of the object.
*/
const Vector3& getPosition() const { return mPosition; }

/**
* @brief Gets world position of the object.
* @brief Sets the world position of the object.
*/
void setWorldPosition(const Vector3& position);

/**
* @brief Gets the world position of the object.
*
* @note Performance warning: This might involve updating the transforms if the transform is dirty.
*/
Expand All @@ -72,6 +77,11 @@ namespace BansheeEngine
*/
const Quaternion& getRotation() const { return mRotation; }

/**
* @brief Sets the world rotation of the object.
*/
void setWorldRotation(const Quaternion& rotation);

/**
* @brief Gets world rotation of the object.
*
Expand Down
35 changes: 34 additions & 1 deletion BansheeCore/Source/BsSceneObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,39 @@ namespace BansheeEngine
markTfrmDirty();
}

void SceneObject::setWorldPosition(const Vector3& position)
{
if (mParent != nullptr)
{
Vector3 invScale = mParent->getWorldScale();
if (invScale.x != 0) invScale.x = 1.0f / invScale.x;
if (invScale.y != 0) invScale.y = 1.0f / invScale.y;
if (invScale.z != 0) invScale.z = 1.0f / invScale.z;

Quaternion invRotation = mParent->getWorldRotation().inverse();

mPosition = invRotation.rotate(position - mParent->getWorldPosition()) * invScale;
}
else
mPosition = position;

markTfrmDirty();
}

void SceneObject::setWorldRotation(const Quaternion& rotation)
{
if (mParent != nullptr)
{
Quaternion invRotation = mParent->getWorldRotation().inverse();

mRotation = invRotation * rotation;
}
else
mRotation = rotation;

markTfrmDirty();
}

const Vector3& SceneObject::getWorldPosition() const
{
if(!mIsCachedWorldTfrmUpToDate)
Expand Down Expand Up @@ -262,7 +295,7 @@ namespace BansheeEngine

// Update scale
const Vector3& parentScale = mParent->getWorldScale();
// Scale own position by parent scale, NB just combine
// Scale own position by parent scale, just combine
// as equivalent axes, no shearing
mWorldScale = parentScale * mScale;

Expand Down
2 changes: 0 additions & 2 deletions BansheeD3D9RenderSystem/Source/BsD3D9RenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2005,8 +2005,6 @@ namespace BansheeEngine
// no integer params allowed
rsc->setFragmentProgramConstantIntCount(0);
// float params, always 4D
// NB in ps_1_x these are actually stored as fixed point values,
// but they are entered as floats
rsc->setFragmentProgramConstantFloatCount(8);
break;
case 2:
Expand Down
1 change: 0 additions & 1 deletion BansheeD3D9RenderSystem/Source/BsD3D9RenderWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ namespace BansheeEngine


// Register the window class
// NB allow 4 bytes of window data for D3D9RenderWindow pointer
WNDCLASS wc = { 0, PlatformWndProc::_win32WndProc, 0, 0, hInst,
LoadIcon(0, IDI_APPLICATION), LoadCursor(NULL, IDC_ARROW),
(HBRUSH)GetStockObject(BLACK_BRUSH), 0, "D3D9Wnd" };
Expand Down
4 changes: 0 additions & 4 deletions Polish.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ Polish TODO:
- Test checking out source and extracting dependencies and see if it compiles
- Test compiling on another PC

Re-test gamepad buttons now that XInput is active

!!!BUG!!! - When I change parent I don't update individual local position/rotation/scale on scene object
I don't have a way of setting world pos/rot directly on SOs
-----------------

Not so critical
Expand Down

0 comments on commit 2e6a197

Please sign in to comment.