Browse Source

*nothing importand

Panagiotis Christopoulos Charitos 16 years ago
parent
commit
00944e57b0
3 changed files with 56 additions and 17 deletions
  1. 9 10
      src/Main.cpp
  2. 15 7
      src/Physics/MotionState.h
  3. 32 0
      src/Renderer/Dbg.cpp

+ 9 - 10
src/Main.cpp

@@ -36,7 +36,6 @@
 App* app;
 
 // map (hard coded)
-Camera* mainCam;
 MeshNode* floor__,* sarge,* horse,* crate;
 SkelModelNode* imp;
 PointLight* point_lights[10];
@@ -150,7 +149,7 @@ void initPhysics()
 					MeshNode* crate = new MeshNode;
 					crate->init( "models/crate0/crate0.mesh" );
 					crate->scaleLspace = 1.11;
-					MotionState* myMotionState = new MotionState( toAnki( startTransform ), crate);
+					MotionState* myMotionState = new MotionState( startTransform, crate);
 					btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
 					btRigidBody* body = new btRigidBody(rbInfo);
 
@@ -193,10 +192,10 @@ void init()
 	app->scene = new Scene;
 
 	// camera
-	mainCam = new Camera( R::aspectRatio*toRad(60.0), toRad(60.0), 0.5, 200.0 );
-	mainCam->moveLocalY( 3.0 );
-	mainCam->moveLocalZ( 5.7 );
-	mainCam->moveLocalX( -0.3 );
+	app->activeCam = new Camera( R::aspectRatio*toRad(60.0), toRad(60.0), 0.5, 200.0 );
+	app->activeCam->moveLocalY( 3.0 );
+	app->activeCam->moveLocalZ( 5.7 );
+	app->activeCam->moveLocalX( -0.3 );
 
 	// lights
 	point_lights[0] = new PointLight();
@@ -280,9 +279,9 @@ int main( int /*argc*/, char* /*argv*/[] )
 		float scale = 0.01;
 
 		// move the camera
-		static Node* mover = mainCam;
+		static Node* mover = app->activeCam;
 
-		if( I::keys[ SDLK_1 ] ) mover = mainCam;
+		if( I::keys[ SDLK_1 ] ) mover = app->activeCam;
 		if( I::keys[ SDLK_2 ] ) mover = point_lights[0];
 		if( I::keys[ SDLK_3 ] ) mover = spot_lights[0];
 		if( I::keys[ SDLK_4 ] ) mover = point_lights[1];
@@ -313,7 +312,7 @@ int main( int /*argc*/, char* /*argv*/[] )
 		if( I::keys[SDLK_PAGEUP] ) mover->scaleLspace += scale ;
 		if( I::keys[SDLK_PAGEDOWN] ) mover->scaleLspace -= scale ;
 
-		if( I::keys[SDLK_k] ) mainCam->lookAtPoint( point_lights[0]->translationWspace );
+		if( I::keys[SDLK_k] ) app->activeCam->lookAtPoint( point_lights[0]->translationWspace );
 
 		mover->rotationLspace.reorthogonalize();
 
@@ -325,7 +324,7 @@ int main( int /*argc*/, char* /*argv*/[] )
 		dynamicsWorld->stepSimulation( app->timerTick );
 		dynamicsWorld->debugDrawWorld();
 
-		R::render( *mainCam );
+		R::render( *app->activeCam );
 
 		//map.octree.root->bounding_box.render();
 

+ 15 - 7
src/Physics/MotionState.h

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

+ 32 - 0
src/Renderer/Dbg.cpp

@@ -153,6 +153,38 @@ void runStage( const Camera& cam )
 	renderscene(1);
 
 
+	glPushMatrix();
+	R::multMatrix( Mat4( Vec3(5.0, 2.0, 2.0), Mat3::getIdentity(), 1.0 ) );
+	R::Dbg::renderSphere( 1.0, 16 );
+	glPopMatrix();
+
+
+	glMatrixMode( GL_PROJECTION );
+	glPushMatrix();
+	glLoadIdentity();
+	glOrtho( 0, 1, 0, 1, -1, 1 );
+	glMatrixMode( GL_MODELVIEW );
+	glPushMatrix();
+	glLoadIdentity();
+
+
+	Vec4 p = Vec4( Vec3(5.0, 2.0, 2.0), 1.0 );
+	p = app->activeCam->getProjectionMatrix() * (app->activeCam->getViewMatrix() * p);
+	p /= p.w;
+	p = p/2 + 0.5;
+
+	glPointSize( 10 );
+	glBegin( GL_POINTS );
+		R::color3( Vec3(0.0,1.0,0.0) );
+		glVertex3fv( &p[0] );
+	glEnd();
+
+
+
+	glPopMatrix();
+	glMatrixMode( GL_PROJECTION );
+	glPopMatrix();
+
 	// unbind
 	fbo.unbind();
 }