Exemplo n.º 1
0
void drawEnergyDevice(energyDevice_s* ed)
{
	if(!ed)return;

	gsPushMatrix();
		gsSwitchRenderMode(md2GsMode);

		gsTranslate(ed->position.x, ed->position.y, ed->position.z);
		
		switch(ed->orientation)
		{
			case mY:
				gsRotateX(-M_PI);
				break;
			case pX:
				gsRotateZ(M_PI/2);
				break;
			case mX:
				gsRotateZ(-M_PI/2);
				break;
			case pZ:
				gsRotateX(-M_PI/2);
				break;
			case mZ:
				gsRotateX(M_PI/2);
				break;
			default:
				break;
		}

		md2InstanceDraw(&ed->modelInstance);
	gsPopMatrix();
}
Exemplo n.º 2
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();
}
Exemplo n.º 3
0
void drawEmancipationGrid(emancipationGrid_s* eg)
{
	if(!eg)return;
	
	float l=fabs(eg->length);

	// TODO : animate surface texture
	
	gsPushMatrix();
		gsSwitchRenderMode(md2GsMode);

		gsTranslate(eg->position.x, eg->position.y, eg->position.z);

		if(eg->direction)gsRotateY(-(M_PI/2));
		if(eg->length<0)gsRotateY((M_PI/2)*2);
		md2InstanceDraw(&gridInstance);

		gsPushMatrix();
			gsTranslate(l,0,0);
			gsRotateY((M_PI/2)*2);
			md2InstanceDraw(&gridInstance);
		gsPopMatrix();

		gsSwitchRenderMode(-1);

		GPU_SetAttributeBuffers(
			1, // number of attributes
			(u32*)osConvertVirtToPhys(emancipationBaseAddr), // we use the start of linear heap as base since that's where all our buffers are located
			GPU_ATTRIBFMT(0, 3, GPU_FLOAT), // we want v0 (vertex position)
			0xFFE, // mask : we want v0
			0x0, // permutation : we use identity
			1, // number of buffers : we have one attribute per buffer
			(u32[]){(u32)emancipationRectangleVertexData-emancipationBaseAddr}, // buffer offsets (placeholders)
			(u64[]){0x0}, // attribute permutations for each buffer
			(u8[]){1} // number of attributes for each buffer
			);

		gsSetShader(&emancipationProgram);

		gsScale(l, 4.0f, 1.0f);
		gsUpdateTransformation();

		textureBind(&gridSurfaceTexture, GPU_TEXUNIT0);
		GPU_SetFloatUniform(GPU_VERTEX_SHADER, emancipationUniformTextureDimensions, (u32*)(float[]){0.0f, 0.0f, 0.7f, l/8}, 1);
Exemplo n.º 4
0
void drawPlatform(platform_s* pf)
{
	if(!pf)return;

	gsPushMatrix();
		gsSwitchRenderMode(md2GsMode);
		gsTranslate(pf->position.x, pf->position.y, pf->position.z);
		md2InstanceDraw(&platformModelInstance);
	gsPopMatrix();
}
Exemplo n.º 5
0
void drawBigButton(bigButton_s* bb)
{
	if(!bb || !bb->used)return;

	gsPushMatrix();
		gsSwitchRenderMode(md2GsMode);

		gsTranslate(bb->position.x, bb->position.y, bb->position.z);

		bb->modelInstance.texture = bb->active?&bigButtonActiveTexture:&bigButtonTexture;
		md2InstanceDraw(&bb->modelInstance);
	gsPopMatrix();
}
Exemplo n.º 6
0
void drawPortals(portal_s* portals[], int n, renderSceneCallback_t callback, camera_s* c, int depth, u8 stencil)
{
	if(!portals || !portalVertexData || !callback || !c || !depth)return;
	int i;

	gsSwitchRenderMode(-1);

	GPU_SetAttributeBuffers(
		1, // number of attributes
		(u32*)osConvertVirtToPhys(portalBaseAddr), // we use the start of linear heap as base since that's where all our buffers are located
		GPU_ATTRIBFMT(0, 3, GPU_FLOAT), // we want v0 (vertex position)
		0xFFE, // mask : we want v0
		0x0, // permutation : we use identity
		1, // number of buffers : we have one attribute per buffer
		(u32[]){(u32)portalOutlineVertexData-portalBaseAddr}, // buffer offsets (placeholders)
		(u64[]){0x0}, // attribute permutations for each buffer
		(u8[]){1} // number of attributes for each buffer
		);

	gsPushMatrix();
		shaderInstanceSetBool(portalProgram.vertexShader, 0, true);
		gsSetShader(&portalProgram);

		//TEMP
		int colorUniformLoc = shaderInstanceGetUniformLocation(portalProgram.vertexShader, "color");

		GPU_SetTexEnv(0, 
			GPU_TEVSOURCES(GPU_PRIMARY_COLOR, GPU_PRIMARY_COLOR, GPU_PRIMARY_COLOR),
			GPU_TEVSOURCES(GPU_PRIMARY_COLOR, GPU_PRIMARY_COLOR, GPU_PRIMARY_COLOR),
			GPU_TEVOPERANDS(0,0,0), 
			GPU_TEVOPERANDS(0,0,0), 
			GPU_MODULATE, GPU_MODULATE, 
			0xFFFFFFFF);

		for(i=0; i<n; i++)
		{
			portal_s* p = portals[i];

			if(!p->draw)continue;

			GPU_SetFloatUniform(GPU_VERTEX_SHADER, colorUniformLoc, (u32*)(float[]){1.0f, p->color.z, p->color.y, p->color.x}, 1);

			gsPushMatrix();
				gsTranslate(p->position.x, p->position.y, p->position.z);
				gsMultMatrix(p->matrix);

				gsUpdateTransformation();

				GPU_DrawArray(GPU_TRIANGLE_STRIP, portalNumVertices);
			gsPopMatrix();
		}
Exemplo n.º 7
0
void drawPlayerGun(player_s* p)
{
	if(!p)return;

	gsPushMatrix();
		useCamera(&p->camera);
		gsLoadIdentity();

		GPU_SetDepthTestAndWriteMask(true, GPU_ALWAYS, GPU_WRITE_DEPTH);
		gsSwitchRenderMode(-1);

		GPU_SetAttributeBuffers(
			2, // number of attributes
			(u32*)osConvertVirtToPhys(rectangleBaseAddr), // we use the start of linear heap as base since that's where all our buffers are located
			GPU_ATTRIBFMT(0, 3, GPU_FLOAT)|GPU_ATTRIBFMT(1, 2, GPU_FLOAT), // we want v0 (vertex position) and v1 (texcoord)
			0xFFC, // mask : we want v0 and v1
			0x10, // permutation : we use identity
			1, // number of buffers : we have one attribute per buffer
			(u32[]){(u32)rectangleVertexData-rectangleBaseAddr}, // buffer offsets (placeholders)
			(u64[]){0x10}, // attribute permutations for each buffer
			(u8[]){2} // number of attributes for each buffer
			);

		gsSetShader(&passthroughProgram);

		GPU_DrawArray(GPU_TRIANGLES, 6);

		GPU_SetDepthTestAndWriteMask(true, GPU_ALWAYS, GPU_WRITE_ALL);

		GPUCMD_AddWrite(GPUREG_ATTRIBBUFFER0_CONFIG0, (u32)crosshairVertexData-rectangleBaseAddr);
		textureBind(&crosshairTexture, GPU_TEXUNIT0);

		GPU_DrawArray(GPU_TRIANGLES, 6);

		GPU_SetDepthTestAndWriteMask(true, GPU_GREATER, GPU_WRITE_ALL);
		gsSwitchRenderMode(md2GsMode);

		gsTranslate(1.3, -1.65, -3.1);
		gsRotateY(p->tempAngle.y);
		gsRotateX(-p->tempAngle.x);
		gsRotateX(-0.1);
		gsRotateZ(M_PI/2);
		gsRotateY(-M_PI/2);
		gsRotateX(-M_PI/2);
		gsScale(3.0f/8, 3.0f/8, 3.0f/8);

		md2InstanceDraw(&p->gunInstance);
	gsPopMatrix();
}
Exemplo n.º 8
0
void drawEnergyBall(energyBall_s* eb)
{
	if(!eb)return;

	// TODO : decaying alpha

	gsPushMatrix();
		gsSwitchRenderMode(md2GsMode);

		float angle=(eb->modelInstance.currentFrame*1.0f+eb->modelInstance.interpolation);

		gsTranslate(eb->position.x, eb->position.y, eb->position.z);
		
		gsRotateX(angle*0.4);gsRotateY(angle*0.2);gsRotateZ(angle*0.1);

		md2InstanceDraw(&eb->modelInstance);
	gsPopMatrix();
}
Exemplo n.º 9
0
void drawEmancipator(emancipator_s* e)
{
	if(!e || !e->used)return;
	
	e->modelInstance.brightness=maxf(1.0f-(e->counter*1.0f)/BLACKENINGTIME,0.0f);
	e->modelInstance.alpha=(e->counter<BLACKENINGTIME)?(1.0f):(maxf(1.0f-((e->counter-BLACKENINGTIME)*1.0f)/FADINGTIME,0.0f));
	
	gsPushMatrix();
		gsSwitchRenderMode(md2GsMode);

		gsTranslate(e->position.x, e->position.y, e->position.z);

		// TODO : transpose ?
		gsMultMatrix3(e->transformationMatrix);
		
		gsRotateX(e->axis.x*e->angle);
		gsRotateY(e->axis.y*e->angle);
		gsRotateZ(e->axis.z*e->angle);

		md2InstanceDraw(&e->modelInstance);
	gsPopMatrix();
}
Exemplo n.º 10
0
// topscreen
void renderMenuFrame(u32* outBuffer, u32* outDepthBuffer)
{
	GPU_SetViewport((u32*)osConvertVirtToPhys((u32)outDepthBuffer),(u32*)osConvertVirtToPhys((u32)outBuffer),0,0,240,400);
	
	GPU_DepthMap(-1.0f, 0.0f);
	GPU_SetFaceCulling(GPU_CULL_FRONT_CCW);
	GPU_SetStencilTest(false, GPU_ALWAYS, 0x00, 0xFF, 0x00);
	GPU_SetStencilOp(GPU_STENCIL_KEEP, GPU_STENCIL_KEEP, GPU_STENCIL_KEEP);
	GPU_SetBlendingColor(0,0,0,0);
	GPU_SetDepthTestAndWriteMask(true, GPU_GREATER, GPU_WRITE_ALL);
	
	GPUCMD_AddMaskedWrite(GPUREG_0062, 0x1, 0); 
	GPUCMD_AddWrite(GPUREG_0118, 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);

	gsMatrixMode(GS_MODELVIEW);
	gsPushMatrix();
		gsLoadIdentity();
		useCamera(&menuCamera);

		gsSwitchRenderMode(md2GsMode);
		md2InstanceDraw(&gladosInstance);
		md2InstanceDraw(&gladosLairInstance);

	gsPopMatrix();

	GPU_SetDepthTestAndWriteMask(true, GPU_ALWAYS, GPU_WRITE_ALL);
	
	if(currentCameraState==2)
	{
		gsPushMatrix();
			gsSwitchRenderMode(-1);

			GPU_SetAttributeBuffers(
				1, // number of attributes
				(u32*)osConvertVirtToPhys(logoBaseAddr), // we use the start of linear heap as base since that's where all our buffers are located
				GPU_ATTRIBFMT(0, 3, GPU_FLOAT), // we want v0 (vertex position)
				0xFFE, // mask : we want v0
				0x0, // permutation : we use identity
				1, // number of buffers : we have one attribute per buffer
				(u32[]){(u32)logoRectangleVertexData-logoBaseAddr}, // buffer offsets (placeholders)
				(u64[]){0x0}, // attribute permutations for each buffer
				(u8[]){1} // number of attributes for each buffer
				);

			gsSetShader(&logoProgram);

			gsMatrixMode(GS_MODELVIEW);
			gsLoadIdentity();

			gsPushMatrix();
				gsTranslate(0.15f, 0.325f, 0.0f);
				gsScale(64.0f * 2.0f / 240.0f, 64.0f * 2.0f / 400.0f, 1.0f);

				gsTranslate(0.5f, 0.5f, 0.0f);
				gsRotateZ(logoangle+=0.01f);
				gsTranslate(-0.5f, -0.5f, 0.0f);

				gsUpdateTransformation();

				textureBind(&rotateLogoTexture, GPU_TEXUNIT0);
				GPU_SetFloatUniform(GPU_VERTEX_SHADER, logoUniformTextureDimensions, (u32*)(float[]){0.0f, 0.0f, 1.0f, 1.0f}, 1);