int main(int argc, char **argv) { /* Controller Stuff */ maple_device_t * dev; cont_state_t * state; int rquad = 0; int rtri = 0; /* Init PVR API */ if (pvr_init(¶ms) < 0) return -1; printControls(); /* Sets the background color to black */ pvr_set_bg_color(0.0f,0.0f,0.0f); plx_cxt_init(); // Initialize the plx context system plx_cxt_texture(NULL); // No texture will be used plx_cxt_culling(PLX_CULL_NONE); // No culling // GET SOME 3D GOING!! /* Init matrices */ plx_mat3d_init(); /* Clear internal to an identity matrix */ plx_mat3d_mode(PLX_MAT_PROJECTION); /** Projection (frustum, screenview) matrix */ plx_mat3d_identity(); /** Load an identity matrix */ plx_mat3d_perspective(45.0f, 640.0f / 480.0f, 0.1f, 100.0f); // (float angle, float aspect, float znear, float zfar); plx_mat3d_mode(PLX_MAT_MODELVIEW); /** Modelview (rotate, scale) matrix */ while(1) { // Check for the user pressing START dev = maple_enum_dev(0, 0); if(dev == NULL) { printf("Error: Could not find controller in first port.\n"); break; } state = (cont_state_t *)maple_dev_status(dev); if (state->buttons & CONT_START) { break; // exit the program } pvr_wait_ready(); pvr_scene_begin(); pvr_list_begin(PVR_LIST_OP_POLY); // Submit the context plx_cxt_send(PVR_LIST_OP_POLY); // Submit the Header for PVR_LIST_OP_POLY // DRAW THE PYRAMID plx_mat3d_identity(); plx_mat3d_translate(-1.5f, 0.0f, -6.0f); // Move 1.5f units to the left and 6 units into the screen plx_mat3d_rotate(rtri, 0.0f, 1.0f, 0.0f); // Rotate the pyramid angle 'rtri' on the Y axis /* Clear internal to an identity matrix */ plx_mat_identity(); /* "Applying" all matrixs: multiply a matrix onto the "internal" one */ plx_mat3d_apply_all(); // Front Face of Pyramid plx_vert_inpm3(PLX_VERT, 0, 1, 0, plx_pack_color(1.0f, 1.0f, 0.0f, 0.0f)); // Red: Top Of Triangle (Front) plx_vert_inpm3(PLX_VERT, -1, -1, 1, plx_pack_color(1.0f, 0.0f, 1.0f, 0.0f)); // Green: Left Of Triangle (Front) plx_vert_inpm3(PLX_VERT_EOS, 1, -1, 1, plx_pack_color(1.0f, 0.0f, 0.0f, 1.0f)); // Blue: Right Of Triangle (Front) // Right Face of Pyramid plx_vert_inpm3(PLX_VERT, 0, 1, 0, plx_pack_color(1.0f, 1.0f, 0.0f, 0.0f)); // Red: Top Of Triangle (Right) plx_vert_inpm3(PLX_VERT, 1, -1, 1, plx_pack_color(1.0f, 0.0f, 0.0f, 1.0f)); // Blue: Left Of Triangle (Right) plx_vert_inpm3(PLX_VERT_EOS, 1, -1, -1, plx_pack_color(1.0f, 0.0f, 1.0f, 0.0f)); // Green: Right Of Triangle (Right) // Back Face of Pyramid plx_vert_inpm3(PLX_VERT, 0, 1, 0, plx_pack_color(1.0f, 1.0f, 0.0f, 0.0f)); // Red: Top Of Triangle (Back) plx_vert_inpm3(PLX_VERT, 1, -1, -1, plx_pack_color(1.0f, 0.0f, 1.0f, 0.0f)); // Green: Left Of Triangle (Back) plx_vert_inpm3(PLX_VERT_EOS, -1, -1, -1, plx_pack_color(1.0f, 0.0f, 0.0f, 1.0f));// Blue: Right Of Triangle (Back) // Left Face of Pyramid plx_vert_inpm3(PLX_VERT, 0, 1, 0, plx_pack_color(1.0f, 1.0f, 0.0f, 0.0f)); // Red: Top Of Triangle (Left) plx_vert_inpm3(PLX_VERT, -1, -1, -1, plx_pack_color(1.0f, 0.0f, 0.0f, 1.0f)); // Blue: Left Of Triangle (Left) plx_vert_inpm3(PLX_VERT_EOS, -1, -1, 1, plx_pack_color(1.0f, 0.0f, 1.0f, 0.0f)); // Green: Right Of Triangle (Left) // DRAW THE BOX plx_mat3d_identity(); plx_mat3d_translate(1.5f, 0.0f, -6.0f); // Move 1.5f units to the right and 6 units into the screen plx_mat3d_rotate(rquad, 1.0f, 0.0f, 0.0f); // Rotate the box angle 'rquad' on the X axis /* Clear internal to an identity matrix */ plx_mat_identity(); /* "Applying" all matrixs: multiply a matrix onto the "internal" one */ plx_mat3d_apply_all(); // Top Face of Box (GREEN) plx_vert_inpm3(PLX_VERT, -1, 1, 1, plx_pack_color(1.0f, 0.0f, 1.0f, 0.0f)); // Bottom Left Of The Quad (Top) plx_vert_inpm3(PLX_VERT, -1, 1, -1, plx_pack_color(1.0f, 0.0f, 1.0f, 0.0f)); // Top Left Of The Quad (Top) plx_vert_inpm3(PLX_VERT, 1, 1, 1, plx_pack_color(1.0f, 0.0f, 1.0f, 0.0f)); // Bottom Right Of The Quad (Top) plx_vert_inpm3(PLX_VERT_EOS, 1, 1, -1, plx_pack_color(1.0f, 0.0f, 1.0f, 0.0f)); // Top Right Of The Quad (Top) // Bottom Face of Box (ORANGE) plx_vert_inpm3(PLX_VERT, -1, -1, -1, plx_pack_color(1.0f, 1.0f, 0.5f, 0.0f)); // Bottom Left Of The Quad (Bottom) plx_vert_inpm3(PLX_VERT, -1, -1, 1, plx_pack_color(1.0f, 1.0f, 0.5f, 0.0f)); // Top Left Of The Quad (Bottom) plx_vert_inpm3(PLX_VERT, 1, -1, -1, plx_pack_color(1.0f, 1.0f, 0.5f, 0.0f)); // Bottom Right Of The Quad (Bottom) plx_vert_inpm3(PLX_VERT_EOS, 1, -1, 1, plx_pack_color(1.0f, 1.0f, 0.5f, 0.0f)); // Top Right Of The Quad (Bottom) // Front Face of Box (RED) plx_vert_inpm3(PLX_VERT, -1, -1, 1, plx_pack_color(1.0f, 1.0f, 0.0f, 0.0f)); // Bottom Left Of The Quad (Front) plx_vert_inpm3(PLX_VERT, -1, 1, 1, plx_pack_color(1.0f, 1.0f, 0.0f, 0.0f)); // Top Left Of The Quad (Front) plx_vert_inpm3(PLX_VERT, 1, -1, 1, plx_pack_color(1.0f, 1.0f, 0.0f, 0.0f)); // Bottom Right Of The Quad (Front) plx_vert_inpm3(PLX_VERT_EOS, 1, 1, 1, plx_pack_color(1.0f, 1.0f, 0.0f, 0.0f)); // Top Right Of The Quad (Front) // Back Face of Box (YELLOW) plx_vert_inpm3(PLX_VERT, -1, 1, -1, plx_pack_color(1.0f, 1.0f, 1.0f, 0.0f)); // Bottom Left Of The Quad (Back) plx_vert_inpm3(PLX_VERT, -1, -1, -1, plx_pack_color(1.0f, 1.0f, 1.0f, 0.0f)); // Top Left Of The Quad (Back) plx_vert_inpm3(PLX_VERT, 1, 1, -1, plx_pack_color(1.0f, 1.0f, 1.0f, 0.0f)); // Bottom Right Of The Quad (Back) plx_vert_inpm3(PLX_VERT_EOS, 1, -1, -1, plx_pack_color(1.0f, 1.0f, 1.0f, 0.0f));// Top Right Of The Quad (Back) // Left Face of Box (BLUE) plx_vert_inpm3(PLX_VERT, -1, -1, -1, plx_pack_color(1.0f, 0.0f, 0.0f, 1.0f)); // Bottom Left Of The Quad (Left) plx_vert_inpm3(PLX_VERT, -1, 1, -1, plx_pack_color(1.0f, 0.0f, 0.0f, 1.0f)); // Top Left Of The Quad (Left) plx_vert_inpm3(PLX_VERT, -1, -1, 1, plx_pack_color(1.0f, 0.0f, 0.0f, 1.0f)); // Bottom Right Of The Quad (Left) plx_vert_inpm3(PLX_VERT_EOS, -1, 1, 1, plx_pack_color(1.0f, 0.0f, 0.0f, 1.0f)); // Top Right Of The Quad (Left) // Right Face of Box (VIOLET) plx_vert_inpm3(PLX_VERT, 1, -1, 1, plx_pack_color(1.0f, 1.0f, 0.0f, 1.0f)); // Bottom Left Of The Quad (Right) plx_vert_inpm3(PLX_VERT, 1, 1, 1, plx_pack_color(1.0f, 1.0f, 0.0f, 1.0f)); // Top Left Of The Quad (Right) plx_vert_inpm3(PLX_VERT, 1, -1, -1, plx_pack_color(1.0f, 1.0f, 0.0f, 1.0f)); // Bottom Right Of The Quad (Right) plx_vert_inpm3(PLX_VERT_EOS, 1, 1, -1, plx_pack_color(1.0f, 1.0f, 0.0f, 1.0f)); // Top Right Of The Quad (Right) pvr_scene_finish(); rquad -= 2.0f; // Increases the box's rotation angle rtri += 2.0f; // Increases the pyramid's rotation angle } return 0; }
int main(int argc, char **argv) { /* Controller Stuff */ maple_device_t * dev; cont_state_t * state; Model *pModel = NULL; // Holds The Model Data float yrot = 0.0f; // Y Rotation /* vector_t defined in C:\cygwin\usr\local\dc\kos\kos\addons\include\kos\vector.h */ /* Holds 3 floats */ vector_t eye = {75.0f, 75.0f, 75.0f}; vector_t center = {0.0f, 0.0f, 0.0f}; vector_t up = {0.0f, 1.0f, 0.0f}; /* Init PVR API */ if (pvr_init(¶ms) < 0) return -1; printControls(); /* Sets the background color to black */ pvr_set_bg_color(0.0f, 0.0f, 0.0f); /* Load the model */ pModel = new MilkshapeModel(); if ( pModel->loadModelData( "/rd/model.ms3d" ) == false ) // Loads The Model And Checks For Errors { printf("Couldn't load the model data /rd/model.ms3d \n"); return 0; // If Model Didn't Load Quit } // GET SOME 3D GOING!! plx_mat3d_init(); /* Clear internal to an identity matrix */ plx_mat3d_mode(PLX_MAT_PROJECTION); /** Projection (frustum, screenview) matrix */ plx_mat3d_identity(); /** Load an identity matrix */ plx_mat3d_perspective(45.0f, 640.0f / 480.0f, 0.1f, 1000.0f); // (float angle, float aspect, float znear, float zfar); plx_mat3d_mode(PLX_MAT_MODELVIEW); /** Modelview (rotate, scale) matrix */ pModel->reloadTextures(); // Loads Model Textures while(1) { /* Check key status */ dev = maple_enum_dev(0, 0); if(dev == NULL) { printf("Error: Could not find controller in first port.\n"); break; } state = (cont_state_t *)maple_dev_status(dev); if (state->buttons & CONT_START) { break; // exit the program } pvr_wait_ready(); pvr_scene_begin(); pvr_list_begin(PVR_LIST_OP_POLY); plx_mat3d_identity(); plx_mat3d_lookat(&eye,¢er,&up); /* Do a camera "look at" */ plx_mat3d_rotate(yrot, 0.0f, 1.0f, 0.0f); /* Rotate the model by 'yrot' degrees on the Y-Axis */ /* Clear internal to an identity matrix */ plx_mat_identity(); /* "Apply" all matrices */ plx_mat3d_apply_all(); /* Draw the Model */ pModel->draw(); pvr_scene_finish(); yrot += 1.0f; // Increase the 'yrot' angle } // Clean Up!!! pModel->destroyModel(); return 0; }
int main() { std::string nebulaResponse; std::cout << "Start with nebula? [y/N] "; std::getline(std::cin,nebulaResponse); bool makeNebula = (!nebulaResponse.empty() && std::tolower(nebulaResponse[0]) == 'y'); std::cout << std::endl; printControls(); Perlin perlin{(int)PERLIN_WIDTH,(int)PERLIN_HEIGHT}; PlanetSystem system; sf::RenderWindow window(sf::VideoMode(INITIAL_WIDTH,INITIAL_HEIGHT),"Gravity"); Planet planetToAdd(START_MASS,Vec2f::ZERO,Vec2f::ZERO); planetToAdd.drawUnfilled = true; sf::VertexArray velLine; velLine.resize(2); velLine.setPrimitiveType(sf::Lines); velLine[0].color = velLine[1].color = sf::Color::Blue; sf::VertexArray velLineTmp; velLineTmp.resize(2); velLineTmp.setPrimitiveType(sf::Lines); velLineTmp[0].color = velLineTmp[1].color = sf::Color::Blue; sf::View camera(sf::FloatRect(0,0,INITIAL_WIDTH,INITIAL_HEIGHT)); sf::Vector2f prevMouseLoc; bool movingCamera = false; bool running = true; system.setDrawingTrails(true); if(makeNebula) { for(int x=0;x<20;x++) { for(int y=0;y<20;y++) { Vec2f loc = {{(float)(x/20.0*INITIAL_WIDTH), (float)(y/20.0*INITIAL_HEIGHT)}}; Vec2f perlinLoc = {{loc[0]/(float)INITIAL_WIDTH*PERLIN_WIDTH, loc[1]/(float)INITIAL_HEIGHT*PERLIN_HEIGHT}}; double noise = perlin.octaveNoise(perlinLoc[0],perlinLoc[1]); Planet p{(float)(40+noise*60),loc,randomVec(40)}; system.addPlanet(p); } } } window.setFramerateLimit(FPS); while(window.isOpen()) { //std::cout << "tick\n"; sf::Event event; while(window.pollEvent(event)) { switch(event.type) { case sf::Event::Closed: window.close(); break; case sf::Event::Resized: camera.setSize(event.size.width,event.size.height); break; case sf::Event::MouseWheelMoved: { float newRadius = planetToAdd.radius()+event.mouseWheel.delta; planetToAdd.mass = std::min(MAX_MASS,std::exp(newRadius)); } break; case sf::Event::MouseButtonPressed: if(event.mouseButton.button == sf::Mouse::Middle) { system.clear(); } break; case sf::Event::MouseButtonReleased: if(event.mouseButton.button == sf::Mouse::Left) { system.addPlanet(planetToAdd); } case sf::Event::KeyPressed: if(event.key.code == sf::Keyboard::Space) { system.setDrawingTrails(!system.drawingTrails()); } else if(event.key.code == sf::Keyboard::P) { running = !running; } default: break; } } if(sf::Mouse::isButtonPressed(sf::Mouse::Right)) { sf::Vector2f mouseLoc = sf::Vector2f(sf::Mouse::getPosition(window)); if(!movingCamera) { movingCamera = true; } else { camera.move(prevMouseLoc-mouseLoc); } prevMouseLoc = mouseLoc; } else { movingCamera = false; } sf::Vector2f worldOffset = camera.getCenter()-camera.getSize()/2.0f; bool drawVelLine = false; if(!sf::Mouse::isButtonPressed(sf::Mouse::Left)) { sf::Vector2i mouseLoc = sf::Mouse::getPosition(window); planetToAdd.loc[0] = worldOffset.x+mouseLoc.x; planetToAdd.loc[1] = worldOffset.y+mouseLoc.y; velLine[0].position = worldOffset+sf::Vector2f(mouseLoc); } else { drawVelLine = true; velLine[1].position = worldOffset +sf::Vector2f(sf::Mouse::getPosition(window)); planetToAdd.vel[0] = velLine[1].position.x - velLine[0].position.x; planetToAdd.vel[1] = velLine[1].position.y - velLine[0].position.y; planetToAdd.vel *= VEL_SCALAR; } if(running) { system.tick(DT); } window.clear(sf::Color::Black); window.setView(camera); window.draw(system); window.draw(planetToAdd); if(drawVelLine) { window.draw(velLine); } if(!running) { for(auto& planet:system._planets) { makeVelLine(planet,velLineTmp); window.draw(velLineTmp); } } window.display(); } }
int main(int argc, char **argv) { /* Controller Stuff */ maple_device_t * dev; cont_state_t * state; int x, y; float xrot = 0; /* X Rotation */ float yrot = 0; /* Y Rotation */ float zrot = 0; /* Z Rotation */ float points[45][45][3]; // The Array For The Points On The Grid Of Our "Wave" int wiggle_count = 0; // Counter Used To Control How Fast Flag Waves float hold; // Temporarily Holds A Floating Point Value uint32 color = plx_pack_color(1.0f, 1.0f, 1.0f, 1.0f); // Pure white color. Used for images to keep original color plx_texture_t *a_texture; // Storage for 1 texture float float_x, float_y, float_xb, float_yb; // loop counters. /* Init PVR API */ if (pvr_init(¶ms) < 0) return -1; printControls(); /* Sets the background color to blue */ pvr_set_bg_color(0.0f, 0.0f, 1.0f); /* Load the texture */ a_texture = plx_txr_load("/rd/tim.png", 0, PVR_TXRLOAD_16BPP); plx_cxt_init(); // Initialize the plx context system plx_cxt_texture(a_texture); // Texture 'a_texture' will be used with the context system plx_cxt_culling(PLX_CULL_NONE); // No culling // GET SOME 3D GOING!! plx_mat3d_init(); /* Clear internal to an identity matrix */ plx_mat3d_mode(PLX_MAT_PROJECTION); /** Projection (frustum, screenview) matrix */ plx_mat3d_identity(); /** Load an identity matrix */ plx_mat3d_perspective(45.0f, 640.0f / 480.0f, 0.1f, 100.0f); // (float angle, float aspect, float znear, float zfar); plx_mat3d_mode(PLX_MAT_MODELVIEW); /** Modelview (rotate, scale) matrix */ for(float_x = 0.0f; float_x < 9.0f; float_x += 0.2f ) { for(float_y = 0.0f; float_y < 9.0f; float_y += 0.2f) { points[ (int) (float_x*5) ][ (int) (float_y*5) ][0] = float_x - 4.4f; points[ (int) (float_x*5) ][ (int) (float_y*5) ][1] = float_y - 4.4f; points[ (int) (float_x*5) ][ (int) (float_y*5) ][2] = (float) (fsin( ( (float_x*5*8)/360 ) * 3.14159 * 2)); } } while(1) { // Check for the user pressing START dev = maple_enum_dev(0, 0); if(dev == NULL) { printf("Error: Could not find controller in first port.\n"); break; } state = (cont_state_t *)maple_dev_status(dev); if (state->buttons & CONT_START) { break; // exit the program } pvr_wait_ready(); pvr_scene_begin(); pvr_list_begin(PVR_LIST_OP_POLY); // Submit the context plx_cxt_send(PVR_LIST_OP_POLY); // Submit the Header for PVR_LIST_OP_POLY // DRAW THE BOX plx_mat3d_identity(); plx_mat3d_translate(0.0f, 0.0f, -12.0f); // Move 12 units into the screen plx_mat3d_rotate(xrot, 1.0f, 0.0f, 0.0f); // Rotate the Wavy texture angle 'xrot' on the X axis plx_mat3d_rotate(yrot, 0.0f, 1.0f, 0.0f); // Rotate the Wavy texture angle 'yrot' on the Y axis plx_mat3d_rotate(zrot, 0.0f, 0.0f, 1.0f); // Rotate the Wavy texture angle 'zrot' on the Z axis /* Clear internal to an identity matrix */ plx_mat_identity(); /* "Applying" all matrixs: multiply a matrix onto the "internal" one */ plx_mat3d_apply_all(); // Draw each section of the image for (x = 0; x < 44; x++) { for (y = 0; y < 44; y++) { float_x = (float) (x)/44; float_y = (float) (y)/44; float_xb = (float) (x+1)/44; float_yb = (float) (y+1)/44; plx_vert_ifpm3(PLX_VERT, points[x][y+1][0], points[x][y+1][1], points[x][y+1][2], color, float_x, float_yb); plx_vert_ifpm3(PLX_VERT, points[x][y][0], points[x][y][1], points[x][y][2], color, float_x, float_y); plx_vert_ifpm3(PLX_VERT, points[x+1][y+1][0], points[x+1][y+1][1], points[x+1][y+1][2], color, float_xb, float_yb); plx_vert_ifpm3(PLX_VERT_EOS, points[x+1][y][0], points[x+1][y][1], points[x+1][y][2], color, float_xb, float_y); } } pvr_scene_finish(); if (wiggle_count == 2) { // Used To Slow Down The Wave (Every 2nd Frame Only) for( y = 0; y < 45; y++ ) // Loop Through The Y Plane { hold = points[0][y][2]; // Store Current Value One Left Side Of Wave for( x = 0; x < 44; x++) // Loop Through The X Plane { // Current Wave Value Equals Value To The Right points[x][y][2] = points[x+1][y][2]; } points[44][y][2] = hold; // Last Value Becomes The Far Left Stored Value } wiggle_count = 0; // Set Counter Back To Zero } wiggle_count++; // Increase The Counter xrot += 0.3f; // Increase the Wavy Texture's angle(x-axis) rotation yrot += 0.2f; // Increase the Wavy Texture's angle(y-axis) rotation zrot += 0.4f; // Increase the Wavy Texture's angle(z-axis) rotation } // Clean up!!! plx_txr_destroy(a_texture); return 0; }
int main(int argc, char **argv) { /* Controller Stuff */ maple_device_t * dev; cont_state_t * state; int xp = 0; // False (True or False: Pressed X button last) Toggles Filtering int yp = 0; // False (True or False: Pressed Y button last) Toggles Transparency int blend = 0; // blending on/off float x_m, y_m, z_m, u_m, v_m; float xtrans, ztrans, ytrans; float sceneroty; int numtriangles; int filter = 0; // texture filtering method to use (NONE or BILINEAR) uint32 color = plx_pack_color(0.5f, 1.0f, 1.0f, 1.0f); /* Init PVR API */ if (pvr_init(¶ms) < 0) return -1; printControls(); /* Sets the background color to black */ pvr_set_bg_color(0.0f, 0.0f, 0.0f); /* load our world from romdisk */ SetupWorld(); /* Load the textures */ textures[0] = plx_txr_load("/rd/mud.png", 0, PVR_TXRLOAD_16BPP | PVR_TXRLOAD_INVERT_Y); textures[1] = plx_txr_load("/rd/mud.png", 0, PVR_TXRLOAD_16BPP | PVR_TXRLOAD_INVERT_Y); plx_cxt_init(); // Initialize the plx context system plx_cxt_culling(PLX_CULL_NONE); // No culling // GET SOME 3D GOING!! plx_mat3d_init(); /* Clear internal to an identity matrix */ plx_mat3d_mode(PLX_MAT_PROJECTION); /** Projection (frustum, screenview) matrix */ plx_mat3d_identity(); /** Load an identity matrix */ plx_mat3d_perspective(45.0f, 640.0f / 480.0f, 0.1f, 100.0f); // (float angle, float aspect, float znear, float zfar); plx_mat3d_mode(PLX_MAT_MODELVIEW); /** Modelview (rotate, scale) matrix */ /* Set the filters for each texture */ plx_txr_setfilter(textures[0], PLX_FILTER_NONE); plx_txr_setfilter(textures[1], PLX_FILTER_BILINEAR); while(1) { /* Check key status */ dev = maple_enum_dev(0, 0); if(dev == NULL) { printf("Error: Could not find controller in first port.\n"); break; } state = (cont_state_t *)maple_dev_status(dev); if (state->buttons & CONT_START) { break; // exit the program } if (state->buttons & CONT_X && !xp) { xp = 1; filter += 1; // Toggle Filter if (filter > 1) filter = 0; } if (!(state->buttons & CONT_X)) { xp = 0; } if (state->buttons & CONT_Y && !yp) { yp = 1; blend = !blend; // Toggle Blending } if (!(state->buttons & CONT_Y)) { yp = 0; } if (state->buttons & CONT_A) { lookupdown -= 1.0f; // look up } if (state->buttons & CONT_B) { lookupdown += 1.0f; // look down } if (state->buttons & CONT_DPAD_UP) { xpos -= fsin(yrot*piover180) * 0.05f; // moves you forward(bobbing head) zpos -= fcos(yrot*piover180) * 0.05f; if (walkbiasangle >= 359.0f) { walkbiasangle = 0.0f; } else { walkbiasangle += 10.0f; } walkbias = fsin(walkbiasangle * piover180)/20.0f; } if (state->buttons & CONT_DPAD_DOWN) { xpos += fsin(yrot*piover180) * 0.05f; // moves you backward(bobbing head) zpos += fcos(yrot*piover180) * 0.05f; if (walkbiasangle <= 1.0f) { walkbiasangle = 359.0f; } else { walkbiasangle -= 10.0f; } walkbias = fsin(walkbiasangle * piover180)/20.0f; } if (state->buttons & CONT_DPAD_LEFT) { yrot += 1.5f; // Turn Left } if (state->buttons & CONT_DPAD_RIGHT) { yrot -= 1.5f; // Turn Right } pvr_wait_ready(); pvr_scene_begin(); if(blend) { pvr_list_begin(PVR_LIST_TR_POLY); plx_cxt_send(PVR_LIST_TR_POLY); // Submit the Header for PVR_LIST_TR_POLY } else { pvr_list_begin(PVR_LIST_OP_POLY); plx_cxt_send(PVR_LIST_OP_POLY); // Submit the Header for PVR_LIST_OP_POLY } /* Select texture according to filter */ plx_cxt_texture(textures[filter]); xtrans = -xpos; // Used For Player Translation On The X Axis ztrans = -zpos; // Used For Player Translation On The Z Axis ytrans = -walkbias - 0.25f; // Used For Bouncing Motion Up And Down sceneroty = 360.0f - yrot; // 360 Degree Angle For Player Direction plx_mat3d_identity(); plx_mat3d_rotate(lookupdown, 1.0f, 0.0f, 0.0f); // Rotate Up And Down To Look Up And Down plx_mat3d_rotate(sceneroty, 0.0f, 1.0f, 0.0f); // Rotate Depending On Direction Player Is Facing plx_mat3d_translate(xtrans, ytrans, ztrans); // Translate The Scene Based On Player Position /* Clear internal to an identity matrix */ plx_mat_identity(); /* "Applying" all matrixs: multiply a matrix onto the "internal" one */ plx_mat3d_apply_all(); numtriangles = sector1.numtriangles; for (loop = 0; loop < numtriangles; loop++) { // loop through all the triangles // Vertex 1 x_m = sector1.triangle[loop].vertex[0].x; y_m = sector1.triangle[loop].vertex[0].y; z_m = sector1.triangle[loop].vertex[0].z; u_m = sector1.triangle[loop].vertex[0].u; v_m = sector1.triangle[loop].vertex[0].v; plx_vert_ifpm3(PLX_VERT, x_m, y_m, z_m, color, u_m, v_m); // Vertex 2 x_m = sector1.triangle[loop].vertex[1].x; y_m = sector1.triangle[loop].vertex[1].y; z_m = sector1.triangle[loop].vertex[1].z; u_m = sector1.triangle[loop].vertex[1].u; v_m = sector1.triangle[loop].vertex[1].v; plx_vert_ifpm3(PLX_VERT, x_m, y_m, z_m, color, u_m, v_m); // Vertex 3 x_m = sector1.triangle[loop].vertex[2].x; y_m = sector1.triangle[loop].vertex[2].y; z_m = sector1.triangle[loop].vertex[2].z; u_m = sector1.triangle[loop].vertex[2].u; v_m = sector1.triangle[loop].vertex[2].v; plx_vert_ifpm3(PLX_VERT_EOS, x_m, y_m, z_m, color, u_m, v_m); } pvr_scene_finish(); } // Clean up!!! free(sector1.triangle); plx_txr_destroy(textures[0]); plx_txr_destroy(textures[1]); return 0; }