main.c

00001 #include "vlib.h"
00002 
00003 PSP_MODULE_INFO ( "Test vLib", 0, 1, 1 );
00004 PSP_MAIN_THREAD_ATTR ( THREAD_ATTR_USER | THREAD_ATTR_VFPU );
00005 
00006 const int TIMES = 500;
00007 
00008 int main() {
00009   // Overclock the psp to 333mhz
00010   scePowerSetClockFrequency ( 333, 333, 166 );
00011 
00012   start_vLib(); // Init vLib. The RGB is the clear color.
00013   set_linear_filter ( ON ); // Turn the linear filter on.
00014 
00015   set_fog ( 10, 20, RGB ( 0, 0, 0 ) ); // Setup the fog.
00016 
00017   // Load an image
00018   Image *texture = load_image ( "data/texture.png", IN_VRAM );
00019   // Load a model
00020   Model *model = load_model ( "data/model.obj" );
00021 
00022   // Variables for our camera
00023   float xCamPos = 0.0f;
00024   float yCamPos = 0.0f;
00025   float zCamPos = 0.0f;
00026 
00027   float xCamRot = 3.4f;
00028   float yCamRot = 0.0f;
00029   float zoomCam = -2.0f;
00030 
00031   float tempx, tempz, padDist, rotCurrent; // Some variables for out analog controls.
00032 
00033   float camRate;
00034 
00035   texture->height = 50.0f;
00036   texture->width = 50.0f;
00037 
00038   for ( ;; ) {
00039     update_delta_time();
00040 
00042     // Input Section //
00044     read_input ( MASK_NONE, 0, 0 );
00045 
00046     if ( button->pressed.start )
00047       sceKernelExitGame(); // Exit when start is pressed
00048 
00049     // Movement
00050     if ( button->analogY <= -40 || button->analogY >= 40 || button->analogX <= -40 || button->analogX >= 40 ) {
00051       //get analog angle. pad.Ly is negative when you move up, use opposite
00052       rotCurrent = atan2f ( button->analogY, button->analogX );
00053       //need this to have symmetrical pad angles (since cam's 0 angle is down)
00054       if ( rotCurrent < -PI / 2 ) rotCurrent += 2 * PI;
00055       //modifies movement according to current cam angle and pad angle
00056       tempx = vfpu_cosf ( yCamRot + rotCurrent );
00057       tempz = vfpu_sinf ( yCamRot + rotCurrent );
00058 
00059       padDist = sqrtf ( button->analogX * button->analogX + button->analogY * button->analogY );
00060       if ( padDist > 128 ) padDist = 128;
00061 
00062       xCamPos += tempx * padDist * 0.05f * deltaTime;
00063       zCamPos += tempz * padDist * 0.05f * deltaTime;
00064     }
00065 
00066     camRate = 3.0f * deltaTime;
00067     // Adjust camera position
00068     if ( button->held.up && zoomCam < -2.1f )
00069       zoomCam += camRate; // In
00070     if ( button->held.down && zoomCam > -4.8f )
00071       zoomCam -= camRate; // Out
00072     if ( button->held.R )
00073       yCamRot += camRate; // Right
00074     if ( button->held.L )
00075       yCamRot -= camRate; // Left
00076 
00077     if ( button->held.up )
00078       texture->y -= 300.0f * deltaTime;
00079     if ( button->held.down )
00080       texture->y += 300.0f * deltaTime;
00081     if ( button->held.left )
00082       texture->x -= 300.0f * deltaTime;
00083     if ( button->held.right )
00084       texture->x += 300.0f * deltaTime;
00085 
00086     if ( button->held.cross )
00087       texture->height -= 300.0f * deltaTime;
00088     if ( button->held.triangle )
00089       texture->height += 300.0f * deltaTime;
00090     if ( button->held.square )
00091       texture->width -= 300.0f * deltaTime;
00092     if ( button->held.circle )
00093       texture->width += 300.0f * deltaTime;
00094 
00095     if ( button->held.R )
00096       texture->angle += 3.0f * deltaTime; // Right
00097     if ( button->held.L )
00098       texture->angle -= 3.0f * deltaTime; // Left
00099 
00101     // Setup //
00103 
00104     // Start the drawing routine
00105     start_drawing();
00106     // Clear the screen
00107     clear_screen();
00108 
00110     // Drawing //
00112 
00113     // Set our camera
00114     set_camera_3rd_person(xCamPos,yCamPos,zCamPos, xCamRot,yCamRot, zoomCam);
00115     // Draw model
00116     draw_model(model, texture);
00117 
00118     // Draw image
00119     texture->centerX = -(texture->width/2);
00120     texture->centerY = -(texture->height/2);
00121     
00122     draw_image ( texture );
00123 
00125     // Finish Up //
00127 
00128     // End the drawing routine
00129     end_drawing();
00130     // Display the current statistics
00131     fps();
00132     // Flip the screen
00133     flip_screen();
00134   }
00135 
00136   stop_vLib(); // Unit vLib
00137   sceKernelExitGame(); // Exit
00138   return 0; // Return 0 on success! (won't happen though, we just exited!)
00139 }

Generated on Tue Mar 20 23:01:06 2007 for vLib by  doxygen 1.4.7