Esempio n. 1
0
File: util.c Progetto: 4ZM/Slic3r
void
stl_rotate_z(stl_file *stl, float angle)
{
  int i;
  int j;
  
  for(i = 0; i < stl->stats.number_of_facets; i++)
    {
      for(j = 0; j < 3; j++)
	{
	  stl_rotate(&stl->facet_start[i].vertex[j].x,
		     &stl->facet_start[i].vertex[j].y, angle);
	}
    }
  stl_get_size(stl);
	calculate_normals(stl);
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
	float min, max;

	setlocale(LC_ALL, "C");
	process_options(argc, argv);

	snis_srand((unsigned int) random_seed);
	open_simplex_noise(random_seed, &ctx);
	printf("Loading %s\n", heightfile);
	sampledata = load_image(heightfile, &samplew, &sampleh, &samplea,
					&sample_bytes_per_row);
	printf("Loading %s\n", landfile);
	land = load_image(landfile, &landw, &landh, &landa, &landbpr);
	printf("Loading %s\n", waterfile);
	water = load_image(waterfile, &waterw, &waterh, &watera, &waterbpr);
	printf("Allocating output images.\n");
	allocate_output_images();
	printf("Initializing vertices.\n");
	initialize_vertices();
	find_min_max_height(&min, &max);
	add_bumps(initial_bumps);
	add_craters(ncraters);
	printf("Rendering %d total bumps\n", totalbumps);
	render_all_bumps();
	render_all_craters(min, max);
	find_min_max_height(&min, &max);
	printf("min h = %f, max h = %f\n", min, max);
	paint_height_maps(min, max);
	calculate_normals();
	paint_normal_and_height_maps(min, max);
	printf("painting terrain colors\n");
	paint_terrain_colors(min, max);
	printf("Writing color textures\n");
	save_output_images();
	printf("Writing normal maps\n");
	save_normal_maps();
	printf("Writing height maps\n");
	save_height_maps();
	open_simplex_noise_free(ctx);
	printf("Done.\n");
	return 0;
}
Esempio n. 3
0
  void Cube::internal_buffer_data(Abstract_material_ptr i_material)
  {
    const GLsizei vertices = 24;
    m_triangle_count = 36;

    // the 4 vertices of a box 
    const GLfloat box[vertices][4] = 
    {
      /* front */
      {  -m_size, -m_size,  m_size, 1.0f  },   
      {  m_size,  -m_size,  m_size, 1.0f  },   
      {  m_size,  m_size, m_size, 1.0f  },   
      {  -m_size, m_size, m_size, 1.0f  },

      /* left */
      {  -m_size, -m_size,  -m_size, 1.0f },   
      {  -m_size, -m_size,  m_size, 1.0f  },   
      {  -m_size, m_size, m_size, 1.0f  },   
      {  -m_size, m_size, -m_size, 1.0f },

      /* right */
      {  m_size,  -m_size,  m_size, 1.0f  },   
      {  m_size,  -m_size,  -m_size, 1.0f },   
      {  m_size,  m_size, -m_size, 1.0f },   
      {  m_size,  m_size, m_size, 1.0f  },

      /* top */
      {  -m_size, m_size, m_size, 1.0f  },   
      {  m_size,  m_size, m_size, 1.0f  },   
      {  m_size,  m_size, -m_size, 1.0f },   
      {  -m_size, m_size, -m_size, 1.0f },

      /* bottom */
      {  -m_size, -m_size,  -m_size, 1.0f },   
      {  m_size,  -m_size,  -m_size, 1.0f },   
      {  m_size,  -m_size,  m_size, 1.0f  },   
      {  -m_size, -m_size,  m_size, 1.0f  },

      /* back */
      {  m_size,  -m_size,  -m_size, 1.0f },   
      {  -m_size, -m_size,  -m_size, 1.0f },   
      {  -m_size, m_size, -m_size, 1.0f },   
      {  m_size,  m_size, -m_size, 1.0f },
    };

    const GLuint boxindices[36] = 
    { 
      /* front */
      0, 1, 2, 
      2, 3, 0,

      /* left */
      4, 5, 6, 
      6, 7, 4,

      /* right */
      8, 9, 10, 
      10, 11, 8,

      /* top */
      12, 13, 14, 
      14, 15, 12,

      /* bottom */
      16, 17, 18, 
      18, 19, 16,

      /* back */
      20, 21, 22, 
      22, 23, 20,
    };

    GLfloat normals[vertices][4];

    // generate the normals
    calculate_normals(&box[0][0], vertices, &boxindices[0], m_triangle_count, &normals[0][0]);

    // buffer all data
    
    Shader_program * material_shader = i_material->get_shader();
    
    glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id[to_integral(VBO_type::Position)]);
    glBufferData(GL_ARRAY_BUFFER, vertices * 4 * sizeof(GLfloat), box, GL_STATIC_DRAW);
    GLint vertex_attrib_location = material_shader->get_attribute_location(in_position);
    glEnableVertexAttribArray(vertex_attrib_location);
    glVertexAttribPointer(vertex_attrib_location, 4, GL_FLOAT, GL_FALSE, 0, 0);

    glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id[to_integral(VBO_type::Normal)]);
    glBufferData(GL_ARRAY_BUFFER, vertices * 4 * sizeof(GLfloat), normals, GL_STATIC_DRAW);
    GLint normals_attrib_location = material_shader->get_attribute_location(in_normal);
    glEnableVertexAttribArray(normals_attrib_location);
    glVertexAttribPointer(normals_attrib_location, 4, GL_FLOAT, GL_FALSE, 0, 0);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_vbo_id[to_integral(VBO_type::Index)]);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_triangle_count * sizeof(GL_UNSIGNED_INT), boxindices, GL_STATIC_DRAW);

    // disable pointers & unbind buffers
    glDisableVertexAttribArray(vertex_attrib_location);
    glDisableVertexAttribArray(normals_attrib_location);
    glBindBuffer( GL_ARRAY_BUFFER, 0 );
    glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
  }
Esempio n. 4
0
File: main.c Progetto: 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;

}
Esempio n. 5
0
Model::Model(std::vector<tinyobj::shape_t> shapes, std::vector<tinyobj::material_t> materials, std::vector<Material> materials_ref) :
  shapes_(shapes),
  materials_(materials),
  materials_ref_(materials_ref){
  calculate_normals();
}