Explorar el Código

Refactored low-level physics Joint code so it uses descriptor structures for initialization

BearishSun hace 9 años
padre
commit
404e48cf57
Se han modificado 34 ficheros con 1090 adiciones y 842 borrados
  1. 7 0
      Source/BansheeCore/Include/BsCorePrerequisites.h
  2. 18 1
      Source/BansheeCore/Include/BsD6Joint.h
  3. 107 94
      Source/BansheeCore/Include/BsDistanceJoint.h
  4. 1 0
      Source/BansheeCore/Include/BsFJoint.h
  5. 31 24
      Source/BansheeCore/Include/BsFixedJoint.h
  6. 12 1
      Source/BansheeCore/Include/BsHingeJoint.h
  7. 18 0
      Source/BansheeCore/Include/BsJoint.h
  8. 6 6
      Source/BansheeCore/Include/BsPhysics.h
  9. 71 61
      Source/BansheeCore/Include/BsSliderJoint.h
  10. 63 53
      Source/BansheeCore/Include/BsSphericalJoint.h
  11. 11 11
      Source/BansheeCore/Source/BsD6Joint.cpp
  12. 11 11
      Source/BansheeCore/Source/BsDistanceJoint.cpp
  13. 11 11
      Source/BansheeCore/Source/BsFixedJoint.cpp
  14. 11 11
      Source/BansheeCore/Source/BsHingeJoint.cpp
  15. 11 11
      Source/BansheeCore/Source/BsSliderJoint.cpp
  16. 11 11
      Source/BansheeCore/Source/BsSphericalJoint.cpp
  17. 61 61
      Source/BansheePhysX/Include/BsFPhysXJoint.h
  18. 6 6
      Source/BansheePhysX/Include/BsPhysX.h
  19. 85 85
      Source/BansheePhysX/Include/BsPhysXD6Joint.h
  20. 61 61
      Source/BansheePhysX/Include/BsPhysXDistanceJoint.h
  21. 23 23
      Source/BansheePhysX/Include/BsPhysXFixedJoint.h
  22. 1 1
      Source/BansheePhysX/Include/BsPhysXHingeJoint.h
  23. 1 1
      Source/BansheePhysX/Include/BsPhysXSliderJoint.h
  24. 40 40
      Source/BansheePhysX/Include/BsPhysXSphericalJoint.h
  25. 5 3
      Source/BansheePhysX/Source/BsFPhysXJoint.cpp
  26. 12 12
      Source/BansheePhysX/Source/BsPhysX.cpp
  27. 31 3
      Source/BansheePhysX/Source/BsPhysXD6Joint.cpp
  28. 36 3
      Source/BansheePhysX/Source/BsPhysXDistanceJoint.cpp
  29. 17 3
      Source/BansheePhysX/Source/BsPhysXFixedJoint.cpp
  30. 32 3
      Source/BansheePhysX/Source/BsPhysXHingeJoint.cpp
  31. 27 3
      Source/BansheePhysX/Source/BsPhysXSliderJoint.cpp
  32. 97 73
      Source/BansheePhysX/Source/BsPhysXSphericalJoint.cpp
  33. 2 2
      Source/BansheeSL/Include/BsParserFX.h
  34. 153 153
      Source/BansheeSL/Source/BsParserFX.c

+ 7 - 0
Source/BansheeCore/Include/BsCorePrerequisites.h

@@ -378,6 +378,13 @@ namespace BansheeEngine
 	struct RENDER_WINDOW_DESC;
 	struct FONT_DESC;
 	struct CHAR_CONTROLLER_DESC;
+	struct JOINT_DESC;
+	struct FIXED_JOINT_DESC;
+	struct DISTANCE_JOINT_DESC;
+	struct HINGE_JOINT_DESC;
+	struct SLIDER_JOINT_DESC;
+	struct SPHERICAL_JOINT_DESC;
+	struct D6_JOINT_DESC;
 
 	template<class T>
 	class CoreThreadAccessor;

+ 18 - 1
Source/BansheeCore/Include/BsD6Joint.h

@@ -11,6 +11,8 @@ namespace BansheeEngine
 	 *  @{
 	 */
 
+	struct D6_JOINT_DESC;
+
 	/** 
 	 * Represents the most customizable type of joint. This joint type can be used to create all other built-in joint 
 	 * types, and to design your own custom ones, but is less intuitive to use. Allows a specification of a linear 
@@ -95,6 +97,7 @@ namespace BansheeEngine
 		};
 
 	public:
+		D6Joint(const D6_JOINT_DESC& desc) { }
 		virtual ~D6Joint() { }
 
 		/** 
@@ -179,7 +182,21 @@ namespace BansheeEngine
 		virtual void setDriveVelocity(const Vector3& linear, const Vector3& angular) = 0;
 
 		/** Creates a new D6 joint. */
-		static SPtr<D6Joint> create();
+		static SPtr<D6Joint> create(const D6_JOINT_DESC& desc);
+	};
+
+	/** Structure used for initializing a new D6Joint. */
+	struct D6_JOINT_DESC : JOINT_DESC
+	{
+		D6Joint::Motion motion[(UINT32)D6Joint::Axis::Count];
+		D6Joint::Drive drive[(UINT32)D6Joint::DriveType::Count];
+		LimitLinear limitLinear;
+		LimitAngularRange limitTwist;
+		LimitConeRange limitSwing;
+		Vector3 drivePosition;
+		Quaternion driveRotation;
+		Vector3 driveLinearVelocity;
+		Vector3 driveAngularVelocity;
 	};
 
 	/** @} */

+ 107 - 94
Source/BansheeCore/Include/BsDistanceJoint.h

@@ -1,95 +1,108 @@
-//********************************** 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
-{
-	/** @addtogroup Physics
-	 *  @{
-	 */
-
-	/** A joint that maintains an upper or lower (or both) bound on the distance between two bodies. */
-	class BS_CORE_EXPORT DistanceJoint : public Joint
-	{
-	public:
-		/** Controls distance joint options. */
-		enum class Flag
-		{
-			MinDistance = 0x1, /** Enables minimum distance limit. */
-			MaxDistance = 0x2, /** Enables maximum distance limit. */
-			Spring = 0x4 /** Enables spring when maintaining limits. */
-		};
-
-	public:
-		virtual ~DistanceJoint() { }
-
-		/** Returns the current distance between the two joint bodies. */
-		virtual float getDistance() const = 0;
-
-		/**
-		 * Returns the minimum distance the bodies are allowed to be at, they will get no closer. You must enable min
-		 * distance flag in order for this limit to be applied.
-		 */
-		virtual float getMinDistance() const = 0;
-
-		/**
-		 * Sets the minimum distance the bodies are allowed to be at, they will get no closer. You must enable min
-		 * distance flag in order for this limit to be applied.
-		 */
-		virtual void setMinDistance(float value) = 0;
-
-		/**
-		 * Returns the maximum distance the bodies are allowed to be at, they will get no further. You must enable max
-		 * distance flag in order for this limit to be applied.
-		 */
-		virtual float getMaxDistance() const = 0;
-
-		/**
-		 * Sets the maximum distance the bodies are allowed to be at, they will get no further. You must enable max
-		 * distance flag in order for this limit to be applied.
-		 */
-		virtual void setMaxDistance(float value) = 0;
-
-		/**
-		 * Returns the error tolerance of the joint at which the joint becomes active. This value slightly extends the
-		 * lower and upper limit. 
-		 */
-		virtual float getTolerance() const = 0;
-
-		/**
-		 * Sets the error tolerance of the joint at which the joint becomes active. This value slightly extends the
-		 * lower and upper limit. 
-		 */
-		virtual void setTolerance(float value) = 0;
-
-		/**
-		 * Returns a spring that controls how the joint responds when a limit is reached. You must enable the spring flag
-		 * on the joint in order for this to be recognized. 
-		 * 
-		 * @see	Spring
-		 */
-		virtual Spring getSpring() const = 0;
-
-		/**
-		 * Sets a spring that controls how the joint responds when a limit is reached. You must enable the spring flag on
-		 * the joint in order for this to be recognized. 
-		 * 
-		 * @see	Spring
-		 */
-		virtual void setSpring(const Spring& value) = 0;
-
-		/** Enables or disables a flag that controls joint behaviour. */
-		virtual void setFlag(Flag flag, bool enabled) = 0;
-
-		/** Checks whether a certain joint flag is enabled. */
-		virtual bool hasFlag(Flag flag) const = 0;
-
-		/** Creates a new distance joint. */
-		static SPtr<DistanceJoint> create();
-	};
-
-	/** @} */
+//********************************** 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
+{
+	/** @addtogroup Physics
+	 *  @{
+	 */
+
+	struct DISTANCE_JOINT_DESC;
+
+	/** A joint that maintains an upper or lower (or both) bound on the distance between two bodies. */
+	class BS_CORE_EXPORT DistanceJoint : public Joint
+	{
+	public:
+		/** Controls distance joint options. */
+		enum class Flag
+		{
+			MinDistance = 0x1, /** Enables minimum distance limit. */
+			MaxDistance = 0x2, /** Enables maximum distance limit. */
+			Spring = 0x4 /** Enables spring when maintaining limits. */
+		};
+
+	public:
+		DistanceJoint(const DISTANCE_JOINT_DESC& desc) { }
+		virtual ~DistanceJoint() { }
+
+		/** Returns the current distance between the two joint bodies. */
+		virtual float getDistance() const = 0;
+
+		/**
+		 * Returns the minimum distance the bodies are allowed to be at, they will get no closer. You must enable min
+		 * distance flag in order for this limit to be applied.
+		 */
+		virtual float getMinDistance() const = 0;
+
+		/**
+		 * Sets the minimum distance the bodies are allowed to be at, they will get no closer. You must enable min
+		 * distance flag in order for this limit to be applied.
+		 */
+		virtual void setMinDistance(float value) = 0;
+
+		/**
+		 * Returns the maximum distance the bodies are allowed to be at, they will get no further. You must enable max
+		 * distance flag in order for this limit to be applied.
+		 */
+		virtual float getMaxDistance() const = 0;
+
+		/**
+		 * Sets the maximum distance the bodies are allowed to be at, they will get no further. You must enable max
+		 * distance flag in order for this limit to be applied.
+		 */
+		virtual void setMaxDistance(float value) = 0;
+
+		/**
+		 * Returns the error tolerance of the joint at which the joint becomes active. This value slightly extends the
+		 * lower and upper limit. 
+		 */
+		virtual float getTolerance() const = 0;
+
+		/**
+		 * Sets the error tolerance of the joint at which the joint becomes active. This value slightly extends the
+		 * lower and upper limit. 
+		 */
+		virtual void setTolerance(float value) = 0;
+
+		/**
+		 * Returns a spring that controls how the joint responds when a limit is reached. You must enable the spring flag
+		 * on the joint in order for this to be recognized. 
+		 * 
+		 * @see	Spring
+		 */
+		virtual Spring getSpring() const = 0;
+
+		/**
+		 * Sets a spring that controls how the joint responds when a limit is reached. You must enable the spring flag on
+		 * the joint in order for this to be recognized. 
+		 * 
+		 * @see	Spring
+		 */
+		virtual void setSpring(const Spring& value) = 0;
+
+		/** Enables or disables a flag that controls joint behaviour. */
+		virtual void setFlag(Flag flag, bool enabled) = 0;
+
+		/** Checks whether a certain joint flag is enabled. */
+		virtual bool hasFlag(Flag flag) const = 0;
+
+		/** Creates a new distance joint. */
+		static SPtr<DistanceJoint> create(const DISTANCE_JOINT_DESC& desc);
+	};
+
+	/** Structure used for initializing a new DistanceJoint. */
+	struct DISTANCE_JOINT_DESC : JOINT_DESC
+	{
+		float minDistance = 0.0f;
+		float maxDistance = 0.0f;
+		float tolerance = 0.25f;
+		Spring spring;
+		DistanceJoint::Flag flag = (DistanceJoint::Flag)0;
+	};
+
+	/** @} */
 }

+ 1 - 0
Source/BansheeCore/Include/BsFJoint.h

@@ -27,6 +27,7 @@ namespace BansheeEngine
 	class BS_CORE_EXPORT FJoint
 	{
 	public:
+		FJoint(const JOINT_DESC& desc) { }
 		virtual ~FJoint() { }
 
 		/** Returns one of the bodies managed by the joint. */

+ 31 - 24
Source/BansheeCore/Include/BsFixedJoint.h

@@ -1,25 +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
-{
-	/** @addtogroup Physics
-	 *  @{
-	 */
-
-	/** Physics joint that will maintain a fixed distance and orientation between its two attached bodies. */
-	class BS_CORE_EXPORT FixedJoint : public Joint
-	{
-	public:
-		virtual ~FixedJoint() { }
-
-		/** Creates a new fixed joint. */
-		static SPtr<FixedJoint> create();
-	};
-
-	/** @} */
+//********************************** 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
+{
+	/** @addtogroup Physics
+	 *  @{
+	 */
+
+	struct FIXED_JOINT_DESC;
+
+	/** Physics joint that will maintain a fixed distance and orientation between its two attached bodies. */
+	class BS_CORE_EXPORT FixedJoint : public Joint
+	{
+	public:
+		FixedJoint(const FIXED_JOINT_DESC& desc) { }
+		virtual ~FixedJoint() { }
+
+		/** Creates a new fixed joint. */
+		static SPtr<FixedJoint> create(const FIXED_JOINT_DESC& desc);
+	};
+
+	/** Structure used for initializing a new FixedJoint. */
+	struct FIXED_JOINT_DESC : JOINT_DESC
+	{ };
+
+	/** @} */
 }

+ 12 - 1
Source/BansheeCore/Include/BsHingeJoint.h

@@ -11,6 +11,8 @@ namespace BansheeEngine
 	 *  @{
 	 */
 
+	struct HINGE_JOINT_DESC;
+
 	/**
 	 * Hinge joint removes all but a single rotation degree of freedom from its two attached bodies (for example a door 
 	 * hinge). 
@@ -51,6 +53,7 @@ namespace BansheeEngine
 		};
 
 	public:
+		HingeJoint(const HINGE_JOINT_DESC& desc) { }
 		virtual ~HingeJoint() { }
 
 		/** Returns the current angle between the two attached bodes. */
@@ -98,7 +101,15 @@ namespace BansheeEngine
 		virtual bool hasFlag(Flag flag) const = 0;
 
 		/** Creates a new hinge joint. */
-		static SPtr<HingeJoint> create();
+		static SPtr<HingeJoint> create(const HINGE_JOINT_DESC& desc);
+	};
+
+	/** Structure used for initializing a new HingeJoint. */
+	struct HINGE_JOINT_DESC : JOINT_DESC
+	{
+		HingeJoint::Drive drive;
+		LimitAngularRange limit;
+		HingeJoint::Flag flag = (HingeJoint::Flag)0;
 	};
 
 	/** @} */

+ 18 - 0
Source/BansheeCore/Include/BsJoint.h

@@ -12,6 +12,8 @@ namespace BansheeEngine
 	 *  @{
 	 */
 
+	struct JOINT_DESC;
+
 	/** 
 	 * Base class for all Joint types. Joints constrain how two rigidbodies move relative to one another (for example a door 
 	 * hinge). One of the bodies in the joint must always be movable (non-kinematic).
@@ -80,6 +82,22 @@ namespace BansheeEngine
 		FJoint* mInternal = nullptr;
 	};
 
+	/** Structure used for initializing a new Joint. */
+	struct JOINT_DESC
+	{
+		struct BodyInfo
+		{
+			Rigidbody* body = nullptr;
+			Vector3 position;
+			Quaternion rotation;
+		};
+
+		BodyInfo bodies[2];
+		float breakForce = FLT_MAX;
+		float breakTorque = FLT_MAX;
+		bool enableCollision = false;
+	};
+
 	/** 
 	 * Controls spring parameters for a physics joint limits. If a limit is soft (body bounces back due to restition when 
 	 * the limit is reached) the spring will pull the body back towards the limit using the specified parameters.

+ 6 - 6
Source/BansheeCore/Include/BsPhysics.h

@@ -487,22 +487,22 @@ namespace BansheeEngine
 		virtual SPtr<MeshCollider> createMeshCollider(const Vector3& position, const Quaternion& rotation) = 0;
 
 		/** @copydoc FixedJoint::create */
-		virtual SPtr<FixedJoint> createFixedJoint() = 0;
+		virtual SPtr<FixedJoint> createFixedJoint(const FIXED_JOINT_DESC& desc) = 0;
 
 		/** @copydoc DistanceJoint::create */
-		virtual SPtr<DistanceJoint> createDistanceJoint() = 0;
+		virtual SPtr<DistanceJoint> createDistanceJoint(const DISTANCE_JOINT_DESC& desc) = 0;
 
 		/** @copydoc HingeJoint::create */
-		virtual SPtr<HingeJoint> createHingeJoint() = 0;
+		virtual SPtr<HingeJoint> createHingeJoint(const HINGE_JOINT_DESC& desc) = 0;
 
 		/** @copydoc SphericalJoint::create */
-		virtual SPtr<SphericalJoint> createSphericalJoint() = 0;
+		virtual SPtr<SphericalJoint> createSphericalJoint(const SPHERICAL_JOINT_DESC& desc) = 0;
 
 		/** @copydoc SliderJoint::create */
-		virtual SPtr<SliderJoint> createSliderJoint() = 0;
+		virtual SPtr<SliderJoint> createSliderJoint(const SLIDER_JOINT_DESC& desc) = 0;
 
 		/** @copydoc D6Joint::create */
-		virtual SPtr<D6Joint> createD6Joint() = 0;
+		virtual SPtr<D6Joint> createD6Joint(const D6_JOINT_DESC& desc) = 0;
 
 		/** @copydoc CharacterController::create */
 		virtual SPtr<CharacterController> createCharacterController(const CHAR_CONTROLLER_DESC& desc) = 0;

+ 71 - 61
Source/BansheeCore/Include/BsSliderJoint.h

@@ -1,62 +1,72 @@
-//********************************** 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
-{
-	/** @addtogroup Physics
-	 *  @{
-	 */
-
-	/** 
-	 * Joint that removes all but a single translational degree of freedom. Bodies are allowed to move along a single axis. 
-	 */
-	class BS_CORE_EXPORT SliderJoint : public Joint
-	{
-	public:
-		/** Flag that controls slider joint's behaviour. */
-		enum class Flag
-		{
-			Limit = 0x1,
-		};
-
-	public:
-		virtual ~SliderJoint() { }
-
-		/** Returns the current position of the slider. */
-		virtual float getPosition() const = 0;
-
-		/** Returns the current speed of the slider. */
-		virtual float getSpeed() const = 0;
-
-		/** 
-		 * Returns a limit that constrains the movement of the joint to a specific minimum and maximum distance. You must
-		 * enable the limit flag on the joint in order for this to be recognized. 
-		 *
-		 * @see LimitLinearRange
-		 */
-		virtual LimitLinearRange getLimit() const = 0;
-
-		/** 
-		 * Sets a limit that constrains the movement of the joint to a specific minimum and maximum distance. You must
-		 * enable the limit flag on the joint in order for this to be recognized. 
-		 *
-		 * @see LimitLinearRange
-		 */
-		virtual void setLimit(const LimitLinearRange& limit) = 0;
-
-		/** Enables or disables a flag that controls the joint's behaviour. */
-		virtual void setFlag(Flag flag, bool enabled) = 0;
-
-		/** Checks is the specified flag enabled. */
-		virtual bool hasFlag(Flag flag) const = 0;
-
-		/** Creates a new spherical joint. */
-		static SPtr<SliderJoint> create();
-	};
-
-	/** @} */
+//********************************** 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
+{
+	/** @addtogroup Physics
+	 *  @{
+	 */
+
+	struct SLIDER_JOINT_DESC;
+
+	/** 
+	 * Joint that removes all but a single translational degree of freedom. Bodies are allowed to move along a single axis. 
+	 */
+	class BS_CORE_EXPORT SliderJoint : public Joint
+	{
+	public:
+		/** Flag that controls slider joint's behaviour. */
+		enum class Flag
+		{
+			Limit = 0x1,
+		};
+
+	public:
+		SliderJoint(const SLIDER_JOINT_DESC& desc) { }
+		virtual ~SliderJoint() { }
+
+		/** Returns the current position of the slider. */
+		virtual float getPosition() const = 0;
+
+		/** Returns the current speed of the slider. */
+		virtual float getSpeed() const = 0;
+
+		/** 
+		 * Returns a limit that constrains the movement of the joint to a specific minimum and maximum distance. You must
+		 * enable the limit flag on the joint in order for this to be recognized. 
+		 *
+		 * @see LimitLinearRange
+		 */
+		virtual LimitLinearRange getLimit() const = 0;
+
+		/** 
+		 * Sets a limit that constrains the movement of the joint to a specific minimum and maximum distance. You must
+		 * enable the limit flag on the joint in order for this to be recognized. 
+		 *
+		 * @see LimitLinearRange
+		 */
+		virtual void setLimit(const LimitLinearRange& limit) = 0;
+
+		/** Enables or disables a flag that controls the joint's behaviour. */
+		virtual void setFlag(Flag flag, bool enabled) = 0;
+
+		/** Checks is the specified flag enabled. */
+		virtual bool hasFlag(Flag flag) const = 0;
+
+		/** Creates a new spherical joint. */
+		static SPtr<SliderJoint> create(const SLIDER_JOINT_DESC& desc);
+	};
+
+	/** Structure used for initializing a new SliderJoint. */
+	struct SLIDER_JOINT_DESC : JOINT_DESC
+	{
+		LimitLinearRange limit;
+		SliderJoint::Flag flag = (SliderJoint::Flag)0;
+	};
+
+	/** @} */
 }

+ 63 - 53
Source/BansheeCore/Include/BsSphericalJoint.h

@@ -1,54 +1,64 @@
-//********************************** 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
-{
-	/** @addtogroup Physics
-	 *  @{
-	 */
-
-	/** 
-	 * A spherical joint removes all translational degrees of freedom but allows all rotational degrees of freedom. 
-	 * Essentially this ensures that the anchor points of the two bodies are always coincident. Bodies are allowed to
-	 * rotate around the anchor points, and their rotatation can be limited by an elliptical cone.
-	 */
-	class BS_CORE_EXPORT SphericalJoint : public Joint
-	{
-	public:
-		/** Flags that control options for the spherical joint */
-		enum class Flag
-		{
-			Limit = 0x1
-		};
-
-	public:
-		virtual ~SphericalJoint() { }
-
-		/** 
-		 * Returns the limit of the joint. This clamps the rotation inside an eliptical angular cone. You must enable limit
-		 * flag on the joint in order for this to be recognized. 
-		 */
-		virtual LimitConeRange getLimit() const = 0;
-
-		/** 
-		 * Sets the limit of the joint. This clamps the rotation inside an eliptical angular cone. You must enable limit
-		 * flag on the joint in order for this to be recognized. 
-		 */
-		virtual void setLimit(const LimitConeRange& limit) = 0;
-
-		/** Enables or disables a flag that controls the joint's behaviour. */
-		virtual void setFlag(Flag flag, bool enabled) = 0;
-
-		/** Checks is the specified flag enabled. */
-		virtual bool hasFlag(Flag flag) const = 0;
-
-		/** Creates a new spherical joint. */
-		static SPtr<SphericalJoint> create();
-	};
-
-	/** @} */
+//********************************** 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
+{
+	/** @addtogroup Physics
+	 *  @{
+	 */
+
+	struct SPHERICAL_JOINT_DESC;
+
+	/** 
+	 * A spherical joint removes all translational degrees of freedom but allows all rotational degrees of freedom. 
+	 * Essentially this ensures that the anchor points of the two bodies are always coincident. Bodies are allowed to
+	 * rotate around the anchor points, and their rotatation can be limited by an elliptical cone.
+	 */
+	class BS_CORE_EXPORT SphericalJoint : public Joint
+	{
+	public:
+		/** Flags that control options for the spherical joint */
+		enum class Flag
+		{
+			Limit = 0x1
+		};
+
+	public:
+		SphericalJoint(const SPHERICAL_JOINT_DESC& desc);
+		virtual ~SphericalJoint() { }
+
+		/** 
+		 * Returns the limit of the joint. This clamps the rotation inside an eliptical angular cone. You must enable limit
+		 * flag on the joint in order for this to be recognized. 
+		 */
+		virtual LimitConeRange getLimit() const = 0;
+
+		/** 
+		 * Sets the limit of the joint. This clamps the rotation inside an eliptical angular cone. You must enable limit
+		 * flag on the joint in order for this to be recognized. 
+		 */
+		virtual void setLimit(const LimitConeRange& limit) = 0;
+
+		/** Enables or disables a flag that controls the joint's behaviour. */
+		virtual void setFlag(Flag flag, bool enabled) = 0;
+
+		/** Checks is the specified flag enabled. */
+		virtual bool hasFlag(Flag flag) const = 0;
+
+		/** Creates a new spherical joint. */
+		static SPtr<SphericalJoint> create(const SPHERICAL_JOINT_DESC& desc);
+	};
+
+	/** Structure used for initializing a new SphericalJoint. */
+	struct SPHERICAL_JOINT_DESC : JOINT_DESC
+	{
+		LimitConeRange limit;
+		SphericalJoint::Flag flag = (SphericalJoint::Flag)0;
+	};
+
+	/** @} */
 }

+ 11 - 11
Source/BansheeCore/Source/BsD6Joint.cpp

@@ -1,12 +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();
-	}
+//********************************** 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(const D6_JOINT_DESC& desc)
+	{
+		return gPhysics().createD6Joint(desc);
+	}
 }

+ 11 - 11
Source/BansheeCore/Source/BsDistanceJoint.cpp

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

+ 11 - 11
Source/BansheeCore/Source/BsFixedJoint.cpp

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

+ 11 - 11
Source/BansheeCore/Source/BsHingeJoint.cpp

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

+ 11 - 11
Source/BansheeCore/Source/BsSliderJoint.cpp

@@ -1,12 +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();
-	}
+//********************************** 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(const SLIDER_JOINT_DESC& desc)
+	{
+		return gPhysics().createSliderJoint(desc);
+	}
 }

+ 11 - 11
Source/BansheeCore/Source/BsSphericalJoint.cpp

@@ -1,12 +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();
-	}
+//********************************** 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(const SPHERICAL_JOINT_DESC& desc)
+	{
+		return gPhysics().createSphericalJoint(desc);
+	}
 }

+ 61 - 61
Source/BansheePhysX/Include/BsFPhysXJoint.h

@@ -1,62 +1,62 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsPhysXPrerequisites.h"
-#include "BsFJoint.h"
-#include "extensions\PxJoint.h"
-
-namespace BansheeEngine
-{
-	/** @addtogroup PhysX
-	 *  @{
-	 */
-
-	/** PhysX implementation of an FJoint. */
-	class BS_PHYSX_EXPORT FPhysXJoint : public FJoint
-	{
-	public:
-		FPhysXJoint(physx::PxJoint* joint);
-		~FPhysXJoint();
-
-		/** @copydoc FJoint::getBody */
-		Rigidbody* getBody(JointBody body) const override;
-
-		/** @copydoc FJoint::setBody */
-		void setBody(JointBody body, Rigidbody* value) override;
-
-		/** @copydoc FJoint::getPosition */
-		Vector3 getPosition(JointBody body) const override;
-
-		/** @copydoc FJoint::getRotation */
-		Quaternion getRotation(JointBody body) const override;
-
-		/** @copydoc FJoint::setTransform */
-		void setTransform(JointBody body, const Vector3& position, const Quaternion& rotation) override;
-
-		/** @copydoc FJoint::getBreakForce */
-		float getBreakForce() const override;
-
-		/** @copydoc FJoint::setBreakForce */
-		void setBreakForce(float force) override;
-
-		/** @copydoc FJoint::getBreakTorque */
-		float getBreakTorque() const override;
-
-		/** @copydoc FJoint::setBreakTorque */
-		void setBreakTorque(float torque) override;
-
-		/** @copydoc FJoint::getEnableCollision */
-		bool getEnableCollision() const override;
-
-		/** @copydoc FJoint::setEnableCollision */
-		void setEnableCollision(bool value) override;
-
-		/** Gets the internal PhysX joint object. */
-		physx::PxJoint* _getInternal() const { return mJoint; }
-	protected:
-		physx::PxJoint* mJoint;
-	};
-
-	/** @} */
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsPhysXPrerequisites.h"
+#include "BsFJoint.h"
+#include "extensions\PxJoint.h"
+
+namespace BansheeEngine
+{
+	/** @addtogroup PhysX
+	 *  @{
+	 */
+
+	/** PhysX implementation of an FJoint. */
+	class BS_PHYSX_EXPORT FPhysXJoint : public FJoint
+	{
+	public:
+		FPhysXJoint(physx::PxJoint* joint, const JOINT_DESC& desc);
+		~FPhysXJoint();
+
+		/** @copydoc FJoint::getBody */
+		Rigidbody* getBody(JointBody body) const override;
+
+		/** @copydoc FJoint::setBody */
+		void setBody(JointBody body, Rigidbody* value) override;
+
+		/** @copydoc FJoint::getPosition */
+		Vector3 getPosition(JointBody body) const override;
+
+		/** @copydoc FJoint::getRotation */
+		Quaternion getRotation(JointBody body) const override;
+
+		/** @copydoc FJoint::setTransform */
+		void setTransform(JointBody body, const Vector3& position, const Quaternion& rotation) override;
+
+		/** @copydoc FJoint::getBreakForce */
+		float getBreakForce() const override;
+
+		/** @copydoc FJoint::setBreakForce */
+		void setBreakForce(float force) override;
+
+		/** @copydoc FJoint::getBreakTorque */
+		float getBreakTorque() const override;
+
+		/** @copydoc FJoint::setBreakTorque */
+		void setBreakTorque(float torque) override;
+
+		/** @copydoc FJoint::getEnableCollision */
+		bool getEnableCollision() const override;
+
+		/** @copydoc FJoint::setEnableCollision */
+		void setEnableCollision(bool value) override;
+
+		/** Gets the internal PhysX joint object. */
+		physx::PxJoint* _getInternal() const { return mJoint; }
+	protected:
+		physx::PxJoint* mJoint;
+	};
+
+	/** @} */
 }

+ 6 - 6
Source/BansheePhysX/Include/BsPhysX.h

@@ -85,22 +85,22 @@ namespace BansheeEngine
 		SPtr<MeshCollider> createMeshCollider(const Vector3& position, const Quaternion& rotation) override;
 
 		/** @copydoc Physics::createFixedJoint */
-		SPtr<FixedJoint> createFixedJoint() override;
+		SPtr<FixedJoint> createFixedJoint(const FIXED_JOINT_DESC& desc) override;
 
 		/** @copydoc Physics::createDistanceJoint */
-		SPtr<DistanceJoint> createDistanceJoint() override;
+		SPtr<DistanceJoint> createDistanceJoint(const DISTANCE_JOINT_DESC& desc) override;
 
 		/** @copydoc Physics::createHingeJoint */
-		SPtr<HingeJoint> createHingeJoint() override;
+		SPtr<HingeJoint> createHingeJoint(const HINGE_JOINT_DESC& desc) override;
 
 		/** @copydoc Physics::createSphericalJoint */
-		SPtr<SphericalJoint> createSphericalJoint() override;
+		SPtr<SphericalJoint> createSphericalJoint(const SPHERICAL_JOINT_DESC& desc) override;
 
 		/** @copydoc Physics::createSliderJoint */
-		SPtr<SliderJoint> createSliderJoint() override;
+		SPtr<SliderJoint> createSliderJoint(const SLIDER_JOINT_DESC& desc) override;
 
 		/** @copydoc Physics::createD6Joint */
-		SPtr<D6Joint> createD6Joint() override;
+		SPtr<D6Joint> createD6Joint(const D6_JOINT_DESC& desc) override;
 
 		/** @copydoc Physics::createCharacterController*/
 		SPtr<CharacterController> createCharacterController(const CHAR_CONTROLLER_DESC& desc) override;

+ 85 - 85
Source/BansheePhysX/Include/BsPhysXD6Joint.h

@@ -1,86 +1,86 @@
-//********************************** 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
-{
-	/** @addtogroup PhysX
-	 *  @{
-	 */
-
-	/** PhysX implementation of a D6 joint. */
-	class BS_PHYSX_EXPORT PhysXD6Joint : public D6Joint
-	{
-	public:
-		PhysXD6Joint(physx::PxPhysics* physx);
-		~PhysXD6Joint();
-
-		/** @copydoc D6Joint::getMotion */
-		Motion getMotion(Axis axis) const override;
-
-		/** @copydoc D6Joint::setMotion */
-		void setMotion(Axis axis, Motion motion) override;
-
-		/** @copydoc D6Joint::getTwist */
-		Radian getTwist() const override;
-
-		/** @copydoc D6Joint::getSwingY */
-		Radian getSwingY() const override;
-
-		/** @copydoc D6Joint::getSwingZ */
-		Radian getSwingZ() const override;
-
-		/** @copydoc D6Joint::getLimitLinear */
-		LimitLinear getLimitLinear() const override;
-
-		/** @copydoc D6Joint::setLimitLinear */
-		void setLimitLinear(const LimitLinear& limit) override;
-
-		/** @copydoc D6Joint::getLimitTwist */
-		LimitAngularRange getLimitTwist() const override;
-
-		/** @copydoc D6Joint::setLimitTwist */
-		void setLimitTwist(const LimitAngularRange& limit) override;
-
-		/** @copydoc D6Joint::getLimitSwing */
-		LimitConeRange getLimitSwing() const override;
-
-		/** @copydoc D6Joint::setLimitSwing */
-		void setLimitSwing(const LimitConeRange& limit) override;
-
-		/** @copydoc D6Joint::getDrive */
-		Drive getDrive(DriveType type) const override;
-
-		/** @copydoc D6Joint::setDrive */
-		void setDrive(DriveType type, const Drive& drive) override;
-
-		/** @copydoc D6Joint::getDrivePosition */
-		Vector3 getDrivePosition() const override;
-
-		/** @copydoc D6Joint::getDriveRotation */
-		Quaternion getDriveRotation() const override;
-
-		/** @copydoc D6Joint::setDriveTransform */
-		void setDriveTransform(const Vector3& position, const Quaternion& rotation) override;
-
-		/** @copydoc D6Joint::getDriveLinearVelocity */
-		Vector3 getDriveLinearVelocity() const override;
-
-		/** @copydoc D6Joint::getDriveAngularVelocity */
-		Vector3 getDriveAngularVelocity() const override;
-
-		/** @copydoc D6Joint::setDriveVelocity */
-		void setDriveVelocity(const Vector3& linear, const Vector3& angular) override;
-
-	private:
-		/** Returns the internal PhysX representation of the D6 joint. */
-		inline physx::PxD6Joint* getInternal() const;
-	};
-
-	/** @} */
+//********************************** 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
+{
+	/** @addtogroup PhysX
+	 *  @{
+	 */
+
+	/** PhysX implementation of a D6 joint. */
+	class BS_PHYSX_EXPORT PhysXD6Joint : public D6Joint
+	{
+	public:
+		PhysXD6Joint(physx::PxPhysics* physx, const D6_JOINT_DESC& desc);
+		~PhysXD6Joint();
+
+		/** @copydoc D6Joint::getMotion */
+		Motion getMotion(Axis axis) const override;
+
+		/** @copydoc D6Joint::setMotion */
+		void setMotion(Axis axis, Motion motion) override;
+
+		/** @copydoc D6Joint::getTwist */
+		Radian getTwist() const override;
+
+		/** @copydoc D6Joint::getSwingY */
+		Radian getSwingY() const override;
+
+		/** @copydoc D6Joint::getSwingZ */
+		Radian getSwingZ() const override;
+
+		/** @copydoc D6Joint::getLimitLinear */
+		LimitLinear getLimitLinear() const override;
+
+		/** @copydoc D6Joint::setLimitLinear */
+		void setLimitLinear(const LimitLinear& limit) override;
+
+		/** @copydoc D6Joint::getLimitTwist */
+		LimitAngularRange getLimitTwist() const override;
+
+		/** @copydoc D6Joint::setLimitTwist */
+		void setLimitTwist(const LimitAngularRange& limit) override;
+
+		/** @copydoc D6Joint::getLimitSwing */
+		LimitConeRange getLimitSwing() const override;
+
+		/** @copydoc D6Joint::setLimitSwing */
+		void setLimitSwing(const LimitConeRange& limit) override;
+
+		/** @copydoc D6Joint::getDrive */
+		Drive getDrive(DriveType type) const override;
+
+		/** @copydoc D6Joint::setDrive */
+		void setDrive(DriveType type, const Drive& drive) override;
+
+		/** @copydoc D6Joint::getDrivePosition */
+		Vector3 getDrivePosition() const override;
+
+		/** @copydoc D6Joint::getDriveRotation */
+		Quaternion getDriveRotation() const override;
+
+		/** @copydoc D6Joint::setDriveTransform */
+		void setDriveTransform(const Vector3& position, const Quaternion& rotation) override;
+
+		/** @copydoc D6Joint::getDriveLinearVelocity */
+		Vector3 getDriveLinearVelocity() const override;
+
+		/** @copydoc D6Joint::getDriveAngularVelocity */
+		Vector3 getDriveAngularVelocity() const override;
+
+		/** @copydoc D6Joint::setDriveVelocity */
+		void setDriveVelocity(const Vector3& linear, const Vector3& angular) override;
+
+	private:
+		/** Returns the internal PhysX representation of the D6 joint. */
+		inline physx::PxD6Joint* getInternal() const;
+	};
+
+	/** @} */
 }

+ 61 - 61
Source/BansheePhysX/Include/BsPhysXDistanceJoint.h

@@ -1,62 +1,62 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsPhysXPrerequisites.h"
-#include "BsDistanceJoint.h"
-#include "PxPhysics.h"
-#include "extensions\PxDistanceJoint.h"
-
-namespace BansheeEngine
-{
-	/** @addtogroup PhysX
-	 *  @{
-	 */
-
-	/** PhysX implementation of a DistanceJoint */
-	class BS_PHYSX_EXPORT PhysXDistanceJoint : public DistanceJoint
-	{
-	public:
-		PhysXDistanceJoint(physx::PxPhysics* physx);
-		~PhysXDistanceJoint();
-
-		/** @copydoc DistanceJoint::getDistance */
-		float getDistance() const override;
-
-		/** @copydoc DistanceJoint::getMinDistance */
-		float getMinDistance() const override;
-
-		/** @copydoc DistanceJoint::setMinDistance */
-		void setMinDistance(float value) override;
-
-		/** @copydoc DistanceJoint::getMaxDistance */
-		float getMaxDistance() const override;
-
-		/** @copydoc DistanceJoint::setMaxDistance */
-		void setMaxDistance(float value) override;
-
-		/** @copydoc DistanceJoint::getTolerance */
-		float getTolerance() const override;
-
-		/** @copydoc DistanceJoint::setTolerance */
-		void setTolerance(float value) override;
-
-		/** @copydoc DistanceJoint::getSpring */
-		Spring getSpring() const override;
-
-		/** @copydoc DistanceJoint::setSpring */
-		void setSpring(const Spring& value) override;
-
-		/** @copydoc DistanceJoint::setFlag */
-		void setFlag(Flag flag, bool enabled) override;
-
-		/** @copydoc DistanceJoint::hasFlag */
-		bool hasFlag(Flag flag) const override;
-
-	private:
-		/** Returns the internal PhysX representation of the distance joint. */
-		inline physx::PxDistanceJoint* getInternal() const;
-	};
-
-	/** @} */
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsPhysXPrerequisites.h"
+#include "BsDistanceJoint.h"
+#include "PxPhysics.h"
+#include "extensions\PxDistanceJoint.h"
+
+namespace BansheeEngine
+{
+	/** @addtogroup PhysX
+	 *  @{
+	 */
+
+	/** PhysX implementation of a DistanceJoint */
+	class BS_PHYSX_EXPORT PhysXDistanceJoint : public DistanceJoint
+	{
+	public:
+		PhysXDistanceJoint(physx::PxPhysics* physx, const DISTANCE_JOINT_DESC& desc);
+		~PhysXDistanceJoint();
+
+		/** @copydoc DistanceJoint::getDistance */
+		float getDistance() const override;
+
+		/** @copydoc DistanceJoint::getMinDistance */
+		float getMinDistance() const override;
+
+		/** @copydoc DistanceJoint::setMinDistance */
+		void setMinDistance(float value) override;
+
+		/** @copydoc DistanceJoint::getMaxDistance */
+		float getMaxDistance() const override;
+
+		/** @copydoc DistanceJoint::setMaxDistance */
+		void setMaxDistance(float value) override;
+
+		/** @copydoc DistanceJoint::getTolerance */
+		float getTolerance() const override;
+
+		/** @copydoc DistanceJoint::setTolerance */
+		void setTolerance(float value) override;
+
+		/** @copydoc DistanceJoint::getSpring */
+		Spring getSpring() const override;
+
+		/** @copydoc DistanceJoint::setSpring */
+		void setSpring(const Spring& value) override;
+
+		/** @copydoc DistanceJoint::setFlag */
+		void setFlag(Flag flag, bool enabled) override;
+
+		/** @copydoc DistanceJoint::hasFlag */
+		bool hasFlag(Flag flag) const override;
+
+	private:
+		/** Returns the internal PhysX representation of the distance joint. */
+		inline physx::PxDistanceJoint* getInternal() const;
+	};
+
+	/** @} */
 }

+ 23 - 23
Source/BansheePhysX/Include/BsPhysXFixedJoint.h

@@ -1,24 +1,24 @@
-//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
-//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
-#pragma once
-
-#include "BsPhysXPrerequisites.h"
-#include "BsFixedJoint.h"
-#include "PxPhysics.h"
-
-namespace BansheeEngine
-{
-	/** @addtogroup PhysX
-	 *  @{
-	 */
-
-	/** PhysX implementation of a FixedJoint. */
-	class BS_PHYSX_EXPORT PhysXFixedJoint : public FixedJoint
-	{
-	public:
-		PhysXFixedJoint(physx::PxPhysics* physx);
-		~PhysXFixedJoint();
-	};
-
-	/** @} */
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsPhysXPrerequisites.h"
+#include "BsFixedJoint.h"
+#include "PxPhysics.h"
+
+namespace BansheeEngine
+{
+	/** @addtogroup PhysX
+	 *  @{
+	 */
+
+	/** PhysX implementation of a FixedJoint. */
+	class BS_PHYSX_EXPORT PhysXFixedJoint : public FixedJoint
+	{
+	public:
+		PhysXFixedJoint(physx::PxPhysics* physx, const FIXED_JOINT_DESC& desc);
+		~PhysXFixedJoint();
+	};
+
+	/** @} */
 }

+ 1 - 1
Source/BansheePhysX/Include/BsPhysXHingeJoint.h

@@ -17,7 +17,7 @@ namespace BansheeEngine
 	class BS_PHYSX_EXPORT PhysXHingeJoint : public HingeJoint
 	{
 	public:
-		PhysXHingeJoint(physx::PxPhysics* physx);
+		PhysXHingeJoint(physx::PxPhysics* physx, const HINGE_JOINT_DESC& desc);
 		~PhysXHingeJoint();
 
 		/** @copydoc HingeJoint::getAngle */

+ 1 - 1
Source/BansheePhysX/Include/BsPhysXSliderJoint.h

@@ -17,7 +17,7 @@ namespace BansheeEngine
 	class BS_PHYSX_EXPORT PhysXSliderJoint : public SliderJoint
 	{
 	public:
-		PhysXSliderJoint(physx::PxPhysics* physx);
+		PhysXSliderJoint(physx::PxPhysics* physx, const SLIDER_JOINT_DESC& desc);
 		~PhysXSliderJoint();
 
 		/** @copydoc SliderJoint::getPosition */

+ 40 - 40
Source/BansheePhysX/Include/BsPhysXSphericalJoint.h

@@ -1,41 +1,41 @@
-//********************************** 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
-{
-	/** @addtogroup PhysX
-	 *  @{
-	 */
-
-	/** PhysX implementation of a SphericalJoint. */
-	class BS_PHYSX_EXPORT PhysXSphericalJoint : public SphericalJoint
-	{
-	public:
-		PhysXSphericalJoint(physx::PxPhysics* physx);
-		~PhysXSphericalJoint();
-
-		/** @copydoc SphericalJoint::getLimit */
-		LimitConeRange getLimit() const override;
-
-		/** @copydoc SphericalJoint::setLimit */
-		void setLimit(const LimitConeRange& limit) override;
-
-		/** @copydoc SphericalJoint::setFlag */
-		void setFlag(Flag flag, bool enabled) override;
-
-		/** @copydoc SphericalJoint::hasFlag */
-		bool hasFlag(Flag flag) const override;
-
-	private:
-		/** Returns the internal PhysX representation of the spherical joint. */
-		inline physx::PxSphericalJoint* getInternal() const;
-	};
-
-	/** @} */
+//********************************** 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
+{
+	/** @addtogroup PhysX
+	 *  @{
+	 */
+
+	/** PhysX implementation of a SphericalJoint. */
+	class BS_PHYSX_EXPORT PhysXSphericalJoint : public SphericalJoint
+	{
+	public:
+		PhysXSphericalJoint(physx::PxPhysics* physx, const SPHERICAL_JOINT_DESC& desc);
+		~PhysXSphericalJoint();
+
+		/** @copydoc SphericalJoint::getLimit */
+		LimitConeRange getLimit() const override;
+
+		/** @copydoc SphericalJoint::setLimit */
+		void setLimit(const LimitConeRange& limit) override;
+
+		/** @copydoc SphericalJoint::setFlag */
+		void setFlag(Flag flag, bool enabled) override;
+
+		/** @copydoc SphericalJoint::hasFlag */
+		bool hasFlag(Flag flag) const override;
+
+	private:
+		/** Returns the internal PhysX representation of the spherical joint. */
+		inline physx::PxSphericalJoint* getInternal() const;
+	};
+
+	/** @} */
 }

+ 5 - 3
Source/BansheePhysX/Source/BsFPhysXJoint.cpp

@@ -2,6 +2,7 @@
 //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
 #include "BsFPhysXJoint.h"
 #include "BsPhysXRigidbody.h"
+#include "BsJoint.h"
 #include "PxRigidDynamic.h"
 
 using namespace physx;
@@ -16,10 +17,11 @@ namespace BansheeEngine
 		return PxJointActorIndex::eACTOR1;
 	}
 
-	FPhysXJoint::FPhysXJoint(physx::PxJoint* joint)
-		:mJoint(joint)
+	FPhysXJoint::FPhysXJoint(physx::PxJoint* joint, const JOINT_DESC& desc)
+		:FJoint(desc), mJoint(joint)
 	{
-		
+		mJoint->setBreakForce(desc.breakForce, desc.breakTorque);
+		mJoint->setConstraintFlag(PxConstraintFlag::eCOLLISION_ENABLED, desc.enableCollision);
 	}
 
 	FPhysXJoint::~FPhysXJoint()

+ 12 - 12
Source/BansheePhysX/Source/BsPhysX.cpp

@@ -762,34 +762,34 @@ namespace BansheeEngine
 		return bs_shared_ptr_new<PhysXMeshCollider>(mPhysics, position, rotation);
 	}
 
-	SPtr<FixedJoint> PhysX::createFixedJoint()
+	SPtr<FixedJoint> PhysX::createFixedJoint(const FIXED_JOINT_DESC& desc)
 	{
-		return bs_shared_ptr_new<PhysXFixedJoint>(mPhysics);
+		return bs_shared_ptr_new<PhysXFixedJoint>(mPhysics, desc);
 	}
 
-	SPtr<DistanceJoint> PhysX::createDistanceJoint()
+	SPtr<DistanceJoint> PhysX::createDistanceJoint(const DISTANCE_JOINT_DESC& desc)
 	{
-		return bs_shared_ptr_new<PhysXDistanceJoint>(mPhysics);
+		return bs_shared_ptr_new<PhysXDistanceJoint>(mPhysics, desc);
 	}
 
-	SPtr<HingeJoint> PhysX::createHingeJoint()
+	SPtr<HingeJoint> PhysX::createHingeJoint(const HINGE_JOINT_DESC& desc)
 	{
-		return bs_shared_ptr_new<PhysXHingeJoint>(mPhysics);
+		return bs_shared_ptr_new<PhysXHingeJoint>(mPhysics, desc);
 	}
 
-	SPtr<SphericalJoint> PhysX::createSphericalJoint()
+	SPtr<SphericalJoint> PhysX::createSphericalJoint(const SPHERICAL_JOINT_DESC& desc)
 	{
-		return bs_shared_ptr_new<PhysXSphericalJoint>(mPhysics);
+		return bs_shared_ptr_new<PhysXSphericalJoint>(mPhysics, desc);
 	}
 
-	SPtr<SliderJoint> PhysX::createSliderJoint()
+	SPtr<SliderJoint> PhysX::createSliderJoint(const SLIDER_JOINT_DESC& desc)
 	{
-		return bs_shared_ptr_new<PhysXSliderJoint>(mPhysics);
+		return bs_shared_ptr_new<PhysXSliderJoint>(mPhysics, desc);
 	}
 
-	SPtr<D6Joint> PhysX::createD6Joint()
+	SPtr<D6Joint> PhysX::createD6Joint(const D6_JOINT_DESC& desc)
 	{
-		return bs_shared_ptr_new<PhysXD6Joint>(mPhysics);
+		return bs_shared_ptr_new<PhysXD6Joint>(mPhysics, desc);
 	}
 
 	SPtr<CharacterController> PhysX::createCharacterController(const CHAR_CONTROLLER_DESC& desc)

+ 31 - 3
Source/BansheePhysX/Source/BsPhysXD6Joint.cpp

@@ -3,6 +3,8 @@
 #include "BsPhysXD6Joint.h"
 #include "BsFPhysxJoint.h"
 #include "BsPhysX.h"
+#include "BsPhysXRigidbody.h"
+#include "PxRigidDynamic.h"
 
 using namespace physx;
 
@@ -97,12 +99,38 @@ namespace BansheeEngine
 		}
 	}
 
-	PhysXD6Joint::PhysXD6Joint(PxPhysics* physx)
+	PhysXD6Joint::PhysXD6Joint(PxPhysics* physx, const D6_JOINT_DESC& desc)
+		:D6Joint(desc)
 	{
-		PxD6Joint* joint = PxD6JointCreate(*physx, nullptr, PxTransform(PxIdentity), nullptr, PxTransform(PxIdentity));
+		PxRigidActor* actor0 = nullptr;
+		if (desc.bodies[0].body != nullptr)
+			actor0 = static_cast<PhysXRigidbody*>(desc.bodies[0].body)->_getInternal();
+
+		PxRigidActor* actor1 = nullptr;
+		if (desc.bodies[1].body != nullptr)
+			actor1 = static_cast<PhysXRigidbody*>(desc.bodies[1].body)->_getInternal();
+
+		PxTransform tfrm0 = toPxTransform(desc.bodies[0].position, desc.bodies[0].rotation);
+		PxTransform tfrm1 = toPxTransform(desc.bodies[1].position, desc.bodies[1].rotation);
+
+		PxD6Joint* joint = PxD6JointCreate(*physx, actor0, tfrm0, actor1, tfrm1);
 		joint->userData = this;
 
-		mInternal = bs_new<FPhysXJoint>(joint);
+		mInternal = bs_new<FPhysXJoint>(joint, desc);
+
+		// Calls to virtual methods are okay here
+		for (UINT32 i = 0; i < (UINT32)Axis::Count; i++)
+			setMotion((Axis)i, desc.motion[i]);
+
+		for (UINT32 i = 0; i < (UINT32)DriveType::Count; i++)
+			setDrive((DriveType)i, desc.drive[i]);
+
+		setLimitLinear(desc.limitLinear);
+		setLimitTwist(desc.limitTwist);
+		setLimitSwing(desc.limitSwing);
+
+		setDriveTransform(desc.drivePosition, desc.driveRotation);
+		setDriveVelocity(desc.driveLinearVelocity, desc.driveAngularVelocity);
 	}
 
 	PhysXD6Joint::~PhysXD6Joint()

+ 36 - 3
Source/BansheePhysX/Source/BsPhysXDistanceJoint.cpp

@@ -2,6 +2,8 @@
 //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
 #include "BsPhysXDistanceJoint.h"
 #include "BsFPhysxJoint.h"
+#include "BsPhysXRigidbody.h"
+#include "PxRigidDynamic.h"
 
 using namespace physx;
 
@@ -21,12 +23,43 @@ namespace BansheeEngine
 		}
 	}
 
-	PhysXDistanceJoint::PhysXDistanceJoint(PxPhysics* physx)
+	PhysXDistanceJoint::PhysXDistanceJoint(PxPhysics* physx, const DISTANCE_JOINT_DESC& desc)
+		:DistanceJoint(desc)
 	{
-		PxDistanceJoint* joint = PxDistanceJointCreate(*physx, nullptr, PxTransform(PxIdentity), nullptr, PxTransform(PxIdentity));
+		PxRigidActor* actor0 = nullptr;
+		if (desc.bodies[0].body != nullptr)
+			actor0 = static_cast<PhysXRigidbody*>(desc.bodies[0].body)->_getInternal();
+
+		PxRigidActor* actor1 = nullptr;
+		if (desc.bodies[1].body != nullptr)
+			actor1 = static_cast<PhysXRigidbody*>(desc.bodies[1].body)->_getInternal();
+
+		PxTransform tfrm0 = toPxTransform(desc.bodies[0].position, desc.bodies[0].rotation);
+		PxTransform tfrm1 = toPxTransform(desc.bodies[1].position, desc.bodies[1].rotation);
+
+		PxDistanceJoint* joint = PxDistanceJointCreate(*physx, actor0, tfrm0, actor1, tfrm1);
 		joint->userData = this;
 
-		mInternal = bs_new<FPhysXJoint>(joint);
+		mInternal = bs_new<FPhysXJoint>(joint, desc);
+
+		// Calls to virtual methods are okay here
+		setMinDistance(desc.minDistance);
+		setMaxDistance(desc.maxDistance);
+		setTolerance(desc.tolerance);
+		setSpring(desc.spring);
+		
+		PxDistanceJointFlags flags;
+		
+		if(((UINT32)desc.flag & (UINT32)Flag::MaxDistance) != 0)
+			flags |= PxDistanceJointFlag::eMAX_DISTANCE_ENABLED;
+
+		if (((UINT32)desc.flag & (UINT32)Flag::MinDistance) != 0)
+			flags |= PxDistanceJointFlag::eMIN_DISTANCE_ENABLED;
+
+		if (((UINT32)desc.flag & (UINT32)Flag::Spring) != 0)
+			flags |= PxDistanceJointFlag::eSPRING_ENABLED;
+
+		joint->setDistanceJointFlags(flags);
 	}
 
 	PhysXDistanceJoint::~PhysXDistanceJoint()

+ 17 - 3
Source/BansheePhysX/Source/BsPhysXFixedJoint.cpp

@@ -2,18 +2,32 @@
 //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
 #include "BsPhysXFixedJoint.h"
 #include "BsFPhysxJoint.h"
+#include "BsPhysXRigidbody.h"
 #include "extensions\PxFixedJoint.h"
+#include "PxRigidDynamic.h"
 
 using namespace physx;
 
 namespace BansheeEngine
 {
-	PhysXFixedJoint::PhysXFixedJoint(PxPhysics* physx)
+	PhysXFixedJoint::PhysXFixedJoint(PxPhysics* physx, const FIXED_JOINT_DESC& desc)
+		:FixedJoint(desc)
 	{
-		PxFixedJoint* joint = PxFixedJointCreate(*physx, nullptr, PxTransform(PxIdentity), nullptr, PxTransform(PxIdentity));
+		PxRigidActor* actor0 = nullptr;
+		if (desc.bodies[0].body != nullptr)
+			actor0 = static_cast<PhysXRigidbody*>(desc.bodies[0].body)->_getInternal();
+
+		PxRigidActor* actor1 = nullptr;
+		if (desc.bodies[1].body != nullptr)
+			actor1 = static_cast<PhysXRigidbody*>(desc.bodies[1].body)->_getInternal();
+
+		PxTransform tfrm0 = toPxTransform(desc.bodies[0].position, desc.bodies[0].rotation);
+		PxTransform tfrm1 = toPxTransform(desc.bodies[1].position, desc.bodies[1].rotation);
+
+		PxFixedJoint* joint = PxFixedJointCreate(*physx, actor0, tfrm0, actor1, tfrm1);
 		joint->userData = this;
 
-		mInternal = bs_new<FPhysXJoint>(joint);
+		mInternal = bs_new<FPhysXJoint>(joint, desc);
 	}
 
 	PhysXFixedJoint::~PhysXFixedJoint()

+ 32 - 3
Source/BansheePhysX/Source/BsPhysXHingeJoint.cpp

@@ -2,6 +2,8 @@
 //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
 #include "BsPhysXHingeJoint.h"
 #include "BsFPhysxJoint.h"
+#include "BsPhysXRigidbody.h"
+#include "PxRigidDynamic.h"
 
 using namespace physx;
 
@@ -19,12 +21,39 @@ namespace BansheeEngine
 		}
 	}
 
-	PhysXHingeJoint::PhysXHingeJoint(PxPhysics* physx)
+	PhysXHingeJoint::PhysXHingeJoint(PxPhysics* physx, const HINGE_JOINT_DESC& desc)
+		:HingeJoint(desc)
 	{
-		PxRevoluteJoint* joint = PxRevoluteJointCreate(*physx, nullptr, PxTransform(PxIdentity), nullptr, PxTransform(PxIdentity));
+		PxRigidActor* actor0 = nullptr;
+		if (desc.bodies[0].body != nullptr)
+			actor0 = static_cast<PhysXRigidbody*>(desc.bodies[0].body)->_getInternal();
+
+		PxRigidActor* actor1 = nullptr;
+		if (desc.bodies[1].body != nullptr)
+			actor1 = static_cast<PhysXRigidbody*>(desc.bodies[1].body)->_getInternal();
+
+		PxTransform tfrm0 = toPxTransform(desc.bodies[0].position, desc.bodies[0].rotation);
+		PxTransform tfrm1 = toPxTransform(desc.bodies[1].position, desc.bodies[1].rotation);
+
+		PxRevoluteJoint* joint = PxRevoluteJointCreate(*physx, actor0, tfrm0, actor1, tfrm1);
 		joint->userData = this;
 
-		mInternal = bs_new<FPhysXJoint>(joint);
+		mInternal = bs_new<FPhysXJoint>(joint, desc);
+
+		PxRevoluteJointFlags flags;
+
+		if (((UINT32)desc.flag & (UINT32)Flag::Limit) != 0)
+			flags &= PxRevoluteJointFlag::eLIMIT_ENABLED;
+
+		if (((UINT32)desc.flag & (UINT32)Flag::Drive) != 0)
+			flags &= PxRevoluteJointFlag::eDRIVE_ENABLED;
+
+		joint->setRevoluteJointFlags(flags);
+
+		// Must be set after global flags, as it will append to them.
+		// Calls to virtual methods are okay here.
+		setLimit(desc.limit);
+		setDrive(desc.drive);
 	}
 
 	PhysXHingeJoint::~PhysXHingeJoint()

+ 27 - 3
Source/BansheePhysX/Source/BsPhysXSliderJoint.cpp

@@ -3,6 +3,8 @@
 #include "BsPhysXSliderJoint.h"
 #include "BsFPhysxJoint.h"
 #include "BsPhysX.h"
+#include "BsPhysXRigidbody.h"
+#include "PxRigidDynamic.h"
 
 using namespace physx;
 
@@ -18,12 +20,34 @@ namespace BansheeEngine
 		}
 	}
 
-	PhysXSliderJoint::PhysXSliderJoint(PxPhysics* physx)
+	PhysXSliderJoint::PhysXSliderJoint(PxPhysics* physx, const SLIDER_JOINT_DESC& desc)
+		:SliderJoint(desc)
 	{
-		PxPrismaticJoint* joint = PxPrismaticJointCreate(*physx, nullptr, PxTransform(PxIdentity), nullptr, PxTransform(PxIdentity));
+		PxRigidActor* actor0 = nullptr;
+		if (desc.bodies[0].body != nullptr)
+			actor0 = static_cast<PhysXRigidbody*>(desc.bodies[0].body)->_getInternal();
+
+		PxRigidActor* actor1 = nullptr;
+		if (desc.bodies[1].body != nullptr)
+			actor1 = static_cast<PhysXRigidbody*>(desc.bodies[1].body)->_getInternal();
+
+		PxTransform tfrm0 = toPxTransform(desc.bodies[0].position, desc.bodies[0].rotation);
+		PxTransform tfrm1 = toPxTransform(desc.bodies[1].position, desc.bodies[1].rotation);
+
+		PxPrismaticJoint* joint = PxPrismaticJointCreate(*physx, actor0, tfrm0, actor1, tfrm1);
 		joint->userData = this;
 
-		mInternal = bs_new<FPhysXJoint>(joint);
+		mInternal = bs_new<FPhysXJoint>(joint, desc);
+
+		PxPrismaticJointFlags flags;
+
+		if (((UINT32)desc.flag & (UINT32)Flag::Limit) != 0)
+			flags &= PxPrismaticJointFlag::eLIMIT_ENABLED;
+
+		joint->setPrismaticJointFlags(flags);
+
+		// Calls to virtual methods are okay here
+		setLimit(desc.limit);
 	}
 
 	PhysXSliderJoint::~PhysXSliderJoint()

+ 97 - 73
Source/BansheePhysX/Source/BsPhysXSphericalJoint.cpp

@@ -1,74 +1,98 @@
-//********************************** 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());
-		joint->userData = this;
-
-		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.restitution = pxLimit.restitution;
-		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;
-		pxLimit.restitution = limit.restitution;
-
-		getInternal()->setLimitCone(pxLimit);
-	}
-
-	void PhysXSphericalJoint::setFlag(Flag flag, bool enabled)
-	{
-		getInternal()->setSphericalJointFlag(toPxFlag(flag), enabled);
-	}
-
-	bool PhysXSphericalJoint::hasFlag(Flag flag) const
-	{
-		return getInternal()->getSphericalJointFlags() & toPxFlag(flag);
-	}
-
-	PxSphericalJoint* PhysXSphericalJoint::getInternal() const
-	{
-		FPhysXJoint* internal = static_cast<FPhysXJoint*>(mInternal);
-
-		return static_cast<PxSphericalJoint*>(internal->_getInternal());
-	}
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#include "BsPhysXSphericalJoint.h"
+#include "BsFPhysxJoint.h"
+#include "BsPhysXRigidbody.h"
+#include "PxRigidDynamic.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, const SPHERICAL_JOINT_DESC& desc)
+		:SphericalJoint(desc)
+	{
+		PxRigidActor* actor0 = nullptr;
+		if (desc.bodies[0].body != nullptr)
+			actor0 = static_cast<PhysXRigidbody*>(desc.bodies[0].body)->_getInternal();
+
+		PxRigidActor* actor1 = nullptr;
+		if (desc.bodies[1].body != nullptr)
+			actor1 = static_cast<PhysXRigidbody*>(desc.bodies[1].body)->_getInternal();
+
+		PxTransform tfrm0 = toPxTransform(desc.bodies[0].position, desc.bodies[0].rotation);
+		PxTransform tfrm1 = toPxTransform(desc.bodies[1].position, desc.bodies[1].rotation);
+
+		PxSphericalJoint* joint = PxSphericalJointCreate(*physx, actor0, tfrm0, actor1, tfrm1);
+		joint->userData = this;
+
+		mInternal = bs_new<FPhysXJoint>(joint, desc);
+
+		PxSphericalJointFlags flags;
+
+		if (((UINT32)desc.flag & (UINT32)Flag::Limit) != 0)
+			flags &= PxSphericalJointFlag::eLIMIT_ENABLED;
+
+		joint->setSphericalJointFlags(flags);
+
+		// Calls to virtual methods are okay here
+		setLimit(desc.limit);
+	}
+
+	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.restitution = pxLimit.restitution;
+		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;
+		pxLimit.restitution = limit.restitution;
+
+		getInternal()->setLimitCone(pxLimit);
+	}
+
+	void PhysXSphericalJoint::setFlag(Flag flag, bool enabled)
+	{
+		getInternal()->setSphericalJointFlag(toPxFlag(flag), enabled);
+	}
+
+	bool PhysXSphericalJoint::hasFlag(Flag flag) const
+	{
+		return getInternal()->getSphericalJointFlags() & toPxFlag(flag);
+	}
+
+	PxSphericalJoint* PhysXSphericalJoint::getInternal() const
+	{
+		FPhysXJoint* internal = static_cast<FPhysXJoint*>(mInternal);
+
+		return static_cast<PxSphericalJoint*>(internal->_getInternal());
+	}
 }

+ 2 - 2
Source/BansheeSL/Include/BsParserFX.h

@@ -34,7 +34,7 @@
 # define YY_YY_BSPARSERFX_H_INCLUDED
 /* Enabling traces.  */
 #ifndef YYDEBUG
-# define YYDEBUG 1
+# define YYDEBUG 0
 #endif
 #if YYDEBUG
 extern int yydebug;
@@ -225,7 +225,7 @@ typedef struct YYLTYPE {
 typedef union YYSTYPE
 {
 /* Line 2579 of glr.c  */
-#line 74 "..\\..\\Source\\BansheeSL\\BsParserFX.y"
+#line 73 "..\\..\\Source\\BansheeSL\\BsParserFX.y"
 
 	int intValue;
 	float floatValue;

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 153 - 153
Source/BansheeSL/Source/BsParserFX.c


Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio