2
0
Эх сурвалжийг харах

*Added the (still incoplete) Ragdoll
*Misc changes in the Math

Panagiotis Christopoulos Charitos 16 жил өмнө
parent
commit
421ba29d71

+ 2 - 1
TODO

@@ -2,5 +2,6 @@
 *Changes in the blending objects problem. The BS will become one stage and the PPS will be divided in two steps. The first will apply the SSAO and the EdgeAA in the IS_FAI and the second will do the rest
 *Changes in the blending objects problem. The BS will become one stage and the PPS will be divided in two steps. The first will apply the SSAO and the EdgeAA in the IS_FAI and the second will do the rest
 *See this to improve uniform handling http://www.opengl.org/wiki/GLSL_Uniforms
 *See this to improve uniform handling http://www.opengl.org/wiki/GLSL_Uniforms
 *The second Physics demo: Create a box that is geting moved by the user. It has to interact with the other boxes
 *The second Physics demo: Create a box that is geting moved by the user. It has to interact with the other boxes
-*Create custom motion states in bullet that have as a member a Node. Then go though every motion state and update the Node's trf
 *Replace the rotations in Node with Quaternions
 *Replace the rotations in Node with Quaternions
+*Set the gravity of a certain body to a lower value and see how it behaves
+*In the Ragdoll bullet demo try to change the distances of the bodies

+ 1 - 2
src/Math/Quat.h

@@ -13,8 +13,6 @@ class Quat
 	public:
 	public:
 		// data members
 		// data members
 		float x, y, z, w;
 		float x, y, z, w;
-		static Quat zero;
-		static Quat ident;
 		// constructors & distructors
 		// constructors & distructors
 		explicit Quat();
 		explicit Quat();
 		explicit Quat( float f );
 		explicit Quat( float f );
@@ -45,6 +43,7 @@ class Quat
 		Quat  slerp( const Quat& q1, float t ) const; ///< returns slerp( this, q1, t )
 		Quat  slerp( const Quat& q1, float t ) const; ///< returns slerp( this, q1, t )
 		Quat  getRotated( const Quat& b ) const; ///< The same as Quat * Quat
 		Quat  getRotated( const Quat& b ) const; ///< The same as Quat * Quat
 		void  rotate( const Quat& b ); ///< @see getRotated
 		void  rotate( const Quat& b ); ///< @see getRotated
+		static const Quat& getIdentity();
 };
 };
 
 
 
 

+ 7 - 1
src/Math/Quat.inl.h

@@ -108,7 +108,7 @@ inline Quat::Quat( const Axisang& axisang )
 	float lengthsq = axisang.axis.getLengthSquared();
 	float lengthsq = axisang.axis.getLengthSquared();
 	if( isZero( lengthsq ) )
 	if( isZero( lengthsq ) )
 	{
 	{
-		ME = ident;
+		ME = getIdentity();
 		return;
 		return;
 	}
 	}
 
 
@@ -273,5 +273,11 @@ inline Quat Quat::slerp( const Quat& q1_, float t ) const
 	return Quat( sum );
 	return Quat( sum );
 }
 }
 
 
+// getIdentity
+inline const Quat::Quat& getIdentity()
+{
+	static Quat ident( 0.0, 0.0, 0.0, 1.0 );
+	return ident;
+}
 
 
 } // end namespace
 } // end namespace

+ 3 - 0
src/Math/Transform.h

@@ -17,6 +17,9 @@ class Transform
 		explicit Transform();
 		explicit Transform();
 		         Transform( const Transform& b );
 		         Transform( const Transform& b );
 		explicit Transform( const Mat4& m4 );
 		explicit Transform( const Mat4& m4 );
+		explicit Transform( const Vec3& origin, const Quat& rotation_ );
+
+		static const Transform& getIdentity();
 };
 };
 
 
 
 

+ 12 - 0
src/Math/Transform.inl.h

@@ -23,5 +23,17 @@ inline Transform::Transform( const Mat4& m4 )
 	translation = m4.getTranslationPart();
 	translation = m4.getTranslationPart();
 }
 }
 
 
+// constructor [Vec3, Quat]
+inline Transform::Transform( const Vec3& origin, const Quat& rotation_ ):
+	rotation(rotation_), translation(origin)
+{}
+
+// getIdentity
+inline const Transform& Transform::getIdentity()
+{
+	static Transform ident( Vec3(0.0), Quat::getIdentity() );
+	return ident;
+}
+
 
 
 } // end namespace
 } // end namespace

+ 10 - 4
src/Physics/MotionState.h

@@ -12,12 +12,12 @@
 class MotionState: public btMotionState
 class MotionState: public btMotionState
 {
 {
 	protected:
 	protected:
-		btTransform mPos1;
+		btTransform worldTransform;
 		Node* node;
 		Node* node;
 
 
 	public:
 	public:
-		MotionState( const btTransform& initialPos, Node* node_ ):
-			mPos1( initialPos ),
+		MotionState( const btTransform& initialTransform, Node* node_ ):
+			worldTransform( initialTransform ),
 			node( node_ )
 			node( node_ )
 		{
 		{
 			DEBUG_ERR( node_==NULL );
 			DEBUG_ERR( node_==NULL );
@@ -28,11 +28,17 @@ class MotionState: public btMotionState
 
 
 		virtual void getWorldTransform( btTransform &worldTrans ) const
 		virtual void getWorldTransform( btTransform &worldTrans ) const
 		{
 		{
-			worldTrans = mPos1;
+			worldTrans = worldTransform;
+		}
+
+		const btTransform& getWorldTransform() const
+		{
+			return worldTransform;
 		}
 		}
 
 
 		virtual void setWorldTransform( const btTransform &worldTrans )
 		virtual void setWorldTransform( const btTransform &worldTrans )
 		{
 		{
+			worldTransform = worldTrans;
 			btQuaternion rot = worldTrans.getRotation();
 			btQuaternion rot = worldTrans.getRotation();
 			node->rotationLspace = Mat3( Quat( toAnki(rot) ) );
 			node->rotationLspace = Mat3( Quat( toAnki(rot) ) );
 			btVector3 pos = worldTrans.getOrigin();
 			btVector3 pos = worldTrans.getOrigin();

+ 1 - 61
src/Physics/PhyCommon.h

@@ -5,67 +5,7 @@
 #include <btBulletDynamicsCommon.h>
 #include <btBulletDynamicsCommon.h>
 #include "Common.h"
 #include "Common.h"
 #include "Math.h"
 #include "Math.h"
+#include "PhyConversions.h"
 #include "MotionState.h"
 #include "MotionState.h"
 
 
-
-
-//=====================================================================================================================================
-// CONVERSIONS FROM BULLET MATH TO ANKI AND THE OPPOSITE                                                                              =
-//=====================================================================================================================================
-inline Vec3 toAnki( const btVector3& v )
-{
-	return Vec3( v.x(), v.y(), v.z() );
-}
-
-inline Vec4 toAnki( const btVector4& v )
-{
-	return Vec4( v.x(), v.y(), v.z(), v.w() );
-}
-
-inline Mat3 toAnki( const btMatrix3x3& m )
-{
-	Mat3 m3;
-	m3.setRows( toAnki(m[0]), toAnki(m[1]), toAnki(m[2]) );
-	return m3;
-}
-
-inline Quat toAnki( const btQuaternion& q )
-{
-	return Quat( q.x(), q.y(), q.z(), q.w() );
-}
-
-inline Mat4 toAnki( const btTransform& t )
-{
-	Mat4 m;
-	t.getOpenGLMatrix( &m[0] );
-	m.transpose();
-	return m;
-}
-
-inline btVector3 toBt( const Vec3& v )
-{
-	return btVector3( v.x,  v.y, v.z );
-}
-
-inline btVector4 toBt( const Vec4& v )
-{
-	return btVector4( v.x,  v.y, v.z, v.w );
-}
-
-inline btMatrix3x3 toBt( const Mat3 m )
-{
-	btMatrix3x3 r;
-	r[0] = toBt(m.getRow(0));
-	r[1] = toBt(m.getRow(1));
-	r[2] = toBt(m.getRow(2));
-	return r;
-}
-
-inline btTransform toBt( const Mat4& m )
-{
-	btTransform r;
-	r.setFromOpenGLMatrix( &(m.getTransposed())[0] );
-	return r;
-}
-
 #endif
 #endif

+ 62 - 0
src/Physics/PhyConversions.h

@@ -0,0 +1,62 @@
+#ifndef _PHYCONVERSIONS_H_
+#define _PHYCONVERSIONS_H_
+
+
+inline Vec3 toAnki( const btVector3& v )
+{
+	return Vec3( v.x(), v.y(), v.z() );
+}
+
+inline Vec4 toAnki( const btVector4& v )
+{
+	return Vec4( v.x(), v.y(), v.z(), v.w() );
+}
+
+inline Mat3 toAnki( const btMatrix3x3& m )
+{
+	Mat3 m3;
+	m3.setRows( toAnki(m[0]), toAnki(m[1]), toAnki(m[2]) );
+	return m3;
+}
+
+inline Quat toAnki( const btQuaternion& q )
+{
+	return Quat( q.x(), q.y(), q.z(), q.w() );
+}
+
+inline Mat4 toAnki( const btTransform& t )
+{
+	Mat4 m;
+	t.getOpenGLMatrix( &m[0] );
+	m.transpose();
+	return m;
+}
+
+inline btVector3 toBt( const Vec3& v )
+{
+	return btVector3( v.x,  v.y, v.z );
+}
+
+inline btVector4 toBt( const Vec4& v )
+{
+	return btVector4( v.x,  v.y, v.z, v.w );
+}
+
+inline btMatrix3x3 toBt( const Mat3 m )
+{
+	btMatrix3x3 r;
+	r[0] = toBt(m.getRow(0));
+	r[1] = toBt(m.getRow(1));
+	r[2] = toBt(m.getRow(2));
+	return r;
+}
+
+inline btTransform toBt( const Mat4& m )
+{
+	btTransform r;
+	r.setFromOpenGLMatrix( &(m.getTransposed())[0] );
+	return r;
+}
+
+
+#endif

+ 64 - 0
src/Physics/Ragdoll.h

@@ -0,0 +1,64 @@
+#ifndef _RAGDOLL_H_
+#define _RAGDOLL_H_
+
+#include "Common.h"
+#include "PhyCommon.h"
+
+
+/**
+ *
+ */
+class Ragdoll
+{
+	public:
+		enum
+		{
+			BP_PELVIS,
+			BP_SPINE,
+			BP_HEAD,
+
+			BP_LEFT_UPPER_ARM,
+			BP_LEFT_LOWER_ARM,
+			BP_LEFT_PALM,
+			BP_LEFT_UPPER_LEG,
+			BP_LEFT_LOWER_LEG,
+			BP_LEFT_FOOT,
+
+			BP_RIGHT_UPPER_ARM,
+			BP_RIGHT_LOWER_ARM,
+			BP_RIGHT_PALM,
+			BP_RIGHT_UPPER_LEG,
+			BP_RIGHT_LOWER_LEG,
+			BP_RIGHT_FOOT,
+
+			BP_NUM
+		};
+
+		enum
+		{
+			JOINT_PELVIS_SPINE,
+			JOINT_SPINE_HEAD,
+
+			JOINT_LEFT_SHOULDER,
+			JOINT_LEFT_ELBOW,
+			JOINT_LEFT_WRIST,
+			JOINT_LEFT_HIP,
+			JOINT_LEFT_KNEE,
+			JOINT_LEFT_ANKLE,
+
+			JOINT_RIGHT_SHOULDER,
+			JOINT_RIGHT_ELBOW,
+			JOINT_RIGHT_WRIST,
+			JOINT_RIGHT_HIP,
+			JOINT_RIGHT_KNEE,
+			JOINT_RIGHT_ANKLE,
+
+			JOINT_NUM
+		};
+
+		btRigidBody*       bodies[BP_NUM];
+		btTypedConstraint* joints[JOINT_NUM];
+};
+
+
+#endif

+ 4 - 8
src/Renderer/Dbg.cpp

@@ -6,11 +6,7 @@
 #include "Node.h"
 #include "Node.h"
 #include "SkelNode.h"
 #include "SkelNode.h"
 #include "App.h"
 #include "App.h"
-
-
-#include "btBulletCollisionCommon.h"
-#include "btBulletDynamicsCommon.h"
-#include "BulletDebuger.h"
+#include "PhyCommon.h"
 
 
 extern btDefaultCollisionConfiguration* collisionConfiguration;
 extern btDefaultCollisionConfiguration* collisionConfiguration;
 extern btCollisionDispatcher* dispatcher;
 extern btCollisionDispatcher* dispatcher;
@@ -31,9 +27,9 @@ void renderscene( int pass )
 		btRigidBody* body = btRigidBody::upcast( colObj );
 		btRigidBody* body = btRigidBody::upcast( colObj );
 		if( body && body->getMotionState() )
 		if( body && body->getMotionState() )
 		{
 		{
-			btDefaultMotionState* myMotionState = (btDefaultMotionState*)body->getMotionState();
-			myMotionState->m_graphicsWorldTrans.getOpenGLMatrix( m );
-			rot = myMotionState->m_graphicsWorldTrans.getBasis();
+			MotionState* myMotionState = (MotionState*)body->getMotionState();
+			myMotionState->getWorldTransform().getOpenGLMatrix( m );
+			rot = myMotionState->getWorldTransform().getBasis();
 		}
 		}
 		else
 		else
 		{
 		{