minor cleanup, camera position tests
authorslack <slack@codemaniacs.com>
Fri, 17 Oct 2008 00:21:24 +0000 (02:21 +0200)
committerslack <slack@codemaniacs.com>
Fri, 17 Oct 2008 00:21:24 +0000 (02:21 +0200)
game.cc
gfx.cc
gfx.h
model.cc

diff --git a/game.cc b/game.cc
index 2ee5c432e6b651fdb16a3baafacc5124c4a90e56..0305bbd54cb88c0f2cf0fba9ebb7f083700d64bb 100644 (file)
--- a/game.cc
+++ b/game.cc
@@ -26,7 +26,10 @@ int game_main(int argc, char **argv)
 
        GFX.perspective(75.0f, 16.0f/9.0f, 0.5f, 1000.0f);
 
-       GFX.look_at(0,0,-15, 0,0,0, 0,1,0);
+       ScePspFVector3 camera_pos    = {10,0,-50};
+       ScePspFVector3 camera_center = {-40, 0, 40};
+       ScePspFVector3 camera_up     = {0, 1, 0};
+       GFX.look_at(&camera_pos, &camera_center, &camera_up);
 
        sceGumMatrixMode(GU_MODEL);
        int i=0;
@@ -35,9 +38,9 @@ int game_main(int argc, char **argv)
                GFX.begin_frame();
                i++;
                sceGumLoadIdentity();
-               sceGumRotateX(0.001f*i);
-               sceGumRotateY(0.001f*i);
-               sceGumRotateZ(0.001f*i);
+               //sceGumRotateX(-3.14159f/2.0f);
+               //sceGumRotateY(-3.14159f/2.0f);
+               sceGumRotateZ(-3.14159f/2.0f);
                sceGuColor(GU_COLOR(1.0f,1.0f,1.0f,0.0f));
                GFX.bind_texture(texture);
                sceGumDrawArray(GU_TRIANGLES, cube.vtype | GU_TRANSFORM_3D, 
diff --git a/gfx.cc b/gfx.cc
index 5bcf1bdac6de4b6e1c8600721fdee5cffa9db8ef..a8d9eed098909f3a982da9d9f7f9f0ca364e8e22 100644 (file)
--- a/gfx.cc
+++ b/gfx.cc
@@ -33,25 +33,25 @@ void Gfx::init()
        
        // Set Render States
        // Enable scissor test, depth test, smooth shading and culling
-       sceGuScissor( 0, 0, SCR_WIDTH, SCR_HEIGHT);
-       sceGuEnable( GU_SCISSOR_TEST );
-       sceGuDepthFunc( GU_GEQUAL );
-       sceGuEnable( GU_DEPTH_TEST );
-       sceGuShadeModel( GU_SMOOTH );
-       sceGuFrontFace( GU_CCW );
-       sceGuEnable( GU_CULL_FACE );
-       sceGuEnable( GU_CLIP_PLANES );
+       sceGuScissor(0, 0, SCR_WIDTH, SCR_HEIGHT);
+       sceGuEnable(GU_SCISSOR_TEST);
+       sceGuDepthFunc(GU_GEQUAL);
+       sceGuEnable(GU_DEPTH_TEST);
+       sceGuShadeModel(GU_SMOOTH);
+       sceGuFrontFace(GU_CCW);
+       sceGuEnable(GU_CULL_FACE);
+       sceGuEnable(GU_CLIP_PLANES);
        
        // set clear color/depth
        sceGuClearColor( GU_COLOR( 0.0f, 0.0f, 0.0f, 1.0f ) ); 
        sceGuClearDepth(0);     
 
        // setup texture
-       sceGuEnable(GU_TEXTURE_2D);                     //Enable Texture2D
-       sceGuTexFunc( GU_TFX_MODULATE, GU_TCC_RGB );
-       sceGuTexFilter( GU_LINEAR, GU_LINEAR );         // Linear filtering (Good Quality) (NEW)
-       sceGuTexScale( 1.0f, 1.0f );                    // No scaling
-       sceGuTexOffset( 0.0f, 0.0f );
+       sceGuEnable(GU_TEXTURE_2D);                         //Enable Texture2D
+       sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGB);
+       sceGuTexFilter(GU_LINEAR, GU_LINEAR);           // Linear filtering
+       sceGuTexScale(1.0f, 1.0f);                  // No scaling
+       sceGuTexOffset(0.0f, 0.0f);
 
        sceGuFinish();
        sceGuSync(0,0);
@@ -61,7 +61,7 @@ void Gfx::init()
        // finish
 
        // init fps counter
-       sceRtcGetCurrentTick( &fps_tick_last );
+       sceRtcGetCurrentTick(&fps_tick_last);
        tick_resolution = sceRtcGetTickResolution();
 }
 
@@ -74,18 +74,18 @@ void Gfx::cleanup()
 void Gfx::update_fps( void )
 {
        frames_drawn++;
-       sceRtcGetCurrentTick( &fps_tick_now );
+       sceRtcGetCurrentTick(&fps_tick_now);
 
        if( ((fps_tick_now - fps_tick_last)/((float)tick_resolution)) >= 1.0f )
        {
                fps_tick_last = fps_tick_now;
                //sprintf( fps_display, "ticks=%f, FPS: %d", ((double)fps_tick_now/(double)tick_resolution), frames_drawn );
-               sprintf( fps_display, "FPS: %d", frames_drawn );
+               sprintf(fps_display, "FPS: %d", frames_drawn);
                frames_drawn = 0;
        }
-       pspDebugScreenSetOffset( (int)fbp0 );
-       pspDebugScreenSetXY( 0, 0 );
-       pspDebugScreenPrintf( fps_display );
+       pspDebugScreenSetOffset((int)fbp0);
+       pspDebugScreenSetXY(0, 0);
+       pspDebugScreenPrintf(fps_display);
 
 }
 
@@ -117,6 +117,13 @@ void Gfx::perspective(float fov, float aspect, float znear, float zfar)
        sceGumPerspective(fov, aspect, znear, zfar);
 }
 
+void Gfx::look_at(ScePspFVector3 *eye, ScePspFVector3 *center, ScePspFVector3 *up)
+{
+       sceGumMatrixMode(GU_VIEW);
+       sceGumLoadIdentity();
+       sceGumLookAt(eye, center, up);
+}
+
 void Gfx::look_at(float eye_x, float eye_y, float eye_z,
                        float center_x, float center_y, float center_z,
                        float up_x, float up_y, float up_z)
@@ -134,3 +141,5 @@ void Gfx::bind_texture(const Texture& t)
        sceGuTexMode(t.mode, 0, 0, t.swizzled? 1: 0);
        sceGuTexImage(0, t.width, t.height, t.width, t.pixels); 
 }
+
+
diff --git a/gfx.h b/gfx.h
index e13ace865944f936857cb2fd3f9da0faaf2dce15..175f410dd45c7cefdf7667b4c5db1fe562087175 100644 (file)
--- a/gfx.h
+++ b/gfx.h
@@ -34,6 +34,7 @@ class Gfx: public Singleton<Gfx>
        void look_at(float eye_x, float eye_y, float eye_z,
                        float center_x, float center_y, float center_z,
                        float up_x, float up_y, float up_z);
+       void look_at(ScePspFVector3 *eye, ScePspFVector3 *center, ScePspFVector3 *up);
 
        // Texture
        void bind_texture(const Texture& t);
index eefc8431e84ed83830de2d34f0a9e295f761d7fb..fcf254f707a8d5c0b5a81e07ff13450abb16bab4 100644 (file)
--- a/model.cc
+++ b/model.cc
@@ -19,22 +19,22 @@ struct ModelHeader
 size_t Model::vertex_size()
 {
        size_t result=0;
-       if ((vtype & GU_TEXTURE_BITS) == GU_TEXTURE_8BIT) { printf("GU_TEXTURE_8BIT\n"); result += 2; }
-       else if ((vtype & GU_TEXTURE_BITS) == GU_TEXTURE_16BIT) { printf("GU_TEXTURE_16BIT\n"); result +=4; }
-       else if ((vtype & GU_TEXTURE_BITS) == GU_TEXTURE_32BITF) { printf("GU_TEXTURE_32BITF\n"); result += 8; }
+       if ((vtype & GU_TEXTURE_BITS) == GU_TEXTURE_8BIT)        { result += 2; }
+       else if ((vtype & GU_TEXTURE_BITS) == GU_TEXTURE_16BIT)  { result += 4; }
+       else if ((vtype & GU_TEXTURE_BITS) == GU_TEXTURE_32BITF) { result += 8; }
 
-       if ((vtype & GU_COLOR_BITS) == GU_COLOR_5650) { printf("GU_COLOR_5650\n"); result += 2; }
-       else if ((vtype & GU_COLOR_BITS) == GU_COLOR_5551) { printf("GU_COLOR_5551\n"); result += 2; }
-       else if ((vtype & GU_COLOR_BITS) == GU_COLOR_4444) { printf("GU_COLOR_4444\n"); result += 2; }
-       else if ((vtype & GU_COLOR_BITS) == GU_COLOR_8888) { printf("GU_COLOR_8888\n"); result += 4; }
+       if ((vtype & GU_COLOR_BITS) == GU_COLOR_5650)      { result += 2; }
+       else if ((vtype & GU_COLOR_BITS) == GU_COLOR_5551) { result += 2; }
+       else if ((vtype & GU_COLOR_BITS) == GU_COLOR_4444) { result += 2; }
+       else if ((vtype & GU_COLOR_BITS) == GU_COLOR_8888) { result += 4; }
 
-       if ((vtype & GU_NORMAL_BITS) == GU_NORMAL_8BIT) { printf("GU_NORMAL_8BIT\n"); result += 3; }
-       else if ((vtype & GU_NORMAL_BITS) == GU_NORMAL_16BIT) { printf("GU_NORMAL_16BIT\n"); result += 6; }
-       else if ((vtype & GU_NORMAL_BITS) == GU_NORMAL_32BITF) { printf("GU_NORMAL_32BITF\n"); result += 12; }
+       if ((vtype & GU_NORMAL_BITS) == GU_NORMAL_8BIT)        { result += 3; }
+       else if ((vtype & GU_NORMAL_BITS) == GU_NORMAL_16BIT)  { result += 6; }
+       else if ((vtype & GU_NORMAL_BITS) == GU_NORMAL_32BITF) { result += 12; }
 
-       if ((vtype & GU_VERTEX_BITS) == GU_VERTEX_8BIT) { printf("GU_VERTEX_8BIT\n"); result += 3; }
-       else if ((vtype & GU_VERTEX_BITS) == GU_VERTEX_16BIT) { printf("GU_VERTEX_16BIT\n"); result += 6; }
-       else if ((vtype & GU_VERTEX_BITS) == GU_VERTEX_32BITF) { printf("GU_VERTEX_32BITF\n"); result += 12; }
+       if ((vtype & GU_VERTEX_BITS) == GU_VERTEX_8BIT)        { result += 3; }
+       else if ((vtype & GU_VERTEX_BITS) == GU_VERTEX_16BIT)  { result += 6; }
+       else if ((vtype & GU_VERTEX_BITS) == GU_VERTEX_32BITF) { result += 12; }
 
        return result;
 }