Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm attempting to create a 3d tree procedurally. I'm hoping that someone can check my vector rotation maths, as I'm a bit confused.

I'm using an l-system (a recursive algorithm for generating branches).

The trunk of the tree is the root node. It's orientation is aligned to the y axis.

In the next iteration of the tree (e.g. the first branches), I might create a branch that is oriented say by +10 degrees in the X axis and a similar amount in the Z axis, relative to the trunk.

I know that I should keep a rotation matrix at each branch, so that it can be applied to child branches, along with any modifications to the child branch.

My questions then:

for the trunk, the rotation matrix - is that just the identity matrix * initial orientation vector ?

for the first branch (and subsequent branches) - I'll "inherit" the rotation matrix of the parent branch, and apply x and z rotations to that also.


using glm::normalize;
using glm::rotateX;
using glm::vec4;    
using glm::mat4;
using glm::rotate;

vec4 vYAxis     = vec4(0.0f, 1.0f, 0.0f, 0.0f);
vec4 vInitial   = normalize( rotateX( vYAxis, 10.0f ) );

mat4 mRotation  = mat4(1.0);

// trunk rotation matrix = identity * initial orientation vector
mRotation *= vInitial;

// first branch = parent rotation matrix * this branches rotations
mRotation *= rotate( 10.0f, 1.0f, 0.0f, 0.0f );     // x rotation
mRotation *= rotate( 10.0f, 0.0f, 0.0f, 1.0f );     // z rotation

Are my maths and approach correct, or am I completely wrong?

Finally, I'm using the glm library with OpenGL / C++ for this. Is the order of x rotation and z rotation important?

share|improve this question
just test your code and see the results, if there was any problem ask how to solve them –  Ali.S Nov 25 '11 at 22:43
add comment

1 Answer

up vote 0 down vote accepted

From what I can see your approach is good, and your math seems alright as well. I would compile the code and see what the result is to make sure though.

share|improve this answer
well, my l-system code compiles okay, but it'll be a while before I can display anything on-screen. I'll need to write the code that utilizes the l-system to draw a tree before I can tell if anything is wrong! –  user3643 Nov 26 '11 at 5:57
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.