I've been trying draw a rectangle perpendicular to a movable camera. Was thinking that if the camera held its distance to the point where it was pointing and the rectangle would rotate as much as the camera then it should show up without perspective. Now when the camera tilts though, the rectangle appears further away and skewed.
Code:
float h2;
float fov;
float fov2;
float cameraY;
float cameraZ;
float xRot;
int boxW;
void setup() {
size(200, 200, P3D);
h2 = height/2;
fov = PI / 3;// 60°
fov2 = fov / 2;
cameraZ = h2 / (float) tan(fov / 2);
boxW = 25;
}
void draw(){
background(200);
xRot = map(mouseY,0,height,fov2*-1,fov2);
cameraY = cameraZ*sin(xRot);
camera(0, cameraY, cameraZ, 0, 0, 0, 0, 1, 0);
noFill();
stroke(50,200,50);
box(boxW);
rectMode(CENTER);
rect(0,0,width, height);
rotateX(2*PI-xRot);
stroke(255,50,50);
rect(0,0,width, height);
}
Is there some fundamental aspect of the 3D camera which has passed me by?