Tips for Fractal Plant Project
- I suggest working from low-level to high-level. Change the angle and position of the leaf by changing the matrix. Then draw two leaves, using
additional calls to glUniform3f and glDrawElements to change the matrix and draw again.
Then you are ready to think about implementing a function to draw the
leaf and draw a stem.
- You'll need to draw stems as well as leaves.
The easiest way to do this is to
add the vertices for a stem, with colors, to the existing leaf_vertices array
(maybe change its name to something more generic), and the triangles for the stem to the existing leaf_indices array. Then add glDrawElements commands to
draw the stem, not starting at the begininning of the array.
- You may use the glm library to multiply matrices, but I'd like to see you
set up your own elementary transformation matrices. So you may not use glm::translate, glm::rotate, etc.
To get an arbitrary matrix into a glm::mat3, do this (notice the matrix
is stored by columns, not rows!):
glm::mat3 rot = glm::mat3(
glm::vec3( cos(M_PI/3), sin(M_PI/3), 0.0),
glm::vec3(-sin(M_PI/3), cos(M_PI/3), 0.0),
glm::vec3(0.0, 0.0, 1.0));
- To use glm in this program, you need to include
glm/glm.hpp
glm/gtc/type_ptr.hpp
glm/gtc/matrix_transform.hpp
- The function glm::value_ptr converts a glm matrix back to
a vector of floats that can be fed down to the GPU in the
glUniformMatrix3fv command.
-
Here is a little function that writes out a matrix by rows, for
debugging:
void printMat(glm::mat3 myMatrix){
int i,j;
for (j=0; j<3; j++){
for (i=0; i<3; i++){
printf("%f ",myMatrix[i][j]);
}
printf("\n");
}
}