#include "bird.hpp" void bird::initialize_bird() { // Initialize the temporary mesh_drawable that will be inserted in the hierarchy mesh_drawable b_base; mesh_drawable b_head; mesh_drawable b_beak; mesh_drawable b_eye; mesh_drawable b_wingl1; mesh_drawable b_wingl2; mesh_drawable b_wingr1; mesh_drawable b_wingr2; // Create the geometry of the meshes // Note: this geometry must be set in their local coordinates with respect to their position in the hierarchy (and with respect to their animation) b_base.initialize_data_on_gpu(mesh_primitive_ellipsoid({ 1.7f,1,1 })); b_head.initialize_data_on_gpu(mesh_primitive_sphere(0.6f)); b_eye.initialize_data_on_gpu(mesh_primitive_sphere(0.1f)); b_beak.initialize_data_on_gpu(mesh_primitive_cone(0.3f, 0.4f, { 0,0,0 }, { 1,0,0 })); b_wingl1.initialize_data_on_gpu(mesh_primitive_quadrangle({ 1,0,0 }, { 1,1.5f,0 }, { -1,1.5f,0 }, { -1,0,0 })); b_wingl2.initialize_data_on_gpu(mesh_primitive_quadrangle({ 1,0,0 }, { 0.2f,1,0 }, { -0.4,1,0 }, { -1, 0, 0 })); b_wingr1.initialize_data_on_gpu(mesh_primitive_quadrangle({ -1,0,0 }, { -1,-1.5f,0 }, { 1,-1.5f,0 }, { 1,0,0 })); b_wingr2.initialize_data_on_gpu(mesh_primitive_quadrangle({ -1, 0, 0 }, { -0.4,-1,0 }, { 0.2f,-1,0 }, { 1,0,0 })); // Set the color of some elements vec3 color1 = { 0.8f, 0.5f, 0.7f }; vec3 color2 = { 1.0f, 0.8f, 0.0f }; vec3 color_w = { 1.0f, 1.0f, 1.0f }; vec3 color_b = { 0.0f,0.0f,0.0f }; vec3 color_o = { 1.0f,0.23f,0.0f }; b_base.material.color = color_w; b_head.material.color = color_w; b_beak.material.color = color_o; b_eye.material.color = color_b; b_wingl1.material.color = color_w; b_wingl2.material.color = color_w; b_wingr1.material.color = color_w; b_wingr2.material.color = color_w; // Add the elements in the hierarchy // The syntax is hierarchy.add(mesh_drawable, "name of the parent element", [optional: local translation in the hierarchy]) // Notes: // - An element must necessarily be added after its parent // - The first element (without explicit name of its parent) is assumed to be the root. bird.add(b_base, "Bird base"); bird.add(b_head, "Bird head", "Bird base", { 2.0f,0,0.6f }); bird.add(b_beak, "Bird beak", "Bird head", { 0.4f, 0, 0 }); bird.add(b_eye, "Bird eye left", "Bird head", { 0.4f, -0.15f,0.4f }); bird.add(b_eye, "Bird eye right", "Bird head", { 0.4f, 0.15f,0.4f }); bird.add(b_wingl1, "Bird wing left1", "Bird base"); bird.add(b_wingl2, "Bird wing left2", "Bird wing left1", { 0,1.5f,0 }); bird.add(b_wingr1, "Bird wing right1", "Bird base"); bird.add(b_wingr2, "Bird wing right2", "Bird wing right1", { 0,-1.5f,0 }); /* TD5 example mesh_drawable cube_base; mesh_drawable cylinder_base; mesh_drawable sphere_junction; mesh_drawable cylinder1; mesh_drawable cube1; mesh_drawable cylinder1_son; mesh_drawable cyl2; mesh_drawable cyl3; cube_base.initialize_data_on_gpu(mesh_primitive_cube()); cube_base.model.scaling = 0.15f; cylinder_base.initialize_data_on_gpu(mesh_primitive_cylinder(0.05f, { 0,0,0 }, { 0,0,0.5f })); sphere_junction.initialize_data_on_gpu(mesh_primitive_sphere(0.1f)); cylinder1.initialize_data_on_gpu(mesh_primitive_cylinder(0.05f, { 0,0,0 }, { 1.0f,0,0 })); cube1.initialize_data_on_gpu(mesh_primitive_cube()); cube1.model.scaling = 0.15f; cylinder1_son.initialize_data_on_gpu(mesh_primitive_cylinder(0.03f, { 0,0,-0.25f }, { 0.0f,0,0.25f })); cyl2.initialize_data_on_gpu(mesh_primitive_cylinder(0.03f, { 0,-0.1f,0 }, { 0,0.1f,0 })); cylinder1.material.color = color1; cube1.material.color = color1; cylinder1.material.color = color1; cylinder1_son.material.color = color1; cyl2.material.color = color2; cyl3.material.color = color2; hierarchy.add(cube_base, "Cube base"); hierarchy.add(cylinder_base, "Cylinder base", "Cube base"); hierarchy.add(sphere_junction, "Sphere junction", "Cylinder base", { 0,0,0.5f }); // the translation is used to place the sphere at the extremity of the cylinder hierarchy.add(cylinder1, "Cylinder1", "Sphere junction"); hierarchy.add(cube1, "Cube1", "Cylinder1", { 1.0f,0,0 }); // the translation is used to place the cube at the extremity of the cylinder hierarchy.add(cylinder1_son, "Cylinder1 son", "Cube1"); hierarchy.add(cyl2, "Cyl2", "Cylinder1 son", { 0,0,-0.25f }); hierarchy.add(cyl2, "Cyl3", "Cylinder1 son", { 0,0,0.25f }); */ }