Hello!
Remember the good old Turtle-Graphic as in LOGO?
It is a 2D tool to make a virtual turtle paint rectangles and stuff. It carries a pen and you tell it to go straight ahead or to turn on the spot. Since it carries a pen, it draws a line if it moves.
To draw a rectangle you tell it to repeat 4 times: go forward 100, turn right 90°.
That's it. Very convenient. I did this in processing (see http://www.openprocessing.org/visuals/?visualID=774).
I now want to build something similar in processing, but in 3D. Imagine a water turtle; it can turn left and right, swim forward and now also can turn its nose up and down and paint lines leading up or down by certain degree. It should paint a cube by combining 4 rectangles with 90° nose-angle.
But my math fails here. I can’t work out the implementation.
I have a certain position of the turtle (TurtleX,TurtleY,TurtleZ) and two angles, the traditional angle in the plane of the turtle (right/left) and the new 3D-angle, showing the nose-up-down-angle.
If the turtle now goes forward, I want to take into account the given length and the two angles.
I calculate the new position by transforming the old position to a new position, draw a line between the old position and the new position and set the new position as the new Turtle-position (TurtleX,TurtleY,TurtleZ).
For the transformation I use translate, rotateX and rotateY. But it doesn’t work at all!
Besides: I draw a point just to be able to retrieve its position (by modelX). In fact, I don't need the point at all.
Here is a sniplet of the code; full code was too long, forum software rejected it
.
// translate and turn
translate (OldX,OldY,OldZ);
rotateX(WinkelVertikal); // xrot
rotateZ(WinkelHorizontal); // zrot
point (OldX,OldY,OldZ);
// it was drawn at ( .., .., ..), store that location
float x = modelX(OldX,OldY,OldZ);
float y = modelY(OldX,OldY,OldZ);
float z = modelZ(OldX,OldY,OldZ);
// clear out all the transformations (read out Matrix)
popMatrix();
// get the (x, y, z) coordinate
TurtleX = x; //
TurtleY = y; //
TurtleZ = z; //
</snip>
How can I do it right?
All help appreciate!
Thanks a lot!
Greetings, Chris