Procházet zdrojové kódy

Added ability to set world position and rotation to SceneObjects

Marko Pintera před 11 roky
rodič
revize
2e6a197523

+ 13 - 3
BansheeCore/Include/BsSceneObject.h

@@ -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.
 		 */
@@ -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.
 		 *

+ 34 - 1
BansheeCore/Source/BsSceneObject.cpp

@@ -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)
@@ -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;
 

+ 0 - 2
BansheeD3D9RenderSystem/Source/BsD3D9RenderSystem.cpp

@@ -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:

+ 0 - 1
BansheeD3D9RenderSystem/Source/BsD3D9RenderWindow.cpp

@@ -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" };

+ 0 - 4
Polish.txt

@@ -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