Sfoglia il codice sorgente

*Addition to Math
*Change in the motion state. needs testing

Panagiotis Christopoulos Charitos 16 anni fa
parent
commit
55f592dfdf

+ 3 - 4
src/Main.cpp

@@ -29,10 +29,9 @@
 #include "SkelAnimCtrl.h"
 #include "SkelNode.h"
 #include "LightProps.h"
-#include <btBulletCollisionCommon.h>
-#include <btBulletDynamicsCommon.h>
 #include "BulletDebuger.h"
-#include "MotionState.h"
+#include "PhyCommon.h"
+#include "Parser.h"
 
 App* app;
 
@@ -151,7 +150,7 @@ void initPhysics()
 					MeshNode* crate = new MeshNode;
 					crate->init( "models/crate0/crate0.mesh" );
 					crate->scaleLspace = 1.11;
-					MotionState* myMotionState = new MotionState(startTransform, crate);
+					MotionState* myMotionState = new MotionState( toAnki( startTransform ), crate);
 					btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
 					btRigidBody* body = new btRigidBody(rbInfo);
 

+ 2 - 1
src/Math/Quat.h

@@ -13,7 +13,7 @@ class Quat
 	public:
 		// data members
 		float x, y, z, w;
-		// constructors & distructors
+		// constructors & destructors
 		explicit Quat();
 		explicit Quat( float f );
 		explicit Quat( float x, float y, float z, float w );
@@ -33,6 +33,7 @@ class Quat
 		// other
 		void  setFrom2Vec3( const Vec3& v0, const Vec3& v1 ); ///< calculates a quat from v0 to v1
 		float getLength() const;
+		Quat  getInverted() const;
 		void  invert();
 		void  conjugate();
 		Quat  getConjugated() const;

+ 10 - 3
src/Math/Quat.inl.h

@@ -187,15 +187,22 @@ inline float Quat::getLength() const
 	return M::sqrt( w*w + x*x + y*y + z*z );
 }
 
-// invert
-inline void Quat::invert()
+
+// getInverted
+inline Quat Quat::getInverted() const
 {
 	float norm = w*w + x*x + y*y + z*z;
 
 	DEBUG_ERR( isZero(norm) ); // Norm is zero
 
 	float normi = 1.0 / norm;
-	ME = Quat( -normi*x, -normi*y, -normi*z, normi*w );
+	return Quat( -normi*x, -normi*y, -normi*z, normi*w );
+}
+
+// invert
+inline void Quat::invert()
+{
+	ME = getInverted();
 }
 
 // print

+ 2 - 1
src/Math/Transform.h

@@ -12,12 +12,13 @@ class Transform
 {
 	PROPERTY_RW( Quat, rotation, setRotation, getRotation );
 	PROPERTY_RW( Vec3, translation, setOrigin, getOrigin );
+	PROPERTY_RW( float, scale, setScale, getScale );
 
 	public:
 		explicit Transform();
 		         Transform( const Transform& b );
 		explicit Transform( const Mat4& m4 );
-		explicit Transform( const Vec3& origin, const Quat& rotation_ );
+		explicit Transform( const Vec3& origin, const Quat& rotation_, float scale_ );
 
 		static const Transform& getIdentity();
 };

+ 4 - 4
src/Math/Transform.inl.h

@@ -23,15 +23,15 @@ inline Transform::Transform( const Mat4& m4 )
 	translation = m4.getTranslationPart();
 }
 
-// constructor [Vec3, Quat]
-inline Transform::Transform( const Vec3& origin, const Quat& rotation_ ):
-	rotation(rotation_), translation(origin)
+// constructor [Vec3, Quat, float]
+inline Transform::Transform( const Vec3& origin, const Quat& rotation_, float scale_ ):
+	rotation(rotation_), translation(origin), scale(scale_)
 {}
 
 // getIdentity
 inline const Transform& Transform::getIdentity()
 {
-	static Transform ident( Vec3(0.0), Quat::getIdentity() );
+	static Transform ident( Vec3(0.0), Quat::getIdentity(), 1.0 );
 	return ident;
 }
 

+ 3 - 3
src/Math/Vec3.h

@@ -57,9 +57,9 @@ class Vec3
 		void  normalize();
 		Vec3  getNormalized() const;
 		Vec3  getProjection( const Vec3& toThis ) const;
-		Vec3  getRotated( const Quat& q ) const; // returns q * this * q.Conjucated() aka returns a rotated this. 18 muls, 12 adds
+		Vec3  getRotated( const Quat& q ) const; ///< Returns q * this * q.Conjucated() aka returns a rotated this. 18 muls, 12 adds
 		void  rotate( const Quat& q );
-		Vec3  lerp( const Vec3& v1, float t ) const; // return lerp( this, v1, t )
+		Vec3  lerp( const Vec3& v1, float t ) const; ///< return lerp( this, v1, t )
 		void  print() const;
 		// transformations. The faster way is by far the mat4 * vec3 or the Transformed( Vec3, Mat3 )
 		Vec3  getTransformed( const Vec3& translate, const Mat3& rotate, float scale ) const;
@@ -70,7 +70,7 @@ class Vec3
 		void  transform( const Vec3& translate, const Quat& rotate, float scale );
 		Vec3  getTransformed( const Vec3& translate, const Quat& rotate ) const;
 		void  transform( const Vec3& translate, const Quat& rotate );
-		Vec3  getTransformed( const Mat4& transform ) const;  // 9 muls, 9 adds
+		Vec3  getTransformed( const Mat4& transform ) const;  ///< 9 muls, 9 adds
 		void  transform( const Mat4& transform );
 };
 

+ 1 - 1
src/Math/Vec3.inl.h

@@ -258,7 +258,7 @@ inline Vec3 Vec3::getProjection( const Vec3& toThis ) const
 // Rotated
 inline Vec3 Vec3::getRotated( const Quat& q ) const
 {
-	DEBUG_ERR( !isZero(1.0f-q.getLength()) ); // Not normalized quat
+	DEBUG_ERR( !isZero(1.0-q.getLength()) ); // Not normalized quat
 
 	/*float vmult = 2.0f*(q.x*x + q.y*y + q.z*z);
 	float crossmult = 2.0*q.w;

+ 7 - 12
src/Physics/MotionState.h

@@ -12,15 +12,14 @@
 class MotionState: public btMotionState
 {
 	protected:
-		btTransform worldTransform;
 		Node* node;
 
 	public:
-		MotionState( const btTransform& initialTransform, Node* node_ ):
-			worldTransform( initialTransform ),
+		MotionState( const Mat4& transform, Node* node_ ):
 			node( node_ )
 		{
 			DEBUG_ERR( node_==NULL );
+			setWorldTransform( toBt(transform) );
 		}
 
 		virtual ~MotionState()
@@ -28,21 +27,17 @@ class MotionState: public btMotionState
 
 		virtual void getWorldTransform( btTransform &worldTrans ) const
 		{
-			worldTrans = worldTransform;
+			worldTrans = toBt( node->transformationWspace );
 		}
 
-		const btTransform& getWorldTransform() const
+		btTransform getWorldTransform() const
 		{
-			return worldTransform;
+			return toBt( node->transformationWspace );
 		}
 
-		virtual void setWorldTransform( const btTransform &worldTrans )
+		virtual void setWorldTransform( const btTransform& worldTrans )
 		{
-			worldTransform = worldTrans;
-			btQuaternion rot = worldTrans.getRotation();
-			node->rotationLspace = Mat3( Quat( toAnki(rot) ) );
-			btVector3 pos = worldTrans.getOrigin();
-			node->translationLspace = Vec3( toAnki(pos) );
+			node->transformationWspace = toAnki( worldTrans );
 		}
 };
 

+ 3 - 0
src/Scene/Node.h

@@ -14,6 +14,9 @@ class Controller;
 /// Scene Node
 class Node
 {
+	PROPERTY_RW( Transform, localTransform, setLocalTransform, getLocalTransform );
+	PROPERTY_RW( Transform, worldTransform, setWorldTransform, getWorldTransform );
+
 	// data
 	public:
 		enum Type

+ 19 - 0
src/Scene/ParticleEmitter.h

@@ -0,0 +1,19 @@
+#ifndef _PARTICLEEMITTER_H_
+#define _PARTICLEEMITTER_H_
+
+#include "Common.h"
+#include "Node.h"
+
+class ParticleEmitter: public Node
+{
+	public:
+
+		class Particle: public Node
+		{
+
+		};
+
+		Vec<Particle*> particles;
+};
+
+#endif