Hi I’m a new coder on processing. I have long and complex code but I prepared a simple code to you for my question.
float camX = 0;
float camY = 0;
float camZ = (height/2)/tan(PI/6) - 260;
float x, y, z = 0;
float rotX = 0, rotY = 0;
float lastX, lastY;
float distX, distY;
void setup() {
size(1600, 1000, P3D);
}
void draw() {
background(0);
camera(camX, camY, camZ, //default camera position without 360 degree
x, y, z, //where it is looking to
0, 1, 0); //eye openness
rotateX(rotX + distY);
rotateY(rotY + distX);
beginShape(QUADS);
vertex(-350, 100.1, 350); // Upper left to Corner
vertex(350, 100.1, 350); // Upper right to Corner
vertex(350, 100.1, -350); // Bottom right to Corner
vertex(-350, 100.1, -350); // Bottom left to Corner
endShape();
if (keyPressed)
{
if (key == 'w') { // FRONT
camZ += 5;
} else if (key == 's') { // BACK
camZ -= 5;
} else if (key == 'a') { // LEFT
camX += 5;
x += 5;
} else if (key == 'd') { // RIGHT
camX -=5;
x -= 5;
}
}
}
public void mousePressed() {
lastX = mouseX;
lastY = mouseY;
}
public void mouseDragged() {
distX = radians(mouseX - lastX);
distY = radians(lastY - mouseY);
}
public void mouseReleased() {
rotX += distY;
rotY += distX;
distX = distY = 0;
}
So, I want to make a camera that can only go around the vertices of which was given.The camera won’t go outside from the white area. How to make that happened? Also there is a bug when I go further on the area. The camera changes the way when it reachs the half of the area. Can you help me about fixing that bug? Thank you.