void collideObjectRoom(physicalPoint_s* pp, room_s* r) { if(!pp || !r)return; vect3Df_s oldPosition = pp->position; // float length=vmagf(pp->speed); bool ret=false; pp->position = vaddf(pp->position,pp->speed); ret = checkObjectCollision(pp, r); pp->contact=ret; vect3Df_s os=pp->speed; pp->speed=vect3Df(pp->position.x-oldPosition.x, pp->position.y-oldPosition.y, pp->position.z-oldPosition.z); pp->speed=vect3Df((os.x*pp->speed.x>0)?(pp->speed.x):(0),(os.y*pp->speed.y>0)?(pp->speed.y):(0),(os.z*pp->speed.z>0)?(pp->speed.z):(0)); if(pp->contact) { //floor friction vect3Df_s s=vsubf(pp->speed,vmulf(normGravityVector,vdotf(normGravityVector,pp->speed))); pp->speed=vsubf(pp->speed,vdivf(s,2)); }else{ //air friction vect3Df_s s=vsubf(pp->speed,vmulf(normGravityVector,vdotf(normGravityVector,pp->speed))); pp->speed=vsubf(pp->speed,vdivf(s,32)); } if(fabs(pp->speed.x)<0.01f)pp->speed.x=0; if(fabs(pp->speed.z)<0.01f)pp->speed.z=0; }
void drawPlayer(player_s* p) { if(!p)return; gsPushMatrix(); camera_s* c=&p->camera; gsTranslate(p->object.position.x,p->object.position.y-4.0f,p->object.position.z); float m[9]; vect3Df_s v1 = moveCameraVector(c, vect3Df(1.0f, 0.0f, 0.0f), false); vect3Df_s v2 = moveCameraVector(c, vect3Df(0.0f, 0.0f, 1.0f), false); m[0]=v1.x;m[3]=v1.y;m[6]=v1.z; m[1]=0.0f;m[4]=1.0f;m[7]=0.0f; m[2]=v2.x;m[5]=v2.y;m[8]=v2.z; gsMultMatrix3(m); gsScale(1.2f,1.2f,1.2f); gsRotateY(M_PI); md2InstanceDraw(&p->ratmanInstance); gsPopMatrix(); }
void updatePlatform(platform_s* pf, player_s* p) { if(!pf)return; if(pf->ao.active) { if(pf->touched && p->object.position.y>pf->position.y+p->object.radius) { p->object.position=vaddf(p->object.position,pf->velocity); }else if(pf->oldTouched){ p->object.speed=vaddf(p->object.speed,pf->velocity); } if(pf->direction) { if(vdotf(vsubf(pf->position,pf->destination),pf->velocity)>0) { if(pf->backandforth) { pf->velocity=vmulf(pf->velocity,-1); pf->direction=false; }else{ pf->velocity=vect3Df(0,0,0); pf->ao.active=false; } } }else{ if(vdotf(vsubf(pf->position,pf->origin),pf->velocity)>0) { pf->velocity=vmulf(pf->velocity,-1); pf->direction=true; } } int i; for(i=0; i<NUMOBJECTS; i++) { if(objects[i].used && intersectOBBPlatform(pf, &objects[i])) { objects[i].position = vaddf(objects[i].position, pf->velocity); } } pf->position=vaddf(pf->position,pf->velocity); } if(pf->aar) { pf->aar->position = vaddf(pf->position, vect3Df(-PLATFORMSIZE, PLATFORMHEIGHT, -PLATFORMSIZE)); } pf->ao.oldActive=pf->ao.active; pf->oldTouched=pf->touched; pf->touched=false; }
void initPortal(portal_s* p) { if(!p)return; // p->position = vect3Df(); p->target = NULL; updatePortalOrientation(p, vect3Df(0.0f, 0.0f, 1.0f), vect3Df(-1.0f, 0.0f, 0.0f)); p->color = vect3Df(1.0f, 1.0f, 1.0f); p->open = false; p->draw = false; }
void warpPortalMatrix(portal_s* p, float* m) //3x3 { if(!m)return; vect3Df_s x=warpPortalVector(p,vect3Df(m[0],m[3],m[6])); vect3Df_s y=warpPortalVector(p,vect3Df(m[1],m[4],m[7])); vect3Df_s z=warpPortalVector(p,vect3Df(m[2],m[5],m[8])); m[0]=x.x;m[3]=x.y;m[6]=x.z; m[1]=y.x;m[4]=y.y;m[7]=y.z; m[2]=z.x;m[5]=z.y;m[8]=z.z; }
void initBigButton(bigButton_s* bb, room_s* r, vect3Di_s pos) { if(!bb || !r)return; bb->room=r; md2InstanceInit(&bb->modelInstance, &bigButtonModel, &bigButtonTexture); {//for collisions rectangle_s rec; rectangle_s* recp; rec.material=NULL; rec.position=vaddi(pos,vect3Di(-1,1,-1)); rec.size=vect3Di(2,0,2); rec.normal=vect3Df(0,-1.0f,0); recp=addRoomRectangle(r, rec); if(recp){recp->hide=true;recp->collides=true;bb->surface=recp;} rec.position=vaddi(pos,vect3Di(-1,0,-1)); rec.size=vect3Di(2,1,0); rec.normal=vect3Df(0,0,-1.0f); recp=addRoomRectangle(r, rec); if(recp){recp->hide=true;recp->collides=true;} rec.position=vaddi(pos,vect3Di(-1,1,1)); rec.size=vect3Di(2,-1,0); rec.normal=vect3Df(0,0,1.0f); recp=addRoomRectangle(r, rec); if(recp){recp->hide=true;recp->collides=true;} rec.position=vaddi(pos,vect3Di(-1,0,-1)); rec.size=vect3Di(0,1,2); rec.normal=vect3Df(-1.0f,0,0); recp=addRoomRectangle(r, rec); if(recp){recp->hide=true;recp->collides=true;} rec.position=vaddi(pos,vect3Di(1,1,-1)); rec.size=vect3Di(0,-1,2) ;rec.normal=vect3Df(1.0f,0,0); recp=addRoomRectangle(r, rec); if(recp){recp->hide=true;recp->collides=true;} } // pos=vect(pos.x+r->position.x, pos.y, pos.z+r->position.y); bb->position=convertRectangleVector(pos); initActivator(&bb->activator); bb->active=false; bb->used=true; }
void getPortalBoundingBox(portal_s* p, camera_s* c, vect3Di_s* topleft, vect3Di_s* bottomright, float* depth) { if(!p || !topleft || !bottomright || !depth)return; vect4Df_s v; float mX=1.0f, MX=-1.0f; float mY=1.0f, MY=-1.0f; *depth = 1000.0f; v = projectPointCamera(c, vaddf(p->position, vect3Df(p->plane[0].x*PORTAL_WIDTH+p->plane[1].x*PORTAL_HEIGHT, p->plane[0].y*PORTAL_WIDTH+p->plane[1].y*PORTAL_HEIGHT, p->plane[0].z*PORTAL_WIDTH+p->plane[1].z*PORTAL_HEIGHT))); if(v.x < mX) mX = v.x; if(v.y < mY) mY = v.y; if(v.x > MX) MX = v.x; if(v.y > MY) MY = v.y; if(*depth > -v.w) *depth = -v.w; v = projectPointCamera(c, vaddf(p->position, vect3Df(p->plane[0].x*PORTAL_WIDTH-p->plane[1].x*PORTAL_HEIGHT, p->plane[0].y*PORTAL_WIDTH-p->plane[1].y*PORTAL_HEIGHT, p->plane[0].z*PORTAL_WIDTH-p->plane[1].z*PORTAL_HEIGHT))); if(v.x < mX) mX = v.x; if(v.y < mY) mY = v.y; if(v.x > MX) MX = v.x; if(v.y > MY) MY = v.y; if(*depth > -v.w) *depth = -v.w; v = projectPointCamera(c, vaddf(p->position, vect3Df(-p->plane[0].x*PORTAL_WIDTH-p->plane[1].x*PORTAL_HEIGHT, -p->plane[0].y*PORTAL_WIDTH-p->plane[1].y*PORTAL_HEIGHT, -p->plane[0].z*PORTAL_WIDTH-p->plane[1].z*PORTAL_HEIGHT))); if(v.x < mX) mX = v.x; if(v.y < mY) mY = v.y; if(v.x > MX) MX = v.x; if(v.y > MY) MY = v.y; if(*depth > -v.w) *depth = -v.w; v = projectPointCamera(c, vaddf(p->position, vect3Df(-p->plane[0].x*PORTAL_WIDTH+p->plane[1].x*PORTAL_HEIGHT, -p->plane[0].y*PORTAL_WIDTH+p->plane[1].y*PORTAL_HEIGHT, -p->plane[0].z*PORTAL_WIDTH+p->plane[1].z*PORTAL_HEIGHT))); if(v.x < mX) mX = v.x; if(v.y < mY) mY = v.y; if(v.x > MX) MX = v.x; if(v.y > MY) MY = v.y; if(*depth > -v.w) *depth = -v.w; topleft->x = (mX+1.0f)*240/2; topleft->y = (mY+1.0f)*400/2; bottomright->x = (MX+1.0f)*240/2; bottomright->y = (MY+1.0f)*400/2; if(topleft->x < 0) topleft->x = 0; if(topleft->y < 0) topleft->y = 0; if(bottomright->x > 240) bottomright->x = 240; if(bottomright->y > 400) bottomright->y = 400; }
vect3Df_s warpPortalVector(portal_s* p, vect3Df_s v) { if(!p)return vect3Df(0.0f, 0.0f, 0.0f); portal_s* p2=p->target; if(!p2)return vect3Df(0.0f, 0.0f, 0.0f); v = multMatrix44Vect3(p->matrix, v, true); // rotation v.x = -v.x; v.z = -v.z; return multMatrix44Vect3(p2->matrix, v, false); }
u8 checkObjectElevatorCollision(physicalPoint_s* o, room_s* r, elevator_s* ev) { if(!o || !r || !ev)return 0; u8 ret=0; if(collideRectangle(o,vaddf(ev->realPosition,vect3Df(-ELEVATOR_SIZE/2,0,-ELEVATOR_SIZE/2)),vect3Df(ELEVATOR_SIZE,0,ELEVATOR_SIZE)))ret=2; vect3Df_s u=vect3Df(o->position.x-ev->position.x,0,o->position.z-ev->position.z); float v=vmagf(u); if(fabs(o->position.y-ev->position.y)>ELEVATOR_HEIGHT)return ret; if(ev->state==ELEVATOR_OPEN) { switch(ev->direction&(~(1<<ELEVATOR_UPDOWNBIT))) { case 1: if(u.x<-(v*cos(ELEVATOR_ANGLE)))return ret; break; case 4: if(u.z>(v*cos(ELEVATOR_ANGLE)))return ret; break; case 5: if(u.z<-(v*cos(ELEVATOR_ANGLE)))return ret; break; default: if(u.x>(v*cos(ELEVATOR_ANGLE)))return ret; break; } } if(v<ELEVATOR_RADIUS_IN) { if(v+o->radius>=ELEVATOR_RADIUS_IN) { u=vdivf(vmulf(u,ELEVATOR_RADIUS_IN-o->radius-v),v); o->position=vaddf(o->position,u); ret=1; } }else if(v<o->radius+ELEVATOR_RADIUS_OUT) { u=vdivf(vmulf(u,o->radius+ELEVATOR_RADIUS_OUT-v),v); o->position=vaddf(o->position,u); ret=1; } return ret; }
bool collideRectangle(physicalPoint_s* o, vect3Df_s p, vect3Df_s s) { if(!o)return false; vect3Df_s o2 = getClosestPointRectangle(p, s, o->position); int i; for(i=0; i < NUM_PORTALS; i++) { if(portals[i].target && portals[i].open && portals[i].target->open)collidePortal(p, s, &portals[i], &o2); } vect3Df_s v = vsubf(o2, o->position); float gval = vdotf(v, normGravityVector); vect3Df_s v2 = vsubf(v, vmulf(normGravityVector, gval)); float sqd = (v2.x*v2.x)+(v2.y*v2.y)+(v2.z*v2.z)+((gval*gval)/ transY); if(sqd < o->sqRadius) { float sqd = (v2.x*v2.x)+(v2.y*v2.y)+(v2.z*v2.z)+(gval*gval)/transY; float d = sqrtf(sqd); v = vdivf(vmulf(vect3Df(v.x, v.y, v.z), -(o->radius-d)), d); o->position = vaddf(o->position, v); return true; } return false; }
void initPlayer(player_s* p) { if(!p)return; initPhysicalPoint(&p->object, vect3Df(0,0,0), PLAYER_RADIUS); initCamera(&p->camera); md2InstanceInit(&p->gunInstance, &gunModel, &gunTextureOrange); md2InstanceInit(&p->ratmanInstance, &ratmanModel, &ratmanTexture); p->ratmanInstance.speed=0.1f; p->oldInPortal = p->inPortal = false; passthroughDvlb = DVLB_ParseFile((u32*)passthrough_vsh_shbin, passthrough_vsh_shbin_size); shaderProgramInit(&passthroughProgram); if(!passthroughDvlb)return; shaderProgramSetVsh(&passthroughProgram, &passthroughDvlb->DVLE[0]); rectangleVertexData = linearAlloc(sizeof(rectangleData)); memcpy(rectangleVertexData, rectangleData, sizeof(rectangleData)); crosshairVertexData = linearAlloc(sizeof(crosshairData)); memcpy(crosshairVertexData, crosshairData, sizeof(crosshairData)); p->flying = false; p->life = 80; p->walkCnt1 = 0; p->walkCnt2 = 0; }
void initPlatform(platform_s* pf, room_s* r, vect3Di_s orig, vect3Di_s dest, u8 id, bool BAF) { if(!pf || !r)return; // orig=vect3Df(orig.x+r->position.x, orig.y, orig.z+r->position.y); // dest=vect3Df(dest.x+r->position.x, dest.y, dest.z+r->position.y); pf->id=id; pf->origin=convertRectangleVector(orig); pf->destination=convertRectangleVector(dest); pf->position=pf->origin; pf->velocity=vdivf(vnormf(vsubf(pf->destination,pf->origin)),16); pf->direction=true; pf->touched=false; pf->backandforth=true; initActivatableObject(&pf->ao); pf->ao.active=true; pf->aar=createAAR(vaddf(pf->position, vect3Df(-PLATFORMSIZE, PLATFORMHEIGHT, -PLATFORMSIZE)), vect3Df(2*PLATFORMSIZE, 0.0f, 2*PLATFORMSIZE), vect3Df(0.0f, 1.0f, 0.0f)); // addPlatform(id,vmulf(pf->origin,4),vmulf(pf->destination,4),BAF); //TEMP pf->used=true; }
void updatePlayer(player_s* p, room_s* r) { if(!p)return; md2InstanceUpdate(&p->gunInstance); md2InstanceUpdate(&p->ratmanInstance); if(!p->flying) p->object.speed = vaddf(p->object.speed, vmulf(normGravityVector, 0.04f)); vect3Df_s prevPosition = p->object.position; collideObjectRoom(&p->object, r); if(p->inPortal && !p->oldInPortal)playSFX(portalEnterSFX[rand()%2]); else if(!p->inPortal && p->oldInPortal)playSFX(portalExitSFX[rand()%2]); int i; for(i=0; i < NUM_PORTALS; i++) { if(portals[i].target)checkPortalPlayerWarp(p, &portals[i]); } updateCamera(&p->camera); float alignment = -vdotf(vect3Df(p->camera.orientation[0][0],p->camera.orientation[0][1],p->camera.orientation[0][2]), normGravityVector); // printf("alignment : %f \n",alignment); { if(alignment>0.001) { if(alignment>0.125)rotateMatrixZ((float*)p->camera.orientation, -0.5f*0.15f, true); else if(alignment>0.0625)rotateMatrixZ((float*)p->camera.orientation, -0.25f*0.15f, true); else if(alignment>0.03125)rotateMatrixZ((float*)p->camera.orientation, -0.125f*0.07f, true); }else if(alignment<-0.001) { if(alignment<-0.125)rotateMatrixZ((float*)p->camera.orientation, 0.5f*0.15f, true); else if(alignment<-0.0625)rotateMatrixZ((float*)p->camera.orientation, 0.25f*0.15f, true); else if(alignment<-0.03125)rotateMatrixZ((float*)p->camera.orientation, 0.125f*0.07f, true); } } // fixMatrix(c->orientation); //compensate floating point errors p->camera.position = vaddf(p->object.position, vect3Df(0.0f, cos(p->walkCnt1)*0.14f, 0.0f)); if(vmagf(p->object.speed) < 0.03f || !p->object.contact)md2InstanceChangeAnimation(&p->ratmanInstance, 0, false); if(p->flying) p->object.speed = vect3Df(0,0,0); //TEMP p->tempAngle = vmulf(p->tempAngle, 0.65f); }
bool intersectOBBButton(bigButton_s* bb, OBB_s* o) { if(!bb || !o || !bb->surface)return false; vect3Df_s s; getBoxAABB(o, &s); return intersectAABBAAR(o->position, s, vaddf(bb->position, vect3Df(-TILESIZE_FLOAT, 1.0f, -TILESIZE_FLOAT)), vect3Df(TILESIZE_FLOAT*2,0,TILESIZE_FLOAT*2)); }
bool intersectOBBPlatform(platform_s* pf, OBB_s* o) { if(!pf || !o)return false; vect3Df_s s; getBoxAABB(o, &s); return intersectAABBAAR(o->position, s, vaddf(pf->position, vect3Df(-PLATFORMSIZE, 1.0f, -PLATFORMSIZE)), vect3Df(PLATFORMSIZE*2,0,PLATFORMSIZE*2)); }
void updateEnergyBall(room_s* r, energyBall_s* eb) { if(!eb)return; vect3Df_s l=eb->position; vect3Df_s ip=l, normal; rectangle_s* col=collideGridCell(getCurrentCell(r,eb->position), eb->launcher?eb->launcher->surface:NULL, l, eb->direction, eb->speed, &ip, &normal); if(!col)col=collideGridCell(getCurrentCell(r,vaddf(eb->position,vmulf(eb->direction,eb->speed))), eb->launcher?eb->launcher->surface:NULL, l, eb->direction, eb->speed, &ip, &normal); if(col) { // printf("COL COL COL %d\n",col->collides); energyDevice_s* ed=isEnergyCatcherSurface(col); if(ed && !ed->active) { //caught md2InstanceChangeAnimation(&ed->modelInstance,2,false); md2InstanceChangeAnimation(&ed->modelInstance,1,true); killEnergyBall(eb); if(eb->launcher)eb->launcher->active=false; ed->active=true; return; } vect3Df_s v=vect3Df(0,0,0); float x, y, z; portal_s* portal=NULL; int i; for(i=0; i<NUM_PORTALS && !portal; i++) { if(isPointInPortal(&portals[i],ip,&v,&x,&y,&z))portal=&portals[i]; if(portal && fabs(z)>=0.1f)portal=NULL; } if(portal && !portal->target)portal=NULL; if(!portal) { eb->position=ip; eb->direction=vsubf(eb->direction,vmulf(normal,2*vdotf(eb->direction,normal))); eb->position=vaddf(eb->position,vmulf(eb->direction,ENERGYBALLSIZE)); }else if(portal->target && portal->open && portal->target->open){ eb->position=vaddf(eb->position,vmulf(eb->direction,eb->speed)); warpEnergyBall(portal,eb); eb->position=vaddf(eb->position,vmulf(eb->direction,eb->speed)); } }else{ eb->position=vaddf(eb->position,vmulf(eb->direction,eb->speed)); } md2InstanceUpdate(&eb->modelInstance); if(!eb->life)killEnergyBall(eb); else eb->life--; }
void initPhysicalPoint(physicalPoint_s* pp, vect3Df_s position, float radius) { if(!pp)return; pp->position = position; pp->speed = vect3Df(0.0f, 0.0f, 0.0f); pp->radius = radius; pp->sqRadius = radius * radius; pp->contact = false; }
void initEmancipator(emancipator_s* e, md2_instance_t* mi, vect3Df_s pos, float* m) { if(!e)return; e->position=pos; e->modelInstance=*mi; if(m)memcpy(e->transformationMatrix,m,sizeof(float)*9); else{ m=e->transformationMatrix; m[0]=m[4]=m[8]=1.0f; m[1]=m[2]=m[3]=0; m[5]=m[6]=m[7]=0; } e->counter=0; e->angle=0; e->velocity=vect3Df(randFloat(-1.0f, 1.0f),1.0f,randFloat(-1.0f, 1.0f)); e->velocity=vdivf(vnormf(e->velocity),16); e->axis=vect3Df(randFloat(-1.0f, 1.0f),randFloat(-1.0f, 1.0f),randFloat(-1.0f, 1.0f)); e->axis=vnormf(e->axis); playSFX(emancipationSFX); e->used=true; }
void shootPlayerGun(player_s* p, room_s* r, portal_s* portal) { if(!p)return; if(p->gunInstance.currentAnim == PORTALGUN_SHOOT)return; md2InstanceChangeAnimation(&p->gunInstance, PORTALGUN_IDLE, false); md2InstanceChangeAnimation(&p->gunInstance, PORTALGUN_SHOOT, true); vect3Df_s position; rectangle_s* rec = collideLineMapClosest(r, NULL, p->camera.position, vect3Df(-p->camera.orientation[2][0], -p->camera.orientation[2][1], -p->camera.orientation[2][2]), 1000.0f, &position, NULL); if(rec && rec->portalable) { portal_s oldPortal = *portal; vect3Df_s normal = rec->normal; vect3Df_s plane0 = vect3Df(p->camera.orientation[0][0], p->camera.orientation[0][1], p->camera.orientation[0][2]); plane0 = vnormf(vsubf(plane0, vmulf(normal, vdotf(normal, plane0)))); position = vaddf(position, vmulf(normal, -0.05f)); portal->position = position; updatePortalOrientation(portal, plane0, normal); isPortalOnWall(r, portal, true); portal->draw = true; portal->open = true; if(isPortalOnWall(r, portal, false)) { ejectPortalOBBs(portal); ejectPortalOBBs(portal->target); }else{ *portal = oldPortal; } } }
bool checkObjectCollision(physicalPoint_s* o, room_s* r) { bool ret=false; gridCell_s* gc = getCurrentCell(r, o->position); // listCell_s* l = r->rectangles.first; // while(l) // { // if(l->data.collides) // { // l->data.touched = collideRectangle(o, convertRectangleVector(l->data.position), convertRectangleVector(l->data.size)); // ret = l->data.touched || ret; // } // l = l->next; // } int i; for(i=0;i<gc->numRectangles;i++) { rectangle_s* rec=gc->rectangles[i]; if(rec->collides) { rec->touched = collideRectangle(o, convertRectangleVector(rec->position), convertRectangleVector(rec->size)); ret = rec->touched || ret; } } //platforms for(i=0;i<NUMPLATFORMS;i++) { if(platform[i].used && collideRectangle(o,vaddf(platform[i].position,vect3Df(-PLATFORMSIZE,0,-PLATFORMSIZE)),vect3Df(PLATFORMSIZE*2,0,PLATFORMSIZE*2))) //add culling { platform[i].touched=true; ret=true; } } //elevators u8 val=0; if((entryWallDoor.used && checkObjectElevatorCollision(o,r,&entryWallDoor.elevator)) || (exitWallDoor.used && (val=checkObjectElevatorCollision(o,r,&exitWallDoor.elevator))))ret=true; if(val==2)closeElevator(&exitWallDoor.elevator); //timed buttons if(checkObjectTimedButtonsCollision(o,r))ret=true; return ret; }
// topscreen void renderFrame() { GPU_SetViewport((u32*)osConvertVirtToPhys((u32)gpuDOut),(u32*)osConvertVirtToPhys((u32)gpuOut),0,0,240*2,400); GPU_DepthRange(-1.0f, 0.0f); GPU_SetFaceCulling(GPU_CULL_BACK_CCW); GPU_SetStencilTest(false, GPU_ALWAYS, 0x00, 0xFF, 0x00); GPU_SetStencilOp(GPU_KEEP, GPU_KEEP, GPU_KEEP); GPU_SetBlendingColor(0,0,0,0); GPU_SetDepthTestAndWriteMask(true, GPU_GREATER, GPU_WRITE_ALL); GPUCMD_AddSingleParam(0x00010062, 0); GPUCMD_AddSingleParam(0x000F0118, 0); //setup shader SHDR_UseProgram(shader, 0); GPU_SetAlphaBlending(GPU_BLEND_ADD, GPU_BLEND_ADD, GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA); GPU_SetAlphaTest(false, GPU_ALWAYS, 0x00); GPU_SetTextureEnable(GPU_TEXUNIT0); GPU_SetTexEnv(0, GPU_TEVSOURCES(GPU_TEXTURE0, GPU_PRIMARY_COLOR, GPU_PRIMARY_COLOR), GPU_TEVSOURCES(GPU_TEXTURE0, GPU_PRIMARY_COLOR, GPU_PRIMARY_COLOR), GPU_TEVOPERANDS(0,0,0), GPU_TEVOPERANDS(0,0,0), GPU_MODULATE, GPU_MODULATE, 0xFFFFFFFF); GPU_SetDummyTexEnv(1); GPU_SetDummyTexEnv(2); GPU_SetDummyTexEnv(3); GPU_SetDummyTexEnv(4); GPU_SetDummyTexEnv(5); //texturing stuff GPU_SetTexture(GPU_TEXUNIT0, (u32*)osConvertVirtToPhys((u32)texData),128,128,GPU_TEXTURE_MAG_FILTER(GPU_NEAREST)|GPU_TEXTURE_MIN_FILTER(GPU_NEAREST),GPU_RGBA8); GPU_SetAttributeBuffers(3, (u32*)osConvertVirtToPhys((u32)texData), GPU_ATTRIBFMT(0, 3, GPU_FLOAT)|GPU_ATTRIBFMT(1, 2, GPU_FLOAT)|GPU_ATTRIBFMT(2, 3, GPU_FLOAT), 0xFFC, 0x210, 1, (u32[]){0x00000000}, (u64[]){0x210}, (u8[]){3}); //setup lighting (this is specific to our shader) vect3Df_s lightDir=vnormf(vect3Df(cos(lightAngle), -1.0f, sin(lightAngle))); GPU_SetUniform(SHDR_GetUniformRegister(shader, "lightDirection", 0), (u32*)(float[]){0.0f, -lightDir.z, -lightDir.y, -lightDir.x}, 1);
bool collideLineRectangle(rectangle_s* rec, vect3Df_s o, vect3Df_s v, float d, float* kk, vect3Df_s* ip) { if(!rec)return false; vect3Df_s n=vect3Df(fabs(rec->normal.x),fabs(rec->normal.y),fabs(rec->normal.z)); float p1=vdotf(v,n); if(fabs(p1)>0.001f) { vect3Df_s p = convertRectangleVector(rec->position); vect3Df_s s = convertRectangleVector(rec->size); float p2=vdotf(vsubf(p,o),n); float k=p2/p1; s8 sign=((s.x>0)^(s.y<0)^(s.z>0)^(p1<0))?(-1):(1); if(kk) { *kk=k+sign; } if(k<0 || k>d){return false;} vect3Df_s i=vaddf(o,vmulf(v,k)); if(ip)*ip=i; i=vsubf(i,p); bool r=true; if(s.x) { if(s.x>0)r=r&&i.x<s.x&&i.x>=0; else r=r&&i.x>s.x&&i.x<=0; } if(s.y) { if(s.y>0)r=r&&i.y<s.y&&i.y>=0; else r=r&&i.y>s.y&&i.y<=0; } if(s.z) { if(s.z>0)r=r&&i.z<s.z&&i.z>=0; else r=r&&i.z>s.z&&i.z<=0; } return r; } return false; }
vect3Df_s getClosestPointRectangle(vect3Df_s rectOrigin, vect3Df_s rectSize, vect3Df_s o) { vect3Df_s u1, u2; float x,y,sx,sy; if(rectSize.x){sx=fabs(rectSize.x);u1=vect3Df((rectSize.x>0)?(1.0f):(-(1.0f)),0,0);} else{sx=fabs(rectSize.y);u1=vect3Df(0,(rectSize.y>0)?(1.0f):(-(1.0f)),0);} if(rectSize.z){sy=fabs(rectSize.z);u2=vect3Df(0,0,(rectSize.z>0)?(1.0f):(-(1.0f)));} else{sy=fabs(rectSize.y);u2=vect3Df(0,(rectSize.y>0)?(1.0f):(-(1.0f)),0);} o=vsubf(o, rectOrigin); x=vdotf(o, u1); y=vdotf(o, u2); bool r=true; r=r && x<sx && x>=0; r=r && y<sy && y>=0; if(r)return vaddf(rectOrigin, vect3Df((x*u1.x)+(y*u2.x), (x*u1.y)+(y*u2.y), (x*u1.z)+(y*u2.z))); if(x<0) { x=0; if(y<0)y=0; else if(y>sy)y=sy; }else if(x>sx) { x=sx; if(y<0)y=0; else if(y>sy)y=sy; }else if(y<0) { y=0; if(x<0)x=0; else if(x>sx)y=sx; }else if(y>sy) { y=sy; if(x<0)x=0; else if(x>sx)x=sx; } return vaddf(rectOrigin, vect3Df((x*u1.x)+(y*u2.x), (x*u1.y)+(y*u2.y), (x*u1.z)+(y*u2.z))); }
void updateEmancipationGrid(player_s* pl, emancipationGrid_s* eg) { if(!eg)return; vect3Df_s pos, sp; getEmancipationGridAAR(eg,&pos,&sp); if(intersectAABBAAR(pl->object.position, vect3Df(PLAYER_RADIUS,PLAYER_RADIUS*5,PLAYER_RADIUS), pos, sp)) { resetPortals(); } int i; for(i=0;i<NUMOBJECTS;i++) { OBB_s* o = &objects[i]; if(o->used && collideBoxGrid(eg, o)) { createEmancipator(o->modelInstance, o->position, o->transformationMatrix); resetDispenserCube(o); printf("imma emancipate your shit\n"); } } }
void initEnergyDevice(room_s* r, energyDevice_s* ed, vect3Di_s pos, deviceOrientation_t or, bool type) { if(!ed)return; initActivator(&ed->activator); md2InstanceInit(&ed->modelInstance, type?(&energyLauncherModel):(&energyCatcherModel), &energyLauncherTexture); ed->orientation=or; ed->surface=NULL; {//for collisions rectangle_s rec; rectangle_s* recp; rec.material=NULL; if(or!=mY) { rec.position=vaddi(pos,vect3Di(-1,4,-1)); rec.size=vect3Di(2,0,2); rec.normal=vect3Df(0,-1.0f,0); recp=addRoomRectangle(r, rec); if(recp){recp->hide=true;recp->collides=true;} if(or==pY)ed->surface=recp; } if(or!=pY) { rec.position=vaddi(pos,vect3Di(1,-4,1)); rec.size=vect3Di(-2,0,-2); rec.normal=vect3Df(0,1.0f,0); recp=addRoomRectangle(r, rec); if(recp){recp->hide=true;recp->collides=true;} if(or==mY)ed->surface=recp; } if(or!=pZ) { rec.position=vaddi(pos,vect3Di(-1,-4,-1)); rec.size=vect3Di(2,8,0); rec.normal=vect3Df(0,0,1.0f); recp=addRoomRectangle(r, rec); if(recp){recp->hide=true;recp->collides=true;} if(or==mZ)ed->surface=recp; } if(or!=mZ) { rec.position=vaddi(pos,vect3Di(-1,4,1)); rec.size=vect3Di(2,-8,0); rec.normal=vect3Df(0,0,-1.0f); recp=addRoomRectangle(r, rec); if(recp){recp->hide=true;recp->collides=true;} if(or==pZ)ed->surface=recp; } if(or!=pX) { rec.position=vaddi(pos,vect3Di(-1,-4,-1)); rec.size=vect3Di(0,8,2); rec.normal=vect3Df(1.0f,0,0); recp=addRoomRectangle(r, rec); if(recp){recp->hide=true;recp->collides=true;} if(or==mX)ed->surface=recp; } if(or!=mX) { rec.position=vaddi(pos,vect3Di(1,4,-1)); rec.size=vect3Di(0,-8,2); rec.normal=vect3Df(-1.0f,0,0); recp=addRoomRectangle(r, rec); if(recp){recp->hide=true;recp->collides=true;} if(or==pX)ed->surface=recp; } } // pos=vect3Di(pos.x+r->position.x, pos.y, pos.z+r->position.y); ed->position=convertRectangleVector(pos); ed->active=type; ed->type=type; ed->used=true; }
// topscreen void renderFrame() { //setup lighting (specific to our vertex shader) vect3Df_s lightDir = vnormf(vect3Df(cos(lightAngle), -1.0f, sin(lightAngle))); glUniform4fv(lightDirection, 1, (float[]){0.0f, -lightDir.z, -lightDir.y, -lightDir.x});
vect3Df_s convertRectangleVector(vect3Di_s v) { return vect3Df(v.x*TILESIZE_FLOAT*2, v.y*HEIGHTUNIT_FLOAT, v.z*TILESIZE_FLOAT*2); }
void updateControls(player_s* p) { circlePosition cpad; circlePosition cstick; hidCircleRead(&cpad); irrstCstickRead(&cstick); rotatePlayer(p, vect3Df((abs(cstick.dy)<5)?0:(-cstick.dy*0.001f), (abs(cstick.dx)<5)?0:(cstick.dx*0.001f), 0.0f)); if(abs(cpad.dx) > 15 || abs(cpad.dy) > 15) //dead zone { float factor = 0.0015f; if(p->flying)factor*=2; else if(!p->object.contact)factor*=0.06f; else updatePlayerWalk(p, cpad.dy*factor*2, cpad.dx*factor); movePlayer(p, vect3Df(cpad.dx*factor, 0.0f, -cpad.dy*factor)); } if(keysDown()&KEY_ZL) { // "USE" key vect3Df_s u = moveCameraVector(&p->camera, vect3Df(0.0f, 0.0f, -1.0f), true); timedButton_s* tb = collideRayTimedButtons(p->object.position, u, TILESIZE_FLOAT*2); if(tb) { activateTimedButton(tb); }else{ OBB_s* o = collideRayBoxes(p->object.position, u, TILESIZE_FLOAT*4); if(o) { gravityGunObject = o; } } } if(keysDown()&KEY_ZR) { // JUMP key if(p->object.contact) { p->object.speed.y += 0.6f; } } if(gravityGunObject) { if(!(keysHeld()&KEY_ZL)) { gravityGunObject = NULL; md2InstanceChangeAnimation(&p->gunInstance, 0, false); md2InstanceChangeAnimation(&p->gunInstance, 1, true); }else{ const vect3Df_s u = moveCameraVector(&p->camera, vect3Df(0.0f, 0.0f, -5.0f), true); const vect3Df_s t = vaddf(u, p->object.position); const vect3Df_s v = vmulf(vsubf(t, gravityGunObject->position), 1.75f); setObbVelocity(gravityGunObject, v); md2InstanceChangeAnimation(&p->gunInstance, 2, false); } }else if(p->gunInstance.currentAnim == 2){ md2InstanceChangeAnimation(&p->gunInstance, 0, false); md2InstanceChangeAnimation(&p->gunInstance, 1, true); } }