I am having some trouble with the camera function at the end. It does work to a decent extent, but I am wondering if anyone can help me solve the following problems with it:
- sensitivity too high for looking up and down
- is not able to look straight down, will just look down until it slows to a stop then reverses direction
- (not entirely sure it is a problem) when looking down, the rotation speed of the camera speeds up.
int w = 600;
int h = 600;
float camX = w/2, camY = h/2, camZ = 50;
float mousex = mouseX, mousey = mouseY;
void settings(){
size(w, h, P3D);
}
void setup(){
background(200);
frameRate(60);
fill(255);
stroke(0);
strokeWeight(5);
}
void draw(){
background(200);
square(0, 0, 600);
//move(3);
mousex = mouseX;
mousey = mouseY;
camera(camX, camY, camZ, camX+cos(mousex/50)-sin(mousey/50), camY+sin(mousex/50)-sin(mousey/50), camZ+sin(mousey/100), 0, 0, -1);
}
Nice work!
below my version with avoidClipping()
(no clipping). Also I suggest lights().
It’s interesting that your version is MUCH faster than it would be when you wouldn’t copy the mouseX
and mouseY
to your extra variables. Neat.
I think there is a library with the purpose 1st person.
Remark
I personally don’t like that you change the up orientation of the cam (the last 3 params).
I know it’s because you want to use square.
I think it’ll work but you always have to figure what is up when placing more object in the world.
Sketch
(I kept your up orientation)
int w = 600;
int h = 600;
float camX = w/2, camY = h/2, camZ = 50;
float mousex, mousey;
void settings() {
size(w, h, P3D);
}
void setup() {
background(200);
frameRate(60);
avoidClipping();
fill(255, 0, 0);
stroke(0);
strokeWeight(5);
}
void draw() {
background(200);
lights();
mousex = mouseX;
mousey = mouseY;
camera(camX, camY, camZ,
camX+cos(mousex/50)-sin(mousey/50), camY+sin(mousex/50)-sin(mousey/50), camZ+sin(mousey/100),
0, 0, -1);
square(0, 0, 600);
}//func draw
// -------------------------------------------------------------------------------------------------------
void avoidClipping() {
// avoid clipping (at camera):
// https : //
// forum.processing.org/two/discussion/4128/quick-q-how-close-is-too-close-why-when-do-3d-objects-disappear
perspective(PI/3.0, (float) width/height, 1, 1000000);
}//func
//
1 Like