I still need to update the direction vector manually. However, I can use OpenGL's functions to rotate as many points at a time as I require (that is, the entire agent 3D object). In order to determine that my vector rotation and the OpenGL rotation were in-sync, I decided to draw a representation of the direction vector in the world coordinate space (translated to the origin of the agent object) as a simple line, and to draw a more complex agent object in its own coordinate space (rotated with OpenGL). Here are the steps for each frame:
- Initialize the canvas
- Translate to set the camera's position
- Draw the board, using world coordinates
- Push the OpenGL transformation matrix (this allows us to draw each agent individually, without regards to the others)
- For each agent...
- Translate to the agent's position
- Push the transformation matrix again (this allows us to draw the direction vector after the object itself has been drawn)
- Rotate around the z axis, to put OpenGL into the agent's coordinate space
- Draw the agent object
- Pop the previously-pushed transformation matrix, to return to world coordinates (centered at the origin of the current agent)
- Draw the direction vector
- Pop the transformation matrix again, to center once again at the world's origin (permitting the next Translate to move the coordinate system center to the origin of the next agent)
No comments:
Post a Comment