//-------------------------------------------------------------------- // Función: CParticles::Update // Creador: Nacho (AMD) // Fecha: Wednesday 14/02/2007 19:48:41 //-------------------------------------------------------------------- void CParticles::Update(float dt, CLevel* pTheLevel, CSound* pSoundPlayer) { CVideo * pVideo = CVideo::GetSingleton(); m_fAngType3 += (240.0f * dt); m_fAngType3 = MAT_NormalizarAngulo360(m_fAngType3); CBall* pBall = pTheLevel->GetBall(); CSmoke* pSmoke = pTheLevel->GetSmoke(); VECTOR3 vecBallPos = pBall->GetPosition(); VECTOR2 vecBallVel = pBall->GetVelocity(); float fBallRadius = pBall->GetRadius(); sceGuEnable(GU_BLEND); sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA); ENEMY* pEnemies = pTheLevel->GetEnemies(); int iNumEnemies = pTheLevel->GetNumEnemies(); ///--- TIPO 0: Disparo amarillo ////////////////////////////////////////////////////////////////////// pVideo->EnableTexture(m_pTexture[0]); for (int i=0; i<MAX_PARTICLES; i++) { if (m_pParticleArray[0][i].enable) { m_pParticleArray[0][i].timeStamp += dt; if (m_pParticleArray[0][i].timeStamp >= 5.0f) { m_pParticleArray[0][i].enable = false; m_pParticleArray[0][i].next = m_iFreeSlot[0]; m_iFreeSlot[0] = i; continue; } m_pParticleArray[0][i].pos.x += m_pParticleArray[0][i].vel.x * dt; m_pParticleArray[0][i].pos.y += m_pParticleArray[0][i].vel.y * dt; stCollisionData data; data.radius = 1.0f; data.x = m_pParticleArray[0][i].pos.x; data.y = m_pParticleArray[0][i].pos.y; data.velX = m_pParticleArray[0][i].vel.x; data.velY = m_pParticleArray[0][i].vel.y; if (pTheLevel->TestCollision(&data, false)) { m_pParticleArray[0][i].pos.x = data.x; m_pParticleArray[0][i].pos.y = data.y; m_pParticleArray[0][i].vel.x = data.velX; m_pParticleArray[0][i].vel.y = data.velY; } for (int a=0; a<iNumEnemies; a++) { if (pEnemies[a].active) { ///--- sierra ///--- rebota if ((pEnemies[a].type == 0) || (pEnemies[a].type == 3)) { VECTOR3 vDis; VECTOR3 vTemp = {m_pParticleArray[0][i].pos.x, m_pParticleArray[0][i].pos.y, 4.0f}; VECTOR3 vTemp2 = {pEnemies[a].posX + 4.0f, pEnemies[a].posY + 4.0f, 4.0f}; MAT_VectorSubtract(&vDis, &vTemp2, &vTemp); float length = MAT_VectorQuadraticLength(&vDis); if (length < 6.25f) { m_pParticleArray[0][i].enable = false; m_pParticleArray[0][i].next = m_iFreeSlot[0]; m_iFreeSlot[0] = i; pSmoke->AddExplosion(vTemp2, 20.0f, true); pEnemies[a].active = false; pSoundPlayer->Play(SOUND_ENE_EXPLO); break; } } ///--- dirigidos ///--- rectos else if ((pEnemies[a].type == 1) || (pEnemies[a].type == 2)) { VECTOR3 vTemp = {0}; if (pEnemies[a].rot==0) { vTemp.x = pEnemies[a].posX+2.0f; vTemp.y = pEnemies[a].posY+4.0f; } else if (pEnemies[a].rot==3) { vTemp.x = pEnemies[a].posX+4.0f; vTemp.y = pEnemies[a].posY+2.0f; } else if (pEnemies[a].rot==2) { vTemp.x = pEnemies[a].posX+6.0f; vTemp.y = pEnemies[a].posY+4.0f; } else if (pEnemies[a].rot==1) { vTemp.x = pEnemies[a].posX+4.0f; vTemp.y = pEnemies[a].posY+6.0f; } vTemp.z = 4.0f; VECTOR3 vDis; VECTOR3 vTemp2 = {m_pParticleArray[0][i].pos.x, m_pParticleArray[0][i].pos.y, 4.0f}; MAT_VectorSubtract(&vDis, &vTemp, &vTemp2); float disx = vecBallPos.x - m_pParticleArray[0][i].pos.x,; float length = MAT_VectorQuadraticLength(&vDis); if (length < 6.0f) { m_pParticleArray[0][i].enable = false; m_pParticleArray[0][i].next = m_iFreeSlot[0]; m_iFreeSlot[0] = i; pSmoke->AddExplosion(vTemp, 20.0f, true); pEnemies[a].active = false; pSoundPlayer->Play(SOUND_ENE_EXPLO); int pan = 127; if (disx < 0.0f) { if (disx < -32.0f) { pan = 255; } else { pan = MAT_Clamp(128 + (int)(((-disx) / 32.0f) * 127.0f), 128, 255); } } else { if (disx > 32.0f) { pan = 0; } else { pan = MAT_Clamp((int)(127.0f - ((disx / 32.0f) * 127.0f)), 0, 127); } } pSoundPlayer->Play(SOUND_ENE_EXPLO, pan); break; } } } } if (!m_pParticleArray[0][i].enable) continue; ///--- render sceGumMatrixMode(GU_MODEL); sceGumLoadIdentity(); { VECTOR3 pos = { m_pParticleArray[0][i].pos.x -1.0f, -(m_pParticleArray[0][i].pos.y + 1.0f), 4.0f }; VECTOR3 scale = { 2.0f, 2.0f, 2.0f }; sceGumTranslate(&pos); sceGumScale(&scale); } if (m_pParticleArray[0][i].timeStamp >= 4.0f) { int alpha = (int)MAT_Clampf((5.0f - m_pParticleArray[0][i].timeStamp) * 255.0f, 0.0f, 255.0f); sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); sceGuAmbientColor(COLOR_ARGB(alpha, 255, 255, 255)); m_pQuad->Render(); sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, COLOR_ARGB(alpha, alpha, alpha, alpha), 0xffffffff); m_pQuad->Render(); sceGuAmbientColor(0xffffffff); } else { sceGuAmbientColor(0xffffffff); m_pQuad->Render(); sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, 0xffffffff, 0xffffffff); m_pQuad->Render(); } sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0); }
int main(int argc, char* argv[]) { unsigned int i,j; pspDebugScreenInit(); SetupCallbacks(); #ifdef ENABLE_PROFILER // Enable profiling pspDebugProfilerClear(); pspDebugProfilerEnable(); #endif // initialize global context g_context.iterationCount = NUM_VERTEX_BUFFERS * NUM_ITERATIONS; g_context.t = 0; g_context.sint = 0; // initialize torus for (i = 0; i < NUM_SLICES; ++i) { for (j = 0; j < NUM_ROWS; ++j) { float s = i + 0.5f, t = j; float x,y,z; x = (RING_SIZE + RING_RADIUS * cosf(s * ((GU_PI*2)/NUM_SLICES))) * cosf(t * ((GU_PI*2)/NUM_ROWS)); y = (RING_SIZE + RING_RADIUS * cosf(s * ((GU_PI*2)/NUM_SLICES))) * sinf(t * ((GU_PI*2)/NUM_ROWS)); z = RING_RADIUS * sinf(s * ((GU_PI*2)/NUM_SLICES)); torus_vertices[j + i * NUM_ROWS].x = x; torus_vertices[j + i * NUM_ROWS].y = y; torus_vertices[j + i * NUM_ROWS].z = z; } } // initialize torus modifiers for (j = 0; j < NUM_ROWS; ++j) { float t = j; torus_modifiers[j].x = 0; torus_modifiers[j].y = 0; torus_modifiers[j].z = 0.3*cosf( t * 8.0f *((GU_PI*2)/NUM_ROWS) ); } // init GU and set callbacks sceGuInit(); // 0x01 - user callback // 0x04 - 'rendering finished' callback sceGuSetCallback(1, &mySignalHandler); sceGuSetCallback(4, &myFinishHandler); // setup GU sceGuStart(GU_DIRECT,list); sceGuDrawBuffer(GU_PSM_8888,(void*)0,BUF_WIDTH); sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,(void*)0x88000,BUF_WIDTH); sceGuDepthBuffer((void*)0x110000,BUF_WIDTH); sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2)); sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT); sceGuDepthRange(0xc350,0x2710); sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT); sceGuEnable(GU_SCISSOR_TEST); sceGuAlphaFunc(GU_GREATER,0,0xff); sceGuEnable(GU_ALPHA_TEST); sceGuDepthFunc(GU_GEQUAL); sceGuEnable(GU_DEPTH_TEST); sceGuFrontFace(GU_CW); sceGuShadeModel(GU_SMOOTH); sceGuEnable(GU_CULL_FACE); sceGuEnable(GU_TEXTURE_2D); sceGuFinish(); sceGuSync(0,0); sceDisplayWaitVblankStart(); sceGuDisplay(GU_TRUE); // run sample #ifdef USING_SIGNALS sceGuCallMode(1); #endif // generate callable command-list with texture setup { sceGuStart(GU_CALL, smallList1); // setup texture sceGuTexMode(GU_PSM_5551,0,0,0); sceGuTexImage(0,32,32,32,ball_start); // width, height, buffer width, tbp sceGuTexFunc(GU_TFX_MODULATE,GU_TCC_RGBA); // NOTE: this enables reads of the alpha-component from the texture, otherwise blend/test won't work sceGuTexFilter(GU_NEAREST,GU_NEAREST); sceGuTexWrap(GU_CLAMP,GU_CLAMP); sceGuTexScale(1,1); sceGuTexOffset(0,0); sceGuAmbientColor(0xffffffff); sceGuFinish(); sceGuSync(0,0); } // generate callable command-list for cube rendering { sceGuStart(GU_CALL, smallList2); // draw cube sceGuDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,12*3,0,cubeVertices); sceGuFinish(); sceGuSync(0,0); } for(;;) { sceGuStart(GU_DIRECT,list); unsigned int i = 0; for( ; i < NUM_VERTEX_BUFFERS; i++ ) g_context.vbuffer[i] = sceGuGetMemory((NUM_SLICES/g_context.iterationCount) * 2 * NUM_ROWS * sizeof(Vertex)); g_context.vertsRendered = 0; // clear screen sceGuClearColor(0x00334455); sceGuClearDepth(0); sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT); // setup matrices sceGumMatrixMode(GU_PROJECTION); sceGumLoadIdentity(); sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f); sceGumMatrixMode(GU_VIEW); sceGumLoadIdentity(); sceGumMatrixMode(GU_MODEL); { ScePspFVector3 pos = {0.0f,0.0f,-3.5f}; ScePspFVector3 rot = {g_context.t * 0.3f * (GU_PI/180.0f), g_context.t * 0.7f * (GU_PI/180.0f), g_context.t * 1.3f * (GU_PI/180.0f)}; sceGumLoadIdentity(); sceGumTranslate(&pos); sceGumRotateXYZ(&rot); } sceGumStoreMatrix(&g_context.world); // call pregenerated command-list to setup texture sceGuCallList(smallList1); // start billboard rendering render_billboards(0); // call pregenerated command-list to render cube { ScePspFVector3 scale = {0.3f, 0.3f, 0.3f}; sceGumScale(&scale); } sceGumUpdateMatrix(); sceGuCallList(smallList2); #ifndef USING_SIGNALS // HACK: sceGuFinish() is called inside the signal interupt handler when all rendering job is done // this is done in order to stall GPU if it is ahead of CPU sceGuFinish(); #endif sceGuSync(0,0); #ifndef ENABLE_FRAMERATE // wait for next frame sceDisplayWaitVblankStart(); #endif sceGuSwapBuffers(); pspDebugScreenSetXY(0,0); #ifdef ENABLE_PROFILER // Print profile information to the screen pspDebugProfilerPrint(); #endif #ifdef ENABLE_FRAMERATE // simple frame rate counter static float curr_ms = 1.0f; static struct timeval time_slices[16]; static int t = 0; float curr_fps = 1.0f / curr_ms; t++; float vertsPerSec = g_context.vertsRendered*curr_fps; float kbPerSec = vertsPerSec * sizeof(Vertex) / 1024.0f; gettimeofday(&time_slices[t & 15],0); pspDebugScreenPrintf("fps: %d.%03d ms: %d vert/s: %dK MB/s: %d.%03d",(int)curr_fps, ((int)(curr_fps*1000.0f)%1000), (int)(curr_ms*1000.0f), (int)(vertsPerSec/1000.0f), (int)(kbPerSec/1024.0f), (int)((1000.0f/1024.0f)*((int)kbPerSec%1024)) ); if (!(t & 15)) { struct timeval last_time = time_slices[0]; unsigned int i; curr_ms = 0; for (i = 1; i < 16; ++i) { struct timeval curr_time = time_slices[i]; int curr_time_usec = curr_time.tv_usec + curr_time.tv_sec * 1000000; int last_time_usec = last_time.tv_usec + last_time.tv_sec * 1000000; if( last_time_usec < curr_time_usec ) curr_ms += (( curr_time_usec - last_time_usec ) * (1.0f/1000000.0f)); last_time = time_slices[i]; } curr_ms /= 15.0f; } #endif } sceGuTerm(); sceKernelExitGame(); return 0; }
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); } }