I’m writing a little OGL app that simulates flocking behaviour. I got them moving nicely, so I then wanted to get them pointing in the direction they’re flying. Enter “Computer Graphics: Principles and Practice” by Foley, van Dam, et al. I turn to page 221, and lo! there’s a nice looking way of doing exactly what I want. It tells me to create a rotation matrix thus:
| | | | | | 0
|y x DOF| |DOF x (y x DOF)| |DOF| 0
| | | | | | 0
0 0 0 1
where y is the “up” vector (in this case [0,1,0]), DOF is the vector in which the object has just moved, and x means the cross product.
Now, it says that if DOF is near or equal to y then the matrix degenerates, fair enough (what appears to happen is that the matrix becomes a shear matrix, rather than a rotation one). However, I seem to get shearing way before DOF appoaches y, and because normal vectors don’t like shear matrices, I get some odd lighting at steeper angles.
Is anyone familiar with this way of figuring a rotation matrix? If so can you shed any light on why I get a shear matrix and not a rotation one? I know that in a standard OpenGL matrix, elements 4 and 8 control shearing as well as being part of rotation, so I guess these numbers are getting too big (with the other rotational parts getting too small), but is there anything I can do about it?
On a related note, it also says in CG:PP that this method doesn’t handle banking. Whilst I’m not too bothered about this, it would be nice to have my birds banking as well as pitching and yawing. Any ideas?
I’ll post some sample code if people need it.
Thanks in advance guys,
[This message has been edited by JohnD (edited 05-17-2000).]