예제 #1
0
 ExperimentalApp() : GLFWApp(940, 720, "GlCamera Sandbox App")
 {
     int width, height;
     glfwGetWindowSize(window, &width, &height);
     glViewport(0, 0, width, height);
     
     cameraController.set_camera(&camera);
     
     camera.look_at({0, 8, 24}, {0, 0, 0});
     cameraZ = camera.pose.position.z;
     
     simpleShader.reset(new GlShader(read_file_text("assets/shaders/simple_vert.glsl"), read_file_text("assets/shaders/simple_frag.glsl")));
     
     {
         lights.resize(2);
         lights[0].color = float3(249.f / 255.f, 228.f / 255.f, 157.f / 255.f);
         lights[0].pose.position = float3(25, 15, 0);
         lights[1].color = float3(255.f / 255.f, 242.f / 255.f, 254.f / 255.f);
         lights[1].pose.position = float3(-25, 15, 0);
     }
     
     {
         cameraPositions.resize(2);
         cameraPositions[0] = Renderable(make_frustum());
         cameraPositions[0].pose.position = float3(0, 8, +24);
         cameraPositions[0].mesh.set_non_indexed(GL_LINES);
         
         cameraPositions[1] = Renderable(make_frustum());
         cameraPositions[1].pose.position = float3(0, 8, -24);
         cameraPositions[1].mesh.set_non_indexed(GL_LINES);
     }
     
     {
         proceduralModels.resize(4);
         
         proceduralModels[0] = Renderable(make_sphere(1.0));
         proceduralModels[0].pose.position = float3(0, 2, +8);
         
         proceduralModels[1] = Renderable(make_cube());
         proceduralModels[1].pose.position = float3(0, 2, -8);
         
         proceduralModels[2] = Renderable(make_icosahedron());
         proceduralModels[2].pose.position = float3(8, 2, 0);
         
         proceduralModels[3] = Renderable(make_octohedron());
         proceduralModels[3].pose.position = float3(-8, 2, 0);
     }
     
     start = look_at_pose(float3(0, 8, +24), float3(-8, 2, 0));
     end = look_at_pose(float3(0, 8, -24), float3(-8, 2, 0));
     
     grid = RenderableGrid(1, 64, 64);
     
     gl_check_error(__FILE__, __LINE__);
 }
예제 #2
0
static void reshape(int w, int h)
{
	glViewport(0, 0, (GLsizei)w, (GLsizei)h);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	make_frustum(60, w / (GLfloat)h, 1.0, 100.0);
	glMatrixMode(GL_MODELVIEW);
}
예제 #3
0
// Equivalent to gluPerspective
const float4x4 make_perspective(float fov, float aspect_ratio, float near, float far)
{
	float ymax = near * tanf(fov * M_PI / 360.0f);
	float xmax = ymax * aspect_ratio;
	return make_frustum(-xmax, xmax, -ymax, ymax, near, far);	
}