We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello I am trying to get a 3D "Line" (the "line" is really a box() but you get the idea) I am drawing to rotate around one end the same way a 2D line does. In the example below you can see that the red line which is your standard line() object rotates around one of its points. I would like to get my box() object which is in green to rotate the same way as the red line. Any advice would be greatly appreciated.
void setup()
{
size(640,360,P3D);
}
float n=0;
void draw(){
background(255);
//GREEN LINE
pushMatrix();
stroke(0,255,0);
translate(width/2, height/2);
rotate(n);
box(90,1,1);
popMatrix();
//RED LINE
pushMatrix();
stroke(255,0,0);
translate(width/2, height/2);
rotate(n);
line(0,0,-95,100);
popMatrix();
n=n+0.01;
}
Answers
Thanks!! TfGuy44 that really helped. So if I understand this correctly the second call of translate moves the center of rotation of the line 45 units in the x direction? so I must first translate the line to the center of the screen and then translate it again in order to rotate it?
The first translate moves the (0,0,0) point so that it is in the middle of the screen. When you call
rotate()
, you're actually callingrotateZ()
, which rotates space around the Z-axis. The second call to translate() then moves the (0,0,0) point along the (now) ROTATED X-axis. It moves the origin 45 units away from where we rotated, which makes it look like a 90-units long box is now spinning about the center of the screen.The important thing to realize is that your call to rotate() is changing the direction that the X-axis points!
There is also a version of line with 6 parameters
It's a 3d line
Also look at my turtle code, there is a function
drawLine
iircWhich gives you a thin rect as a line
Use it with
lights();
I posted some additional code above