Преглед изворни кода

Refactored native Joint components so they use the descriptor structure for initialization

BearishSun пре 9 година
родитељ
комит
d1f5784a43

+ 2 - 10
Source/BansheeCore/Include/BsCD6Joint.h

@@ -97,15 +97,7 @@ namespace BansheeEngine
 		/** @copydoc CJoint::createInternal */
 		/** @copydoc CJoint::createInternal */
 		SPtr<Joint> createInternal() override;
 		SPtr<Joint> createInternal() override;
 
 
-		D6Joint::Motion mMotion[(UINT32)D6Joint::Axis::Count];
-		D6Joint::Drive mDrive[(UINT32)D6Joint::DriveType::Count];
-		LimitLinear mLimitLinear;
-		LimitAngularRange mLimitTwist;
-		LimitConeRange mLimitSwing;
-		Vector3 mDrivePosition;
-		Quaternion mDriveRotation;
-		Vector3 mDriveLinearVelocity;
-		Vector3 mDriveAngularVelocity;
+		D6_JOINT_DESC mDesc;
 
 
 		/************************************************************************/
 		/************************************************************************/
 		/* 								RTTI		                     		*/
 		/* 								RTTI		                     		*/
@@ -116,7 +108,7 @@ namespace BansheeEngine
 		RTTITypeBase* getRTTI() const override;
 		RTTITypeBase* getRTTI() const override;
 
 
 	protected:
 	protected:
-		CD6Joint() {} // Serialization only
+		CD6Joint(); // Serialization only
      };
      };
 
 
 	 /** @} */
 	 /** @} */

+ 122 - 127
Source/BansheeCore/Include/BsCD6JointRTTI.h

@@ -1,128 +1,123 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsCorePrerequisites.h"
-#include "BsRTTIType.h"
-#include "BsCD6Joint.h"
-#include "BsGameObjectRTTI.h"
-
-namespace BansheeEngine
-{
-	/** @cond RTTI */
-	/** @addtogroup RTTI-Impl-Core
-	 *  @{
-	 */
-
-	float stiffness = 0.0f;
-	float damping = 0.0f;
-	float forceLimit = FLT_MAX;
-	bool acceleration = false;
-
-	class BS_CORE_EXPORT CD6JointRTTI : public RTTIType<CD6Joint, CJoint, CD6JointRTTI>
-	{
-		D6Joint::Motion& getMotion(CD6Joint* obj, UINT32 idx) { return obj->mMotion[idx]; }
-		void setMotion(CD6Joint* obj, UINT32 idx, D6Joint::Motion& value) { obj->mMotion[idx] = value; }
-		UINT32 getMotionCount(CD6Joint* obj) { return (UINT32)D6Joint::Motion::Count; }
-		void setMotionCount(CD6Joint* obj, UINT32 size) { /* Do nothing */ }
-
-		float& getDriveStiffness(CD6Joint* obj, UINT32 idx) { return obj->mDrive[idx].stiffness; }
-		void setDriveStiffness(CD6Joint* obj, UINT32 idx, float& value) { obj->mDrive[idx].stiffness = value; }
-
-		float& getDriveDamping(CD6Joint* obj, UINT32 idx) { return obj->mDrive[idx].damping; }
-		void setDriveDamping(CD6Joint* obj, UINT32 idx, float& value) { obj->mDrive[idx].damping = value; }
-
-		float& getDriveForceLimit(CD6Joint* obj, UINT32 idx) { return obj->mDrive[idx].forceLimit; }
-		void setDriveForceLimit(CD6Joint* obj, UINT32 idx, float& value) { obj->mDrive[idx].forceLimit = value; }
-
-		bool& getDriveAcceleration(CD6Joint* obj, UINT32 idx) { return obj->mDrive[idx].acceleration; }
-		void setDriveAcceleration(CD6Joint* obj, UINT32 idx, bool& value) { obj->mDrive[idx].acceleration = value; }
-
-		UINT32 getDriveCount(CD6Joint* obj) { return (UINT32)D6Joint::DriveType::Count; }
-		void setDriveCount(CD6Joint* obj, UINT32 size) { /* Do nothing */ }
-
-		BS_PLAIN_MEMBER_NAMED(mLimitLinearExtent, mLimitLinear.extent)
-		BS_PLAIN_MEMBER_NAMED(mLimitLinearContactDist, mLimitTwist.contactDist)
-		BS_PLAIN_MEMBER_NAMED(mLimitLinearRestitution, mLimitTwist.restitution)
-		BS_PLAIN_MEMBER_NAMED(mLimitLinearSpringDamping, mLimitTwist.spring.damping)
-		BS_PLAIN_MEMBER_NAMED(mLimitLinearSpringStiffness, mLimitTwist.spring.stiffness)
-
-		BS_PLAIN_MEMBER_NAMED(mLimitTwistLower, mLimitTwist.lower)
-		BS_PLAIN_MEMBER_NAMED(mLimitTwistUpper, mLimitTwist.upper)
-		BS_PLAIN_MEMBER_NAMED(mLimitTwistContactDist, mLimitTwist.contactDist)
-		BS_PLAIN_MEMBER_NAMED(mLimitTwistRestitution, mLimitTwist.restitution)
-		BS_PLAIN_MEMBER_NAMED(mLimitTwistSpringDamping, mLimitTwist.spring.damping)
-		BS_PLAIN_MEMBER_NAMED(mLimitTwistSpringStiffness, mLimitTwist.spring.stiffness)
-
-		BS_PLAIN_MEMBER_NAMED(mLimitSwingYLimitAngle, mLimitSwing.yLimitAngle)
-		BS_PLAIN_MEMBER_NAMED(mLimitSwingZLimitAngle, mLimitSwing.zLimitAngle)
-		BS_PLAIN_MEMBER_NAMED(mLimitSwingContactDist, mLimitSwing.contactDist)
-		BS_PLAIN_MEMBER_NAMED(mLimitSwingRestitution, mLimitSwing.restitution)
-		BS_PLAIN_MEMBER_NAMED(mLimitSwingSpringDamping, mLimitSwing.spring.damping)
-		BS_PLAIN_MEMBER_NAMED(mLimitSwingSpringStiffness, mLimitSwing.spring.stiffness)
-
-		BS_PLAIN_MEMBER(mDrivePosition)
-		BS_PLAIN_MEMBER(mDriveRotation)
-		BS_PLAIN_MEMBER(mDriveLinearVelocity)
-		BS_PLAIN_MEMBER(mDriveAngularVelocity)
-
-	public:
-		CD6JointRTTI()
-		{
-			addPlainArrayField("mMotion", 0, &CD6JointRTTI::getMotion, &CD6JointRTTI::getMotionCount, 
-				&CD6JointRTTI::setMotion, &CD6JointRTTI::setMotionCount);
-			addPlainArrayField("mDriveStiffnes", 1, &CD6JointRTTI::getDriveStiffness, &CD6JointRTTI::getDriveCount, 
-				&CD6JointRTTI::setDriveStiffness, &CD6JointRTTI::setDriveCount);
-			addPlainArrayField("mDriveDamping", 2, &CD6JointRTTI::getDriveDamping, &CD6JointRTTI::getDriveCount, 
-				&CD6JointRTTI::setDriveDamping, &CD6JointRTTI::setDriveCount);
-			addPlainArrayField("mDriveForceLimit", 3, &CD6JointRTTI::getDriveForceLimit, &CD6JointRTTI::getDriveCount, 
-				&CD6JointRTTI::setDriveForceLimit, &CD6JointRTTI::setDriveCount);
-			addPlainArrayField("mDriveAcceleartion", 4, &CD6JointRTTI::getDriveAcceleration, &CD6JointRTTI::getDriveCount, 
-				&CD6JointRTTI::setDriveAcceleration, &CD6JointRTTI::setDriveCount);
-
-			BS_ADD_PLAIN_FIELD(mLimitLinearExtent, 5);
-			BS_ADD_PLAIN_FIELD(mLimitLinearContactDist, 6);
-			BS_ADD_PLAIN_FIELD(mLimitLinearRestitution, 7);
-			BS_ADD_PLAIN_FIELD(mLimitLinearSpringDamping, 8);
-			BS_ADD_PLAIN_FIELD(mLimitLinearSpringStiffness, 9);
-
-			BS_ADD_PLAIN_FIELD(mLimitTwistLower, 10);
-			BS_ADD_PLAIN_FIELD(mLimitTwistUpper, 11);
-			BS_ADD_PLAIN_FIELD(mLimitTwistContactDist, 12);
-			BS_ADD_PLAIN_FIELD(mLimitTwistRestitution, 13);
-			BS_ADD_PLAIN_FIELD(mLimitTwistSpringDamping, 14);
-			BS_ADD_PLAIN_FIELD(mLimitTwistSpringStiffness, 15);
-
-			BS_ADD_PLAIN_FIELD(mLimitSwingYLimitAngle, 16);
-			BS_ADD_PLAIN_FIELD(mLimitSwingZLimitAngle, 17);
-			BS_ADD_PLAIN_FIELD(mLimitSwingContactDist, 18);
-			BS_ADD_PLAIN_FIELD(mLimitSwingRestitution, 19);
-			BS_ADD_PLAIN_FIELD(mLimitSwingSpringDamping, 20);
-			BS_ADD_PLAIN_FIELD(mLimitSwingSpringStiffness, 21);
-
-			BS_ADD_PLAIN_FIELD(mDrivePosition, 22);
-			BS_ADD_PLAIN_FIELD(mDriveRotation, 23);
-			BS_ADD_PLAIN_FIELD(mDriveLinearVelocity, 24);
-			BS_ADD_PLAIN_FIELD(mDriveAngularVelocity, 25);
-		}
-
-		const String& getRTTIName() override
-		{
-			static String name = "CD6Joint";
-			return name;
-		}
-
-		UINT32 getRTTIId() override
-		{
-			return TID_CD6Joint;
-		}
-
-		SPtr<IReflectable> newRTTIObject() override
-		{
-			return GameObjectRTTI::createGameObject<CD6Joint>();
-		}
-	};
-
-	/** @} */
-	/** @endcond */
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsRTTIType.h"
+#include "BsCD6Joint.h"
+#include "BsGameObjectRTTI.h"
+
+namespace BansheeEngine
+{
+	/** @cond RTTI */
+	/** @addtogroup RTTI-Impl-Core
+	 *  @{
+	 */
+
+	class BS_CORE_EXPORT CD6JointRTTI : public RTTIType<CD6Joint, CJoint, CD6JointRTTI>
+	{
+		D6Joint::Motion& getMotion(CD6Joint* obj, UINT32 idx) { return obj->mDesc.motion[idx]; }
+		void setMotion(CD6Joint* obj, UINT32 idx, D6Joint::Motion& value) { obj->mDesc.motion[idx] = value; }
+		UINT32 getMotionCount(CD6Joint* obj) { return (UINT32)D6Joint::Motion::Count; }
+		void setMotionCount(CD6Joint* obj, UINT32 size) { /* Do nothing */ }
+
+		float& getDriveStiffness(CD6Joint* obj, UINT32 idx) { return obj->mDesc.drive[idx].stiffness; }
+		void setDriveStiffness(CD6Joint* obj, UINT32 idx, float& value) { obj->mDesc.drive[idx].stiffness = value; }
+
+		float& getDriveDamping(CD6Joint* obj, UINT32 idx) { return obj->mDesc.drive[idx].damping; }
+		void setDriveDamping(CD6Joint* obj, UINT32 idx, float& value) { obj->mDesc.drive[idx].damping = value; }
+
+		float& getDriveForceLimit(CD6Joint* obj, UINT32 idx) { return obj->mDesc.drive[idx].forceLimit; }
+		void setDriveForceLimit(CD6Joint* obj, UINT32 idx, float& value) { obj->mDesc.drive[idx].forceLimit = value; }
+
+		bool& getDriveAcceleration(CD6Joint* obj, UINT32 idx) { return obj->mDesc.drive[idx].acceleration; }
+		void setDriveAcceleration(CD6Joint* obj, UINT32 idx, bool& value) { obj->mDesc.drive[idx].acceleration = value; }
+
+		UINT32 getDriveCount(CD6Joint* obj) { return (UINT32)D6Joint::DriveType::Count; }
+		void setDriveCount(CD6Joint* obj, UINT32 size) { /* Do nothing */ }
+
+		BS_PLAIN_MEMBER_NAMED(mLimitLinearExtent, mDesc.limitLinear.extent)
+		BS_PLAIN_MEMBER_NAMED(mLimitLinearContactDist, mDesc.limitTwist.contactDist)
+		BS_PLAIN_MEMBER_NAMED(mLimitLinearRestitution, mDesc.limitTwist.restitution)
+		BS_PLAIN_MEMBER_NAMED(mLimitLinearSpringDamping, mDesc.limitTwist.spring.damping)
+		BS_PLAIN_MEMBER_NAMED(mLimitLinearSpringStiffness, mDesc.limitTwist.spring.stiffness)
+
+		BS_PLAIN_MEMBER_NAMED(mLimitTwistLower, mDesc.limitTwist.lower)
+		BS_PLAIN_MEMBER_NAMED(mLimitTwistUpper, mDesc.limitTwist.upper)
+		BS_PLAIN_MEMBER_NAMED(mLimitTwistContactDist, mDesc.limitTwist.contactDist)
+		BS_PLAIN_MEMBER_NAMED(mLimitTwistRestitution, mDesc.limitTwist.restitution)
+		BS_PLAIN_MEMBER_NAMED(mLimitTwistSpringDamping, mDesc.limitTwist.spring.damping)
+		BS_PLAIN_MEMBER_NAMED(mLimitTwistSpringStiffness, mDesc.limitTwist.spring.stiffness)
+
+		BS_PLAIN_MEMBER_NAMED(mLimitSwingYLimitAngle, mDesc.limitSwing.yLimitAngle)
+		BS_PLAIN_MEMBER_NAMED(mLimitSwingZLimitAngle, mDesc.limitSwing.zLimitAngle)
+		BS_PLAIN_MEMBER_NAMED(mLimitSwingContactDist, mDesc.limitSwing.contactDist)
+		BS_PLAIN_MEMBER_NAMED(mLimitSwingRestitution, mDesc.limitSwing.restitution)
+		BS_PLAIN_MEMBER_NAMED(mLimitSwingSpringDamping, mDesc.limitSwing.spring.damping)
+		BS_PLAIN_MEMBER_NAMED(mLimitSwingSpringStiffness, mDesc.limitSwing.spring.stiffness)
+
+		BS_PLAIN_MEMBER_NAMED(mDrivePosition, mDesc.drivePosition)
+		BS_PLAIN_MEMBER_NAMED(mDriveRotation, mDesc.driveRotation)
+		BS_PLAIN_MEMBER_NAMED(mDriveLinearVelocity, mDesc.driveLinearVelocity)
+		BS_PLAIN_MEMBER_NAMED(mDriveAngularVelocity, mDesc.driveAngularVelocity)
+
+	public:
+		CD6JointRTTI()
+		{
+			addPlainArrayField("mMotion", 0, &CD6JointRTTI::getMotion, &CD6JointRTTI::getMotionCount, 
+				&CD6JointRTTI::setMotion, &CD6JointRTTI::setMotionCount);
+			addPlainArrayField("mDriveStiffnes", 1, &CD6JointRTTI::getDriveStiffness, &CD6JointRTTI::getDriveCount, 
+				&CD6JointRTTI::setDriveStiffness, &CD6JointRTTI::setDriveCount);
+			addPlainArrayField("mDriveDamping", 2, &CD6JointRTTI::getDriveDamping, &CD6JointRTTI::getDriveCount, 
+				&CD6JointRTTI::setDriveDamping, &CD6JointRTTI::setDriveCount);
+			addPlainArrayField("mDriveForceLimit", 3, &CD6JointRTTI::getDriveForceLimit, &CD6JointRTTI::getDriveCount, 
+				&CD6JointRTTI::setDriveForceLimit, &CD6JointRTTI::setDriveCount);
+			addPlainArrayField("mDriveAcceleartion", 4, &CD6JointRTTI::getDriveAcceleration, &CD6JointRTTI::getDriveCount, 
+				&CD6JointRTTI::setDriveAcceleration, &CD6JointRTTI::setDriveCount);
+
+			BS_ADD_PLAIN_FIELD(mLimitLinearExtent, 5);
+			BS_ADD_PLAIN_FIELD(mLimitLinearContactDist, 6);
+			BS_ADD_PLAIN_FIELD(mLimitLinearRestitution, 7);
+			BS_ADD_PLAIN_FIELD(mLimitLinearSpringDamping, 8);
+			BS_ADD_PLAIN_FIELD(mLimitLinearSpringStiffness, 9);
+
+			BS_ADD_PLAIN_FIELD(mLimitTwistLower, 10);
+			BS_ADD_PLAIN_FIELD(mLimitTwistUpper, 11);
+			BS_ADD_PLAIN_FIELD(mLimitTwistContactDist, 12);
+			BS_ADD_PLAIN_FIELD(mLimitTwistRestitution, 13);
+			BS_ADD_PLAIN_FIELD(mLimitTwistSpringDamping, 14);
+			BS_ADD_PLAIN_FIELD(mLimitTwistSpringStiffness, 15);
+
+			BS_ADD_PLAIN_FIELD(mLimitSwingYLimitAngle, 16);
+			BS_ADD_PLAIN_FIELD(mLimitSwingZLimitAngle, 17);
+			BS_ADD_PLAIN_FIELD(mLimitSwingContactDist, 18);
+			BS_ADD_PLAIN_FIELD(mLimitSwingRestitution, 19);
+			BS_ADD_PLAIN_FIELD(mLimitSwingSpringDamping, 20);
+			BS_ADD_PLAIN_FIELD(mLimitSwingSpringStiffness, 21);
+
+			BS_ADD_PLAIN_FIELD(mDrivePosition, 22);
+			BS_ADD_PLAIN_FIELD(mDriveRotation, 23);
+			BS_ADD_PLAIN_FIELD(mDriveLinearVelocity, 24);
+			BS_ADD_PLAIN_FIELD(mDriveAngularVelocity, 25);
+		}
+
+		const String& getRTTIName() override
+		{
+			static String name = "CD6Joint";
+			return name;
+		}
+
+		UINT32 getRTTIId() override
+		{
+			return TID_CD6Joint;
+		}
+
+		SPtr<IReflectable> newRTTIObject() override
+		{
+			return GameObjectRTTI::createGameObject<CD6Joint>();
+		}
+	};
+
+	/** @} */
+	/** @endcond */
 }
 }

+ 2 - 6
Source/BansheeCore/Include/BsCDistanceJoint.h

@@ -73,11 +73,7 @@ namespace BansheeEngine
 		/** @copydoc CJoint::createInternal */
 		/** @copydoc CJoint::createInternal */
 		SPtr<Joint> createInternal() override;
 		SPtr<Joint> createInternal() override;
 
 
-		float mMinDistance = 0.0f;
-		float mMaxDistance = 0.0f;
-		float mTolerance = 0.25f;
-		Spring mSpring;
-		DistanceJoint::Flag mFlag = (DistanceJoint::Flag)0;
+		DISTANCE_JOINT_DESC mDesc;
 
 
 		/************************************************************************/
 		/************************************************************************/
 		/* 								RTTI		                     		*/
 		/* 								RTTI		                     		*/
@@ -88,7 +84,7 @@ namespace BansheeEngine
 		RTTITypeBase* getRTTI() const override;
 		RTTITypeBase* getRTTI() const override;
 
 
 	protected:
 	protected:
-		CDistanceJoint() {} // Serialization only
+		CDistanceJoint();// Serialization only
      };
      };
 
 
 	 /** @} */
 	 /** @} */

+ 55 - 55
Source/BansheeCore/Include/BsCDistanceJointRTTI.h

@@ -1,56 +1,56 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsCorePrerequisites.h"
-#include "BsRTTIType.h"
-#include "BsCDistanceJoint.h"
-#include "BsGameObjectRTTI.h"
-
-namespace BansheeEngine
-{
-	/** @cond RTTI */
-	/** @addtogroup RTTI-Impl-Core
-	 *  @{
-	 */
-
-	class BS_CORE_EXPORT CDistanceJointRTTI : public RTTIType<CDistanceJoint, CJoint, CDistanceJointRTTI>
-	{
-		BS_PLAIN_MEMBER(mFlag)
-		BS_PLAIN_MEMBER(mMinDistance)
-		BS_PLAIN_MEMBER(mMaxDistance)
-		BS_PLAIN_MEMBER(mTolerance)
-		BS_PLAIN_MEMBER_NAMED(mSpringDamping, mSpring.damping)
-		BS_PLAIN_MEMBER_NAMED(mSpringStiffness, mSpring.stiffness)
-
-	public:
-		CDistanceJointRTTI()
-		{
-			BS_ADD_PLAIN_FIELD(mFlag, 0);
-			BS_ADD_PLAIN_FIELD(mMinDistance, 1);
-			BS_ADD_PLAIN_FIELD(mMaxDistance, 2);
-			BS_ADD_PLAIN_FIELD(mTolerance, 3);
-			BS_ADD_PLAIN_FIELD(mSpringDamping, 4);
-			BS_ADD_PLAIN_FIELD(mSpringStiffness, 5);
-		}
-
-		const String& getRTTIName() override
-		{
-			static String name = "CDistanceJoint";
-			return name;
-		}
-
-		UINT32 getRTTIId() override
-		{
-			return TID_CDistanceJoint;
-		}
-
-		SPtr<IReflectable> newRTTIObject() override
-		{
-			return GameObjectRTTI::createGameObject<CDistanceJoint>();
-		}
-	};
-
-	/** @} */
-	/** @endcond */
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsRTTIType.h"
+#include "BsCDistanceJoint.h"
+#include "BsGameObjectRTTI.h"
+
+namespace BansheeEngine
+{
+	/** @cond RTTI */
+	/** @addtogroup RTTI-Impl-Core
+	 *  @{
+	 */
+
+	class BS_CORE_EXPORT CDistanceJointRTTI : public RTTIType<CDistanceJoint, CJoint, CDistanceJointRTTI>
+	{
+		BS_PLAIN_MEMBER_NAMED(mFlag, mDesc.flag)
+		BS_PLAIN_MEMBER_NAMED(mMinDistance, mDesc.minDistance)
+		BS_PLAIN_MEMBER_NAMED(mMaxDistance, mDesc.maxDistance)
+		BS_PLAIN_MEMBER_NAMED(mTolerance, mDesc.tolerance)
+		BS_PLAIN_MEMBER_NAMED(mSpringDamping, mDesc.spring.damping)
+		BS_PLAIN_MEMBER_NAMED(mSpringStiffness, mDesc.spring.stiffness)
+
+	public:
+		CDistanceJointRTTI()
+		{
+			BS_ADD_PLAIN_FIELD(mFlag, 0);
+			BS_ADD_PLAIN_FIELD(mMinDistance, 1);
+			BS_ADD_PLAIN_FIELD(mMaxDistance, 2);
+			BS_ADD_PLAIN_FIELD(mTolerance, 3);
+			BS_ADD_PLAIN_FIELD(mSpringDamping, 4);
+			BS_ADD_PLAIN_FIELD(mSpringStiffness, 5);
+		}
+
+		const String& getRTTIName() override
+		{
+			static String name = "CDistanceJoint";
+			return name;
+		}
+
+		UINT32 getRTTIId() override
+		{
+			return TID_CDistanceJoint;
+		}
+
+		SPtr<IReflectable> newRTTIObject() override
+		{
+			return GameObjectRTTI::createGameObject<CDistanceJoint>();
+		}
+	};
+
+	/** @} */
+	/** @endcond */
 }
 }

+ 4 - 1
Source/BansheeCore/Include/BsCFixedJoint.h

@@ -5,6 +5,7 @@
 #include "BsCorePrerequisites.h"
 #include "BsCorePrerequisites.h"
 #include "BsFixedJoint.h"
 #include "BsFixedJoint.h"
 #include "BsCJoint.h"
 #include "BsCJoint.h"
+#include "BsJoint.h"
 
 
 namespace BansheeEngine 
 namespace BansheeEngine 
 {
 {
@@ -40,6 +41,8 @@ namespace BansheeEngine
 		/** @copydoc CJoint::createInternal */
 		/** @copydoc CJoint::createInternal */
 		SPtr<Joint> createInternal() override;
 		SPtr<Joint> createInternal() override;
 
 
+		FIXED_JOINT_DESC mDesc;
+
 		/************************************************************************/
 		/************************************************************************/
 		/* 								RTTI		                     		*/
 		/* 								RTTI		                     		*/
 		/************************************************************************/
 		/************************************************************************/
@@ -49,7 +52,7 @@ namespace BansheeEngine
 		RTTITypeBase* getRTTI() const override;
 		RTTITypeBase* getRTTI() const override;
 
 
 	protected:
 	protected:
-		CFixedJoint() {} // Serialization only
+		CFixedJoint(); // Serialization only
      };
      };
 
 
 	 /** @} */
 	 /** @} */

+ 2 - 4
Source/BansheeCore/Include/BsCHingeJoint.h

@@ -64,9 +64,7 @@ namespace BansheeEngine
 		/** @copydoc CJoint::createInternal */
 		/** @copydoc CJoint::createInternal */
 		SPtr<Joint> createInternal() override;
 		SPtr<Joint> createInternal() override;
 
 
-		HingeJoint::Flag mFlag = (HingeJoint::Flag)0;
-		HingeJoint::Drive mDrive;
-		LimitAngularRange mLimit;
+		HINGE_JOINT_DESC mDesc;
 
 
 		/************************************************************************/
 		/************************************************************************/
 		/* 								RTTI		                     		*/
 		/* 								RTTI		                     		*/
@@ -77,7 +75,7 @@ namespace BansheeEngine
 		RTTITypeBase* getRTTI() const override;
 		RTTITypeBase* getRTTI() const override;
 
 
 	protected:
 	protected:
-		CHingeJoint() {} // Serialization only
+		CHingeJoint(); // Serialization only
      };
      };
 
 
 	 /** @} */
 	 /** @} */

+ 65 - 65
Source/BansheeCore/Include/BsCHingeJointRTTI.h

@@ -1,66 +1,66 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsCorePrerequisites.h"
-#include "BsRTTIType.h"
-#include "BsCHingeJoint.h"
-#include "BsGameObjectRTTI.h"
-
-namespace BansheeEngine
-{
-	/** @cond RTTI */
-	/** @addtogroup RTTI-Impl-Core
-	 *  @{
-	 */
-
-	class BS_CORE_EXPORT CHingeJointRTTI : public RTTIType<CHingeJoint, CJoint, CHingeJointRTTI>
-	{
-		BS_PLAIN_MEMBER(mFlag)
-		BS_PLAIN_MEMBER_NAMED(mDriveSpeed, mDrive.speed)
-		BS_PLAIN_MEMBER_NAMED(mDriveForceLimit, mDrive.forceLimit)
-		BS_PLAIN_MEMBER_NAMED(mDriveGearRatio, mDrive.gearRatio)
-		BS_PLAIN_MEMBER_NAMED(mDriveFreeSpin, mDrive.freeSpin)
-		BS_PLAIN_MEMBER_NAMED(mLimitLower, mLimit.lower)
-		BS_PLAIN_MEMBER_NAMED(mLimitUpper, mLimit.upper)
-		BS_PLAIN_MEMBER_NAMED(mLimitContactDist, mLimit.contactDist)
-		BS_PLAIN_MEMBER_NAMED(mLimitRestitution, mLimit.restitution)
-		BS_PLAIN_MEMBER_NAMED(mSpringDamping, mLimit.spring.damping)
-		BS_PLAIN_MEMBER_NAMED(mSpringStiffness, mLimit.spring.stiffness)
-
-	public:
-		CHingeJointRTTI()
-		{
-			BS_ADD_PLAIN_FIELD(mFlag, 0);
-			BS_ADD_PLAIN_FIELD(mDriveSpeed, 1);
-			BS_ADD_PLAIN_FIELD(mDriveForceLimit, 2);
-			BS_ADD_PLAIN_FIELD(mDriveGearRatio, 3);
-			BS_ADD_PLAIN_FIELD(mDriveFreeSpin, 4);
-			BS_ADD_PLAIN_FIELD(mLimitLower, 5);
-			BS_ADD_PLAIN_FIELD(mLimitUpper, 6);
-			BS_ADD_PLAIN_FIELD(mLimitContactDist, 7);
-			BS_ADD_PLAIN_FIELD(mLimitRestitution, 8);
-			BS_ADD_PLAIN_FIELD(mSpringDamping, 9);
-			BS_ADD_PLAIN_FIELD(mSpringStiffness, 10);
-		}
-
-		const String& getRTTIName() override
-		{
-			static String name = "CHingeJoint";
-			return name;
-		}
-
-		UINT32 getRTTIId() override
-		{
-			return TID_CHingeJoint;
-		}
-
-		SPtr<IReflectable> newRTTIObject() override
-		{
-			return GameObjectRTTI::createGameObject<CHingeJoint>();
-		}
-	};
-
-	/** @} */
-	/** @endcond */
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsRTTIType.h"
+#include "BsCHingeJoint.h"
+#include "BsGameObjectRTTI.h"
+
+namespace BansheeEngine
+{
+	/** @cond RTTI */
+	/** @addtogroup RTTI-Impl-Core
+	 *  @{
+	 */
+
+	class BS_CORE_EXPORT CHingeJointRTTI : public RTTIType<CHingeJoint, CJoint, CHingeJointRTTI>
+	{
+		BS_PLAIN_MEMBER_NAMED(mFlag, mDesc.flag)
+		BS_PLAIN_MEMBER_NAMED(mDriveSpeed, mDesc.drive.speed)
+		BS_PLAIN_MEMBER_NAMED(mDriveForceLimit, mDesc.drive.forceLimit)
+		BS_PLAIN_MEMBER_NAMED(mDriveGearRatio, mDesc.drive.gearRatio)
+		BS_PLAIN_MEMBER_NAMED(mDriveFreeSpin, mDesc.drive.freeSpin)
+		BS_PLAIN_MEMBER_NAMED(mLimitLower, mDesc.limit.lower)
+		BS_PLAIN_MEMBER_NAMED(mLimitUpper, mDesc.limit.upper)
+		BS_PLAIN_MEMBER_NAMED(mLimitContactDist, mDesc.limit.contactDist)
+		BS_PLAIN_MEMBER_NAMED(mLimitRestitution, mDesc.limit.restitution)
+		BS_PLAIN_MEMBER_NAMED(mSpringDamping, mDesc.limit.spring.damping)
+		BS_PLAIN_MEMBER_NAMED(mSpringStiffness, mDesc.limit.spring.stiffness)
+
+	public:
+		CHingeJointRTTI()
+		{
+			BS_ADD_PLAIN_FIELD(mFlag, 0);
+			BS_ADD_PLAIN_FIELD(mDriveSpeed, 1);
+			BS_ADD_PLAIN_FIELD(mDriveForceLimit, 2);
+			BS_ADD_PLAIN_FIELD(mDriveGearRatio, 3);
+			BS_ADD_PLAIN_FIELD(mDriveFreeSpin, 4);
+			BS_ADD_PLAIN_FIELD(mLimitLower, 5);
+			BS_ADD_PLAIN_FIELD(mLimitUpper, 6);
+			BS_ADD_PLAIN_FIELD(mLimitContactDist, 7);
+			BS_ADD_PLAIN_FIELD(mLimitRestitution, 8);
+			BS_ADD_PLAIN_FIELD(mSpringDamping, 9);
+			BS_ADD_PLAIN_FIELD(mSpringStiffness, 10);
+		}
+
+		const String& getRTTIName() override
+		{
+			static String name = "CHingeJoint";
+			return name;
+		}
+
+		UINT32 getRTTIId() override
+		{
+			return TID_CHingeJoint;
+		}
+
+		SPtr<IReflectable> newRTTIObject() override
+		{
+			return GameObjectRTTI::createGameObject<CHingeJoint>();
+		}
+	};
+
+	/** @} */
+	/** @endcond */
 }
 }

+ 8 - 6
Source/BansheeCore/Include/BsCJoint.h

@@ -20,7 +20,7 @@ namespace BansheeEngine
     class BS_CORE_EXPORT CJoint : public Component
     class BS_CORE_EXPORT CJoint : public Component
     {
     {
     public:
     public:
-		CJoint(const HSceneObject& parent);
+		CJoint(const HSceneObject& parent, JOINT_DESC& desc);
 		virtual ~CJoint() {}
 		virtual ~CJoint() {}
 
 
 		/** @copydoc Joint::getBody */
 		/** @copydoc Joint::getBody */
@@ -104,6 +104,9 @@ namespace BansheeEngine
 		/** Notifies the joint that one of the attached rigidbodies moved and that its transform needs updating. */
 		/** Notifies the joint that one of the attached rigidbodies moved and that its transform needs updating. */
 		void notifyRigidbodyMoved(const HRigidbody& body);
 		void notifyRigidbodyMoved(const HRigidbody& body);
 
 
+		/** Calculates the local position/rotation that needs to be applied to the particular joint body. */
+		void getLocalTransform(JointBody body, Vector3& position, Quaternion& rotation);
+
 		/** Updates the local transform for the specified body attached to the joint. */
 		/** Updates the local transform for the specified body attached to the joint. */
 		void updateTransform(JointBody body);
 		void updateTransform(JointBody body);
 
 
@@ -115,9 +118,9 @@ namespace BansheeEngine
 		HRigidbody mBodies[2];
 		HRigidbody mBodies[2];
 		Vector3 mPositions[2];
 		Vector3 mPositions[2];
 		Quaternion mRotations[2];
 		Quaternion mRotations[2];
-		float mBreakForce = FLT_MAX;
-		float mBreakTorque = FLT_MAX;
-		bool mEnableCollision = false;
+
+	private:
+		JOINT_DESC& mDesc;
 
 
 		/************************************************************************/
 		/************************************************************************/
 		/* 								RTTI		                     		*/
 		/* 								RTTI		                     		*/
@@ -127,8 +130,7 @@ namespace BansheeEngine
 		static RTTITypeBase* getRTTIStatic();
 		static RTTITypeBase* getRTTIStatic();
 		RTTITypeBase* getRTTI() const override;
 		RTTITypeBase* getRTTI() const override;
 
 
-	protected:
-		CJoint() {} // Serialization only
+		CJoint(JOINT_DESC& desc); // Serialization only
      };
      };
 
 
 	 /** @} */
 	 /** @} */

+ 64 - 64
Source/BansheeCore/Include/BsCJointRTTI.h

@@ -1,65 +1,65 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsCorePrerequisites.h"
-#include "BsRTTIType.h"
-#include "BsCJoint.h"
-
-namespace BansheeEngine
-{
-	/** @cond RTTI */
-	/** @addtogroup RTTI-Impl-Core
-	 *  @{
-	 */
-
-	class BS_CORE_EXPORT CJointRTTI : public RTTIType<CJoint, Component, CJointRTTI>
-	{
-		BS_REFL_MEMBER_NAMED(mBodyA, mBodies[0]);
-		BS_REFL_MEMBER_NAMED(mBodyB, mBodies[1]);
-
-		BS_PLAIN_MEMBER_NAMED(mPositionA, mPositions[0]);
-		BS_PLAIN_MEMBER_NAMED(mPositionB, mPositions[1]);
-
-		BS_PLAIN_MEMBER_NAMED(mRotationA, mRotations[0]);
-		BS_PLAIN_MEMBER_NAMED(mRotationB, mRotations[1]);
-
-		BS_PLAIN_MEMBER(mBreakForce)
-		BS_PLAIN_MEMBER(mBreakTorque)
-		BS_PLAIN_MEMBER(mEnableCollision)
-
-	public:
-		CJointRTTI()
-		{
-			BS_ADD_REFL_FIELD(mBodyA, 0);
-			BS_ADD_REFL_FIELD(mBodyB, 1);
-			BS_ADD_PLAIN_FIELD(mPositionA, 2);
-			BS_ADD_PLAIN_FIELD(mPositionB, 3);
-			BS_ADD_PLAIN_FIELD(mRotationA, 4);
-			BS_ADD_PLAIN_FIELD(mRotationB, 5);
-			BS_ADD_PLAIN_FIELD(mBreakForce, 6);
-			BS_ADD_PLAIN_FIELD(mBreakTorque, 7);
-			BS_ADD_PLAIN_FIELD(mEnableCollision, 8);
-		}
-
-		const String& getRTTIName() override
-		{
-			static String name = "CJoint";
-			return name;
-		}
-
-		UINT32 getRTTIId() override
-		{
-			return TID_CJoint;
-		}
-
-		std::shared_ptr<IReflectable> newRTTIObject() override
-		{
-			BS_EXCEPT(InternalErrorException, "Cannot instantiate an abstract class.");
-			return nullptr;
-		}
-	};
-
-	/** @} */
-	/** @endcond */
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsRTTIType.h"
+#include "BsCJoint.h"
+
+namespace BansheeEngine
+{
+	/** @cond RTTI */
+	/** @addtogroup RTTI-Impl-Core
+	 *  @{
+	 */
+
+	class BS_CORE_EXPORT CJointRTTI : public RTTIType<CJoint, Component, CJointRTTI>
+	{
+		BS_REFL_MEMBER_NAMED(mBodyA, mBodies[0]);
+		BS_REFL_MEMBER_NAMED(mBodyB, mBodies[1]);
+
+		BS_PLAIN_MEMBER_NAMED(mPositionA, mPositions[0]);
+		BS_PLAIN_MEMBER_NAMED(mPositionB, mPositions[1]);
+
+		BS_PLAIN_MEMBER_NAMED(mRotationA, mRotations[0]);
+		BS_PLAIN_MEMBER_NAMED(mRotationB, mRotations[1]);
+
+		BS_PLAIN_MEMBER_NAMED(mBreakForce, mDesc.breakForce)
+		BS_PLAIN_MEMBER_NAMED(mBreakTorque, mDesc.breakTorque)
+		BS_PLAIN_MEMBER_NAMED(mEnableCollision, mDesc.enableCollision)
+
+	public:
+		CJointRTTI()
+		{
+			BS_ADD_REFL_FIELD(mBodyA, 0);
+			BS_ADD_REFL_FIELD(mBodyB, 1);
+			BS_ADD_PLAIN_FIELD(mPositionA, 2);
+			BS_ADD_PLAIN_FIELD(mPositionB, 3);
+			BS_ADD_PLAIN_FIELD(mRotationA, 4);
+			BS_ADD_PLAIN_FIELD(mRotationB, 5);
+			BS_ADD_PLAIN_FIELD(mBreakForce, 6);
+			BS_ADD_PLAIN_FIELD(mBreakTorque, 7);
+			BS_ADD_PLAIN_FIELD(mEnableCollision, 8);
+		}
+
+		const String& getRTTIName() override
+		{
+			static String name = "CJoint";
+			return name;
+		}
+
+		UINT32 getRTTIId() override
+		{
+			return TID_CJoint;
+		}
+
+		std::shared_ptr<IReflectable> newRTTIObject() override
+		{
+			BS_EXCEPT(InternalErrorException, "Cannot instantiate an abstract class.");
+			return nullptr;
+		}
+	};
+
+	/** @} */
+	/** @endcond */
 }
 }

+ 2 - 3
Source/BansheeCore/Include/BsCSliderJoint.h

@@ -58,8 +58,7 @@ namespace BansheeEngine
 		/** @copydoc CJoint::createInternal */
 		/** @copydoc CJoint::createInternal */
 		SPtr<Joint> createInternal() override;
 		SPtr<Joint> createInternal() override;
 
 
-		SliderJoint::Flag mFlag = (SliderJoint::Flag)0;
-		LimitLinearRange mLimit;
+		SLIDER_JOINT_DESC mDesc;
 
 
 		/************************************************************************/
 		/************************************************************************/
 		/* 								RTTI		                     		*/
 		/* 								RTTI		                     		*/
@@ -70,7 +69,7 @@ namespace BansheeEngine
 		RTTITypeBase* getRTTI() const override;
 		RTTITypeBase* getRTTI() const override;
 
 
 	protected:
 	protected:
-		CSliderJoint() {} // Serialization only
+		CSliderJoint(); // Serialization only
      };
      };
 
 
 	 /** @} */
 	 /** @} */

+ 57 - 57
Source/BansheeCore/Include/BsCSliderJointRTTI.h

@@ -1,58 +1,58 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsCorePrerequisites.h"
-#include "BsRTTIType.h"
-#include "BsCSliderJoint.h"
-#include "BsGameObjectRTTI.h"
-
-namespace BansheeEngine
-{
-	/** @cond RTTI */
-	/** @addtogroup RTTI-Impl-Core
-	 *  @{
-	 */
-
-	class BS_CORE_EXPORT CSliderJointRTTI : public RTTIType<CSliderJoint, CJoint, CSliderJointRTTI>
-	{
-		BS_PLAIN_MEMBER(mFlag)
-		BS_PLAIN_MEMBER_NAMED(mLimitLower, mLimit.lower)
-		BS_PLAIN_MEMBER_NAMED(mLimitUpper, mLimit.upper)
-		BS_PLAIN_MEMBER_NAMED(mLimitContactDist, mLimit.contactDist)
-		BS_PLAIN_MEMBER_NAMED(mLimitRestitution, mLimit.restitution)
-		BS_PLAIN_MEMBER_NAMED(mSpringDamping, mLimit.spring.damping)
-		BS_PLAIN_MEMBER_NAMED(mSpringStiffness, mLimit.spring.stiffness)
-
-	public:
-		CSliderJointRTTI()
-		{
-			BS_ADD_PLAIN_FIELD(mFlag, 0);
-			BS_ADD_PLAIN_FIELD(mLimitLower, 1);
-			BS_ADD_PLAIN_FIELD(mLimitUpper, 2);
-			BS_ADD_PLAIN_FIELD(mLimitContactDist, 3);
-			BS_ADD_PLAIN_FIELD(mLimitRestitution, 4);
-			BS_ADD_PLAIN_FIELD(mSpringDamping, 5);
-			BS_ADD_PLAIN_FIELD(mSpringStiffness, 6);
-		}
-
-		const String& getRTTIName() override
-		{
-			static String name = "CSliderJoint";
-			return name;
-		}
-
-		UINT32 getRTTIId() override
-		{
-			return TID_CSliderJoint;
-		}
-
-		SPtr<IReflectable> newRTTIObject() override
-		{
-			return GameObjectRTTI::createGameObject<CSliderJoint>();
-		}
-	};
-
-	/** @} */
-	/** @endcond */
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsRTTIType.h"
+#include "BsCSliderJoint.h"
+#include "BsGameObjectRTTI.h"
+
+namespace BansheeEngine
+{
+	/** @cond RTTI */
+	/** @addtogroup RTTI-Impl-Core
+	 *  @{
+	 */
+
+	class BS_CORE_EXPORT CSliderJointRTTI : public RTTIType<CSliderJoint, CJoint, CSliderJointRTTI>
+	{
+		BS_PLAIN_MEMBER_NAMED(mFlag, mDesc.flag)
+		BS_PLAIN_MEMBER_NAMED(mLimitLower, mDesc.limit.lower)
+		BS_PLAIN_MEMBER_NAMED(mLimitUpper, mDesc.limit.upper)
+		BS_PLAIN_MEMBER_NAMED(mLimitContactDist, mDesc.limit.contactDist)
+		BS_PLAIN_MEMBER_NAMED(mLimitRestitution, mDesc.limit.restitution)
+		BS_PLAIN_MEMBER_NAMED(mSpringDamping, mDesc.limit.spring.damping)
+		BS_PLAIN_MEMBER_NAMED(mSpringStiffness, mDesc.limit.spring.stiffness)
+
+	public:
+		CSliderJointRTTI()
+		{
+			BS_ADD_PLAIN_FIELD(mFlag, 0);
+			BS_ADD_PLAIN_FIELD(mLimitLower, 1);
+			BS_ADD_PLAIN_FIELD(mLimitUpper, 2);
+			BS_ADD_PLAIN_FIELD(mLimitContactDist, 3);
+			BS_ADD_PLAIN_FIELD(mLimitRestitution, 4);
+			BS_ADD_PLAIN_FIELD(mSpringDamping, 5);
+			BS_ADD_PLAIN_FIELD(mSpringStiffness, 6);
+		}
+
+		const String& getRTTIName() override
+		{
+			static String name = "CSliderJoint";
+			return name;
+		}
+
+		UINT32 getRTTIId() override
+		{
+			return TID_CSliderJoint;
+		}
+
+		SPtr<IReflectable> newRTTIObject() override
+		{
+			return GameObjectRTTI::createGameObject<CSliderJoint>();
+		}
+	};
+
+	/** @} */
+	/** @endcond */
 }
 }

+ 2 - 3
Source/BansheeCore/Include/BsCSphericalJoint.h

@@ -52,8 +52,7 @@ namespace BansheeEngine
 		/** @copydoc CJoint::createInternal */
 		/** @copydoc CJoint::createInternal */
 		SPtr<Joint> createInternal() override;
 		SPtr<Joint> createInternal() override;
 
 
-		SphericalJoint::Flag mFlag = (SphericalJoint::Flag)0;
-		LimitConeRange mLimit;
+		SPHERICAL_JOINT_DESC mDesc;
 
 
 		/************************************************************************/
 		/************************************************************************/
 		/* 								RTTI		                     		*/
 		/* 								RTTI		                     		*/
@@ -64,7 +63,7 @@ namespace BansheeEngine
 		RTTITypeBase* getRTTI() const override;
 		RTTITypeBase* getRTTI() const override;
 
 
 	protected:
 	protected:
-		CSphericalJoint() {} // Serialization only
+		CSphericalJoint(); // Serialization only
      };
      };
 
 
 	 /** @} */
 	 /** @} */

+ 57 - 57
Source/BansheeCore/Include/BsCSphericalJointRTTI.h

@@ -1,58 +1,58 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsCorePrerequisites.h"
-#include "BsRTTIType.h"
-#include "BsCSphericalJoint.h"
-#include "BsGameObjectRTTI.h"
-
-namespace BansheeEngine
-{
-	/** @cond RTTI */
-	/** @addtogroup RTTI-Impl-Core
-	 *  @{
-	 */
-
-	class BS_CORE_EXPORT CSphericalJointRTTI : public RTTIType<CSphericalJoint, CJoint, CSphericalJointRTTI>
-	{
-		BS_PLAIN_MEMBER(mFlag)
-		BS_PLAIN_MEMBER_NAMED(mYLimitAngle, mLimit.yLimitAngle)
-		BS_PLAIN_MEMBER_NAMED(mZLimitAngle, mLimit.zLimitAngle)
-		BS_PLAIN_MEMBER_NAMED(mLimitContactDist, mLimit.contactDist)
-		BS_PLAIN_MEMBER_NAMED(mLimitRestitution, mLimit.restitution)
-		BS_PLAIN_MEMBER_NAMED(mSpringDamping, mLimit.spring.damping)
-		BS_PLAIN_MEMBER_NAMED(mSpringStiffness, mLimit.spring.stiffness)
-
-	public:
-		CSphericalJointRTTI()
-		{
-			BS_ADD_PLAIN_FIELD(mFlag, 0);
-			BS_ADD_PLAIN_FIELD(mYLimitAngle, 1);
-			BS_ADD_PLAIN_FIELD(mZLimitAngle, 2);
-			BS_ADD_PLAIN_FIELD(mLimitContactDist, 3);
-			BS_ADD_PLAIN_FIELD(mLimitRestitution, 4);
-			BS_ADD_PLAIN_FIELD(mSpringDamping, 5);
-			BS_ADD_PLAIN_FIELD(mSpringStiffness, 6);
-		}
-
-		const String& getRTTIName() override
-		{
-			static String name = "CSphericalJoint";
-			return name;
-		}
-
-		UINT32 getRTTIId() override
-		{
-			return TID_CSphericalJoint;
-		}
-
-		SPtr<IReflectable> newRTTIObject() override
-		{
-			return GameObjectRTTI::createGameObject<CSphericalJoint>();
-		}
-	};
-
-	/** @} */
-	/** @endcond */
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsRTTIType.h"
+#include "BsCSphericalJoint.h"
+#include "BsGameObjectRTTI.h"
+
+namespace BansheeEngine
+{
+	/** @cond RTTI */
+	/** @addtogroup RTTI-Impl-Core
+	 *  @{
+	 */
+
+	class BS_CORE_EXPORT CSphericalJointRTTI : public RTTIType<CSphericalJoint, CJoint, CSphericalJointRTTI>
+	{
+		BS_PLAIN_MEMBER_NAMED(mFlag, mDesc.flag)
+		BS_PLAIN_MEMBER_NAMED(mYLimitAngle, mDesc.limit.yLimitAngle)
+		BS_PLAIN_MEMBER_NAMED(mZLimitAngle, mDesc.limit.zLimitAngle)
+		BS_PLAIN_MEMBER_NAMED(mLimitContactDist, mDesc.limit.contactDist)
+		BS_PLAIN_MEMBER_NAMED(mLimitRestitution, mDesc.limit.restitution)
+		BS_PLAIN_MEMBER_NAMED(mSpringDamping, mDesc.limit.spring.damping)
+		BS_PLAIN_MEMBER_NAMED(mSpringStiffness, mDesc.limit.spring.stiffness)
+
+	public:
+		CSphericalJointRTTI()
+		{
+			BS_ADD_PLAIN_FIELD(mFlag, 0);
+			BS_ADD_PLAIN_FIELD(mYLimitAngle, 1);
+			BS_ADD_PLAIN_FIELD(mZLimitAngle, 2);
+			BS_ADD_PLAIN_FIELD(mLimitContactDist, 3);
+			BS_ADD_PLAIN_FIELD(mLimitRestitution, 4);
+			BS_ADD_PLAIN_FIELD(mSpringDamping, 5);
+			BS_ADD_PLAIN_FIELD(mSpringStiffness, 6);
+		}
+
+		const String& getRTTIName() override
+		{
+			static String name = "CSphericalJoint";
+			return name;
+		}
+
+		UINT32 getRTTIId() override
+		{
+			return TID_CSphericalJoint;
+		}
+
+		SPtr<IReflectable> newRTTIObject() override
+		{
+			return GameObjectRTTI::createGameObject<CSphericalJoint>();
+		}
+	};
+
+	/** @} */
+	/** @endcond */
 }
 }

+ 183 - 179
Source/BansheeCore/Source/BsCD6Joint.cpp

@@ -1,180 +1,184 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsCD6Joint.h"
-#include "BsSceneObject.h"
-#include "BsCD6JointRTTI.h"
-
-namespace BansheeEngine
-{
-	CD6Joint::CD6Joint(const HSceneObject& parent)
-		: CJoint(parent)
-	{
-		setName("D6Joint");
-	}
-
-	D6Joint::Motion CD6Joint::getMotion(D6Joint::Axis axis) const
-	{
-		return mMotion[(int)axis];
-	}
-
-	void CD6Joint::setMotion(D6Joint::Axis axis, D6Joint::Motion motion)
-	{
-		if (mMotion[(int)axis] == motion)
-			return;
-
-		mMotion[(int)axis] = motion;
-
-		if (mInternal != nullptr)
-			_getInternal()->setMotion(axis, motion);
-	}
-
-	Radian CD6Joint::getTwist() const
-	{
-		if (mInternal == nullptr)
-			return Radian(0.0f);
-
-		return _getInternal()->getTwist();
-	}
-
-	Radian CD6Joint::getSwingY() const
-	{
-		if (mInternal == nullptr)
-			return Radian(0.0f);
-
-		return _getInternal()->getSwingY();
-	}
-
-	Radian CD6Joint::getSwingZ() const
-	{
-		if (mInternal == nullptr)
-			return Radian(0.0f);
-
-		return _getInternal()->getSwingZ();
-	}
-
-	LimitLinear CD6Joint::getLimitLinear() const
-	{
-		return mLimitLinear;
-	}
-
-	void CD6Joint::setLimitLinear(const LimitLinear& limit)
-	{
-		if (mLimitLinear == limit)
-			return;
-
-		mLimitLinear = limit;
-
-		if (mInternal != nullptr)
-			_getInternal()->setLimitLinear(limit);
-	}
-
-	LimitAngularRange CD6Joint::getLimitTwist() const
-	{
-		return mLimitTwist;
-	}
-
-	void CD6Joint::setLimitTwist(const LimitAngularRange& limit)
-	{
-		if (mLimitTwist == limit)
-			return;
-
-		mLimitTwist = limit;
-
-		if (mInternal != nullptr)
-			_getInternal()->setLimitTwist(limit);
-	}
-
-	LimitConeRange CD6Joint::getLimitSwing() const
-	{
-		return mLimitSwing;
-	}
-
-	void CD6Joint::setLimitSwing(const LimitConeRange& limit)
-	{
-		if (mLimitSwing == limit)
-			return;
-
-		mLimitSwing = limit;
-
-		if (mInternal != nullptr)
-			_getInternal()->setLimitSwing(limit);
-	}
-
-	D6Joint::Drive CD6Joint::getDrive(D6Joint::DriveType type) const
-	{
-		return mDrive[(int)type];
-	}
-
-	void CD6Joint::setDrive(D6Joint::DriveType type, const D6Joint::Drive& drive)
-	{
-		if (mDrive[(int)type] == drive)
-			return;
-
-		mDrive[(int)type] = drive;
-
-		if (mInternal != nullptr)
-			_getInternal()->setDrive(type, drive);
-	}
-
-	Vector3 CD6Joint::getDrivePosition() const
-	{
-		return mDrivePosition;
-	}
-
-	Quaternion CD6Joint::getDriveRotation() const
-	{
-		return mDriveRotation;
-	}
-
-	void CD6Joint::setDriveTransform(const Vector3& position, const Quaternion& rotation)
-	{
-		if (mDrivePosition == position && mDriveRotation == rotation)
-			return;
-
-		mDrivePosition = position;
-		mDriveRotation = rotation;
-
-		if (mInternal != nullptr)
-			_getInternal()->setDriveTransform(position, rotation);
-	}
-
-	Vector3 CD6Joint::getDriveLinearVelocity() const
-	{
-		return mDriveLinearVelocity;
-	}
-
-	Vector3 CD6Joint::getDriveAngularVelocity() const
-	{
-		return mDriveAngularVelocity;
-	}
-
-	void CD6Joint::setDriveVelocity(const Vector3& linear, const Vector3& angular)
-	{
-		if (mDriveLinearVelocity == linear && mDriveAngularVelocity == angular)
-			return;
-
-		mDriveLinearVelocity = linear;
-		mDriveAngularVelocity = angular;
-
-		if (mInternal != nullptr)
-			_getInternal()->setDriveVelocity(linear, angular);
-	}
-
-	SPtr<Joint> CD6Joint::createInternal()
-	{
-		SPtr<Joint> joint = D6Joint::create();
-
-		joint->_setOwner(PhysicsOwnerType::Component, this);
-		return joint;
-	}
-
-	RTTITypeBase* CD6Joint::getRTTIStatic()
-	{
-		return CD6JointRTTI::instance();
-	}
-
-	RTTITypeBase* CD6Joint::getRTTI() const
-	{
-		return CD6Joint::getRTTIStatic();
-	}
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#include "BsCD6Joint.h"
+#include "BsSceneObject.h"
+#include "BsCD6JointRTTI.h"
+
+namespace BansheeEngine
+{
+	CD6Joint::CD6Joint()
+		: CJoint(mDesc)
+	{ }
+
+	CD6Joint::CD6Joint(const HSceneObject& parent)
+		: CJoint(parent, mDesc)
+	{
+		setName("D6Joint");
+	}
+
+	D6Joint::Motion CD6Joint::getMotion(D6Joint::Axis axis) const
+	{
+		return mDesc.motion[(int)axis];
+	}
+
+	void CD6Joint::setMotion(D6Joint::Axis axis, D6Joint::Motion motion)
+	{
+		if (mDesc.motion[(int)axis] == motion)
+			return;
+
+		mDesc.motion[(int)axis] = motion;
+
+		if (mInternal != nullptr)
+			_getInternal()->setMotion(axis, motion);
+	}
+
+	Radian CD6Joint::getTwist() const
+	{
+		if (mInternal == nullptr)
+			return Radian(0.0f);
+
+		return _getInternal()->getTwist();
+	}
+
+	Radian CD6Joint::getSwingY() const
+	{
+		if (mInternal == nullptr)
+			return Radian(0.0f);
+
+		return _getInternal()->getSwingY();
+	}
+
+	Radian CD6Joint::getSwingZ() const
+	{
+		if (mInternal == nullptr)
+			return Radian(0.0f);
+
+		return _getInternal()->getSwingZ();
+	}
+
+	LimitLinear CD6Joint::getLimitLinear() const
+	{
+		return mDesc.limitLinear;
+	}
+
+	void CD6Joint::setLimitLinear(const LimitLinear& limit)
+	{
+		if (mDesc.limitLinear == limit)
+			return;
+
+		mDesc.limitLinear = limit;
+
+		if (mInternal != nullptr)
+			_getInternal()->setLimitLinear(limit);
+	}
+
+	LimitAngularRange CD6Joint::getLimitTwist() const
+	{
+		return mDesc.limitTwist;
+	}
+
+	void CD6Joint::setLimitTwist(const LimitAngularRange& limit)
+	{
+		if (mDesc.limitTwist == limit)
+			return;
+
+		mDesc.limitTwist = limit;
+
+		if (mInternal != nullptr)
+			_getInternal()->setLimitTwist(limit);
+	}
+
+	LimitConeRange CD6Joint::getLimitSwing() const
+	{
+		return mDesc.limitSwing;
+	}
+
+	void CD6Joint::setLimitSwing(const LimitConeRange& limit)
+	{
+		if (mDesc.limitSwing == limit)
+			return;
+
+		mDesc.limitSwing = limit;
+
+		if (mInternal != nullptr)
+			_getInternal()->setLimitSwing(limit);
+	}
+
+	D6Joint::Drive CD6Joint::getDrive(D6Joint::DriveType type) const
+	{
+		return mDesc.drive[(int)type];
+	}
+
+	void CD6Joint::setDrive(D6Joint::DriveType type, const D6Joint::Drive& drive)
+	{
+		if (mDesc.drive[(int)type] == drive)
+			return;
+
+		mDesc.drive[(int)type] = drive;
+
+		if (mInternal != nullptr)
+			_getInternal()->setDrive(type, drive);
+	}
+
+	Vector3 CD6Joint::getDrivePosition() const
+	{
+		return mDesc.drivePosition;
+	}
+
+	Quaternion CD6Joint::getDriveRotation() const
+	{
+		return mDesc.driveRotation;
+	}
+
+	void CD6Joint::setDriveTransform(const Vector3& position, const Quaternion& rotation)
+	{
+		if (mDesc.drivePosition == position && mDesc.driveRotation == rotation)
+			return;
+
+		mDesc.drivePosition = position;
+		mDesc.driveRotation = rotation;
+
+		if (mInternal != nullptr)
+			_getInternal()->setDriveTransform(position, rotation);
+	}
+
+	Vector3 CD6Joint::getDriveLinearVelocity() const
+	{
+		return mDesc.driveLinearVelocity;
+	}
+
+	Vector3 CD6Joint::getDriveAngularVelocity() const
+	{
+		return mDesc.driveAngularVelocity;
+	}
+
+	void CD6Joint::setDriveVelocity(const Vector3& linear, const Vector3& angular)
+	{
+		if (mDesc.driveLinearVelocity == linear && mDesc.driveAngularVelocity == angular)
+			return;
+
+		mDesc.driveLinearVelocity = linear;
+		mDesc.driveAngularVelocity = angular;
+
+		if (mInternal != nullptr)
+			_getInternal()->setDriveVelocity(linear, angular);
+	}
+
+	SPtr<Joint> CD6Joint::createInternal()
+	{
+		SPtr<Joint> joint = D6Joint::create();
+
+		joint->_setOwner(PhysicsOwnerType::Component, this);
+		return joint;
+	}
+
+	RTTITypeBase* CD6Joint::getRTTIStatic()
+	{
+		return CD6JointRTTI::instance();
+	}
+
+	RTTITypeBase* CD6Joint::getRTTI() const
+	{
+		return CD6Joint::getRTTIStatic();
+	}
 }
 }

+ 127 - 123
Source/BansheeCore/Source/BsCDistanceJoint.cpp

@@ -1,124 +1,128 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsCDistanceJoint.h"
-#include "BsSceneObject.h"
-#include "BsCDistanceJointRTTI.h"
-
-namespace BansheeEngine
-{
-	CDistanceJoint::CDistanceJoint(const HSceneObject& parent)
-		: CJoint(parent)
-	{
-		setName("DistanceJoint");
-	}
-
-	float CDistanceJoint::getDistance() const
-	{
-		if (mInternal == nullptr)
-			return 0.0f;
-
-		return _getInternal()->getDistance();
-	}
-
-	float CDistanceJoint::getMinDistance() const
-	{
-		return mMinDistance;
-	}
-
-	void CDistanceJoint::setMinDistance(float value)
-	{
-		if (mMinDistance == value)
-			return;
-
-		mMinDistance = value;
-
-		if (mInternal != nullptr)
-			_getInternal()->setMinDistance(value);
-	}
-
-	float CDistanceJoint::getMaxDistance() const
-	{
-		return mMaxDistance;
-	}
-
-	void CDistanceJoint::setMaxDistance(float value)
-	{
-		if (mMaxDistance == value)
-			return;
-
-		mMaxDistance = value;
-
-		if (mInternal != nullptr)
-			_getInternal()->setMaxDistance(value);
-	}
-
-	float CDistanceJoint::getTolerance() const
-	{
-		return mTolerance;
-	}
-
-	void CDistanceJoint::setTolerance(float value)
-	{
-		if (mTolerance == value)
-			return;
-
-		mTolerance = value;
-
-		if (mInternal != nullptr)
-			_getInternal()->setTolerance(value);
-	}
-
-	Spring CDistanceJoint::getSpring() const
-	{
-		return mSpring;
-	}
-
-	void CDistanceJoint::setSpring(const Spring& value)
-	{
-		if (mSpring == value)
-			return;
-
-		mSpring = value;
-
-		if(mInternal != nullptr)
-			_getInternal()->setSpring(value);
-	}
-
-	void CDistanceJoint::setFlag(DistanceJoint::Flag flag, bool enabled)
-	{
-		bool isEnabled = ((UINT32)mFlag & (UINT32)flag) != 0;
-		if (isEnabled == enabled)
-			return;
-
-		if (enabled)
-			mFlag = (DistanceJoint::Flag)((UINT32)mFlag | (UINT32)flag);
-		else
-			mFlag = (DistanceJoint::Flag)((UINT32)mFlag & ~(UINT32)flag);
-
-		if (mInternal != nullptr)
-			_getInternal()->setFlag(flag, enabled);
-	}
-
-	bool CDistanceJoint::hasFlag(DistanceJoint::Flag flag) const
-	{
-		return ((UINT32)mFlag & (UINT32)flag) != 0;
-	}
-
-	SPtr<Joint> CDistanceJoint::createInternal()
-	{
-		SPtr<Joint> joint = DistanceJoint::create();
-
-		joint->_setOwner(PhysicsOwnerType::Component, this);
-		return joint;
-	}
-
-	RTTITypeBase* CDistanceJoint::getRTTIStatic()
-	{
-		return CDistanceJointRTTI::instance();
-	}
-
-	RTTITypeBase* CDistanceJoint::getRTTI() const
-	{
-		return CDistanceJoint::getRTTIStatic();
-	}
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#include "BsCDistanceJoint.h"
+#include "BsSceneObject.h"
+#include "BsCDistanceJointRTTI.h"
+
+namespace BansheeEngine
+{
+	CDistanceJoint::CDistanceJoint()
+		: CJoint(mDesc)
+	{ }
+
+	CDistanceJoint::CDistanceJoint(const HSceneObject& parent)
+		: CJoint(parent, mDesc)
+	{
+		setName("DistanceJoint");
+	}
+
+	float CDistanceJoint::getDistance() const
+	{
+		if (mInternal == nullptr)
+			return 0.0f;
+
+		return _getInternal()->getDistance();
+	}
+
+	float CDistanceJoint::getMinDistance() const
+	{
+		return mDesc.minDistance;
+	}
+
+	void CDistanceJoint::setMinDistance(float value)
+	{
+		if (mDesc.minDistance == value)
+			return;
+
+		mDesc.minDistance = value;
+
+		if (mInternal != nullptr)
+			_getInternal()->setMinDistance(value);
+	}
+
+	float CDistanceJoint::getMaxDistance() const
+	{
+		return mDesc.maxDistance;
+	}
+
+	void CDistanceJoint::setMaxDistance(float value)
+	{
+		if (mDesc.maxDistance == value)
+			return;
+
+		mDesc.maxDistance = value;
+
+		if (mInternal != nullptr)
+			_getInternal()->setMaxDistance(value);
+	}
+
+	float CDistanceJoint::getTolerance() const
+	{
+		return mDesc.tolerance;
+	}
+
+	void CDistanceJoint::setTolerance(float value)
+	{
+		if (mDesc.tolerance == value)
+			return;
+
+		mDesc.tolerance = value;
+
+		if (mInternal != nullptr)
+			_getInternal()->setTolerance(value);
+	}
+
+	Spring CDistanceJoint::getSpring() const
+	{
+		return mDesc.spring;
+	}
+
+	void CDistanceJoint::setSpring(const Spring& value)
+	{
+		if (mDesc.spring == value)
+			return;
+
+		mDesc.spring = value;
+
+		if(mInternal != nullptr)
+			_getInternal()->setSpring(value);
+	}
+
+	void CDistanceJoint::setFlag(DistanceJoint::Flag flag, bool enabled)
+	{
+		bool isEnabled = ((UINT32)mDesc.flag & (UINT32)flag) != 0;
+		if (isEnabled == enabled)
+			return;
+
+		if (enabled)
+			mDesc.flag = (DistanceJoint::Flag)((UINT32)mDesc.flag | (UINT32)flag);
+		else
+			mDesc.flag = (DistanceJoint::Flag)((UINT32)mDesc.flag & ~(UINT32)flag);
+
+		if (mInternal != nullptr)
+			_getInternal()->setFlag(flag, enabled);
+	}
+
+	bool CDistanceJoint::hasFlag(DistanceJoint::Flag flag) const
+	{
+		return ((UINT32)mDesc.flag & (UINT32)flag) != 0;
+	}
+
+	SPtr<Joint> CDistanceJoint::createInternal()
+	{
+		SPtr<Joint> joint = DistanceJoint::create(mDesc);
+
+		joint->_setOwner(PhysicsOwnerType::Component, this);
+		return joint;
+	}
+
+	RTTITypeBase* CDistanceJoint::getRTTIStatic()
+	{
+		return CDistanceJointRTTI::instance();
+	}
+
+	RTTITypeBase* CDistanceJoint::getRTTI() const
+	{
+		return CDistanceJoint::getRTTIStatic();
+	}
 }
 }

+ 36 - 32
Source/BansheeCore/Source/BsCFixedJoint.cpp

@@ -1,33 +1,37 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsCFixedJoint.h"
-#include "BsSceneObject.h"
-#include "BsCRigidbody.h"
-#include "BsCFixedJointRTTI.h"
-
-namespace BansheeEngine
-{
-	CFixedJoint::CFixedJoint(const HSceneObject& parent)
-		: CJoint(parent)
-	{
-		setName("FixedJoint");
-	}
-
-	SPtr<Joint> CFixedJoint::createInternal()
-	{
-		SPtr<Joint> joint = FixedJoint::create();
-
-		joint->_setOwner(PhysicsOwnerType::Component, this);
-		return joint;
-	}
-
-	RTTITypeBase* CFixedJoint::getRTTIStatic()
-	{
-		return CFixedJointRTTI::instance();
-	}
-
-	RTTITypeBase* CFixedJoint::getRTTI() const
-	{
-		return CFixedJoint::getRTTIStatic();
-	}
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#include "BsCFixedJoint.h"
+#include "BsSceneObject.h"
+#include "BsCRigidbody.h"
+#include "BsCFixedJointRTTI.h"
+
+namespace BansheeEngine
+{
+	CFixedJoint::CFixedJoint() 
+		:CJoint(mDesc)
+	{ }
+
+	CFixedJoint::CFixedJoint(const HSceneObject& parent)
+		: CJoint(parent, mDesc)
+	{
+		setName("FixedJoint");
+	}
+
+	SPtr<Joint> CFixedJoint::createInternal()
+	{
+		SPtr<Joint> joint = FixedJoint::create(mDesc);
+
+		joint->_setOwner(PhysicsOwnerType::Component, this);
+		return joint;
+	}
+
+	RTTITypeBase* CFixedJoint::getRTTIStatic()
+	{
+		return CFixedJointRTTI::instance();
+	}
+
+	RTTITypeBase* CFixedJoint::getRTTI() const
+	{
+		return CFixedJoint::getRTTIStatic();
+	}
 }
 }

+ 103 - 99
Source/BansheeCore/Source/BsCHingeJoint.cpp

@@ -1,100 +1,104 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsCHingeJoint.h"
-#include "BsSceneObject.h"
-#include "BsCHingeJointRTTI.h"
-
-namespace BansheeEngine
-{
-	CHingeJoint::CHingeJoint(const HSceneObject& parent)
-		: CJoint(parent)
-	{
-		setName("HingeJoint");
-	}
-
-	Radian CHingeJoint::getAngle() const
-	{
-		if (mInternal == nullptr)
-			return Radian(0.0f);
-
-		return _getInternal()->getAngle();
-	}
-
-	float CHingeJoint::getSpeed() const
-	{
-		if (mInternal == nullptr)
-			return 0.0f;
-
-		return _getInternal()->getSpeed();
-	}
-
-	LimitAngularRange CHingeJoint::getLimit() const
-	{
-		return mLimit;
-	}
-
-	void CHingeJoint::setLimit(const LimitAngularRange& limit)
-	{
-		if (limit == mLimit)
-			return;
-
-		mLimit = limit;
-
-		if (mInternal != nullptr)
-			_getInternal()->setLimit(limit);
-	}
-
-	HingeJoint::Drive CHingeJoint::getDrive() const
-	{
-		return mDrive;
-	}
-
-	void CHingeJoint::setDrive(const HingeJoint::Drive& drive)
-	{
-		if (drive == mDrive)
-			return;
-
-		mDrive = drive;
-
-		if (mInternal != nullptr)
-			_getInternal()->setDrive(drive);
-	}
-
-	void CHingeJoint::setFlag(HingeJoint::Flag flag, bool enabled)
-	{
-		bool isEnabled = ((UINT32)mFlag & (UINT32)flag) != 0;
-		if (isEnabled == enabled)
-			return;
-
-		if (enabled)
-			mFlag = (HingeJoint::Flag)((UINT32)mFlag | (UINT32)flag);
-		else
-			mFlag = (HingeJoint::Flag)((UINT32)mFlag & ~(UINT32)flag);
-
-		if (mInternal != nullptr)
-			_getInternal()->setFlag(flag, enabled);
-	}
-
-	bool CHingeJoint::hasFlag(HingeJoint::Flag flag) const
-	{
-		return ((UINT32)mFlag & (UINT32)flag) != 0;
-	}
-
-	SPtr<Joint> CHingeJoint::createInternal()
-	{
-		SPtr<Joint> joint = HingeJoint::create();
-
-		joint->_setOwner(PhysicsOwnerType::Component, this);
-		return joint;
-	}
-
-	RTTITypeBase* CHingeJoint::getRTTIStatic()
-	{
-		return CHingeJointRTTI::instance();
-	}
-
-	RTTITypeBase* CHingeJoint::getRTTI() const
-	{
-		return CHingeJoint::getRTTIStatic();
-	}
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#include "BsCHingeJoint.h"
+#include "BsSceneObject.h"
+#include "BsCHingeJointRTTI.h"
+
+namespace BansheeEngine
+{
+	CHingeJoint::CHingeJoint()
+		: CJoint(mDesc)
+	{ }
+
+	CHingeJoint::CHingeJoint(const HSceneObject& parent)
+		: CJoint(parent, mDesc)
+	{
+		setName("HingeJoint");
+	}
+
+	Radian CHingeJoint::getAngle() const
+	{
+		if (mInternal == nullptr)
+			return Radian(0.0f);
+
+		return _getInternal()->getAngle();
+	}
+
+	float CHingeJoint::getSpeed() const
+	{
+		if (mInternal == nullptr)
+			return 0.0f;
+
+		return _getInternal()->getSpeed();
+	}
+
+	LimitAngularRange CHingeJoint::getLimit() const
+	{
+		return mDesc.limit;
+	}
+
+	void CHingeJoint::setLimit(const LimitAngularRange& limit)
+	{
+		if (limit == mDesc.limit)
+			return;
+
+		mDesc.limit = limit;
+
+		if (mInternal != nullptr)
+			_getInternal()->setLimit(limit);
+	}
+
+	HingeJoint::Drive CHingeJoint::getDrive() const
+	{
+		return mDesc.drive;
+	}
+
+	void CHingeJoint::setDrive(const HingeJoint::Drive& drive)
+	{
+		if (drive == mDesc.drive)
+			return;
+
+		mDesc.drive = drive;
+
+		if (mInternal != nullptr)
+			_getInternal()->setDrive(drive);
+	}
+
+	void CHingeJoint::setFlag(HingeJoint::Flag flag, bool enabled)
+	{
+		bool isEnabled = ((UINT32)mDesc.flag & (UINT32)flag) != 0;
+		if (isEnabled == enabled)
+			return;
+
+		if (enabled)
+			mDesc.flag = (HingeJoint::Flag)((UINT32)mDesc.flag | (UINT32)flag);
+		else
+			mDesc.flag = (HingeJoint::Flag)((UINT32)mDesc.flag & ~(UINT32)flag);
+
+		if (mInternal != nullptr)
+			_getInternal()->setFlag(flag, enabled);
+	}
+
+	bool CHingeJoint::hasFlag(HingeJoint::Flag flag) const
+	{
+		return ((UINT32)mDesc.flag & (UINT32)flag) != 0;
+	}
+
+	SPtr<Joint> CHingeJoint::createInternal()
+	{
+		SPtr<Joint> joint = HingeJoint::create(mDesc);
+
+		joint->_setOwner(PhysicsOwnerType::Component, this);
+		return joint;
+	}
+
+	RTTITypeBase* CHingeJoint::getRTTIStatic()
+	{
+		return CHingeJointRTTI::instance();
+	}
+
+	RTTITypeBase* CHingeJoint::getRTTI() const
+	{
+		return CHingeJoint::getRTTIStatic();
+	}
 }
 }

+ 72 - 52
Source/BansheeCore/Source/BsCJoint.cpp

@@ -10,8 +10,12 @@ using namespace std::placeholders;
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	CJoint::CJoint(const HSceneObject& parent)
-		: Component(parent)
+	CJoint::CJoint(JOINT_DESC& desc)
+		:mDesc(desc)
+	{ }
+
+	CJoint::CJoint(const HSceneObject& parent, JOINT_DESC& desc)
+		: Component(parent), mDesc(desc)
 	{
 	{
 		setName("Joint");
 		setName("Joint");
 
 
@@ -36,14 +40,28 @@ namespace BansheeEngine
 		if (value != nullptr)
 		if (value != nullptr)
 			mBodies[(int)body]->_setJoint(mThisHandle);
 			mBodies[(int)body]->_setJoint(mThisHandle);
 
 
+		// If joint already exists, destroy it if we removed all bodies, otherwise update its transform
 		if(mInternal != nullptr)
 		if(mInternal != nullptr)
 		{
 		{
-			Rigidbody* rigidbody = nullptr;
-			if (value != nullptr)
-				rigidbody = value->_getInternal();
-
-			mInternal->setBody(body, rigidbody);
-			updateTransform(body);
+			if (mBodies[0] == nullptr && mBodies[1] == nullptr)
+				destroyInternal();
+			else
+			{
+				Rigidbody* rigidbody = nullptr;
+				if (value != nullptr)
+					rigidbody = value->_getInternal();
+
+				mInternal->setBody(body, rigidbody);
+				updateTransform(body);
+			}
+		}
+		else // If joint doesn't exist, check if we can create it
+		{
+			// Must be an active component and at least one of the bodies must be non-null
+			if (SO()->getActive() && mBodies[0] != nullptr || mBodies[1] != nullptr)
+			{
+				restoreInternal();
+			}
 		}
 		}
 	}
 	}
 
 
@@ -65,21 +83,21 @@ namespace BansheeEngine
 		mPositions[(int)body] = position;
 		mPositions[(int)body] = position;
 		mRotations[(int)body] = rotation;
 		mRotations[(int)body] = rotation;
 
 
-		if(mInternal != nullptr)
+		if (mInternal != nullptr)
 			updateTransform(body);
 			updateTransform(body);
 	}
 	}
 
 
 	float CJoint::getBreakForce() const
 	float CJoint::getBreakForce() const
 	{
 	{
-		return mBreakForce;
+		return mDesc.breakForce;
 	}
 	}
 
 
 	void CJoint::setBreakForce(float force)
 	void CJoint::setBreakForce(float force)
 	{
 	{
-		if (mBreakForce == force)
+		if (mDesc.breakForce == force)
 			return;
 			return;
 
 
-		mBreakForce = force;
+		mDesc.breakForce = force;
 
 
 		if (mInternal != nullptr)
 		if (mInternal != nullptr)
 			mInternal->setBreakForce(force);
 			mInternal->setBreakForce(force);
@@ -87,15 +105,15 @@ namespace BansheeEngine
 
 
 	float CJoint::getBreakTorque() const
 	float CJoint::getBreakTorque() const
 	{
 	{
-		return mBreakTorque;
+		return mDesc.breakTorque;
 	}
 	}
 
 
 	void CJoint::setBreakToque(float torque)
 	void CJoint::setBreakToque(float torque)
 	{
 	{
-		if (mBreakTorque == torque)
+		if (mDesc.breakTorque == torque)
 			return;
 			return;
 
 
-		mBreakTorque = torque;
+		mDesc.breakTorque = torque;
 
 
 		if (mInternal != nullptr)
 		if (mInternal != nullptr)
 			mInternal->setBreakTorque(torque);
 			mInternal->setBreakTorque(torque);
@@ -103,15 +121,15 @@ namespace BansheeEngine
 
 
 	bool CJoint::getEnableCollision() const
 	bool CJoint::getEnableCollision() const
 	{
 	{
-		return mEnableCollision;
+		return mDesc.enableCollision;
 	}
 	}
 
 
 	void CJoint::setEnableCollision(bool value)
 	void CJoint::setEnableCollision(bool value)
 	{
 	{
-		if (mEnableCollision == value)
+		if (mDesc.enableCollision == value)
 			return;
 			return;
 
 
-		mEnableCollision = value;
+		mDesc.enableCollision = value;
 
 
 		if (mInternal != nullptr)
 		if (mInternal != nullptr)
 			mInternal->setEnableCollision(value);
 			mInternal->setEnableCollision(value);
@@ -130,22 +148,25 @@ namespace BansheeEngine
 		if (mBodies[1] != nullptr)
 		if (mBodies[1] != nullptr)
 			mBodies[1]->_setJoint(HJoint());
 			mBodies[1]->_setJoint(HJoint());
 
 
-		destroyInternal();
+		if(mInternal != nullptr)
+			destroyInternal();
 	}
 	}
 
 
 	void CJoint::onDisabled()
 	void CJoint::onDisabled()
 	{
 	{
-		destroyInternal();
+		if (mInternal != nullptr)
+			destroyInternal();
 	}
 	}
 
 
 	void CJoint::onEnabled()
 	void CJoint::onEnabled()
 	{
 	{
-		restoreInternal();
+		if(mBodies[0] != nullptr || mBodies[1] != nullptr)
+			restoreInternal();
 	}
 	}
 
 
 	void CJoint::onTransformChanged(TransformChangedFlags flags)
 	void CJoint::onTransformChanged(TransformChangedFlags flags)
 	{
 	{
-		if (!SO()->getActive())
+		if (mInternal == nullptr)
 			return;
 			return;
 
 
 		// We're ignoring this during physics update because it would cause problems if the joint itself was moved by physics
 		// We're ignoring this during physics update because it would cause problems if the joint itself was moved by physics
@@ -165,32 +186,23 @@ namespace BansheeEngine
 	{
 	{
 		if (mInternal == nullptr)
 		if (mInternal == nullptr)
 		{
 		{
-			mInternal = createInternal();
-
-			mInternal->onJointBreak.connect(std::bind(&CJoint::triggerOnJointBroken, this));
-		}
-
-		// Note: Merge into one call to avoid many virtual function calls
-		Rigidbody* bodies[2];
+			if (mBodies[0] != nullptr)
+				mDesc.bodies[0].body = mBodies[0]->_getInternal();
+			else
+				mDesc.bodies[0].body = nullptr;
 
 
-		if (mBodies[0] != nullptr)
-			bodies[0] = mBodies[0]->_getInternal();
-		else
-			bodies[0] = nullptr;
+			if (mBodies[1] != nullptr)
+				mDesc.bodies[1].body = mBodies[1]->_getInternal();
+			else
+				mDesc.bodies[1].body = nullptr;
 
 
-		if (mBodies[1] != nullptr)
-			bodies[1] = mBodies[1]->_getInternal();
-		else
-			bodies[1] = nullptr;
+			getLocalTransform(JointBody::A, mDesc.bodies[0].position, mDesc.bodies[0].rotation);
+			getLocalTransform(JointBody::B, mDesc.bodies[1].position, mDesc.bodies[1].rotation);
 
 
-		mInternal->setBody(JointBody::A, bodies[0]);
-		mInternal->setBody(JointBody::B, bodies[1]);
-		mInternal->setBreakForce(mBreakForce);
-		mInternal->setBreakTorque(mBreakTorque);
-		mInternal->setEnableCollision(mEnableCollision);
+			mInternal = createInternal();
 
 
-		updateTransform(JointBody::A);
-		updateTransform(JointBody::B);
+			mInternal->onJointBreak.connect(std::bind(&CJoint::triggerOnJointBroken, this));
+		}
 	}
 	}
 
 
 	void CJoint::destroyInternal()
 	void CJoint::destroyInternal()
@@ -202,6 +214,9 @@ namespace BansheeEngine
 
 
 	void CJoint::notifyRigidbodyMoved(const HRigidbody& body)
 	void CJoint::notifyRigidbodyMoved(const HRigidbody& body)
 	{
 	{
+		if (mInternal == nullptr)
+			return;
+
 		// If physics update is in progress do nothing, as its the joint itself that's probably moving the body
 		// If physics update is in progress do nothing, as its the joint itself that's probably moving the body
 		if (gPhysics()._isUpdateInProgress())
 		if (gPhysics()._isUpdateInProgress())
 			return;
 			return;
@@ -219,8 +234,15 @@ namespace BansheeEngine
 		Vector3 localPos;
 		Vector3 localPos;
 		Quaternion localRot;
 		Quaternion localRot;
 
 
-		localPos = mPositions[(int)body];
-		localRot = mRotations[(int)body];
+		getLocalTransform(body, localPos, localRot);
+
+		mInternal->setTransform(body, localPos, localRot);
+	}
+
+	void CJoint::getLocalTransform(JointBody body, Vector3& position, Quaternion& rotation)
+	{
+		position = mPositions[(int)body];
+		rotation = mRotations[(int)body];
 
 
 		// Transform to world space of the related body
 		// Transform to world space of the related body
 		HRigidbody rigidbody = mBodies[(int)body];
 		HRigidbody rigidbody = mBodies[(int)body];
@@ -228,17 +250,15 @@ namespace BansheeEngine
 		{
 		{
 			Quaternion worldRot = rigidbody->SO()->getWorldRotation();
 			Quaternion worldRot = rigidbody->SO()->getWorldRotation();
 
 
-			localRot = worldRot * localRot;
-			localPos = worldRot.rotate(localPos) + rigidbody->SO()->getWorldPosition();
+			rotation = worldRot * rotation;
+			position = worldRot.rotate(position) + rigidbody->SO()->getWorldPosition();
 		}
 		}
 
 
 		// Transform to space local to the joint
 		// Transform to space local to the joint
 		Quaternion invRotation = SO()->getWorldRotation().inverse();
 		Quaternion invRotation = SO()->getWorldRotation().inverse();
 
 
-		localPos = invRotation.rotate(localPos - SO()->getWorldPosition());
-		localRot = invRotation * localRot;
-
-		mInternal->setTransform(body, localPos, localRot);
+		position = invRotation.rotate(position - SO()->getWorldPosition());
+		rotation = invRotation * rotation;
 	}
 	}
 	
 	
 	void CJoint::triggerOnJointBroken()
 	void CJoint::triggerOnJointBroken()

+ 87 - 83
Source/BansheeCore/Source/BsCSliderJoint.cpp

@@ -1,84 +1,88 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsCSliderJoint.h"
-#include "BsSceneObject.h"
-#include "BsCSliderJointRTTI.h"
-
-namespace BansheeEngine
-{
-	CSliderJoint::CSliderJoint(const HSceneObject& parent)
-		: CJoint(parent)
-	{
-		setName("SliderJoint");
-	}
-
-	float CSliderJoint::getPosition() const
-	{
-		if (mInternal == nullptr)
-			return 0.0f;
-
-		return _getInternal()->getPosition();
-	}
-
-	float CSliderJoint::getSpeed() const
-	{
-		if (mInternal == nullptr)
-			return 0.0f;
-
-		return _getInternal()->getSpeed();
-	}
-
-	LimitLinearRange CSliderJoint::getLimit() const
-	{
-		return mLimit;
-	}
-
-	void CSliderJoint::setLimit(const LimitLinearRange& limit)
-	{
-		if (mLimit == limit)
-			return;
-
-		mLimit = limit;
-
-		if (mInternal != nullptr)
-			_getInternal()->setLimit(limit);
-	}
-
-	void CSliderJoint::setFlag(SliderJoint::Flag flag, bool enabled)
-	{
-		bool isEnabled = ((UINT32)mFlag & (UINT32)flag) != 0;
-		if (isEnabled == enabled)
-			return;
-
-		if (enabled)
-			mFlag = (SliderJoint::Flag)((UINT32)mFlag | (UINT32)flag);
-		else
-			mFlag = (SliderJoint::Flag)((UINT32)mFlag & ~(UINT32)flag);
-
-		if (mInternal != nullptr)
-			_getInternal()->setFlag(flag, enabled);
-	}
-
-	bool CSliderJoint::hasFlag(SliderJoint::Flag flag) const
-	{
-		return ((UINT32)mFlag & (UINT32)flag) != 0;
-	}
-
-	SPtr<Joint> CSliderJoint::createInternal()
-	{
-		SPtr<Joint> joint = SliderJoint::create();
-
-		joint->_setOwner(PhysicsOwnerType::Component, this);
-		return joint;
-	}
-
-	RTTITypeBase* CSliderJoint::getRTTIStatic()
-	{
-		return CSliderJointRTTI::instance();
-	}
-
-	RTTITypeBase* CSliderJoint::getRTTI() const
-	{
-		return CSliderJoint::getRTTIStatic();
-	}
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#include "BsCSliderJoint.h"
+#include "BsSceneObject.h"
+#include "BsCSliderJointRTTI.h"
+
+namespace BansheeEngine
+{
+	CSliderJoint::CSliderJoint()
+		: CJoint(mDesc)
+	{ }
+
+	CSliderJoint::CSliderJoint(const HSceneObject& parent)
+		: CJoint(parent, mDesc)
+	{
+		setName("SliderJoint");
+	}
+
+	float CSliderJoint::getPosition() const
+	{
+		if (mInternal == nullptr)
+			return 0.0f;
+
+		return _getInternal()->getPosition();
+	}
+
+	float CSliderJoint::getSpeed() const
+	{
+		if (mInternal == nullptr)
+			return 0.0f;
+
+		return _getInternal()->getSpeed();
+	}
+
+	LimitLinearRange CSliderJoint::getLimit() const
+	{
+		return mDesc.limit;
+	}
+
+	void CSliderJoint::setLimit(const LimitLinearRange& limit)
+	{
+		if (mDesc.limit == limit)
+			return;
+
+		mDesc.limit = limit;
+
+		if (mInternal != nullptr)
+			_getInternal()->setLimit(limit);
+	}
+
+	void CSliderJoint::setFlag(SliderJoint::Flag flag, bool enabled)
+	{
+		bool isEnabled = ((UINT32)mDesc.flag & (UINT32)flag) != 0;
+		if (isEnabled == enabled)
+			return;
+
+		if (enabled)
+			mDesc.flag = (SliderJoint::Flag)((UINT32)mDesc.flag | (UINT32)flag);
+		else
+			mDesc.flag = (SliderJoint::Flag)((UINT32)mDesc.flag & ~(UINT32)flag);
+
+		if (mInternal != nullptr)
+			_getInternal()->setFlag(flag, enabled);
+	}
+
+	bool CSliderJoint::hasFlag(SliderJoint::Flag flag) const
+	{
+		return ((UINT32)mDesc.flag & (UINT32)flag) != 0;
+	}
+
+	SPtr<Joint> CSliderJoint::createInternal()
+	{
+		SPtr<Joint> joint = SliderJoint::create(mDesc);
+
+		joint->_setOwner(PhysicsOwnerType::Component, this);
+		return joint;
+	}
+
+	RTTITypeBase* CSliderJoint::getRTTIStatic()
+	{
+		return CSliderJointRTTI::instance();
+	}
+
+	RTTITypeBase* CSliderJoint::getRTTI() const
+	{
+		return CSliderJoint::getRTTIStatic();
+	}
 }
 }

+ 71 - 67
Source/BansheeCore/Source/BsCSphericalJoint.cpp

@@ -1,68 +1,72 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#include "BsCSphericalJoint.h"
-#include "BsSceneObject.h"
-#include "BsCSphericalJointRTTI.h"
-
-namespace BansheeEngine
-{
-	CSphericalJoint::CSphericalJoint(const HSceneObject& parent)
-		: CJoint(parent)
-	{
-		setName("SphericalJoint");
-	}
-
-	LimitConeRange CSphericalJoint::getLimit() const
-	{
-		return mLimit;
-	}
-
-	void CSphericalJoint::setLimit(const LimitConeRange& limit)
-	{
-		if (limit == mLimit)
-			return;
-
-		mLimit = limit;
-
-		if (mInternal != nullptr)
-			_getInternal()->setLimit(limit);
-	}
-	
-	void CSphericalJoint::setFlag(SphericalJoint::Flag flag, bool enabled)
-	{
-		bool isEnabled = ((UINT32)mFlag & (UINT32)flag) != 0;
-		if (isEnabled == enabled)
-			return;
-
-		if (enabled)
-			mFlag = (SphericalJoint::Flag)((UINT32)mFlag | (UINT32)flag);
-		else
-			mFlag = (SphericalJoint::Flag)((UINT32)mFlag & ~(UINT32)flag);
-
-		if (mInternal != nullptr)
-			_getInternal()->setFlag(flag, enabled);
-	}
-
-	bool CSphericalJoint::hasFlag(SphericalJoint::Flag flag) const
-	{
-		return ((UINT32)mFlag & (UINT32)flag) != 0;
-	}
-
-	SPtr<Joint> CSphericalJoint::createInternal()
-	{
-		SPtr<Joint> joint = SphericalJoint::create();
-
-		joint->_setOwner(PhysicsOwnerType::Component, this);
-		return joint;
-	}
-
-	RTTITypeBase* CSphericalJoint::getRTTIStatic()
-	{
-		return CSphericalJointRTTI::instance();
-	}
-
-	RTTITypeBase* CSphericalJoint::getRTTI() const
-	{
-		return CSphericalJoint::getRTTIStatic();
-	}
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#include "BsCSphericalJoint.h"
+#include "BsSceneObject.h"
+#include "BsCSphericalJointRTTI.h"
+
+namespace BansheeEngine
+{
+	CSphericalJoint::CSphericalJoint()
+		: CJoint(mDesc)
+	{ }
+
+	CSphericalJoint::CSphericalJoint(const HSceneObject& parent)
+		: CJoint(parent, mDesc)
+	{
+		setName("SphericalJoint");
+	}
+
+	LimitConeRange CSphericalJoint::getLimit() const
+	{
+		return mDesc.limit;
+	}
+
+	void CSphericalJoint::setLimit(const LimitConeRange& limit)
+	{
+		if (limit == mDesc.limit)
+			return;
+
+		mDesc.limit = limit;
+
+		if (mInternal != nullptr)
+			_getInternal()->setLimit(limit);
+	}
+	
+	void CSphericalJoint::setFlag(SphericalJoint::Flag flag, bool enabled)
+	{
+		bool isEnabled = ((UINT32)mDesc.flag & (UINT32)flag) != 0;
+		if (isEnabled == enabled)
+			return;
+
+		if (enabled)
+			mDesc.flag = (SphericalJoint::Flag)((UINT32)mDesc.flag | (UINT32)flag);
+		else
+			mDesc.flag = (SphericalJoint::Flag)((UINT32)mDesc.flag & ~(UINT32)flag);
+
+		if (mInternal != nullptr)
+			_getInternal()->setFlag(flag, enabled);
+	}
+
+	bool CSphericalJoint::hasFlag(SphericalJoint::Flag flag) const
+	{
+		return ((UINT32)mDesc.flag & (UINT32)flag) != 0;
+	}
+
+	SPtr<Joint> CSphericalJoint::createInternal()
+	{
+		SPtr<Joint> joint = SphericalJoint::create(mDesc);
+
+		joint->_setOwner(PhysicsOwnerType::Component, this);
+		return joint;
+	}
+
+	RTTITypeBase* CSphericalJoint::getRTTIStatic()
+	{
+		return CSphericalJointRTTI::instance();
+	}
+
+	RTTITypeBase* CSphericalJoint::getRTTI() const
+	{
+		return CSphericalJoint::getRTTIStatic();
+	}
 }
 }