Sale!

CSCE 441 Assignment 2 – Hierarchical Transforms solved

$35.00 $21.00

Category: You will receive a download link of the .ZIP file upon Payment

Description

5/5 - (1 vote)

Write a program that allows you to create a robot that you can manipulate with the keyboard.
You are free to create your own robotic character, but there should be at least 10 components in
the robot, and the hierarchy should not be at. For example, in the gures below, we have the
following hierarchy:
Torso
Head
Upper le arm
Lower le arm
Upper right arm
Lower right arm
Upper le leg
Lower le leg
Upper right leg
Lower right leg
2/10/2020 CSCE 441 – Assignment 2
courses.cs.tamu.edu/sueda/CSCE441/2020S/assignments/A2/index.html 2/5
When a parent component is transformed, all of its descendants should be transformed
appropriately. e keyboard control should be as follows:
‘.’ (period): traverse the hierarchy forward
‘,’ (comma): traverse the hierarchy backward
‘x’, ‘X’: increment/decrement x angle
‘y’, ‘Y’: increment/decrement y angle
‘z’, ‘Z’: increment/decrement z angle
By pressing the period and comma keys, you should be able to select dierent components in the
hierarchy. You must draw the selected component so that it is distinguishable from unselected
components. e x/X, y/Y, and z/Z keys should change the rotation angle of the selected
component. In the le gure above, the torso is the selected component, and in the right gure,
one of the lower legs is the selected component. Here, the selected component is drawn darker
than the unselected components, but you can color it the way you want or draw it slightly bier.
Step 1
Start from your Lab 0 code base.
1. Create your A2 project folder and copy the L00 les and folders into it.
2. Modify CMakeLists.txt to change the project name (line 4).
2/10/2020 CSCE 441 – Assignment 2
courses.cs.tamu.edu/sueda/CSCE441/2020S/assignments/A2/index.html 3/5
3. Add GLM calls so that you can draw transformed suares. (If you’re not sure how to do this,
you may want to start with Lab 4.) You should go through the various helper classes (e.g.,
Shape, Program, etc.) to understand roughly what they are doing.
4. Add support for keyboard input (x/X, y/Y, z/Z) by using the glfwSetCharCallback()
function.
Step 2
Create a class that represents a component. is class should contain the necessary member
variables so that you can make a tree data structure out of these components. e root of the tree
should represent the torso, which means that transforming the torso transforms everything else.
In addition to the member variables reuired for the tree hierarchy, the class should also have the
following:
A vec3 representing the translation of the component’s joint with respect to the parent
component’s joint.
A vec3 representing the current joint angles about the X, Y, and Z axes of the component’s
joint. (You may want to start with Z-rotations only.)
A vec3 representing the translation of the component’s mesh with respect to its joint.
A vec3 representing the X, Y, and Z scaling factors for the mesh.
A member method for drawing itself and its children.
Any additional variable(s) and method(s) you see t.
e drawing code should be recursive – in other words, in the render() function in main.cpp ,
there should be a single draw call on the root component, and all the other components should be
drawn recursively from the root. In the main render() function, you should create an instance of
the matrix stack class and pass it to the root component’s drawing function. Make sure to pass the
matrix stack by reference or as a (smart) pointer.
e component’s rendering method should simply take the current state of the component and
draw it. You should not create the robot hierarchy in this method. In other words, the scene setup
must be done in main’s init() rather than in main’s render() . Whenever the keyboard is
pressed, the char_callback() function is called. Update the robot’s joint angles inside this
function.
For this assignment, the 3D rotation of the joint should be represented simply as a concatenation
of three separate rotation matrices about the x-, y-, and z-axes: Rx * Ry * Rz . e position of the
joint should not be at the center of the box. For example, the elbow joint should be positioned
between the upper and lower arms.
You must draw the selected component dierently from unselected components. For example, in
the images above, the selected component is darker than the other components. You can either
change the color (like above) or change the size.
Changing the color: is reuires you to slightly modify the vertex shader. Assuming you are
starting with L4, the last line in the vertex shader is computing the attribute variable vCol ,
which is the vertex color. You will have to modify this line so that the output color becomes
dierent. You will need to pass in a uniform variable so that you can tell if the component
you are currently drawing is selected or not.
Changing the size: is reuires you to modify the modelview matrix depending on whether
the current component is selected or not.
2/10/2020 CSCE 441 – Assignment 2
courses.cs.tamu.edu/sueda/CSCE441/2020S/assignments/A2/index.html 4/5
e traversal of the tree with the period and comma keys should be in depth-rst or breadth-rst
order. Do not hardcode this traversal order – your code should be set up so that it works with any
tree.
HINT: Debuing OpenGL & GLSL
Set the Program class to be verbose by calling the setVerbose() function. If there is a GLSL
compilation error, then you will see the error in the console. For example, if the varying
variables of the vertex shader and the fragment shaders do not match up, it will tell you so.
Make sure to set verbose to be false aer debuing.
Use GLSL::checkError(GET_FILE_LINE); to nd which OpenGL call caused an error. is
function will assert if there were any OpenGL errors before getting to this line. You can use
this to winnow down which OpenGL function is causing an error. For example, if you put
this line at the top, the middle, and the bottom of your function, and if the assertion
happens in the middle, you know that the error must be happening in the top half of your
function. Once nd exactly which OpenGL call is causing the error, you can Google the
OpenGL function to gure out what caused the error. For example, maybe one of the
arguments should not have been zero or null.
Bonus
Put a sphere (sphere2.obj) at each joint.
Animate a running/walking/etc. model by bending some or all of the joints with time, using
glfwGetTime() . Animated joints do not need to be controlled with the keyboard.
Point breakdown
20 points for proper use of Program and Shape classes.
55 points for a functioning hierarchical robot with recursive, object-oriented design.
15 points for being able to select dierent components with the keyboard and for showing
the current selection with a dierent color or size.
10 points for coding style and general execution.
2.5 points bonus for spheres at the joints.
2.5 points bonus for animation.
Total: 105 points
What to hand in
Failing to follow these points may decrease your “general execution” score. Make sure that your
code compiles and runs by typing, for example:
> mkdir build
> cd build
> cmake ..
> make
> ./A2 ../resources
Make sure the arguments are exactly as specied.
Include a README le (ascii or PDF) that includes:
Your name
CSCE 441 – Assignment 2
courses.cs.tamu.edu/sueda/CSCE441/2020S/assignments/A2/index.html 5/5
Citations for any downloaded code
Plus anything else of note
Remove unnecessary debug printouts.
Remove unnecessary debug code that has been commented out.
Hand in src/ , resources/ , CMakeLists.txt , and your readme le. e resources folder
should contain the obj les.
Do not hand in the build directory, the executable, old save les (*.~) , or object les
(*.o) .
Create a single zip le of all the reuired les. e lename of this zip le should be
USERNAME.zip (e.g., sueda.zip ). e zip le should extract everything into a folder named
USERNAME/ (e.g. sueda/ ).
When you unzip this le, it should extract src/ , resources/ , CMakeLists.txt , and
your README le to the current directory.