We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, trying some simple projects in 3D.
For my step 1 project I decided to rotate a plane. I created a plane, however, simple rotateY doesn't help me much, as I would like to rotate against some arbitrary point.
But then I run it this: - I first translate to the point against which I want to rotate - I rotate by some angle - I draw the plane (but as I have previously 'translated' my plane is no a bit off)
In the end, I want the plane to be rotated against any axis. For instance, against the middle of the plane.
This is my code:
int step = 10;
int a = 1;
void setup() {
size (800, 800, P3D);
}
void draw() {
background (0, 0, 0);
a = a + 1;
translate (width/2, 0);
for (int y = 0; y < height; y += 10) {
fill (255,0,0);
ellipse (0, y, 5, 5);
}
rotateY (radians(a));
for (int i = width/2 - 100; i < width/2 + 100; ) {
i += step;
for (int j = height/2 - 100; j < height/2 + 100; j += step) {
pushMatrix();
translate (i, j);
fill (255, 255, 255);
ellipse (0, 0, 5, 5);
popMatrix();
}
}
}
Answers
Hello !
Your first "translate" should be inside an another pushMatrix/popMatrix. Then, in your loop, apply the rotation in the push/popMatrix corresponding to each element, but it's important to apply the rotation BEFORE the translation - the result will be very different if you put it after the translation -
(if you define the rotation before the translation, it means that the origin of the mesh is at the center of the object ; when you apply a translation, you move the object from its center )
Good luck !
Tried out, but missed something, I guess - so it didn't work in the end. And, if I enclose the translate operator in push/pop Matrix ... It won't play any role at all.
Decided there is no need to draw everything every frame - decided to make a shape... Unfortunately, doesn't work at the moment.
you has made few mistakes
move mouse left and right please
here