Browse Source

Replaced the rotation,translation and scale in SceneNode with Transform objects

Panagiotis Christopoulos Charitos 15 years ago
parent
commit
47baa0372e

+ 2 - 2
build/README

@@ -11,9 +11,9 @@ This will generate a "Makefile". To build just type:
 
 make
 
-And the build will will begin. 
+And the build will begin. 
 
-Sometimes I forget to update all the targets. The debug is always updated though
+WARNING: Sometimes I forget to update all the targets. The debug is always updated though
 
 The gen.cfg.py files contain the build options of every target. Their format is pretty straightforward and minimal
 

+ 18 - 18
src/Main.cpp

@@ -128,7 +128,7 @@ void initPhysics()
 					//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
 					MeshNode* crate = new MeshNode;
 					crate->init( "models/crate0/crate0.mesh" );
-					crate->scaleLspace = 1.11;
+					crate->getLocalTransform().setScale( 1.11 );
 
 					Transform trf( SCALING*Vec3(2.0*i + start_x, 20+2.0*k + start_y, 2.0*j + start_z), Mat3::getIdentity(), 1.0 );
 					body = app->getScene()->getPhyWorld()->createNewRigidBody( mass, trf, colShape, crate );
@@ -156,7 +156,7 @@ void initPhysics()
 
 
 
-	/*for (int i=0; i<app->getScene()->getPhyWorld()->getDynamicsWorld()->getCollisionObjectArray().size();i++)
+	/*for( int i=0; i<app->getScene()->getPhyWorld()->getDynamicsWorld()->getCollisionObjectArray().size();i++ )
 	{
 		btCollisionObject* colObj = app->getScene()->getPhyWorld()->getDynamicsWorld()->getCollisionObjectArray()[i];
 		btRigidBody* body = btRigidBody::upcast(colObj);
@@ -214,45 +214,45 @@ void init()
 	// lights
 	point_lights[0] = new PointLight();
 	point_lights[0]->init( "maps/temple/light0.light" );
-	point_lights[0]->setLocalTransformation( Vec3( -1.0, 2.4, 1.0 ), Mat3::getIdentity(), 1.0 );
+	point_lights[0]->setLocalTransform( Transform( Vec3( -1.0, 2.4, 1.0 ), Mat3::getIdentity(), 1.0 ) );
 	point_lights[1] = new PointLight();
 	point_lights[1]->init( "maps/temple/light1.light" );
-	point_lights[1]->setLocalTransformation( Vec3( 2.5, 1.4, 1.0 ), Mat3::getIdentity(), 1.0 );
+	point_lights[1]->setLocalTransform( Transform( Vec3( 2.5, 1.4, 1.0 ), Mat3::getIdentity(), 1.0 ) );
 
 	spot_lights[0] = new SpotLight();
 	spot_lights[0]->init( "maps/temple/light2.light" );
-	spot_lights[0]->setLocalTransformation( Vec3( 1.3, 4.3, 3.0 ), Mat3( Euler(toRad(-20), toRad(20), 0.0) ), 1.0 );
+	spot_lights[0]->setLocalTransform( Transform( Vec3( 1.3, 4.3, 3.0 ), Mat3( Euler(toRad(-20), toRad(20), 0.0) ), 1.0 ) );
 	spot_lights[1] = new SpotLight();
 	spot_lights[1]->init( "maps/temple/light3.light" );
-	spot_lights[1]->setLocalTransformation( Vec3( -2.3, 6.3, 2.9 ), Mat3( Euler(toRad(-70), toRad(-20), 0.0) ), 1.0 );
+	spot_lights[1]->setLocalTransform( Transform( Vec3( -2.3, 6.3, 2.9 ), Mat3( Euler(toRad(-70), toRad(-20), 0.0) ), 1.0 ) );
 
 	// horse
 	horse = new MeshNode();
 	horse->init( "meshes/horse/horse.mesh" );
-	horse->setLocalTransformation( Vec3( -2, 0, 1 ), Mat3( Euler(-M::PI/2, 0.0, 0.0) ), 0.5 );
+	horse->setLocalTransform( Transform( Vec3( -2, 0, 1 ), Mat3( Euler(-M::PI/2, 0.0, 0.0) ), 0.5 ) );
 	
 	// sarge
 	sarge = new MeshNode();
 	sarge->init( "meshes/sphere/sphere16.mesh" );
-	//sarge->setLocalTransformation( Vec3( 0, -2.8, 1.0 ), Mat3( Euler(-M::PI/2, 0.0, 0.0) ), 1.1 );
-	sarge->setLocalTransformation( Vec3( 0, 2.0, 2.0 ), Mat3::getIdentity(), 0.4 );
+	//sarge->setLocalTransform( Vec3( 0, -2.8, 1.0 ), Mat3( Euler(-M::PI/2, 0.0, 0.0) ), 1.1 );
+	sarge->setLocalTransform( Transform( Vec3( 0, 2.0, 2.0 ), Mat3::getIdentity(), 0.4 ) );
 	
 	// floor
 	floor__ = new MeshNode();
 	floor__->init( "maps/temple/Cube.019.mesh" );
-	floor__->setLocalTransformation( Vec3(0.0, -0.19, 0.0), Mat3( Euler(-M::PI/2, 0.0, 0.0) ), 0.8 );
+	floor__->setLocalTransform( Transform( Vec3(0.0, -0.19, 0.0), Mat3( Euler(-M::PI/2, 0.0, 0.0) ), 0.8 ) );
 
 	// imp	
 	imp = new SkelModelNode();
 	imp->init( "models/imp/imp.smdl" );
-	imp->setLocalTransformation( Vec3( 0.0, 2.11, 0.0 ), Mat3( Euler(-M::PI/2, 0.0, 0.0) ), 0.7 );
+	imp->setLocalTransform( Transform( Vec3( 0.0, 2.11, 0.0 ), Mat3( Euler(-M::PI/2, 0.0, 0.0) ), 0.7 ) );
 	imp->meshNodes[0]->meshSkelCtrl->skelNode->skelAnimCtrl->skelAnim = Rsrc::skelAnims.load( "models/imp/walk.imp.anim" );
 	imp->meshNodes[0]->meshSkelCtrl->skelNode->skelAnimCtrl->step = 0.8;
 
 	// particle emitter
 	partEmitter = new ParticleEmitter;
 	partEmitter->init( NULL );
-	partEmitter->translationLspace = Vec3( 3.0, 0.0, 0.0 );
+	partEmitter->getLocalTransform().setOrigin( Vec3( 3.0, 0.0, 0.0 ) );
 
 	// crate
 	/*crate = new MeshNode;
@@ -330,10 +330,10 @@ int main( int argc, char* argv[] )
 		}
 		if( I::keys[SDLK_q] ) mover->rotateLocalZ( ang );
 		if( I::keys[SDLK_e] ) mover->rotateLocalZ( -ang );
-		if( I::keys[SDLK_PAGEUP] ) mover->scaleLspace += scale ;
-		if( I::keys[SDLK_PAGEDOWN] ) mover->scaleLspace -= scale ;
+		if( I::keys[SDLK_PAGEUP] ) mover->getLocalTransform().getScale() += scale ;
+		if( I::keys[SDLK_PAGEDOWN] ) mover->getLocalTransform().getScale() -= scale ;
 
-		if( I::keys[SDLK_k] ) app->getActiveCam()->lookAtPoint( point_lights[0]->translationWspace );
+		if( I::keys[SDLK_k] ) app->getActiveCam()->lookAtPoint( point_lights[0]->getWorldTransform().getOrigin() );
 
 
 		if( I::keys[SDLK_o] == 1 )
@@ -345,7 +345,7 @@ int main( int argc, char* argv[] )
 			body->forceActivationState( ACTIVE_TAG );
 		}
 
-		mover->rotationLspace.reorthogonalize();
+		mover->getLocalTransform().getRotation().reorthogonalize();
 
 		//static_cast<btRigidBody*>(dynamicsWorld->getCollisionObjectArray()[1])->getMotionState()->setWorldTransform( toBt(point_lights[0]->transformationWspace) );
 		//dynamicsWorld->getCollisionObjectArray()[3]->setWorldTransform( toBt(point_lights[0]->transformationWspace) );
@@ -368,8 +368,8 @@ int main( int argc, char* argv[] )
 		Ui::setFontWidth( 0.03 );
 		Ui::printf( "frame:%d fps:%dms\n", R::framesNum, (App::getTicks()-ticks_) );
 		//Ui::print( "Movement keys: arrows,w,a,s,d,q,e,shift,space\nSelect objects: keys 1 to 5\n" );
-		Ui::printf( "Mover: Pos(%.2f %.2f %.2f) Angs(%.2f %.2f %.2f)", mover->translationWspace.x, mover->translationWspace.y, mover->translationWspace.z,
-								 toDegrees(Euler(mover->rotationWspace).x), toDegrees(Euler(mover->rotationWspace).y), toDegrees(Euler(mover->rotationWspace).z) );
+		/*Ui::printf( "Mover: Pos(%.2f %.2f %.2f) Angs(%.2f %.2f %.2f)", mover->translationWspace.x, mover->translationWspace.y, mover->translationWspace.z,
+								 toDegrees(Euler(mover->rotationWspace).x), toDegrees(Euler(mover->rotationWspace).y), toDegrees(Euler(mover->rotationWspace).z) );*/
 
 		if( I::keys[SDLK_ESCAPE] ) break;
 		if( I::keys[SDLK_F11] ) app->togleFullScreen();

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

@@ -153,7 +153,7 @@ inline Mat4::Mat4( float f )
 // constructor [Transform]
 inline Mat4::Mat4( const Transform& t )
 {
-	ME = Mat4( t.getOrigin(), Mat3(t.getRotation()), t.getScale() );
+	ME = Mat4( t.getOrigin(), t.getRotation(), t.getScale() );
 }
 
 // 4x4 + 4x4

+ 1 - 0
src/Math/Transform.h

@@ -24,6 +24,7 @@ class Transform
 		// funcs
 		void setIdentity();
 		static const Transform& getIdentity();
+		static Transform combineTransformations( const Transform& a, const Transform& b ); ///< @see M::combineTransformations
 };
 
 

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

@@ -42,5 +42,13 @@ inline const Transform& Transform::getIdentity()
 	return ident;
 }
 
+// combineTransformations
+inline Transform Transform::combineTransformations( const Transform& a, const Transform& b )
+{
+	Transform out;
+	M::combineTransformations( a.origin, a.rotation, a.scale, b.origin, b.rotation, b.scale, out.origin, out.rotation, out.scale );
+	return out;
+}
+
 
 } // end namespace

+ 2 - 0
src/Math/Vec3.h

@@ -73,6 +73,8 @@ class Vec3
 		void  transform( const Vec3& translate, const Quat& rotate );
 		Vec3  getTransformed( const Mat4& transform ) const;  ///< 9 muls, 9 adds
 		void  transform( const Mat4& transform );
+		Vec3  getTransformed( const Transform& transform ) const;
+		void  transform( const Transform& transform );
 };
 
 

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

@@ -343,5 +343,17 @@ inline void Vec3::transform( const Mat4& transform )
 	ME = getTransformed( transform );
 }
 
+// getTransformed [Transform]
+inline Vec3 Vec3::getTransformed( const Transform& transform ) const
+{
+	return (transform.getRotation() * (ME * transform.getScale())) + transform.getOrigin();
+}
+
+// getTransformed [Transform]
+inline void Vec3::transform( const Transform& transform )
+{
+	ME = getTransformed( transform );
+}
+
 
 } // end namespace

+ 9 - 4
src/Physics/MotionState.h

@@ -26,7 +26,7 @@ class MotionState: public btMotionState
 		virtual ~MotionState()
 		{}
 
-		virtual void getWorldTransform( btTransform &worldTrans ) const
+		virtual void getWorldTransform( btTransform& worldTrans ) const
 		{
 			worldTrans = worldTransform;
 		}
@@ -36,13 +36,18 @@ class MotionState: public btMotionState
 			return worldTransform;
 		}
 
-		virtual void setWorldTransform( const btTransform &worldTrans )
+		virtual void setWorldTransform( const btTransform& worldTrans )
 		{
+			float originalScale = node->getLocalTransform().getScale();
 			worldTransform = worldTrans;
-			btQuaternion rot = worldTrans.getRotation();
+
+			node->setLocalTransform( Transform( toAnki( worldTrans ) ) );
+			node->getLocalTransform().setScale( originalScale );
+
+			/*btQuaternion rot = worldTrans.getRotation();
 			node->rotationLspace = Mat3( Quat( toAnki(rot) ) );
 			btVector3 pos = worldTrans.getOrigin();
-			node->translationLspace = Vec3( toAnki(pos) );
+			node->translationLspace = Vec3( toAnki(pos) );*/
 		}
 };
 

+ 22 - 4
src/Renderer/Dbg.cpp

@@ -113,8 +113,8 @@ void init()
 
 float projectRadius( float r, const Vec3& location, const Camera& cam )
 {
-	Vec3 axis = cam.rotationWspace.getXAxis();
-	float c = axis.dot( cam.translationWspace );
+	Vec3 axis = cam.getWorldTransform().getRotation().getXAxis();
+	float c = axis.dot( cam.getWorldTransform().getOrigin() );
 	float dist = axis.dot( location ) - c;
 
 	/*if( dist > 0.0 )
@@ -374,7 +374,25 @@ void renderSphere( float r, int p )
 //=====================================================================================================================================
 void renderCube( bool cols, float size )
 {
-	size *= 0.5f;
+	Vec3 maxPos( 0.5 );
+	Vec3 minPos( -0.5 );
+	float vertPositions[] = { maxPos.x, maxPos.y, maxPos.z,   // right top front
+	                          minPos.x, maxPos.y, maxPos.z,   // left top front
+	                          minPos.x, minPos.y, maxPos.z,   // left bottom front
+	                          maxPos.x, minPos.y, maxPos.z,   // right bottom front
+	                          maxPos.x, maxPos.y, minPos.z,   // right top back
+	                          minPos.x, maxPos.y, minPos.z,   // left top back
+	                          minPos.x, minPos.y, minPos.z,   // left bottom back
+	                          maxPos.x, minPos.y, minPos.z }; // right bottom back
+
+	uint vertIndices [] = { 0, 1, 2, 3, 4, 5, 6, 7, 4, 0, 3, 7, 1, 5, 6, 2, 0, 4, 5, 1, 3, 2, 6, 7, 5, 4, 7, 6 };
+
+	glEnableClientState( GL_VERTEX_ARRAY );
+	glVertexPointer( 3, GL_FLOAT, 0, vertPositions );
+	glDrawElements( GL_QUADS, sizeof(vertIndices)/sizeof(uint), GL_UNSIGNED_INT, vertIndices );
+	glDisableClientState( GL_VERTEX_ARRAY );
+
+	/*size *= 0.5;
 	glBegin(GL_QUADS);
 		// Front Face
 		if(cols) glColor3f( 0.0, 0.0, 1.0 );
@@ -418,7 +436,7 @@ void renderCube( bool cols, float size )
 		glTexCoord2f(1.0, 0.0); glVertex3f(-size, -size,  size);
 		glTexCoord2f(1.0, 1.0); glVertex3f(-size,  size,  size);
 		glTexCoord2f(0.0, 1.0); glVertex3f(-size,  size, -size);
-	glEnd();
+	glEnd();*/
 }
 
 

+ 6 - 6
src/Renderer/Is.cpp

@@ -90,7 +90,7 @@ static void initSMOUVS()
 static void DrawSMOUVS( const PointLight& light )
 {
 	const float scale = 1.2;
-	R::multMatrix( Mat4( light.translationWspace, Mat3::getIdentity(), light.radius*scale ) );
+	R::multMatrix( Mat4( light.getWorldTransform().getOrigin(), Mat3::getIdentity(), light.radius*scale ) );
 
 	R::noShaders();
 
@@ -341,7 +341,7 @@ static void setStencilMask( const Camera& cam, const SpotLight& light )
 		{ { x, -y, z }, {-x, -y, z }, {-x,  y, z } }, // front bottom left
 	};
 
-	R::multMatrix( lcam.transformationWspace );
+	R::multMatrix( Mat4(lcam.getWorldTransform()) );
 	glEnableClientState( GL_VERTEX_ARRAY );
 	glVertexPointer( 3, GL_FLOAT, 0, verts );
 	glDrawArrays( GL_TRIANGLES, 0, tris_num*3 );
@@ -372,7 +372,7 @@ PointLightPass
 static void PointLightPass( const Camera& cam, const PointLight& light )
 {
 	//** make a check wether the point light passes the frustum test **
-	bsphere_t sphere( light.translationWspace, light.radius );
+	bsphere_t sphere( light.getWorldTransform().getOrigin(), light.radius );
 	if( !cam.insideFrustum( sphere ) ) return;
 
 	//** set the scissors **
@@ -393,7 +393,7 @@ static void PointLightPass( const Camera& cam, const PointLight& light )
 	shader.locTexUnit( shader.uniLocs.msDepthFai, R::Ms::depthFai, 3 );
 	glUniform2fv( shader.uniLocs.planes, 1, &planes[0] );
 
-	Vec3 lightPosEyeSpace = light.translationWspace.getTransformed( cam.getViewMatrix() );
+	Vec3 lightPosEyeSpace = light.getWorldTransform().getOrigin().getTransformed( cam.getViewMatrix() );
 	glUniform3fv( shader.uniLocs.lightPos, 1, &lightPosEyeSpace[0] );
 	glUniform1f( shader.uniLocs.lightInvRadius, 1.0/light.radius );
 	glUniform3fv( shader.uniLocs.lightDiffuseCol, 1, &Vec3(light.lightProps->getDiffuseColor())[0] );
@@ -465,7 +465,7 @@ static void SpotLightPass( const Camera& cam, const SpotLight& light )
 	glUniform2fv( shdr->uniLocs.planes, 1, &planes[0] );
 
 	// the light params
-	Vec3 light_pos_eye_space = light.translationWspace.getTransformed( cam.getViewMatrix() );
+	Vec3 light_pos_eye_space = light.getWorldTransform().getOrigin().getTransformed( cam.getViewMatrix() );
 	glUniform3fv( shdr->uniLocs.lightPos, 1, &light_pos_eye_space[0] );
 	glUniform1f( shdr->uniLocs.lightInvRadius, 1.0/light.getDistance() );
 	glUniform3fv( shdr->uniLocs.lightDiffuseCol, 1, &Vec3(light.lightProps->getDiffuseColor())[0] );
@@ -482,7 +482,7 @@ static void SpotLightPass( const Camera& cam, const SpotLight& light )
 	// Bias * P_light * V_light * inv( V_cam )
 	static Mat4 bias_m4( 0.5, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0 );
 	Mat4 tex_projection_mat;
-	tex_projection_mat = bias_m4 * light.camera.getProjectionMatrix() * light.camera.getViewMatrix() * cam.transformationWspace;
+	tex_projection_mat = bias_m4 * light.camera.getProjectionMatrix() * light.camera.getViewMatrix() * Mat4(cam.getWorldTransform());
 	glUniformMatrix4fv( shdr->uniLocs.texProjectionMat, 1, true, &tex_projection_mat[0] );
 
 	// the shadow stuff

+ 2 - 0
src/Renderer/Renderer.h

@@ -49,7 +49,9 @@ extern void DrawQuad( int vertCoords_uni_loc );
 
 // ogl and glu wrappers
 inline void   multMatrix( const Mat4& m4 ) { glMultMatrixf( &(m4.getTransposed())(0,0) ); } ///< OpenGL wrapper
+inline void   multMatrix( const Transform& trf ) { glMultMatrixf( &(Mat4(trf).getTransposed())(0,0) ); } ///< OpenGL wrapper
 inline void   loadMatrix( const Mat4& m4 ) { glLoadMatrixf( &(m4.getTransposed())(0,0) ); } ///< OpenGL wrapper
+inline void   loadMatrix( const Transform& trf ) { glLoadMatrixf( &(Mat4(trf).getTransposed())(0,0) ); } ///< OpenGL wrapper
 
 inline void   color3( const Vec3& v ) { glColor3fv( &((Vec3&)v)[0] ); } ///< OpenGL wrapper
 inline void   color4( const Vec4& v ) { glColor4fv( &((Vec4&)v)[0] ); } ///< OpenGL wrapper

+ 10 - 8
src/Scene/Camera.cpp

@@ -22,7 +22,7 @@ void Camera::setAll( float fovx_, float fovy_, float znear_, float zfar_ )
 void Camera::render()
 {
 	glPushMatrix();
-	R::multMatrix( transformationWspace );
+	R::multMatrix( Mat4( getWorldTransform() ) );
 
 	const float camLen = 1.0;
 	float tmp0 = camLen / tan( (PI - fovX)*0.5 ) + 0.001;
@@ -73,10 +73,10 @@ void Camera::render()
 void Camera::lookAtPoint( const Vec3& point )
 {
 	const Vec3& j = Vec3( 0.0, 1.0, 0.0 );
-	Vec3 vdir = (point - translationLspace).getNormalized();
+	Vec3 vdir = (point - getLocalTransform().getOrigin()).getNormalized();
 	Vec3 vup = j - vdir * j.dot(vdir);
 	Vec3 vside = vdir.cross( vup );
-	rotationLspace.setColumns( vside, vup, -vdir );
+	getLocalTransform().getRotation().setColumns( vside, vup, -vdir );
 }
 
 
@@ -112,7 +112,9 @@ void Camera::calcLSpaceFrustumPlanes()
 void Camera::updateWSpaceFrustumPlanes()
 {
 	for( uint i=0; i<6; i++ )
-		wspaceFrustumPlanes[i] = lspaceFrustumPlanes[i].Transformed( translationWspace, rotationWspace, scaleWspace );
+	{
+		wspaceFrustumPlanes[i] = lspaceFrustumPlanes[i].Transformed( getWorldTransform().getOrigin(), getWorldTransform().getRotation(), getWorldTransform().getScale() );
+	}
 }
 
 
@@ -149,11 +151,11 @@ bool Camera::insideFrustum( const Camera& cam ) const
 	points[1] = Vec3( -x, y, z ); // top left
 	points[2] = Vec3( -x, -y, z ); // bottom left
 	points[3] = Vec3( x, -y, z ); // bottom right
-	points[4] = Vec3( cam.translationWspace ); // eye (already in world space)
+	points[4] = Vec3( cam.getWorldTransform().getOrigin() ); // eye (already in world space)
 
 	// transform them to the given camera's world space (exept the eye)
 	for( uint i=0; i<4; i++ )
-		points[i].transform( cam.translationWspace, cam.rotationWspace, cam.scaleWspace );
+		points[i].transform( getWorldTransform() );
 
 
 	//** the collision code **
@@ -214,8 +216,8 @@ void Camera::updateViewMatrix()
 
 
 	// The view matrix is: Mview = camera.world_transform.Inverted(). Bus instead of inverting we do the following:
-	Mat3 camInvertedRot = rotationWspace.getTransposed();
-	Vec3 camInvertedTsl = -( camInvertedRot * translationWspace );
+	Mat3 camInvertedRot = getWorldTransform().getRotation().getTransposed();
+	Vec3 camInvertedTsl = -( camInvertedRot * getWorldTransform().getOrigin() );
 	viewMat = Mat4( camInvertedTsl, camInvertedRot );
 }
 

+ 2 - 2
src/Scene/Light.cpp

@@ -59,7 +59,7 @@ static void RenderSphere( const Mat4& tsl, const Vec3& col )
 //=====================================================================================================================================
 void PointLight::render()
 {
-	RenderSphere( transformationWspace, lightProps->getDiffuseColor() );
+	RenderSphere( Mat4(getWorldTransform()), lightProps->getDiffuseColor() );
 }
 
 
@@ -68,5 +68,5 @@ void PointLight::render()
 //=====================================================================================================================================
 void SpotLight::render()
 {
-	RenderSphere( transformationWspace, lightProps->getDiffuseColor() );
+	RenderSphere( Mat4(getWorldTransform()), lightProps->getDiffuseColor() );
 }

+ 1 - 1
src/Scene/MeshNode.cpp

@@ -42,7 +42,7 @@ void MeshNode::deinit()
 void MeshNode::render( Material* mtl ) const
 {
 	glPushMatrix();
-	R::multMatrix( transformationWspace );
+	R::multMatrix( Mat4(getWorldTransform()) );
 
 	// if we have skeleton controller
 	if( meshSkelCtrl )

+ 6 - 5
src/Scene/ParticleEmitter.cpp

@@ -13,7 +13,7 @@ void ParticleEmitter::Particle::render()
 	if( lifeTillDeath < 0 ) return;
 
 	glPushMatrix();
-	R::multMatrix( transformationWspace );
+	R::multMatrix( getWorldTransform() );
 
 	glBegin( GL_POINTS );
 		glVertex3fv( &(Vec3(0.0))[0] );
@@ -148,7 +148,7 @@ void ParticleEmitter::update()
 			{
 				pos = minStartingPos;
 			}
-			pos += translationWspace;
+			pos += getWorldTransform().getOrigin();
 			part->body->setWorldTransform( toBt( Mat4( pos, Mat3::getIdentity(), 1.0 ) ) );
 
 			// do the rest
@@ -180,14 +180,15 @@ void ParticleEmitter::render()
 	uint vertIndices [] = { 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 3, 7, 2, 6 };
 
 	glPushMatrix();
-	R::multMatrix( transformationWspace );
+	R::multMatrix( getWorldTransform() );
 
 	R::color3( Vec3(1.0) );
 
-	glEnableClientState( GL_VERTEX_ARRAY );
+	/*glEnableClientState( GL_VERTEX_ARRAY );
 	glVertexPointer( 3, GL_FLOAT, 0, vertPositions );
 	glDrawElements( GL_LINES, sizeof(vertIndices)/sizeof(uint), GL_UNSIGNED_INT, vertIndices );
-	glDisableClientState( GL_VERTEX_ARRAY );
+	glDisableClientState( GL_VERTEX_ARRAY );*/
+	R::Dbg::renderCube();
 
 	glPopMatrix();
 }

+ 11 - 25
src/Scene/SceneNode.cpp

@@ -14,13 +14,9 @@ void SceneNode::commonConstructorCode()
 {
 	parent = NULL;
 	isCompound = false;
-	translationLspace = Vec3( 0.0 );
-	scaleLspace = 1.0;
-	rotationLspace = Mat3::getIdentity();
-	translationWspace = Vec3( 0.0 );
-	scaleWspace = 1.0;
-	rotationWspace = Mat3::getIdentity();
 	bvolumeLspace = NULL;
+	getWorldTransform().setIdentity();
+	getLocalTransform().setIdentity();
 
 	DEBUG_ERR( app->getScene() == NULL );
 	app->getScene()->registerNode( this );
@@ -28,7 +24,7 @@ void SceneNode::commonConstructorCode()
 
 
 //=====================================================================================================================================
-// ~SceneNode                                                                                                                            =
+// Destructor                                                                                                                         =
 //=====================================================================================================================================
 SceneNode::~SceneNode()
 {
@@ -44,23 +40,13 @@ void SceneNode::updateWorldTransform()
 {
 	if( parent )
 	{
-		/* the original code:
-		scaleWspace = parent->scaleWspace * scaleLspace;
-		rotationWspace = parent->rotationWspace * rotationLspace;
-		translationWspace = translationLspace.Transformed( parent->translationWspace, parent->rotationWspace, parent->scaleWspace ); */
-		combineTransformations( parent->translationWspace, parent->rotationWspace, parent->scaleWspace,
-		                        translationLspace, rotationLspace, scaleLspace,
-		                        translationWspace, rotationWspace, scaleWspace );
+		worldTransform = Transform::combineTransformations( parent->getWorldTransform(), localTransform );
 	}
 	else // else copy
 	{
-		scaleWspace = scaleLspace;
-		rotationWspace = rotationLspace;
-		translationWspace = translationLspace;
+		worldTransform = localTransform;
 	}
 
-	transformationWspace = Mat4( translationWspace, rotationWspace, scaleWspace );
-
 
 	// transform the bvolume
 	/*if( bvolumeLspace != NULL )
@@ -103,20 +89,20 @@ void SceneNode::updateWorldTransform()
 //=====================================================================================================================================
 void SceneNode::moveLocalX( float distance )
 {
-	Vec3 x_axis = rotationLspace.getColumn(0);
-	translationLspace += x_axis * distance;
+	Vec3 x_axis = localTransform.getRotation().getColumn(0);
+	getLocalTransform().getOrigin() += x_axis * distance;
 }
 
 void SceneNode::moveLocalY( float distance )
 {
-	Vec3 y_axis = rotationLspace.getColumn(1);
-	translationLspace += y_axis * distance;
+	Vec3 y_axis = localTransform.getRotation().getColumn(1);
+	getLocalTransform().getOrigin() += y_axis * distance;
 }
 
 void SceneNode::moveLocalZ( float distance )
 {
-	Vec3 z_axis = rotationLspace.getColumn(2);
-	translationLspace += z_axis * distance;
+	Vec3 z_axis = localTransform.getRotation().getColumn(2);
+	getLocalTransform().getOrigin() += z_axis * distance;
 }
 
 

+ 5 - 6
src/Scene/SceneNode.h

@@ -30,7 +30,7 @@ class SceneNode
 			NT_PARTICLE_EMITTER
 		};
 
-		Vec3  translationLspace;
+		/*Vec3  translationLspace;
 		Mat3  rotationLspace;
 		float scaleLspace;
 
@@ -38,7 +38,7 @@ class SceneNode
 		Mat3  rotationWspace;
 		float scaleWspace;
 
-		Mat4 transformationWspace;
+		Mat4 transformationWspace;*/
 
 		SceneNode* parent;
 		Vec<SceneNode*> childs;
@@ -63,15 +63,14 @@ class SceneNode
 		virtual void deinit() = 0;
 		virtual void updateWorldStuff() { updateWorldTransform(); } ///< This update happens only when the object gets moved. Override it if you want more
 		void updateWorldTransform();
-		void rotateLocalX( float angDegrees ) { rotationLspace.rotateXAxis( angDegrees ); }
-		void rotateLocalY( float angDegrees ) { rotationLspace.rotateYAxis( angDegrees ); }
-		void rotateLocalZ( float angDegrees ) { rotationLspace.rotateZAxis( angDegrees ); }
+		void rotateLocalX( float angDegrees ) { localTransform.getRotation().rotateXAxis( angDegrees ); }
+		void rotateLocalY( float angDegrees ) { localTransform.getRotation().rotateYAxis( angDegrees ); }
+		void rotateLocalZ( float angDegrees ) { localTransform.getRotation().rotateZAxis( angDegrees ); }
 		void moveLocalX( float distance );
 		void moveLocalY( float distance );
 		void moveLocalZ( float distance );
 		void addChild( SceneNode* node );
 		void removeChild( SceneNode* node );
-		void setLocalTransformation( const Vec3& t, const Mat3& r, float s ) { translationLspace=t; rotationLspace=r; scaleLspace=s; }
 };
 
 

+ 1 - 1
src/Scene/SkelNode.cpp

@@ -40,7 +40,7 @@ void SkelNode::deinit()
 void SkelNode::render()
 {
 	glPushMatrix();
-	R::multMatrix( transformationWspace );
+	R::multMatrix( Mat4(getWorldTransform()) );
 
 	//glPointSize( 4.0f );
 	//glLineWidth( 2.0f );