I was creating a 3-d modeling program and was working on camera controls, when I realized that I couldn’t make a camera system that would just update the camera’s position and other values, rather than just creating a new camera. Is there any better way to do this so camera movements are preserved when another operation is used?
float mouseW;
void mouseWheel(MouseEvent event) {
mouseW = event.getCount();
println(mouseW);
}
void op() {
if (name!=null) {
if (name=="Save") {
} else if (name=="Import") {
selectInput("Please select an object(.obj) file for import.", "importobj");
name=null;
} else if (name=="Shapes") {
} else if (name=="Pencil") {
} else if (name=="Clay") {
} else if (name=="Camera") {
if (mouseButton==LEFT) {
//rot
camera(mouseX, mouseY, (height/2) / tan(PI/6), width/2, height/2, 0, 0, 1, 0);
} else if (mouseW!=0.0) {
if (mouseW>0) {
camera(0, 10, 0, 0, 0, 0, 0, 1, 0);//add+sub rather than change?
} else if (mouseW<0) {
camera(0, -10, 0, 0, 0, 0, 0, 1, 0);
}
} else if (mouseButton==RIGHT) {
//lrud
camera(mouseX, 0, mouseY, 0, 0, 0, 0, 1, 0);
}
}
}
}
P.s. If I’m being too vague, ask for the info I missed.
Thank you so much for the great answer! I was just wondering one last thing, if I wanted to create a UI overlay for the camera class, where in the code you gave me could I put it so it would stay in the same part of the screen the whole time?
Yes. The draw method would look something like this
void draw(){
backround(0); // or whatever colour you want
pushMatrix();
// In this part of draw do all your 3D camera and rendering stuff
popMatrix();
hint(DISABLE_DEPTH_TEST);
// Normal 2D pixel coordinate space prevails lol
// Draw any 2D stuff here e.g. menus
hint(ENABLE_DEPTH_TEST);
// End of draw method
}
I’m sorry to waste your time, but I’m curious how to actually define and use the camera class. I have something along the lines of this in my draw loop:
But I’m not sure what to put in the cam.applyto field(I tried googling, but for some reason nothing in the docs worked for me). This will be the last question, thanks in advance.
Also you can’t do this. This first three values represent the XYZ coordinates for the eye, the second three the XYZ coordinates of where you are looking at.
They can’t be the same position in 3D space. Review the reference for the camera(...) method.