Ejemplo n.º 1
0
void F_grafi(float angle) {

  MATRIX local_world1;
  VECTOR object_rotation1 = { 0.00f, 0.00f, 0.00f, 1.00f }, object_pos = {
  0.00f, 0.00f, 0.00f, 1.00f};
  object_rotation1[2] = angle;
  create_local_world(local_world1, object_pos, object_rotation1);
  //fondo
  calcular_vertices_rotados(&(vertices_fondo[36 * 2]), 36,
                            &(vertices_fondo[36 * 2]), local_world1);
  calcular_vertices_rotados(vertices_fondo, 12, vertices_fondo, local_world1);
  calcular_vertices_rotados(&(vertices_fondo[36]), 12, &(vertices_fondo[36]),
                            local_world1);
  calcular_vertices_rotados(&(vertices_fondo[36 * 4]), 12,
                            &(vertices_fondo[36 * 4]), local_world1);
  calcular_vertices_rotados(&(vertices_fondo[36 * 5]), 12,
                            &(vertices_fondo[36 * 5]), local_world1);
  //cara
  calcular_vertices_rotados(&(vertices[36 * 2]), 36, &(vertices[36 * 2]),
                            local_world1);
  calcular_vertices_rotados(vertices, 12, vertices, local_world1);
  calcular_vertices_rotados(&(vertices[36]), 12, &(vertices[36]), local_world1);
  calcular_vertices_rotados(&(vertices[36 * 4]), 12, &(vertices[36 * 4]),
                            local_world1);
  calcular_vertices_rotados(&(vertices[36 * 5]), 12, &(vertices[36 * 5]),
                            local_world1);
}
Ejemplo n.º 2
0
void D_grafi(float angle) {

  MATRIX local_world1;
  VECTOR object_rotation1 = { 0.00f, 0.00f, 0.00f, 1.00f }, object_pos = {
  0.00f, 0.00f, 0.00f, 1.00f};
  object_rotation1[1] = angle;
  create_local_world(local_world1, object_pos, object_rotation1);

  //fondo
  calcular_vertices_rotados(&(vertices_fondo[5 * 36]), 36,
                            &(vertices_fondo[5 * 36]), local_world1);

  calcular_vertices_rotados(&(vertices_fondo[0 + 8]), 4,
                            &(vertices_fondo[0 + 8]), local_world1);
  calcular_vertices_rotados(&(vertices_fondo[12 + 8]), 4,
                            &(vertices_fondo[12 + 8]), local_world1);
  calcular_vertices_rotados(&(vertices_fondo[24 + 8]), 4,
                            &(vertices_fondo[24 + 8]), local_world1);


  calcular_vertices_rotados(&(vertices_fondo[36 + 8]), 4,
                            &(vertices_fondo[36 + 8]), local_world1);
  calcular_vertices_rotados(&(vertices_fondo[36 + 12 + 8]), 4,
                            &(vertices_fondo[36 + 12 + 8]), local_world1);
  calcular_vertices_rotados(&(vertices_fondo[36 + 24 + 8]), 4,
                            &(vertices_fondo[36 + 24 + 8]), local_world1);

  calcular_vertices_rotados(&(vertices_fondo[2 * 36 + 24]), 12,
                            &(vertices_fondo[2 * 36 + 24]), local_world1);

  calcular_vertices_rotados(&(vertices_fondo[3 * 36 + 24]), 12,
                            &(vertices_fondo[3 * 36 + 24]), local_world1);

  //cara
  calcular_vertices_rotados(&(vertices[5 * 36]), 36, &(vertices[5 * 36]),
                            local_world1);

  calcular_vertices_rotados(&(vertices[0 + 8]), 4, &(vertices[0 + 8]),
                            local_world1);
  calcular_vertices_rotados(&(vertices[12 + 8]), 4, &(vertices[12 + 8]),
                            local_world1);
  calcular_vertices_rotados(&(vertices[24 + 8]), 4, &(vertices[24 + 8]),
                            local_world1);


  calcular_vertices_rotados(&(vertices[36 + 8]), 4, &(vertices[36 + 8]),
                            local_world1);
  calcular_vertices_rotados(&(vertices[36 + 12 + 8]), 4,
                            &(vertices[36 + 12 + 8]), local_world1);
  calcular_vertices_rotados(&(vertices[36 + 24 + 8]), 4,
                            &(vertices[36 + 24 + 8]), local_world1);

  calcular_vertices_rotados(&(vertices[2 * 36 + 24]), 12,
                            &(vertices[2 * 36 + 24]), local_world1);

  calcular_vertices_rotados(&(vertices[3 * 36 + 24]), 12,
                            &(vertices[3 * 36 + 24]), local_world1);
}
Ejemplo n.º 3
0
Archivo: main.c Proyecto: ps2dev/gsKit
int render(GSGLOBAL *gsGlobal)
{
#ifdef TEX_BG
	u64 TexCol = GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00);
	GSTEXTURE bigtex;
#endif
#ifdef FHD_BG
	GSTEXTURE fhdbg;
#endif
	int i;

	// Matrices to setup the 3D environment and camera
	MATRIX local_world;
	MATRIX local_light;
	MATRIX world_view;
	MATRIX view_screen;
	MATRIX local_screen;

	VECTOR *temp_normals;
	VECTOR *temp_lights;
	color_f_t *temp_colours;
	vertex_f_t *temp_vertices;

	xyz_t   *verts;
	color_t *colors;

	// Allocate calculation space.
	temp_normals  = (VECTOR     *)memalign(128, sizeof(VECTOR)     * vertex_count);
	temp_lights   = (VECTOR     *)memalign(128, sizeof(VECTOR)     * vertex_count);
	temp_colours  = (color_f_t  *)memalign(128, sizeof(color_f_t)  * vertex_count);
	temp_vertices = (vertex_f_t *)memalign(128, sizeof(vertex_f_t) * vertex_count);

	// Allocate register space.
	verts  = (xyz_t   *)memalign(128, sizeof(xyz_t)   * vertex_count);
	colors = (color_t *)memalign(128, sizeof(color_t) * vertex_count);

#ifdef TEX_BG
	bigtex.Filter = GS_FILTER_LINEAR;
	bigtex.Delayed = 0;
	gsKit_texture_jpeg(gsGlobal, &bigtex, "host:bigtex.jpg");
#endif

#ifdef FHD_BG
	fhdbg.Filter = GS_FILTER_LINEAR;
	fhdbg.Delayed = 1;
	fhdbg.Vram = GSKIT_ALLOC_ERROR;
	gsKit_texture_jpeg(gsGlobal, &fhdbg, "host:fhdbg.jpg");
	gsKit_hires_prepare_bg(gsGlobal, &fhdbg);
	gsKit_hires_set_bg(gsGlobal, &fhdbg);
#endif

	printf("VRAM used: %dKiB\n", gsGlobal->CurrentPointer / 1024);
	printf("VRAM free: %dKiB\n", 4096 - (gsGlobal->CurrentPointer / 1024));

	// Create the view_screen matrix.
	create_view_screen(view_screen, 16.0f/9.0f, -0.20f, 0.20f, -0.20f, 0.20f, 1.00f, 2000.00f);

	if (gsGlobal->ZBuffering == GS_SETTING_ON)
		gsKit_set_test(gsGlobal, GS_ZTEST_ON);

	// A,B,C,D,FIX = 0,1,0,1,0:
	// A = 0 = Cs (Color Source)
	// B = 1 = Cd (Color Destination)
	// C = 0 = As (Alpha Source)
	// D = 1 = Cd (Color Destination)
	// FIX = not used
	//
	// Resulting color = (A-B)*C+D = (Cs-Cd)*As+Cd
	// This will blend the source over the destination
	// Note:
	// - Alpha 0x00 = fully transparent
	// - Alpha 0x80 = fully visible
	gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0, 1, 0, 1, 128), 0);
	gsGlobal->PrimAlphaEnable = GS_SETTING_OFF;
	gsGlobal->PrimAAEnable = GS_SETTING_ON;

	// The main loop...
	for (;;)
	{
		// Spin the teapot a bit.
		object_rotation[1] += 0.005f; while (object_rotation[1] > 3.14f) { object_rotation[1] -= 6.28f; }

		// Create the local_world matrix.
		create_local_world(local_world, object_position, object_rotation);

		// Create the local_light matrix.
		create_local_light(local_light, object_rotation);

		// Create the world_view matrix.
		create_world_view(world_view, camera_position, camera_rotation);

		// Create the local_screen matrix.
		create_local_screen(local_screen, local_world, world_view, view_screen);

		// Calculate the normal values.
		calculate_normals(temp_normals, vertex_count, normals, local_light);

		// Calculate the lighting values.
		calculate_lights(temp_lights, vertex_count, temp_normals, light_direction, light_colour, light_type, light_count);

		// Calculate the colour values after lighting.
		calculate_colours((VECTOR *)temp_colours, vertex_count, colours, temp_lights);

		// Calculate the vertex values.
		calculate_vertices((VECTOR *)temp_vertices, vertex_count, vertices, local_screen);

		// Convert floating point vertices to fixed point and translate to center of screen.
		draw_convert_xyz(verts, 2048, 2048, 16, vertex_count, temp_vertices);

		// Convert floating point colours to fixed point.
		draw_convert_rgbq(colors, vertex_count, temp_vertices, temp_colours, 0x80);

#ifdef DYNAMIC_DITHERING
		// Dithering:
		// The standard 4x4 dithering matrix creates static noise to eliminate banding.
		// This static noise is a little visible, and can be improved by changing the matrix every frame
		// Keep adding 5 to get the most noisy pattern possible:
		//   0, 5, 2, 7, 4, 1, 6, 3
		for(i = 0; i < 15; i++)
		    gsGlobal->DitherMatrix[i] = (gsGlobal->DitherMatrix[i] + 5) & 7;
		gsKit_set_dither_matrix(gsGlobal);
#endif

#ifdef TEX_BG
		if(bigtex.Vram != GSKIT_ALLOC_ERROR) {
			gsKit_prim_sprite_texture(gsGlobal, &bigtex,
									0.0f,	// X1
									0.0f,	// Y1
									0.0f,	// U1
									0.0f,	// V1
									gsGlobal->Width,	// X2
									gsGlobal->Height,	// Y2
									bigtex.Width,		// U2
									bigtex.Height,		// V2
									2,
									TexCol);
		}
#endif

		for (i = 0; i < points_count; i+=3) {
			float fX=gsGlobal->Width/2;
			float fY=gsGlobal->Height/2;
			gsKit_prim_triangle_gouraud_3d(gsGlobal
				, (temp_vertices[points[i+0]].x + 1.0f) * fX, (temp_vertices[points[i+0]].y + 1.0f) * fY, verts[points[i+0]].z
				, (temp_vertices[points[i+1]].x + 1.0f) * fX, (temp_vertices[points[i+1]].y + 1.0f) * fY, verts[points[i+1]].z
				, (temp_vertices[points[i+2]].x + 1.0f) * fX, (temp_vertices[points[i+2]].y + 1.0f) * fY, verts[points[i+2]].z
				, colors[points[i+0]].rgbaq, colors[points[i+1]].rgbaq, colors[points[i+2]].rgbaq);
		}
#ifdef HIRES_MODE
		gsKit_hires_sync(gsGlobal);
		gsKit_hires_flip(gsGlobal);
#else
		gsKit_queue_exec(gsGlobal);
		gsKit_sync_flip(gsGlobal);
#endif
	}

	free(temp_normals);
	free(temp_lights);
	free(temp_colours);
	free(temp_vertices);
	free(verts);
	free(colors);

	return 0;

}