Browse Source

More work on adding physics joints

BearishSun 10 years ago
parent
commit
bfe36845c6

+ 6 - 0
BansheeCore/BansheeCore.vcxproj

@@ -315,6 +315,7 @@
     <ClInclude Include="Include\BsCRigidbodyRTTI.h" />
     <ClInclude Include="Include\BsCSphereCollider.h" />
     <ClInclude Include="Include\BsCSphereColliderRTTI.h" />
+    <ClInclude Include="Include\BsD6Joint.h" />
     <ClInclude Include="Include\BsDistanceJoint.h" />
     <ClInclude Include="Include\BsFCollider.h" />
     <ClInclude Include="Include\BsFixedJoint.h" />
@@ -417,7 +418,9 @@
     <ClInclude Include="Include\BsPixelBuffer.h" />
     <ClInclude Include="Include\BsShaderIncludeImporter.h" />
     <ClInclude Include="Include\BsShaderManager.h" />
+    <ClInclude Include="Include\BsSliderJoint.h" />
     <ClInclude Include="Include\BsSphereCollider.h" />
+    <ClInclude Include="Include\BsSphericalJoint.h" />
     <ClInclude Include="Include\BsStringTable.h" />
     <ClInclude Include="Include\BsStringTableManager.h" />
     <ClInclude Include="Include\BsStringTableRTTI.h" />
@@ -506,6 +509,7 @@
     <ClCompile Include="Source\BsCPlaneCollider.cpp" />
     <ClCompile Include="Source\BsCRigidbody.cpp" />
     <ClCompile Include="Source\BsCSphereCollider.cpp" />
+    <ClCompile Include="Source\BsD6Joint.cpp" />
     <ClCompile Include="Source\BsDistanceJoint.cpp" />
     <ClCompile Include="Source\BsFCollider.cpp" />
     <ClCompile Include="Source\BsFixedJoint.cpp" />
@@ -577,7 +581,9 @@
     <ClCompile Include="Source\BsResourceManifest.cpp" />
     <ClCompile Include="Source\BsResourceMetaData.cpp" />
     <ClCompile Include="Source\BsShaderManager.cpp" />
+    <ClCompile Include="Source\BsSliderJoint.cpp" />
     <ClCompile Include="Source\BsSphereCollider.cpp" />
+    <ClCompile Include="Source\BsSphericalJoint.cpp" />
     <ClCompile Include="Source\BsStringTable.cpp" />
     <ClCompile Include="Source\BsStringTableManager.cpp" />
     <ClCompile Include="Source\BsTextureImportOptions.cpp" />

+ 18 - 0
BansheeCore/BansheeCore.vcxproj.filters

@@ -695,6 +695,15 @@
     <ClInclude Include="Include\BsHingeJoint.h">
       <Filter>Header Files\Physics</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsSliderJoint.h">
+      <Filter>Header Files\Physics</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsSphericalJoint.h">
+      <Filter>Header Files\Physics</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsD6Joint.h">
+      <Filter>Header Files\Physics</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsCoreApplication.cpp">
@@ -1099,5 +1108,14 @@
     <ClCompile Include="Source\BsHingeJoint.cpp">
       <Filter>Source Files\Physics</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsSliderJoint.cpp">
+      <Filter>Source Files\Physics</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsSphericalJoint.cpp">
+      <Filter>Source Files\Physics</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsD6Joint.cpp">
+      <Filter>Source Files\Physics</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 68 - 0
BansheeCore/Include/BsD6Joint.h

@@ -0,0 +1,68 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsJoint.h"
+
+namespace BansheeEngine
+{
+	class BS_CORE_EXPORT D6Joint : public Joint
+	{
+	public:
+		enum class Axis
+		{
+			X, Y, Z, Twist, SwingY, SwingZ
+		};
+
+		enum class Motion
+		{
+			Locked, Limited, Free
+		};
+
+		enum class DriveType
+		{
+			X, Y, Z, Swing, Twist, SLERP
+		};
+
+		struct Drive
+		{
+			float stiffness = 0.0f;
+			float damping = 0.0f;
+			float forceLimit = FLT_MAX;
+			bool acceleration = false;
+		};
+
+	public:
+		virtual ~D6Joint() { }
+
+		virtual Motion getMotion(Axis axis) const = 0;
+		virtual void setMotion(Axis axis, Motion motion) = 0;
+
+		virtual Radian getTwist() const = 0;
+		virtual Radian getSwingY() const = 0;
+		virtual Radian getSwingZ() const = 0;
+
+		virtual LimitLinear getLimitLinear() const = 0;
+		virtual void setLimitLinear(const LimitLinear& limit) = 0;
+		
+		virtual LimitAngularRange getLimitTwist() const = 0;
+		virtual void setLimitTwist(const LimitAngularRange& limit) = 0;
+
+		virtual LimitConeRange getLimitSwing() const = 0;
+		virtual void setLimitSwing(const LimitConeRange& limit) = 0;
+	
+		virtual Drive getDrive(DriveType type) const = 0;
+		virtual void setDrive(DriveType type, const Drive& drive) = 0;
+
+		virtual Vector3 getDrivePosition() const = 0;
+		virtual Quaternion getDriveRotation() const = 0;
+		virtual void setDriveTransform(const Vector3& position, const Quaternion& rotation) = 0;
+
+		virtual Vector3 getDriveLinearVelocity() const = 0;
+		virtual Vector3 getDriveAngularVelocity() const = 0;
+		virtual void setDriveVelocity(const Vector3& linear, const Vector3& angular) = 0;
+
+		static SPtr<D6Joint> create();
+	};
+}

+ 2 - 2
BansheeCore/Include/BsHingeJoint.h

@@ -30,8 +30,8 @@ namespace BansheeEngine
 		virtual Radian getAngle() const = 0;
 		virtual float getSpeed() const = 0;
 
-		virtual LimitAngular getLimit() const = 0;
-		virtual void setLimit(const LimitAngular& limit) const = 0;
+		virtual LimitAngularRange getLimit() const = 0;
+		virtual void setLimit(const LimitAngularRange& limit) = 0;
 
 		virtual Drive getDrive() const = 0;
 		virtual void setDrive(const Drive& drive) const = 0;

+ 30 - 11
BansheeCore/Include/BsJoint.h

@@ -40,34 +40,53 @@ namespace BansheeEngine
 		float damping = 0.0f;
 	};
 
+	struct LimitLinearRange
+	{
+		LimitLinearRange()
+		{ }
+
+		LimitLinearRange(float lower, float upper, float contactDist = -1.0f)
+			:lower(lower), upper(upper), contactDist(contactDist)
+		{ }
+
+		LimitLinearRange(float lower, float upper, const Spring& spring)
+			:lower(lower), upper(upper), spring(spring)
+		{ }
+
+		float lower = 0.0f;
+		float upper = 0.0f;
+		float contactDist = -1.0f;
+		Spring spring;
+	};
+
 	struct LimitLinear
 	{
 		LimitLinear()
 		{ }
 
 		LimitLinear(float extent, float contactDist = -1.0f)
-			:extent(extent), contactDist(contactDist)
+			:extent(extent),  contactDist(contactDist)
 		{ }
 
-		LimitLinear(float extent, const Spring& spring)
+		LimitLinear(float extent,const Spring& spring)
 			:extent(extent), spring(spring)
 		{ }
 
-		float extent = FLT_MAX;
+		float extent = 0.0f;
 		float contactDist = -1.0f;
 		Spring spring;
 	};
 
-	struct LimitAngular
+	struct LimitAngularRange
 	{
-		LimitAngular()
+		LimitAngularRange()
 		{ }
 
-		LimitAngular(Radian lower, Radian upper, float contactDist = -1.0f)
+		LimitAngularRange(Radian lower, Radian upper, float contactDist = -1.0f)
 			:lower(lower), upper(upper), contactDist(contactDist)
 		{ }
 
-		LimitAngular(Radian lower, Radian upper, const Spring& spring)
+		LimitAngularRange(Radian lower, Radian upper, const Spring& spring)
 			:lower(lower), upper(upper), spring(spring)
 		{ }
 
@@ -77,16 +96,16 @@ namespace BansheeEngine
 		Spring spring;
 	};
 
-	struct LimitCone
+	struct LimitConeRange
 	{
-		LimitCone()
+		LimitConeRange()
 		{ }
 
-		LimitCone(Radian yLimitAngle, Radian zLimitAngle, float contactDist = -1.0f)
+		LimitConeRange(Radian yLimitAngle, Radian zLimitAngle, float contactDist = -1.0f)
 			:yLimitAngle(yLimitAngle), zLimitAngle(zLimitAngle), contactDist(contactDist)
 		{ }
 
-		LimitCone(Radian yLimitAngle, Radian zLimitAngle, const Spring& spring)
+		LimitConeRange(Radian yLimitAngle, Radian zLimitAngle, const Spring& spring)
 			:yLimitAngle(yLimitAngle), zLimitAngle(zLimitAngle), spring(spring)
 		{ }
 

+ 32 - 0
BansheeCore/Include/BsSliderJoint.h

@@ -0,0 +1,32 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsJoint.h"
+
+namespace BansheeEngine
+{
+	class BS_CORE_EXPORT SliderJoint : public Joint
+	{
+	public:
+		enum class Flag
+		{
+			Limit = 0x1,
+		};
+
+	public:
+		virtual ~SliderJoint() { }
+
+		virtual float getPosition() const = 0;
+		virtual float getSpeed() const = 0;
+
+		virtual LimitLinearRange getLimit() const = 0;
+		virtual void setLimit(const LimitLinearRange& limit) = 0;
+
+		virtual void setFlag(Flag flag, bool enabled) = 0;
+		virtual bool hasFlag(Flag flag) = 0;
+
+		static SPtr<SliderJoint> create();
+	};
+}

+ 29 - 0
BansheeCore/Include/BsSphericalJoint.h

@@ -0,0 +1,29 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsJoint.h"
+
+namespace BansheeEngine
+{
+	class BS_CORE_EXPORT SphericalJoint : public Joint
+	{
+	public:
+		enum class Flag
+		{
+			Limit = 0x1
+		};
+
+	public:
+		virtual ~SphericalJoint() { }
+
+		virtual LimitConeRange getLimit() const = 0;
+		virtual void setLimit(const LimitConeRange& limit) = 0;
+
+		virtual void setFlag(Flag flag, bool enabled) = 0;
+		virtual bool hasFlag(Flag flag) = 0;
+
+		static SPtr<SphericalJoint> create();
+	};
+}

+ 12 - 0
BansheeCore/Source/BsD6Joint.cpp

@@ -0,0 +1,12 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#include "BsD6Joint.h"
+#include "BsPhysics.h"
+
+namespace BansheeEngine
+{
+	SPtr<D6Joint> D6Joint::create()
+	{
+		return gPhysics().createD6Joint();
+	}
+}

+ 12 - 0
BansheeCore/Source/BsSliderJoint.cpp

@@ -0,0 +1,12 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#include "BsSliderJoint.h"
+#include "BsPhysics.h"
+
+namespace BansheeEngine
+{
+	SPtr<SliderJoint> SliderJoint::create()
+	{
+		return gPhysics().createSliderJoint();
+	}
+}

+ 12 - 0
BansheeCore/Source/BsSphericalJoint.cpp

@@ -0,0 +1,12 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#include "BsSphericalJoint.h"
+#include "BsPhysics.h"
+
+namespace BansheeEngine
+{
+	SPtr<SphericalJoint> SphericalJoint::create()
+	{
+		return gPhysics().createSphericalJoint();
+	}
+}

+ 6 - 0
BansheePhysX/BansheePhysX.vcxproj

@@ -250,6 +250,7 @@
     <ClCompile Include="Source\BsPhysX.cpp" />
     <ClCompile Include="Source\BsPhysXBoxCollider.cpp" />
     <ClCompile Include="Source\BsPhysXCapsuleCollider.cpp" />
+    <ClCompile Include="Source\BsPhysXD6Joint.cpp" />
     <ClCompile Include="Source\BsPhysXDistanceJoint.cpp" />
     <ClCompile Include="Source\BsPhysXFixedJoint.cpp" />
     <ClCompile Include="Source\BsPhysXHingeJoint.cpp" />
@@ -259,7 +260,9 @@
     <ClCompile Include="Source\BsPhysXPlaneCollider.cpp" />
     <ClCompile Include="Source\BsPhysXPlugin.cpp" />
     <ClCompile Include="Source\BsPhysXRigidbody.cpp" />
+    <ClCompile Include="Source\BsPhysXSliderJoint.cpp" />
     <ClCompile Include="Source\BsPhysXSphereCollider.cpp" />
+    <ClCompile Include="Source\BsPhysXSphericalJoint.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Include\BsFPhysXJoint.h" />
@@ -267,6 +270,7 @@
     <ClInclude Include="Include\BsPhysXBoxCollider.h" />
     <ClInclude Include="Include\BsFPhysXCollider.h" />
     <ClInclude Include="Include\BsPhysXCapsuleCollider.h" />
+    <ClInclude Include="Include\BsPhysXD6Joint.h" />
     <ClInclude Include="Include\BsPhysXDistanceJoint.h" />
     <ClInclude Include="Include\BsPhysXFixedJoint.h" />
     <ClInclude Include="Include\BsPhysXHingeJoint.h" />
@@ -277,7 +281,9 @@
     <ClInclude Include="Include\BsPhysXPlaneCollider.h" />
     <ClInclude Include="Include\BsPhysXPrerequisites.h" />
     <ClInclude Include="Include\BsPhysXRigidbody.h" />
+    <ClInclude Include="Include\BsPhysXSliderJoint.h" />
     <ClInclude Include="Include\BsPhysXSphereCollider.h" />
+    <ClInclude Include="Include\BsPhysXSphericalJoint.h" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">

+ 18 - 0
BansheePhysX/BansheePhysX.vcxproj.filters

@@ -59,6 +59,15 @@
     <ClCompile Include="Source\BsPhysXHingeJoint.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsPhysXSliderJoint.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsPhysXSphericalJoint.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsPhysXD6Joint.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Include\BsPhysXPrerequisites.h">
@@ -109,5 +118,14 @@
     <ClInclude Include="Include\BsPhysXHingeJoint.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsPhysXSliderJoint.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsPhysXSphericalJoint.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsPhysXD6Joint.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
 </Project>

+ 9 - 0
BansheePhysX/Include/BsPhysX.h

@@ -53,6 +53,13 @@ namespace BansheeEngine
 			const Quaternion& rotation) override;
 		SPtr<MeshCollider> createMeshCollider(const Vector3& position, const Quaternion& rotation) override;
 
+		SPtr<FixedJoint> createFixedJoint() override;
+		SPtr<DistanceJoint> createDistanceJoint() override;
+		SPtr<HingeJoint> createHingeJoint() override;
+		SPtr<SphericalJoint> createSphericalJoint() override;
+		SPtr<SliderJoint> createSliderJoint() override;
+		SPtr<D6Joint> createD6Joint() override;
+
 		void _reportContactEvent(const ContactEvent& event);
 		void _reportTriggerEvent(const TriggerEvent& event);
 
@@ -60,6 +67,7 @@ namespace BansheeEngine
 		physx::PxPhysics* getPhysX() const { return mPhysics; }
 		physx::PxScene* getScene() const { return mScene; }
 		physx::PxCooking* getCooking() const { return mCooking; }
+		physx::PxTolerancesScale getScale() const { return mScale; }
 
 	private:
 		friend class PhysXEventCallback;
@@ -78,6 +86,7 @@ namespace BansheeEngine
 		physx::PxScene* mScene = nullptr;
 
 		physx::PxMaterial* mDefaultMaterial = nullptr;
+		physx::PxTolerancesScale mScale;
 	};
 
 	/** Provides easier access to PhysX. */

+ 48 - 0
BansheePhysX/Include/BsPhysXD6Joint.h

@@ -0,0 +1,48 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsPhysXPrerequisites.h"
+#include "BsD6Joint.h"
+#include "PxPhysics.h"
+#include "extensions\PxD6Joint.h"
+
+namespace BansheeEngine
+{
+	class BS_PHYSX_EXPORT PhysXD6Joint : public D6Joint
+	{
+	public:
+		PhysXD6Joint(physx::PxPhysics* physx);
+		~PhysXD6Joint();
+
+		Motion getMotion(Axis axis) const override;
+		void setMotion(Axis axis, Motion motion) override;
+
+		Radian getTwist() const override;
+		Radian getSwingY() const override;
+		Radian getSwingZ() const override;
+
+		LimitLinear getLimitLinear() const override;
+		void setLimitLinear(const LimitLinear& limit) override;
+
+		LimitAngularRange getLimitTwist() const override;
+		void setLimitTwist(const LimitAngularRange& limit) override;
+
+		LimitConeRange getLimitSwing() const override;
+		void setLimitSwing(const LimitConeRange& limit) override;
+
+		Drive getDrive(DriveType type) const override;
+		void setDrive(DriveType type, const Drive& drive) override;
+
+		Vector3 getDrivePosition() const override;
+		Quaternion getDriveRotation() const override;
+		void setDriveTransform(const Vector3& position, const Quaternion& rotation) override;
+
+		Vector3 getDriveLinearVelocity() const override;
+		Vector3 getDriveAngularVelocity() const override;
+		void setDriveVelocity(const Vector3& linear, const Vector3& angular) override;
+
+	private:
+		inline physx::PxD6Joint* getInternal() const;
+	};
+}

+ 2 - 2
BansheePhysX/Include/BsPhysXHingeJoint.h

@@ -18,8 +18,8 @@ namespace BansheeEngine
 		Radian getAngle() const override;
 		float getSpeed() const override;
 
-		LimitAngular getLimit() const override;
-		void setLimit(const LimitAngular& limit) const override;
+		LimitAngularRange getLimit() const override;
+		void setLimit(const LimitAngularRange& limit) override;
 
 		Drive getDrive() const override;
 		void setDrive(const Drive& drive) const override;

+ 30 - 0
BansheePhysX/Include/BsPhysXSliderJoint.h

@@ -0,0 +1,30 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsPhysXPrerequisites.h"
+#include "BsSliderJoint.h"
+#include "PxPhysics.h"
+#include "extensions\PxPrismaticJoint.h"
+
+namespace BansheeEngine
+{
+	class BS_PHYSX_EXPORT PhysXSliderJoint : public SliderJoint
+	{
+	public:
+		PhysXSliderJoint(physx::PxPhysics* physx);
+		~PhysXSliderJoint();
+
+		float getPosition() const override;
+		float getSpeed() const override;
+
+		LimitLinearRange getLimit() const override;
+		void setLimit(const LimitLinearRange& limit) override;
+
+		void setFlag(Flag flag, bool enabled) override;
+		bool hasFlag(Flag flag) override;
+
+	private:
+		inline physx::PxPrismaticJoint* getInternal() const;
+	};
+}

+ 27 - 0
BansheePhysX/Include/BsPhysXSphericalJoint.h

@@ -0,0 +1,27 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsPhysXPrerequisites.h"
+#include "BsSphericalJoint.h"
+#include "PxPhysics.h"
+#include "extensions\PxSphericalJoint.h"
+
+namespace BansheeEngine
+{
+	class BS_PHYSX_EXPORT PhysXSphericalJoint : public SphericalJoint
+	{
+	public:
+		PhysXSphericalJoint(physx::PxPhysics* physx);
+		~PhysXSphericalJoint();
+
+		LimitConeRange getLimit() const override;
+		void setLimit(const LimitConeRange& limit) override;
+
+		void setFlag(Flag flag, bool enabled) override;
+		bool hasFlag(Flag flag) override;
+
+	private:
+		inline physx::PxSphericalJoint* getInternal() const;
+	};
+}

+ 41 - 6
BansheePhysX/Source/BsPhysX.cpp

@@ -8,6 +8,12 @@
 #include "BsPhysXPlaneCollider.h"
 #include "BsPhysXCapsuleCollider.h"
 #include "BsPhysXMeshCollider.h"
+#include "BsPhysXFixedJoint.h"
+#include "BsPhysXDistanceJoint.h"
+#include "BsPhysXHingeJoint.h"
+#include "BsPhysXSphericalJoint.h"
+#include "BsPhysXSliderJoint.h"
+#include "BsPhysXD6Joint.h"
 #include "BsTaskScheduler.h"
 #include "BsTime.h"
 #include "Bsvector3.h"
@@ -283,12 +289,11 @@ namespace BansheeEngine
 	{
 		PHYSICS_INIT_DESC input; // TODO - Make this an input parameter.
 
-		PxTolerancesScale scale;
-		scale.length = input.typicalLength;
-		scale.speed = input.typicalSpeed;
+		mScale.length = input.typicalLength;
+		mScale.speed = input.typicalSpeed;
 
 		mFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, gPhysXAllocator, gPhysXErrorHandler);
-		mPhysics = PxCreateBasePhysics(PX_PHYSICS_VERSION, *mFoundation, scale);
+		mPhysics = PxCreateBasePhysics(PX_PHYSICS_VERSION, *mFoundation, mScale);
 
 		PxRegisterArticulations(*mPhysics);
 
@@ -297,11 +302,11 @@ namespace BansheeEngine
 			// Note: PhysX supports cooking for specific platforms to make the generated results better. Consider
 			// allowing the meshes to be re-cooked when target platform is changed. Right now we just use the default value.
 
-			PxCookingParams cookingParams(scale);
+			PxCookingParams cookingParams(mScale);
 			mCooking = PxCreateCooking(PX_PHYSICS_VERSION, *mFoundation, cookingParams);
 		}
 
-		PxSceneDesc sceneDesc(scale); // TODO - Test out various other parameters provided by scene desc
+		PxSceneDesc sceneDesc(mScale); // TODO - Test out various other parameters provided by scene desc
 		sceneDesc.gravity = toPxVector(input.gravity);
 		sceneDesc.cpuDispatcher = &gPhysXCPUDispatcher;
 		sceneDesc.filterShader = PhysXFilterShader;
@@ -501,6 +506,36 @@ namespace BansheeEngine
 		return bs_shared_ptr_new<PhysXMeshCollider>(mPhysics, position, rotation);
 	}
 
+	SPtr<FixedJoint> PhysX::createFixedJoint()
+	{
+		return bs_shared_ptr_new<PhysXFixedJoint>(mPhysics);
+	}
+
+	SPtr<DistanceJoint> PhysX::createDistanceJoint()
+	{
+		return bs_shared_ptr_new<PhysXDistanceJoint>(mPhysics);
+	}
+
+	SPtr<HingeJoint> PhysX::createHingeJoint()
+	{
+		return bs_shared_ptr_new<PhysXHingeJoint>(mPhysics);
+	}
+
+	SPtr<SphericalJoint> PhysX::createSphericalJoint()
+	{
+		return bs_shared_ptr_new<PhysXSphericalJoint>(mPhysics);
+	}
+
+	SPtr<SliderJoint> PhysX::createSliderJoint()
+	{
+		return bs_shared_ptr_new<PhysXSliderJoint>(mPhysics);
+	}
+
+	SPtr<D6Joint> PhysX::createD6Joint()
+	{
+		return bs_shared_ptr_new<PhysXD6Joint>(mPhysics);
+	}
+
 	PhysX& gPhysX()
 	{
 		return static_cast<PhysX&>(PhysX::instance());

+ 276 - 0
BansheePhysX/Source/BsPhysXD6Joint.cpp

@@ -0,0 +1,276 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#include "BsPhysXD6Joint.h"
+#include "BsFPhysxJoint.h"
+#include "BsPhysX.h"
+
+using namespace physx;
+
+namespace BansheeEngine
+{
+	PxD6Axis::Enum toPxAxis(PhysXD6Joint::Axis axis)
+	{
+		switch(axis)
+		{
+		default:
+		case PhysXD6Joint::Axis::X:
+			return PxD6Axis::eX;
+		case PhysXD6Joint::Axis::Y:
+			return PxD6Axis::eY;
+		case PhysXD6Joint::Axis::Z:
+			return PxD6Axis::eZ;
+		case PhysXD6Joint::Axis::Twist:
+			return PxD6Axis::eTWIST;
+		case PhysXD6Joint::Axis::SwingY:
+			return PxD6Axis::eSWING1;
+		case PhysXD6Joint::Axis::SwingZ:
+			return PxD6Axis::eSWING2;
+		}
+	}
+
+	PxD6Motion::Enum toPxMotion(PhysXD6Joint::Motion motion)
+	{
+		switch(motion)
+		{
+		default:
+		case PhysXD6Joint::Motion::Free:
+			return PxD6Motion::eFREE;
+		case PhysXD6Joint::Motion::Limited:
+			return PxD6Motion::eLIMITED;
+		case PhysXD6Joint::Motion::Locked:
+			return PxD6Motion::eLOCKED;
+		}
+	}
+
+	PxD6Drive::Enum toPxDrive(PhysXD6Joint::DriveType drive)
+	{
+		switch(drive)
+		{
+		default:
+		case PhysXD6Joint::DriveType::X:
+			return PxD6Drive::eX;
+		case PhysXD6Joint::DriveType::Y:
+			return PxD6Drive::eY;
+		case PhysXD6Joint::DriveType::Z:
+			return PxD6Drive::eZ;
+		case PhysXD6Joint::DriveType::Swing:
+			return PxD6Drive::eSWING;
+		case PhysXD6Joint::DriveType::Twist:
+			return PxD6Drive::eTWIST;
+		case PhysXD6Joint::DriveType::SLERP:
+			return PxD6Drive::eSLERP;
+		}
+	}
+
+	PhysXD6Joint::Motion fromPxMotion(PxD6Motion::Enum motion)
+	{
+		switch (motion)
+		{
+		default:
+		case PxD6Motion::eFREE:
+			return PhysXD6Joint::Motion::Free;
+		case PxD6Motion::eLIMITED:
+			return PhysXD6Joint::Motion::Limited;
+		case PxD6Motion::eLOCKED:
+			return PhysXD6Joint::Motion::Locked;
+		}
+	}
+
+
+	PhysXD6Joint::DriveType fromPxDrive(PxD6Drive::Enum drive)
+	{
+		switch (drive)
+		{
+		default:
+		case PxD6Drive::eX:
+			return PhysXD6Joint::DriveType::X;
+		case PxD6Drive::eY:
+			return PhysXD6Joint::DriveType::Y;
+		case PxD6Drive::eZ:
+			return PhysXD6Joint::DriveType::Z;
+		case PxD6Drive::eSWING:
+			return PhysXD6Joint::DriveType::Swing;
+		case PxD6Drive::eTWIST:
+			return PhysXD6Joint::DriveType::Twist;
+		case PxD6Drive::eSLERP:
+			return PhysXD6Joint::DriveType::SLERP;
+		}
+	}
+
+	PhysXD6Joint::PhysXD6Joint(PxPhysics* physx)
+	{
+		PxD6Joint* joint = PxD6JointCreate(*physx, nullptr, PxTransform(), nullptr, PxTransform());
+
+		mInternal = bs_new<FPhysXJoint>(joint);
+	}
+
+	PhysXD6Joint::~PhysXD6Joint()
+	{
+		bs_delete(mInternal);
+	}
+
+	PhysXD6Joint::Motion PhysXD6Joint::getMotion(Axis axis) const
+	{
+		return fromPxMotion(getInternal()->getMotion(toPxAxis(axis)));
+	}
+
+	void PhysXD6Joint::setMotion(Axis axis, Motion motion)
+	{
+		getInternal()->setMotion(toPxAxis(axis), toPxMotion(motion));
+	}
+
+	Radian PhysXD6Joint::getTwist() const
+	{
+		return Radian(getInternal()->getTwist());
+	}
+
+	Radian PhysXD6Joint::getSwingY() const
+	{
+		return Radian(getInternal()->getSwingYAngle());
+	}
+
+	Radian PhysXD6Joint::getSwingZ() const
+	{
+		return Radian(getInternal()->getSwingZAngle());
+	}
+
+	LimitLinear PhysXD6Joint::getLimitLinear() const
+	{
+		PxJointLinearLimit pxLimit = getInternal()->getLinearLimit();
+
+		LimitLinear limit;
+		limit.extent = pxLimit.value;
+		limit.contactDist = pxLimit.contactDistance;
+		limit.spring.stiffness = pxLimit.stiffness;
+		limit.spring.damping = pxLimit.damping;
+
+		return limit;
+	}
+
+	void PhysXD6Joint::setLimitLinear(const LimitLinear& limit)
+	{
+		PxJointLinearLimit pxLimit(gPhysX().getScale(), limit.extent, limit.contactDist);
+		pxLimit.stiffness = limit.spring.stiffness;
+		pxLimit.damping = limit.spring.damping;
+
+		getInternal()->setLinearLimit(pxLimit);
+	}
+
+	LimitAngularRange PhysXD6Joint::getLimitTwist() const
+	{
+		PxJointAngularLimitPair pxLimit = getInternal()->getTwistLimit();
+
+		LimitAngularRange limit;
+		limit.lower = pxLimit.lower;
+		limit.upper = pxLimit.upper;
+		limit.contactDist = pxLimit.contactDistance;
+		limit.spring.stiffness = pxLimit.stiffness;
+		limit.spring.damping = pxLimit.damping;
+
+		return limit;
+	}
+
+	void PhysXD6Joint::setLimitTwist(const LimitAngularRange& limit)
+	{
+		PxJointAngularLimitPair pxLimit(limit.lower.valueRadians(), limit.upper.valueRadians(), limit.contactDist);
+		pxLimit.stiffness = limit.spring.stiffness;
+		pxLimit.damping = limit.spring.damping;
+
+		getInternal()->setTwistLimit(pxLimit);
+	}
+
+	LimitConeRange PhysXD6Joint::getLimitSwing() const
+	{
+		PxJointLimitCone pxLimit = getInternal()->getSwingLimit();
+
+		LimitConeRange limit;
+		limit.yLimitAngle = pxLimit.yAngle;
+		limit.zLimitAngle = pxLimit.zAngle;
+		limit.contactDist = pxLimit.contactDistance;
+		limit.spring.stiffness = pxLimit.stiffness;
+		limit.spring.damping = pxLimit.damping;
+
+		return limit;
+	}
+
+	void PhysXD6Joint::setLimitSwing(const LimitConeRange& limit)
+	{
+		PxJointLimitCone pxLimit(limit.yLimitAngle.valueRadians(), limit.zLimitAngle.valueRadians(), limit.contactDist);
+		pxLimit.stiffness = limit.spring.stiffness;
+		pxLimit.damping = limit.spring.damping;
+
+		getInternal()->setSwingLimit(pxLimit);
+	}
+
+	PhysXD6Joint::Drive PhysXD6Joint::getDrive(DriveType type) const
+	{
+		PxD6JointDrive pxDrive = getInternal()->getDrive(toPxDrive(type));
+
+		Drive drive;
+		drive.acceleration = pxDrive.flags & PxD6JointDriveFlag::eACCELERATION;
+		drive.stiffness = pxDrive.stiffness;
+		drive.damping = pxDrive.damping;
+		drive.forceLimit = pxDrive.forceLimit;
+
+		return drive;
+	}
+
+	void PhysXD6Joint::setDrive(DriveType type, const Drive& drive)
+	{
+		PxD6JointDrive pxDrive;
+
+		if(drive.acceleration)
+			pxDrive.flags = PxD6JointDriveFlag::eACCELERATION;
+
+		pxDrive.stiffness = drive.stiffness;
+		pxDrive.damping = drive.damping;
+		pxDrive.forceLimit = drive.forceLimit;
+
+		getInternal()->setDrive(toPxDrive(type), pxDrive);
+	}
+
+	Vector3 PhysXD6Joint::getDrivePosition() const
+	{
+		return fromPxVector(getInternal()->getDrivePosition().p);
+	}
+
+	Quaternion PhysXD6Joint::getDriveRotation() const
+	{
+		return fromPxQuaternion(getInternal()->getDrivePosition().q);
+	}
+
+	void PhysXD6Joint::setDriveTransform(const Vector3& position, const Quaternion& rotation)
+	{
+		getInternal()->setDrivePosition(toPxTransform(position, rotation));
+	}
+
+	Vector3 PhysXD6Joint::getDriveLinearVelocity() const
+	{
+		PxVec3 linear;
+		PxVec3 angular;
+
+		getInternal()->getDriveVelocity(linear, angular);
+		return fromPxVector(linear);
+	}
+
+	Vector3 PhysXD6Joint::getDriveAngularVelocity() const
+	{
+		PxVec3 linear;
+		PxVec3 angular;
+
+		getInternal()->getDriveVelocity(linear, angular);
+		return fromPxVector(angular);
+	}
+
+	void PhysXD6Joint::setDriveVelocity(const Vector3& linear, const Vector3& angular)
+	{
+		getInternal()->setDriveVelocity(toPxVector(linear), toPxVector(angular));
+	}
+
+	PxD6Joint* PhysXD6Joint::getInternal() const
+	{
+		FPhysXJoint* internal = static_cast<FPhysXJoint*>(mInternal);
+
+		return static_cast<PxD6Joint*>(internal->_getInternal());
+	}
+}

+ 3 - 3
BansheePhysX/Source/BsPhysXHingeJoint.cpp

@@ -41,11 +41,11 @@ namespace BansheeEngine
 		return getInternal()->getVelocity();
 	}
 
-	LimitAngular PhysXHingeJoint::getLimit() const
+	LimitAngularRange PhysXHingeJoint::getLimit() const
 	{
 		PxJointAngularLimitPair pxLimit = getInternal()->getLimit();
 
-		LimitAngular limit;
+		LimitAngularRange limit;
 		limit.lower = pxLimit.lower;
 		limit.upper = pxLimit.upper;
 		limit.contactDist = pxLimit.contactDistance;
@@ -55,7 +55,7 @@ namespace BansheeEngine
 		return limit;
 	}
 
-	void PhysXHingeJoint::setLimit(const LimitAngular& limit) const
+	void PhysXHingeJoint::setLimit(const LimitAngularRange& limit)
 	{
 		PxJointAngularLimitPair pxLimit(limit.lower.valueRadians(), limit.upper.valueRadians(), limit.contactDist);
 		pxLimit.stiffness = limit.spring.stiffness;

+ 82 - 0
BansheePhysX/Source/BsPhysXSliderJoint.cpp

@@ -0,0 +1,82 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#include "BsPhysXSliderJoint.h"
+#include "BsFPhysxJoint.h"
+#include "BsPhysX.h"
+
+using namespace physx;
+
+namespace BansheeEngine
+{
+	PxPrismaticJointFlag::Enum toPxFlag(PhysXSliderJoint::Flag flag)
+	{
+		switch (flag)
+		{
+		default:
+		case PhysXSliderJoint::Flag::Limit:
+			return PxPrismaticJointFlag::eLIMIT_ENABLED;
+		}
+	}
+
+	PhysXSliderJoint::PhysXSliderJoint(PxPhysics* physx)
+	{
+		PxPrismaticJoint* joint = PxPrismaticJointCreate(*physx, nullptr, PxTransform(), nullptr, PxTransform());
+
+		mInternal = bs_new<FPhysXJoint>(joint);
+	}
+
+	PhysXSliderJoint::~PhysXSliderJoint()
+	{
+		bs_delete(mInternal);
+	}
+
+	float PhysXSliderJoint::getPosition() const
+	{
+		return getInternal()->getPosition();
+	}
+
+	float PhysXSliderJoint::getSpeed() const
+	{
+		return getInternal()->getVelocity();
+	}
+
+	LimitLinearRange PhysXSliderJoint::getLimit() const
+	{
+		PxJointLinearLimitPair pxLimit = getInternal()->getLimit();
+
+		LimitLinearRange limit;
+		limit.lower = pxLimit.lower;
+		limit.upper = pxLimit.upper;
+		limit.contactDist = pxLimit.contactDistance;
+		limit.spring.stiffness = pxLimit.stiffness;
+		limit.spring.damping = pxLimit.damping;
+
+		return limit;
+	}
+
+	void PhysXSliderJoint::setLimit(const LimitLinearRange& limit)
+	{
+		PxJointLinearLimitPair pxLimit(gPhysX().getScale(), limit.lower, limit.upper, limit.contactDist);
+		pxLimit.stiffness = limit.spring.stiffness;
+		pxLimit.damping = limit.spring.damping;
+
+		getInternal()->setLimit(pxLimit);
+	}
+
+	void PhysXSliderJoint::setFlag(Flag flag, bool enabled)
+	{
+		getInternal()->setPrismaticJointFlag(toPxFlag(flag), enabled);
+	}
+
+	bool PhysXSliderJoint::hasFlag(Flag flag)
+	{
+		return getInternal()->getPrismaticJointFlags() & toPxFlag(flag);
+	}
+
+	PxPrismaticJoint* PhysXSliderJoint::getInternal() const
+	{
+		FPhysXJoint* internal = static_cast<FPhysXJoint*>(mInternal);
+
+		return static_cast<PxPrismaticJoint*>(internal->_getInternal());
+	}
+}

+ 71 - 0
BansheePhysX/Source/BsPhysXSphericalJoint.cpp

@@ -0,0 +1,71 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#include "BsPhysXSphericalJoint.h"
+#include "BsFPhysxJoint.h"
+
+using namespace physx;
+
+namespace BansheeEngine
+{
+	PxSphericalJointFlag::Enum toPxFlag(PhysXSphericalJoint::Flag flag)
+	{
+		switch (flag)
+		{
+		default:
+		case PhysXSphericalJoint::Flag::Limit:
+			return PxSphericalJointFlag::eLIMIT_ENABLED;
+		}
+	}
+
+	PhysXSphericalJoint::PhysXSphericalJoint(PxPhysics* physx)
+	{
+		PxSphericalJoint* joint = PxSphericalJointCreate(*physx, nullptr, PxTransform(), nullptr, PxTransform());
+
+		mInternal = bs_new<FPhysXJoint>(joint);
+	}
+
+	PhysXSphericalJoint::~PhysXSphericalJoint()
+	{
+		bs_delete(mInternal);
+	}
+
+	LimitConeRange PhysXSphericalJoint::getLimit() const
+	{
+		PxJointLimitCone pxLimit = getInternal()->getLimitCone();
+
+		LimitConeRange limit;
+		limit.yLimitAngle = pxLimit.yAngle;
+		limit.zLimitAngle = pxLimit.zAngle;
+		limit.contactDist = pxLimit.contactDistance;
+		limit.spring.stiffness = pxLimit.stiffness;
+		limit.spring.damping = pxLimit.damping;
+
+		return limit;
+	}
+
+	void PhysXSphericalJoint::setLimit(const LimitConeRange& limit)
+	{
+		PxJointLimitCone pxLimit(limit.yLimitAngle.valueRadians(), limit.zLimitAngle.valueRadians(), limit.contactDist);
+		pxLimit.stiffness = limit.spring.stiffness;
+		pxLimit.damping = limit.spring.damping;
+
+		getInternal()->setLimitCone(pxLimit);
+	}
+
+	void PhysXSphericalJoint::setFlag(Flag flag, bool enabled)
+	{
+		getInternal()->setSphericalJointFlag(toPxFlag(flag), enabled);
+	}
+
+	bool PhysXSphericalJoint::hasFlag(Flag flag)
+	{
+		return getInternal()->getSphericalJointFlags() & toPxFlag(flag);
+	}
+
+	PxSphericalJoint* PhysXSphericalJoint::getInternal() const
+	{
+		FPhysXJoint* internal = static_cast<FPhysXJoint*>(mInternal);
+
+		return static_cast<PxSphericalJoint*>(internal->_getInternal());
+	}
+}