void make_shape(Shape *vert) { double ray = 1; // radius int height = 1; // height double torus_radius = 1.2; // radius from origin to center of tube double tube_radius = 0.2; // tube radius GLfloat p0[3] = {0,0,0}; GLfloat p1[3] = {0,1,0}; theLine.type = LINE; float l1 = 1.0; float l2 = 0.75; float l3 = 0.50; switch(vert->type) { case HOUSE: make_house(vert);break; case SPHERE: make_sphere(vert, ray); break; case CYLINDER: make_cylinder(vert, ray, height); break; case CONE: make_cone(vert, height, ray); break; case TORUS: make_torus(vert,torus_radius, tube_radius); break; case CUBE: make_cube_smart(vert, 2); break; case LINE: make_line(vert, p0, p1); case SUPER: make_quadric(vert, l1, l2, l3); } }
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__); }
/*TODO add make_cone, make_torus, make_your_shape etc. */ void my_setup(){ crt_render_mode = GL_POLYGON;//GL_LINE_LOOP; crt_shape = HOUSE; crt_transform = NONE_MODE; crt_rs = 20; crt_vs = 10; make_cube_smart(1); make_cylinder(cyl_height,cyl_ray,crt_rs,crt_vs); make_sphere(sph_ray,crt_rs,crt_vs); return; }
/*TODO EC: add make_torus etc. */ void my_setup(void) { theta_x = 0; theta_y = 0; crt_render_mode = GL_LINE_LOOP; crt_shape = HOUSE; crt_rs = 20; crt_vs = 10; make_cylinder(cyl_height,cyl_ray,crt_rs,crt_vs); make_sphere(sph_ray,crt_rs,crt_vs); //add make_torus etc... return; }
/** Create a list of surfaces. */ list356_t* get_surfaces() { debug("get_surfaces()") ; // Spheres along the negative x, y, and z axes. list356_t* surfaces = make_list() ; surface_t* z_sphere ; for (float x=0.0; x>=-40.0; x-=3.0) { lst_add(surfaces, make_sphere(x, 0.0, 0.0f, 1.0f, &GREEN, &GREEN, &WHITE, 100.0f)) ; lst_add(surfaces, make_sphere(0.0f, x, 0.0f, .25, &PURPLE, &PURPLE, &WHITE, 100.0f)) ; lst_add(surfaces, (z_sphere = make_sphere(0.0f, 0.0f, x, .25, &PURPLE, &PURPLE, &WHITE, 100.0f))) ; z_sphere->refl_color = &LIGHT_GREY ; } // A rectangle in the y=-1 plane. surface_t* tri1 = make_triangle( (point3_t){-40, -1, 2}, (point3_t){2, -1, 2}, (point3_t){2, -1, -20}, &LIGHT_GREY, &LIGHT_GREY, &BLACK, 10.0f) ; surface_t* tri2 = make_triangle( (point3_t){-40, -1, 2}, (point3_t){2, -1, -20}, (point3_t){-40, -1, -20}, &LIGHT_GREY, &LIGHT_GREY, &BLACK, 10.0f) ; tri1->refl_color = &DARK_GREY ; tri2->refl_color = &DARK_GREY ; lst_add(surfaces, tri1) ; lst_add(surfaces, tri2) ; return surfaces ; }
ExperimentalApp() : GLFWApp(1280, 800, "Glass Material App") { igm.reset(new gui::ImGuiManager(window)); gui::make_dark_theme(); //cubeTex = load_cubemap(); int width, height; glfwGetWindowSize(window, &width, &height); glViewport(0, 0, width, height); // Debugging views for offscreen surfaces uiSurface.bounds = {0, 0, (float) width, (float) height}; uiSurface.add_child( {{0.0000f, +10},{0, +10},{0.1667f, -10},{0.133f, +10}}); uiSurface.add_child( {{0.1667f, +10},{0, +10},{0.3334f, -10},{0.133f, +10}}); uiSurface.layout(); grid = RenderableGrid(1, 100, 100); cameraController.set_camera(&camera); camera.look_at({0, 2.5, -2.5}, {0, 2.0, 0}); lights[0] = {{0, 10, -10}, {0, 0, 1}}; lights[1] = {{0, 10, 10}, {0, 1, 0}}; Renderable reflectiveSphere = Renderable(make_sphere(2.f)); reflectiveSphere.pose = Pose(float4(0, 0, 0, 1), float3(0, 2, 0)); glassModels.push_back(std::move(reflectiveSphere)); Renderable debugAxis = Renderable(make_axis(), false, GL_LINES); debugAxis.pose = Pose(float4(0, 0, 0, 1), float3(0, 1, 0)); regularModels.push_back(std::move(debugAxis)); Renderable cubeA = Renderable(make_cube()); cubeA.pose = Pose(make_rotation_quat_axis_angle({1, 0, 1}, ANVIL_PI / 3), float3(5, 0, 0)); regularModels.push_back(std::move(cubeA)); Renderable cubeB = Renderable(make_cube()); cubeB.pose = Pose(make_rotation_quat_axis_angle({1, 0, 1}, ANVIL_PI / 4), float3(-5, 0, 0)); regularModels.push_back(std::move(cubeB)); glassMaterialShader = make_watched_shader(shaderMonitor, "assets/shaders/glass_vert.glsl", "assets/shaders/glass_frag.glsl"); simpleShader = make_watched_shader(shaderMonitor, "assets/shaders/simple_vert.glsl", "assets/shaders/simple_frag.glsl"); cubeCamera.reset(new CubemapCamera({1024, 1024})); gl_check_error(__FILE__, __LINE__); }
/** Create a list of surfaces. */ list356_t* get_surfaces() { debug("get_surfaces()") ; // Spheres along the negative x, y, and z axes. list356_t* surfaces = make_list() ; list356_t* bbt_surfaces = make_list() ; surface_t* z_sphere ; surface_t* green_sphere; for (float x=0.0; x>=-400.0; x-=1.0) { lst_add(bbt_surfaces, (green_sphere = make_sphere(x, 0.0, 0.0f, 1.0f, &GREEN, &GREEN, &WHITE, 100.0f))) ; // green_sphere->refl_color = &LIGHT_GREY; lst_add(bbt_surfaces, make_sphere(0.0f, x, 0.0f, .25, &PURPLE, &PURPLE, &WHITE, 100.0f)) ; lst_add(bbt_surfaces, (z_sphere = make_sphere(0.0f, 0.0f, x, .25, &PURPLE, &PURPLE, &WHITE, 100.0f))) ; z_sphere->refl_color = &LIGHT_GREY ; } lst_add(bbt_surfaces, make_sphere(-9.0f, 1.0f, -9.0f, 2.0f, &WHITE, &WHITE, &WHITE, 90.0f)); lst_add(bbt_surfaces, make_sphere(-9.0f, 1.0f, -8.0f, 2.0f, &WHITE, &WHITE, &WHITE, 90.0f)); lst_add(bbt_surfaces, make_sphere(-9.0f, 1.0f, -6.0f, 2.0f, &WHITE, &WHITE, &WHITE, 90.0f)); // A rectangle in the y=-1 plane. surface_t* tri1 = make_triangle( (point3_t){-40, -1, 2}, (point3_t){2, -1, 2}, (point3_t){2, -1, -20}, &LIGHT_GREY, &LIGHT_GREY, &BLACK, 10.0f) ; surface_t* tri2 = make_triangle( (point3_t){-40, -1, 2}, (point3_t){2, -1, -20}, (point3_t){-40, -1, -20}, &LIGHT_GREY, &LIGHT_GREY, &BLACK, 10.0f) ; tri1->refl_color = &DARK_GREY ; tri2->refl_color = &DARK_GREY ; lst_add(surfaces, tri1) ; lst_add(surfaces, tri2) ; // An infinite plane in the y=-2 plane. /* surface_t* plane = make_plane( (point3_t){-40, -2, 2}, (point3_t){2, -2, 2}, (point3_t){2, -2, -20}, &RED, &RED, &BLACK, 10.0f); plane->refl_color = &DARK_GREY; lst_add(surfaces, plane); */ lst_add(surfaces, make_bbt_node(bbt_surfaces)); return surfaces ; }
void parse_obj(char *buffer){ OBJECT *po; char *pshape, *pshine, *pemi, *pamb, *pdiff, *pspec, *ptranslate, *pscale, *protate; my_assert ((num_objects < NUM_OBJECTS), "too many objects"); po = &my_objects[num_objects++]; pshape = strtok(buffer, " "); //printf("pshape is %s\n",pshape); ptranslate = strtok(NULL, "()"); strtok(NULL, "()"); pscale = strtok(NULL, "()"); strtok(NULL, "()"); protate = strtok(NULL, "()"); strtok(NULL, "()"); pshine = strtok(NULL, "()");strtok(NULL, "()"); //printf("pshine is %s\n",pshine); pemi = strtok(NULL, "()"); strtok(NULL, "()"); pamb = strtok(NULL, "()"); strtok(NULL, "()"); pdiff = strtok(NULL, "()"); strtok(NULL, "()"); pspec = strtok(NULL, "()"); strtok(NULL, "()"); po->sid = atoi(pshape); printf("%d",po->sid); po->shine = atof(pshine); parse_floats(ptranslate, po->translate); parse_floats(pscale, po->scale); parse_floats(protate, po->rotate); parse_floats(pemi, po->emi); parse_floats(pamb, po->amb); parse_floats(pdiff, po->diff); parse_floats(pspec, po->spec); // use switch to create your objects, cube given as example switch (po->sid){ case 0: // makes house make_house(po); break; case 1: //cube make_cube_smart(po, 1); break; case 2: make_sphere(po, 1); break; case 3: make_cone(po, 1, 1); break; case 4: make_torus(po, 1.2, .1); break; } // scale, rotate, translate using your real tranformations from assignment 3 depending on input from spec file real_scaling(po, po->scale[0], po->scale[1], po->scale[2]); real_rotation(po, po->rotate[0], 1, 0, 0); real_rotation(po, po->rotate[1], 0, 1, 0); real_rotation(po, po->rotate[2], 0, 0, 1); real_translation(po, po->translate[0], po->translate[1], po->translate[2]); printf("read object\n"); }
/** Create a list of surfaces. */ list356_t* get_surfaces() { list356_t* surfaces = make_list() ; // Table. point3_t vertices[8] = { {0, 0, 1}, {8, 0, 1}, {0, 8, 1}, {8, 8, 1}, {0, 0, -1}, {8, 0, -1}, {0, 8, -1}, {8, 8, -1}, } ; int indices[] = { 0, 1, 3, 0, 3, 2, // top 0, 2, 6, 0, 6, 4, // left 4, 6, 7, 4, 7, 5, // bottom 1, 5, 7, 1, 7, 3, // right 2, 3, 7, 2, 7, 6, // back 0, 4, 5, 0, 5, 1 // front } ; int top_offset = 6 ; int offset = 36 ; list356_t* table_surfaces = make_list() ; for (int i=0; i<top_offset/3; ++i) { lst_add(table_surfaces, make_triangle( vertices[indices[3*i]], vertices[indices[3*i+1]], vertices[indices[3*i+2]], &RED, &RED, &WHITE, 10.0f)) ; } for (int i=top_offset/3; i<offset/3; ++i) { lst_add(table_surfaces, make_triangle( vertices[indices[3*i]], vertices[indices[3*i+1]], vertices[indices[3*i+2]], &GREEN, &GREEN, &WHITE, 10.0f)) ; } // Two purple spheres. lst_add(table_surfaces, make_sphere(6, 6, 1.75+.01, .75, &PURPLE, &PURPLE, &WHITE, 100.0f)) ; lst_add(table_surfaces, make_sphere(5, 2, 1.75+.01, .75, &PURPLE, &PURPLE, &WHITE, 100.0f)) ; // Transparent cube. point3_t cube_vertices[] = { {4, 0, 3}, {5, 0, 3}, {4, 1, 3}, {5, 1, 3}, {4, 0, 1.01}, {5, 0, 1.01}, {4, 1, 1.01}, {5, 1, 1.01}, } ; for (int i=0; i<offset/3; ++i) { surface_t* t = make_triangle( cube_vertices[indices[3*i]], cube_vertices[indices[3*i+1]], cube_vertices[indices[3*i+2]], &BLACK, &BLACK, &WHITE, 10.0f) ; t->refr_index = 1.1f ; t->atten = &GREENISH ; lst_add(surfaces, t) ; } list356_itr_t* itr = lst_iterator(table_surfaces) ; while (lst_has_next(itr)) lst_add(surfaces, lst_next(itr)) ; lst_free(table_surfaces) ; // Plane at z=-1. surface_t* plane = make_plane( (point3_t){0, 0, -1}, (point3_t){1, 0, -1}, (point3_t){1, 1, -1}, &LIGHT_GREY, &LIGHT_GREY, &BLACK, 10.0f) ; plane->refl_color = &LIGHT_GREY ; lst_add(surfaces, plane) ; return surfaces ; }
void maininit(int argc, char **argv) { GLfloat specular [] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat shininess [] = { 100.0 }; GLfloat position [] = { 1.0, 1.0, 1.0, 0.0 }; printf("Press T or Esc\n"); fflush(stdout); glutInit(&argc, argv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_ALPHA | GLUT_DEPTH); glutInitWindowSize(500, 500); glutInitWindowPosition(50, 50); glutCreateWindow("Light"); glBlendFunc (GL_SRC_ALPHA_SATURATE, GL_ONE); // Set the clear color to black glClearColor(0.5, 0.4, 0.3, 0.2); // Set the shading model glShadeModel(GL_SMOOTH); // Set the polygon mode to fill // glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPolygonMode(GL_FRONT, GL_FILL); // Enable depth testing for hidden line removal glEnable(GL_DEPTH_TEST); // Define material properties of specular color and degree of // shininess. Since this is only done once in this particular // example, it applies to all objects. Material properties can // be set for individual objects, individual faces of the objects, // individual vertices of the faces, etc... // glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular); glMaterialfv(GL_FRONT, GL_SPECULAR, specular); // glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shininess); glMaterialfv(GL_FRONT, GL_SHININESS, shininess); // Set the GL_AMBIENT_AND_DIFFUSE color state variable to be the // one referred to by all following calls to glColor // glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); glEnable(GL_COLOR_MATERIAL); // Create a Directional Light Source glLightfv(GL_LIGHT0, GL_POSITION, position); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); // Create the display lists make_sphere(); make_cube(); // Assign reshape() to be the function called whenever // an expose event occurs // tkExposeFunc(reshape); glutReshapeFunc (reshape); // Assign reshape() to be the function called whenever // a reshape event occurs //?? tkReshapeFunc(reshape); // Assign key_down() to be the function called whenever // a key is pressed glutKeyboardFunc (keyboard); // Assign draw() to be the function called whenever a display // event occurs, generally after a resize or expose event // tkDisplayFunc(draw); glutDisplayFunc (draw); // Pass program control to tk's event handling code // In other words, loop forever // tkExec(); glutMainLoop(); }
ExperimentalApp() : GLFWApp(1280, 720, "Shadow App") { glfwSwapInterval(0); gen = std::mt19937(rd()); igm.reset(new gui::ImGuiManager(window)); gui::make_dark_theme(); int width, height; glfwGetWindowSize(window, &width, &height); glViewport(0, 0, width, height); cameraController.set_camera(&camera); camera.farClip = 55.f; camera.look_at({0, 0, +15}, {0, 0, 0}); // Debugging views uiSurface.bounds = {0, 0, (float) width, (float) height}; uiSurface.add_child( {{0.0000f, +10},{0, +10},{0.1667f, -10},{0.133f, +10}}); uiSurface.add_child( {{0.1667f, +10},{0, +10},{0.3334f, -10},{0.133f, +10}}); uiSurface.add_child( {{0.3334f, +10},{0, +10},{0.5009f, -10},{0.133f, +10}}); uiSurface.add_child( {{0.5000f, +10},{0, +10},{0.6668f, -10},{0.133f, +10}}); uiSurface.add_child( {{0.6668f, +10},{0, +10},{0.8335f, -10},{0.133f, +10}}); uiSurface.add_child( {{0.8335f, +10},{0, +10},{1.0000f, -10},{0.133f, +10}}); uiSurface.layout(); fullscreen_post_quad = make_fullscreen_quad(); sceneShader = make_watched_shader(shaderMonitor, "assets/shaders/shadow/scene_vert.glsl", "assets/shaders/shadow/scene_frag.glsl"); shadowmapShader = make_watched_shader(shaderMonitor, "assets/shaders/shadow/shadowmap_vert.glsl", "assets/shaders/shadow/shadowmap_frag.glsl"); pointLightShader = make_watched_shader(shaderMonitor, "assets/shaders/shadow/point_light_vert.glsl", "assets/shaders/shadow/point_light_frag.glsl"); gaussianBlurShader = make_watched_shader(shaderMonitor, "assets/shaders/gaussian_blur_vert.glsl", "assets/shaders/gaussian_blur_frag.glsl"); skydome.recompute(2, 10.f, 1.15f); auto lightDir = skydome.get_light_direction(); sunLight = std::make_shared<DirectionalLight>(lightDir, float3(.50f, .75f, .825f), 64.f); // todo spotLightB shadowDepthTexture.load_data(shadowmapResolution, shadowmapResolution, GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); shadowFramebuffer.attach(GL_DEPTH_ATTACHMENT, shadowDepthTexture); if (!shadowFramebuffer.check_complete()) throw std::runtime_error("incomplete shadow framebuffer"); shadowBlurTexture.load_data(shadowmapResolution, shadowmapResolution, GL_R32F, GL_RGBA, GL_FLOAT, nullptr); shadowBlurFramebuffer.attach(GL_COLOR_ATTACHMENT0, shadowBlurTexture); if (!shadowBlurFramebuffer.check_complete()) throw std::runtime_error("incomplete blur framebuffer"); auto spotLightA = std::make_shared<SpotLight>(float3(0.f, 10.f, 0.f), float3(0.f, -1.f, 0.f), float3(0.766f, 0.766f, 0.005f), 30.0f, float3(1.0f, 0.0f, 0.0001f)); spotLights.push_back(spotLightA); // Single spotlight fbo for (int i = 0; i < 1; ++i) { auto buffer = std::make_shared<SpotLightFramebuffer>(); buffer->create(shadowmapResolution); spotLightFramebuffers.push_back(buffer); } // Point light init { pointLight.reset(new PointLight(float3(0.f, 0.f, 0.f), float3(0, 1, 1), float3(1.0f, 0.05f, 0.0002f))); pointLightFramebuffer.reset(new PointLightFramebuffer()); pointLightFramebuffer->create(float2(shadowmapResolution)); pointLightSphere = std::make_shared<Renderable>(make_sphere(0.5f)); sceneObjects.push_back(pointLightSphere); } viewA.reset(new GLTextureView(shadowDepthTexture.get_gl_handle())); viewB.reset(new GLTextureView(shadowBlurTexture.get_gl_handle())); viewC.reset(new GLTextureView(spotLightFramebuffers[0]->shadowDepthTexture.get_gl_handle())); viewD.reset(new GLTextureView(pointLightFramebuffer->depthBuffer.get_gl_handle())); auto lucy = load_geometry_from_ply("assets/models/stanford/lucy.ply"); rescale_geometry(lucy, 8.0f); auto lucyBounds = lucy.compute_bounds(); auto statue = std::make_shared<Renderable>(lucy); statue->pose.position = {0, 0, 0}; //sceneObjects.push_back(statue); auto hollowCube = load_geometry_from_ply("assets/models/geometry/CubeHollowOpen.ply"); for (auto & v : hollowCube.vertices) v *= 0.20f; auto hCube = std::make_shared<Renderable>(hollowCube); hCube->pose.position = float3(0, 0, 0); hCube->pose.orientation = make_rotation_quat_around_x(ANVIL_PI / 2); //sceneObjects.push_back(hCube); auto curvedMesh = make_curved_plane(2, 1, 8, 8); sceneObjects.push_back(std::make_shared<Renderable>(curvedMesh)); //floor = std::make_shared<Renderable>(make_plane(32.f, 32.f, 64, 64), false); //floor->pose.orientation = make_rotation_quat_axis_angle({1, 0, 0}, -ANVIL_PI / 2); //floor->pose.position = {0, lucyBounds.min().y, 0}; //sceneObjects.push_back(floor); gl_check_error(__FILE__, __LINE__); }
void rg(list356_t* surfaces, point3_t* eye, point3_t* look_at) { //update eye and look_at positions point3_t eye_position = {4.0f, -4.0f, 8.0f} ; point3_t look_at_point = {4.0f, 4.0f, 1.0f} ; *eye = eye_position; *look_at = look_at_point; // Chess board. list356_t* board_surfaces = make_list() ; // All the vertices. point3_t vertices[85] ; for (int x=0; x<9; ++x) { for (int y=0; y<9; ++y) { vertices[9*y+x] = (point3_t){x, y, 1} ; } } vertices[81] = (point3_t){0, 0, -1} ; vertices[82] = (point3_t){8, 0, -1} ; vertices[83] = (point3_t){0, 8, -1} ; vertices[84] = (point3_t){8, 8, -1} ; int indices[138*3] ; int offset = 0 ; // Top of chess board. for (int x=0; x<8; ++x) { for (int y=0; y<8; ++y) { indices[offset++] = 9*y+x ; indices[offset++] = 9*y+x+1 ; indices[offset++] = 9*(y+1)+x+1 ; indices[offset++] = 9*y+x ; indices[offset++] = 9*(y+1)+x+1 ; indices[offset++] = 9*(y+1)+x ; } } int top_offset = offset ; // Sides and bottom. indices[offset++] = 81 ; indices[offset++] = 82; indices[offset++] = 8 ; indices[offset++] = 81 ; indices[offset++] = 8; indices[offset++] = 0 ; indices[offset++] = 8 ; indices[offset++] = 82 ; indices[offset++] = 84 ; indices[offset++] = 8 ; indices[offset++] = 84 ; indices[offset++] = 80 ; indices[offset++] = 72 ; indices[offset++] = 80 ; indices[offset++] = 84 ; indices[offset++] = 72 ; indices[offset++ ] = 84 ; indices[offset++] = 83 ; indices[offset++] = 0 ; indices[offset++] = 72 ; indices[offset++] = 83 ; indices[offset++] = 0 ; indices[offset++] = 83 ; indices[offset++] = 81 ; indices[offset++] = 81 ; indices[offset++] = 83 ; indices[offset++] =84 ; indices[offset++] = 81 ; indices[offset++] = 84 ; indices[offset++] = 82 ; debug("get_surfaces(): final offset = %d", offset) ; // Top as triangles. for (int i=0; i<top_offset/3; ++i) { int c = (i/2)%8 ; int r = (i/2)/8 ; int j = r+c ; color_t* color = j%2 == 0 ? &RED : &BLACK ; lst_add(board_surfaces, make_triangle( vertices[indices[3*i]], vertices[indices[3*i+1]], vertices[indices[3*i+2]], color, color, &WHITE, 10.0f)) ; } // Sides and bottom at triangles. for (int i=top_offset/3; i<offset/3; ++i) { lst_add(board_surfaces, make_triangle( vertices[indices[3*i]], vertices[indices[3*i+1]], vertices[indices[3*i+2]], &LIGHT_GREY, &LIGHT_GREY, &WHITE, 10.0f)) ; } //// "Pieces" //for (int c=0; c<8; ++c) { // for (int r=0; r<2; ++r) { // surface_t* s = make_sphere(c+.5, r+.5, 1.375+.01, .375, // &BLACK, &BLACK, &WHITE, 100.0f) ; // lst_add(board_surfaces, s) ; // } // //for (int r=6; r<8; ++r) { // // lst_add(board_surfaces, make_sphere(c+.5, r+.5, 1.25, .25, // // &WHITE, &WHITE, &WHITE, 100.0f)) ; // //} //} // Draw R manually // Define squares to place spheres on void add_sphere(c,r) { lst_add(board_surfaces, make_sphere(c+.5, r+.5, 1.75, .50, &GREEN, &GREEN, &BLACK, 150.0f)) ; }
ExperimentalApp() : GLFWApp(1280, 800, "Geometric Algorithm Development App") { glfwSwapInterval(0); igm.reset(new gui::ImGuiManager(window)); gui::make_dark_theme(); fixedTimer.start(); lights[0] = {{0, 10, -10}, {0, 0, 1}}; lights[1] = {{0, 10, 10}, {0, 1, 0}}; int width, height; glfwGetWindowSize(window, &width, &height); glViewport(0, 0, width, height); grid = RenderableGrid(1, 100, 100); cameraController.set_camera(&camera); camera.look_at({0, 2.5, -2.5}, {0, 2.0, 0}); simpleShader = make_watched_shader(shaderMonitor, "../assets/shaders/simple_vert.glsl", "assets/shaders/simple_frag.glsl"); normalDebugShader = make_watched_shader(shaderMonitor, "../assets/shaders/normal_debug_vert.glsl", "assets/shaders/normal_debug_frag.glsl"); Renderable debugAxis = Renderable(make_axis(), false, GL_LINES); debugAxis.pose = Pose(float4(0, 0, 0, 1), float3(0, 1, 0)); debugModels.push_back(std::move(debugAxis)); // Initial supershape settings supershape = Renderable(make_supershape_3d(16, 5, 7, 4, 12)); supershape.pose.position = {0, 2, -2}; // Initialize PTF stuff { std::array<float3, 4> controlPoints = {float3(0.0f, 0.0f, 0.0f), float3(0.667f, 0.25f, 0.0f), float3(1.33f, 0.25f, 0.0f), float3(2.0f, 0.0f, 0.0f)}; ptf = make_parallel_transport_frame_bezier(controlPoints, 32); for (int i = 0; i < ptf.size(); ++i) { Renderable p = Renderable(make_cube()); ptfBoxes.push_back(std::move(p)); } } // Initialize Parabolic pointer stuff { // Set up the ground plane used as a nav mesh for the parabolic pointer worldSurface = make_plane(48, 48, 96, 96); for (auto & p : worldSurface.vertices) { float4x4 model = make_rotation_matrix({1, 0, 0}, -ANVIL_PI / 2); p = transform_coord(model, p); } worldSurfaceRenderable = Renderable(worldSurface); parabolicPointer = make_parabolic_pointer(worldSurface, params); } // Initialize objects for ballistic trajectory tests { turret.source = Renderable(make_tetrahedron()); turret.source.pose = Pose({-5, 2, 5}); turret.target = Renderable(make_cube()); turret.target.pose = Pose({0, 0, 40}); turret.bullet = Renderable(make_sphere(1.0f)); } float4x4 tMat = mul(make_translation_matrix({3, 4, 5}), make_rotation_matrix({0, 0, 1}, ANVIL_PI / 2)); auto p = make_pose_from_transform_matrix(tMat); std::cout << tMat << std::endl; std::cout << p << std::endl; gl_check_error(__FILE__, __LINE__); }