From: slack Date: Fri, 17 Oct 2008 00:21:24 +0000 (+0200) Subject: minor cleanup, camera position tests X-Git-Url: http://slack.codemaniacs.com/git/?a=commitdiff_plain;h=6098914ae14e186fc5650ea9dfb23a7bf51e1254;p=laz0r.git minor cleanup, camera position tests --- diff --git a/game.cc b/game.cc index 2ee5c43..0305bbd 100644 --- 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 5bcf1bd..a8d9eed 100644 --- 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 e13ace8..175f410 100644 --- a/gfx.h +++ b/gfx.h @@ -34,6 +34,7 @@ class Gfx: public Singleton 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); diff --git a/model.cc b/model.cc index eefc843..fcf254f 100644 --- 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; }