static unsigned int pgeObjSetColorFromMaterial(pgeObjMtl *material, const char *matname) { int i; unsigned int color = 0xFFFFFFFF; for(i = 0;i < material->nummaterials;i++) if(strcmp(material->materials[i].name, matname) == 0) break; color = GU_COLOR(material->materials[i].ambient[0], material->materials[i].ambient[1], material->materials[i].ambient[2], 1.0f); return color; }
void SetupProjection( void ) { // setup matrices for the triangle sceGumMatrixMode(GU_PROJECTION); sceGumLoadIdentity(); sceGumPerspective( 75.0f, 16.0f/9.0f, 0.5f, 1000.0f); sceGumMatrixMode(GU_VIEW); sceGumLoadIdentity(); sceGuClearColor( GU_COLOR( 0.0f, 0.0f, 0.0f, 1.0f ) ); sceGuClearDepth(0); }
void StateOptions::Draw(StateManager* sManager) { //start rendering mRender->StartFrame(1,1,1); switch(menuState) { case 0: { sceGuDisable(GU_DEPTH_TEST); sceGuEnable(GU_BLEND); sceGuColor(GU_COLOR(1,1,1,1.0f)); for(int x = 0; x < 8; x++) { for(int y = 0; y < 5; y++) { backSprite->SetPosition(x*64,y*64); backSprite->Draw(); } } //Controls buttonSprite->SetPosition(240,120); buttonSprite->Draw(); //sensity - analog stick buttonSprite->SetPosition(240,160); buttonSprite->Draw(); //back buttonSprite->SetPosition(240,200); buttonSprite->Draw(); //selected button sbuttonSprite->SetPosition(240,(selectPos * 40) + 120); sbuttonSprite->Draw(); sceGuDisable(GU_BLEND); sceGuEnable(GU_DEPTH_TEST); //draw subtitles on buttons selectPos == 0 ? DrawText(240,129,GU_COLOR(1,1,0,1) ,default_size,"Controls") : DrawText(240,129,GU_COLOR(1,1,1,1) ,default_size,"Controls"); selectPos == 1 ? DrawText(240,169,GU_COLOR(1,1,0,1) ,default_size,"Analog stick") : DrawText(240,169,GU_COLOR(1,1,1,1) ,default_size,"Analog stick"); selectPos == 2 ? DrawText(240,209,GU_COLOR(1,1,0,1) ,default_size,"Back") : DrawText(240,209,GU_COLOR(1,1,1,1) ,default_size,"Back"); DrawText(240,29,GU_COLOR(1,1,1,1) ,default_size,"Options"); } break; case 1://controls { sceGuDisable(GU_DEPTH_TEST); sceGuEnable(GU_BLEND); sceGuColor(GU_COLOR(1,1,1,1.0f)); for(int x = 0; x < 8; x++) { for(int y = 0; y < 5; y++) { backSprite->SetPosition(x*64,y*64); backSprite->Draw(); } } int starty = 60; //something for(int i = controlStart; i < controlEnd; i++) { if(controlPos == i) { halfsbuttonSprite->SetPosition(160,starty + (i * 30) - (controlStart * 30)); halfsbuttonSprite->Draw(); } else { halfbuttonSprite->SetPosition(160,starty + (i * 30) - (controlStart * 30)); halfbuttonSprite->Draw(); } } //back if(controlPos == 16) { sbuttonSprite->SetPosition(240,260); sbuttonSprite->Draw(); } else { buttonSprite->SetPosition(240,260); buttonSprite->Draw(); } sceGuDisable(GU_BLEND); sceGuEnable(GU_DEPTH_TEST); //write action names starty = 67; mRender->SetFontStyle(default_size,0xFFFFFFFF,0,0x00000000); for(int i = controlStart; i < controlEnd; i++) { //action mRender->DebugPrint(250,starty + (i * 30) - (controlStart * 30)+4,InputHelper::Instance()->getActionName(i).c_str()); } mRender->SetFontStyle(default_big_size,0xFFFFFFFF,0,0x00000200); starty = 65; for(int i = controlStart; i < controlEnd; i++) { //button assigned to this action if(controlPos == i && chooseKeyState == true) mRender->DebugPrint(160,starty + (i * 30) - (controlStart * 30)+4,"..."); else mRender->DebugPrint(160,starty + (i * 30) - (controlStart * 30)+4,InputHelper::Instance()->getButtonName(InputHelper::Instance()->getConnection(i).button).c_str()); } DrawText(240,269,GU_COLOR(1,1,0,1) ,default_size,"Back"); DrawText(240,29,GU_COLOR(1,1,1,1) ,default_size,"Controls"); } break; case 2://analog stick { sceGuDisable(GU_DEPTH_TEST); sceGuEnable(GU_BLEND); sceGuColor(GU_COLOR(1,1,1,1.0f)); for(int x = 0; x < 8; x++) { for(int y = 0; y < 5; y++) { backSprite->SetPosition(x*64,y*64); backSprite->Draw(); } } //something nbuttonSprite->SetPosition(240,100); nbuttonSprite->Draw(); nbuttonSprite->SetPosition(240,130); nbuttonSprite->Draw(); nbuttonSprite->SetPosition(240,160); nbuttonSprite->Draw(); nbuttonSprite->SetPosition(240,190); nbuttonSprite->Draw(); //back buttonSprite->SetPosition(240,260); buttonSprite->Draw(); if(currentAnalogPos < 4) { sbuttonSprite->SetPosition(240,100 + (currentAnalogPos * 30)); sbuttonSprite->Draw(); } else { sbuttonSprite->SetPosition(240,260); sbuttonSprite->Draw(); } moverSprite->SetPosition(144 +((fabs(InputHelper::Instance()->analogYup) * 10) * 20),100); moverSprite->Draw(); moverSprite->SetPosition(144 +((fabs(InputHelper::Instance()->analogYdown) * 10) * 20),130); moverSprite->Draw(); moverSprite->SetPosition(144 +((fabs(InputHelper::Instance()->analogXleft) * 10) * 20),160); moverSprite->Draw(); moverSprite->SetPosition(144 +((fabs(InputHelper::Instance()->analogXright) * 10) * 20),190); moverSprite->Draw(); sceGuDisable(GU_BLEND); sceGuEnable(GU_DEPTH_TEST); mRender->SetFontStyle(default_size,0xFFFFFFFF,0,0x00000200); mRender->DebugPrint(240,109,"Analog up : %d%%",(int)(fabs(InputHelper::Instance()->analogYup) * 100.0f)); mRender->DebugPrint(240,139,"Analog down : %d%%",(int)(fabs(InputHelper::Instance()->analogYdown) * 100.0f)); mRender->DebugPrint(240,169,"Analog left : %d%%",(int)(fabs(InputHelper::Instance()->analogXleft) * 100.0f)); mRender->DebugPrint(240,199,"Analog right : %d%%",(int)(fabs(InputHelper::Instance()->analogXright) * 100.0f)); mRender->DebugPrint(240,269,"Back"); DrawText(240,29,GU_COLOR(1,1,1,1) ,default_size,"Analog stick"); } break; } //end frame mRender->EndFrame(); }
void StateOptions::Draw(StateManager* sManager) { //start rendering mRender->StartFrame(); switch(menuState) { case 0: { sceGuDisable(GU_DEPTH_TEST); sceGuEnable(GU_BLEND); sceGuColor(GU_COLOR(1,1,1,1.0f)); for(int x = 0;x < 16;x++) { for(int y = 0;y < 9;y++) { backSprite->SetPosition(x*32,y*32); backSprite->Draw(); } } logoSprite->Draw(); //Controls buttonSprite->SetPosition(240,120); buttonSprite->Draw(); //sensity - analog stick buttonSprite->SetPosition(240,150); buttonSprite->Draw(); //texture pack buttonSprite->SetPosition(240,180); buttonSprite->Draw(); //back buttonSprite->SetPosition(240,210); buttonSprite->Draw(); //selected button sbuttonSprite->SetPosition(240,(selectPos * 30) + 120); sbuttonSprite->Draw(); sceGuDisable(GU_BLEND); sceGuEnable(GU_DEPTH_TEST); //draw subtitles on buttons mRender->DebugPrint(240,125,"Controls"); mRender->DebugPrint(240,155,"Analog stick"); mRender->DebugPrint(240,185,"Texture pack"); mRender->DebugPrint(240,215,"Back"); } break; case 1://controls { sceGuDisable(GU_DEPTH_TEST); sceGuEnable(GU_BLEND); sceGuColor(GU_COLOR(1,1,1,1.0f)); for(int x = 0;x < 16;x++) { for(int y = 0;y < 9;y++) { backSprite->SetPosition(x*32,y*32); backSprite->Draw(); } } int starty = 60; //something for(int i = controlStart;i < controlEnd;i++) { if(controlPos == i) { halfsbuttonSprite->SetPosition(160,starty + (i * 30) - (controlStart * 30)); halfsbuttonSprite->Draw(); }else { halfbuttonSprite->SetPosition(160,starty + (i * 30) - (controlStart * 30)); halfbuttonSprite->Draw(); } } //back if(controlPos == 16) { sbuttonSprite->SetPosition(240,260); sbuttonSprite->Draw(); }else { buttonSprite->SetPosition(240,260); buttonSprite->Draw(); } sceGuDisable(GU_BLEND); sceGuEnable(GU_DEPTH_TEST); //write action names starty = 67; mRender->SetFontStyle(0.7f,0xFFFFFFFF,0xFF000000,0x00000000); for(int i = controlStart;i < controlEnd;i++) { //action mRender->DebugPrint(250,starty + (i * 30) - (controlStart * 30),InputHelper::Instance()->getActionName(i).c_str()); } mRender->SetFontStyle(0.6f,0xFFFFFFFF,0xFF000000,0x00000200); starty = 65; for(int i = controlStart;i < controlEnd;i++) { //button assigned to this action if(controlPos == i && chooseKeyState == true) mRender->DebugPrint(160,starty + (i * 30) - (controlStart * 30),"..."); else mRender->DebugPrint(160,starty + (i * 30) - (controlStart * 30),InputHelper::Instance()->getButtonName(InputHelper::Instance()->getConnection(i).button).c_str()); } mRender->SetFontStyle(0.5f,0xFFFFFFFF,0xFF000000,0x00000200); mRender->DebugPrint(240,265,"Back"); mRender->DebugPrint(240,20,"CONTROLS"); } break; case 2://analog stick { sceGuDisable(GU_DEPTH_TEST); sceGuEnable(GU_BLEND); sceGuColor(GU_COLOR(1,1,1,1.0f)); for(int x = 0;x < 16;x++) { for(int y = 0;y < 9;y++) { backSprite->SetPosition(x*32,y*32); backSprite->Draw(); } } logoSprite->Draw(); //something buttonSprite->SetPosition(240,100); buttonSprite->Draw(); buttonSprite->SetPosition(240,130); buttonSprite->Draw(); buttonSprite->SetPosition(240,160); buttonSprite->Draw(); buttonSprite->SetPosition(240,190); buttonSprite->Draw(); //back buttonSprite->SetPosition(240,260); buttonSprite->Draw(); if(currentAnalogPos < 4) { sbuttonSprite->SetPosition(240,100 + (currentAnalogPos * 30)); sbuttonSprite->Draw(); }else { sbuttonSprite->SetPosition(240,260); sbuttonSprite->Draw(); } moverSprite->SetPosition(144 +((fabs(InputHelper::Instance()->analogYup) * 10) * 20),100); moverSprite->Draw(); moverSprite->SetPosition(144 +((fabs(InputHelper::Instance()->analogYdown) * 10) * 20),130); moverSprite->Draw(); moverSprite->SetPosition(144 +((fabs(InputHelper::Instance()->analogXleft) * 10) * 20),160); moverSprite->Draw(); moverSprite->SetPosition(144 +((fabs(InputHelper::Instance()->analogXright) * 10) * 20),190); moverSprite->Draw(); sceGuDisable(GU_BLEND); sceGuEnable(GU_DEPTH_TEST); mRender->DebugPrint(240,105,"Analog up : %d%%",(int)(fabs(InputHelper::Instance()->analogYup) * 100.0f)); mRender->DebugPrint(240,135,"Analog down : %d%%",(int)(fabs(InputHelper::Instance()->analogYdown) * 100.0f)); mRender->DebugPrint(240,165,"Analog left : %d%%",(int)(fabs(InputHelper::Instance()->analogXleft) * 100.0f)); mRender->DebugPrint(240,195,"Analog right : %d%%",(int)(fabs(InputHelper::Instance()->analogXright) * 100.0f)); mRender->DebugPrint(240,265,"Back"); } break; case 3: { sceGuDisable(GU_DEPTH_TEST); sceGuEnable(GU_BLEND); sceGuColor(GU_COLOR(1,1,1,1.0f)); for(int x = 0;x < 16;x++) { for(int y = 0;y < 9;y++) { backSprite->SetPosition(x*32,y*32); backSprite->Draw(); } } //select sprite if(TextureHelper::Instance()->packFiles.size() > 0) { selectSaveSprite->SetPosition(240,50 + (loadSavePos * 40) - (loadSaveStart * 40)); selectSaveSprite->Draw(); } //tp files for(int i = loadSaveStart;i <loadSaveMax;i++) { if(loadSavePos == i) { mRender->SetFontStyle(1.0f,0xFF000000,0xFFFFFFFF,0x00000000); mRender->DebugPrint(30,50 + (i * 40) - (loadSaveStart * 40),"%s",TextureHelper::Instance()->packFiles[i].c_str()); }else { mRender->SetFontStyle(0.8f,0xFFFFFFFF,0xFF000000,0x00000000); mRender->DebugPrint(30,50 + (i * 40) - (loadSaveStart * 40),"%s",TextureHelper::Instance()->packFiles[i].c_str()); } } //load buttonSprite->SetPosition(240,235); buttonSprite->Draw(); //back buttonSprite->SetPosition(240,260); buttonSprite->Draw(); //selected button sbuttonSprite->SetPosition(240,(loadSelectPos * 25) + 235); sbuttonSprite->Draw(); sceGuDisable(GU_BLEND); sceGuEnable(GU_DEPTH_TEST); mRender->SetFontStyle(0.5f,0xFFFFFFFF,0xFF000000,0x00000200); mRender->DebugPrint(240,20,"Load Texture Pack"); mRender->DebugPrint(240,240,"Load"); mRender->DebugPrint(240,265,"Back"); } break; } //end frame mRender->EndFrame(); }
void Light::setup(GLint glLightId_in) { GLint lightId = (glLightId_in != -1)?glLightId_in:glLightId; glLightId = lightId; enable(); glMatrixMode(GL_MODELVIEW); if (has_target && (type == LIGHT_SPOT || type == LIGHT_AREA)) { // Vector direction; direction = position; direction -= target; //direction.makeUnit(); //#if !defined(ARCH_PSP) && !defined(OPENGL_ES) && !defined(ARCH_DC) // GLShader::defaultShader.setShaderValue("lightDir",direction); //#endif #ifdef ARCH_PSP ScePspFVector3 lightPosition = { position.x, position.y, position.z }; ScePspFVector3 lightDirection = { direction.x, direction.y, direction.z }; sceGuLight( lightId, GU_SPOTLIGHT, GU_DIFFUSE_AND_SPECULAR, &lightPosition ); //sceGuLight( lightId, GU_SPOTLIGHT, GU_SPECULAR, &lightPosition ); sceGuLightSpot(lightId, &lightDirection, exponent, cutoff); #else #ifndef ARCH_DC GLfloat Direction[] = { direction.x, direction.y, direction.z, 1.0f }; GLfloat Position[] = { position.x, position.y, position.z, 1.0f }; glLightfv(lightId, GL_POSITION, Position); glLightfv(lightId, GL_SPOT_DIRECTION, Direction); #endif #endif } else { if (type==LIGHT_DIRECTIONAL) { direction = XYZ(1,0,0); if (rotation.x || rotation.y || rotation.z || rotation != rotation_last) { Vector direction_in; direction_in = XYZ(1,0,0); // float dirTransform[16]; // glMatrixMode(GL_MODELVIEW); // glPushMatrix(); // glLoadIdentity(); // glRotatef(rotation.z,0,0,1); // glRotatef(rotation.y,0,1,0); // glRotatef(rotation.x,1,0,0); // glGetFloatv(GL_MODELVIEW_MATRIX,dirTransform); // glPopMatrix(); // // matTransform(dirTransform,direction_in,direction); // direction.makeUnit(); directionTransform.pushMatrix(); if (rotation.z) directionTransform.rotate(rotation.z,0,0,1); if (rotation.y) directionTransform.rotate(rotation.y,0,1,0); if (rotation.x) directionTransform.rotate(rotation.x,1,0,0); directionTransform.apply(direction_in, direction); directionTransform.popMatrix(); // direction = XYZ(cos(DEGTORAD(rotation.x)),sin(DEGTORAD(rotation.y)),sin(DEGTORAD(rotation.z))); direction.makeUnit(); rotation_last = rotation; } #ifdef ARCH_PSP ScePspFVector3 lightDirection = { direction.x, direction.y, direction.z }; sceGuLight( lightId, GU_DIRECTIONAL, GU_DIFFUSE_AND_SPECULAR, &lightDirection ); //sceGuLight( lightId, GU_DIRECTIONAL, GU_SPECULAR, &lightDirection ); #else GLfloat Position[] = { direction.x, direction.y, direction.z, 0.0f }; // GLfloat Position[] = { 1, 0, 0, 0.0 }; #ifndef ARCH_DC glLightfv(lightId, GL_POSITION, Position); #endif #endif } #ifndef ARCH_PSP #ifndef ARCH_DC else { if (parent) { glPushMatrix(); parent->transformBegin(); } glPushMatrix(); ObjectController lCtl; lCtl.setRotation(rotation); lCtl.setPosition(position); lCtl.transformBegin(); // // if (position.x || position.y || position.z) // { // glTranslatef(position.x,position.y,position.z); // } // // if (rotation.x || rotation.y || rotation.z) // { // if (rotation.z) // { // glRotatef(rotation.z,0,0,1); // } // if (rotation.y) // { // glRotatef(rotation.y,0,1,0); // } // if (rotation.x) // { // glRotatef(rotation.x,1,0,0); // } // } GLfloat Direction[] = { 0, 0, -1, 1 }; glLightfv(lightId, GL_SPOT_DIRECTION, Direction); GLfloat Position[] = { 0, 0, 0, 1 }; glLightfv(lightId, GL_POSITION, Position); glGetFloatv(GL_MODELVIEW_MATRIX,transMatrix); lCtl.transformEnd(); glPopMatrix(); // glPushMatrix(); // #ifdef ARCH_PSP // ScePspFVector3 lightPosition = { position.x, position.y, position.z }; // //sceGuLight( lightId, GU_POINTLIGHT, GU_AMBIENT_AND_DIFFUSE, &lightPosition ); // sceGuLight( lightId, GU_POINTLIGHT, GU_SPECULAR, &lightPosition ); // #else // GLfloat Position[] = { position.x, position.y, position.z, 1.0 }; // glLightfv(lightId, GL_POSITION, Position); // #endif // glPopMatrix(); if (parent) { parent->transformEnd(); glPopMatrix(); } } #endif #endif // if (type == LIGHT_DIRECTIONAL) // { // GLfloat Position[] = { direction.x, direction.y, direction.z, 0 }; // glLightfv(lightId, GL_POSITION, Position); // } } #ifndef ARCH_DC if (type == LIGHT_POINT) { #ifdef ARCH_PSP ScePspFVector3 lightPosition = { position.x, position.y, position.z }; sceGuLight( lightId, GU_POINTLIGHT, GU_DIFFUSE_AND_SPECULAR, &lightPosition ); // sceGuLight( lightId, GU_POINTLIGHT, GU_SPECULAR, &lightPosition ); #else GLfloat Position[] = { position.x, position.y, position.z, 1 }; glLightfv(lightId, GL_POSITION, Position); // printf("pos: %d, %f, %f, %f\n",lightId,Position[0],Position[1],Position[2]); #endif #ifndef ARCH_PSP if (cutoff) { glLightf(lightId, GL_SPOT_EXPONENT, 1.0f/cutoff); } else { glLightf(lightId, GL_SPOT_EXPONENT, 0); } #endif } #ifndef ARCH_PSP if ((type == LIGHT_SPOT)) // || type == LIGHT_PROJECTOR { glLightf(lightId, GL_SPOT_CUTOFF, cutoff/2.0f); glLightf(lightId, GL_SPOT_EXPONENT, 1.0); } #endif #ifdef ARCH_PSP sceGuLightMode(GU_SEPARATE_SPECULAR_COLOR); sceGuLightColor( lightId, GU_AMBIENT, GU_COLOR( ambient.r, ambient.g, ambient.b, 1.0f )); sceGuLightColor( lightId, GU_DIFFUSE, GU_COLOR( diffuse.r, diffuse.g, diffuse.b, 1.0f )); sceGuLightColor( lightId, GU_SPECULAR, GU_COLOR( specular.r, specular.g, specular.b, 1.0f )); #else //#ifndef OPENGL_ES // glEnable(GL_SEPARATE_SPECULAR_COLOR); // glLightModeli (GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR); // glEnable(GL_COLOR_SUM); //#endif GLfloat Ambient[] = { ambient.r, ambient.g, ambient.b, 1 }; GLfloat Diffuse[] = { diffuse.r, diffuse.g, diffuse.b, 1 }; GLfloat Specular[] = { specular.r, specular.g, specular.b, 1 }; glLightfv(lightId, GL_AMBIENT, Ambient); glLightfv(lightId, GL_DIFFUSE, Diffuse); glLightfv(lightId, GL_SPECULAR, Specular); #endif #ifdef ARCH_PSP sceGuEnable(gl_lights[lightId]); sceGuLightAtt(lightId, constant_attenuation, linear_attenuation, quadratic_attenuation); #else glLightf(lightId, GL_CONSTANT_ATTENUATION, constant_attenuation); glLightf(lightId, GL_LINEAR_ATTENUATION, linear_attenuation); glLightf(lightId, GL_QUADRATIC_ATTENUATION, quadratic_attenuation); glEnable(lightId); #endif #endif };
void Drop::Render(Vector3 playerPos, float camAngle) { if(abs(position.x-playerPos.x) < 8.0f && abs(position.y-playerPos.y) < 5.0f && abs(position.z-playerPos.z) < 8.0f) { active = true; } else { active = false; } if(toDestroy == false && getMe == false && active == true) { if(abs(position.x-playerPos.x) < 0.8f && abs(position.y-playerPos.y) < 1.8f && abs(position.z-playerPos.z) < 0.8f && existingTime >= 0.5f && myCrft->InventoryIsFull(id,amount,stackable) == false && myCrft->HP > 0.0f) { getMe = true; return; } float angle = atan2f(position.x-(playerPos.x+(cosf(camAngle+PI)*4)),position.z-(playerPos.z+(sinf(camAngle+PI)*4)))-PI*0.5f; sceGuColor(GU_COLOR(myCrft->BlockFinalLight(position.x,position.y,position.z),myCrft->BlockFinalLight(position.x,position.y,position.z),myCrft->BlockFinalLight(position.x,position.y,position.z),1.0f)); sceGuEnable(GU_DEPTH_TEST); sceGuEnable(GU_ALPHA_TEST); sceGuEnable(GU_BLEND); if(id < 250) { sceGumPushMatrix(); ScePspFVector3 loc = {position.x,position.y+sinf(levit)*0.09f,position.z}; sceGumTranslate(&loc); ScePspFVector3 sca = {0.25f,0.25f,0.25f}; sceGumScale(&sca); sceGumRotateX(0.0f); sceGumRotateY(angleBlock); sceGumRotateZ(0.0f); myCrft->drawCubes(id,myCrft->BlockFinalLight(position.x,position.y,position.z)); sceGumPopMatrix(); if(amount >= 3 && stackable == true) { sceGumPushMatrix(); ScePspFVector3 loc = {position.x+0.09f,position.y+sinf(levit)*0.09f+0.09f,position.z}; sceGumTranslate(&loc); ScePspFVector3 sca = {0.25f,0.25f,0.25f}; sceGumScale(&sca); sceGumRotateX(0.0f); sceGumRotateY(angleBlock); sceGumRotateZ(0.0f); myCrft->drawCubes(id,myCrft->BlockFinalLight(position.x,position.y,position.z)); sceGumPopMatrix(); } } else { sceGumPushMatrix(); ScePspFVector3 loc = {position.x,position.y+sinf(levit)*0.09f,position.z}; sceGumTranslate(&loc); sceGumRotateX(0.0f); sceGumRotateY(angle); sceGumRotateZ(0.0f); myCrft->drawDropItems(id); sceGumPopMatrix(); } sceGuDisable(GU_BLEND); sceGuDisable(GU_ALPHA_TEST); sceGuDisable(GU_DEPTH_TEST); } }