My first-person camera code is having the following problems: changing the [starting] position of the camera makes the reference sphere disappear, replaced by a white screen; when playing around with the commented-out “box crosshair” code at the bottom, I discovered the point I’m looking at is getting closer and farther from me based on where I’m looking up or down, instead of a perfect sphere of distance as it should be, and the push and pop matrix code at the bottom just completely breaks everything if both are running:
PVector pos = new PVector(w/2, h/2, 50);
PVector lookDir = new PVector(0, pos.z);
void setup() {
background(240);
}
void settings(){
size(w, h, P3D);
}
void look(){
if(keyPressed){
if(key == CODED){
if(keyCode == RIGHT){
if (lookDir.x == 359){
lookDir.x = 0;
}
else{
lookDir.x += 1;
}
println("right");
}
if(keyCode == LEFT){
if (lookDir.x == 0){
lookDir.x = 359;
}
else{
lookDir.x -= 1;
}
println("left");
}
if(keyCode == UP){
if (lookDir.y == 89){
lookDir.y = 89;
}
else{
lookDir.y += 1;
}
print(lookDir.y);
println("up");
}
if(keyCode == DOWN){
if (lookDir.y == -269){
lookDir.y = -269;
}
else{
lookDir.y -= 1;
}
print(lookDir.y);
println("down");
}
}
}
}
void draw() {
background(240);
pushMatrix();
translate(width/2, height/2);
stroke(20);
sphere(200);
popMatrix();
look();
perspective(PI/3.0, width/height, pos.z, pos.z*10);
//pushMatrix();
camera(pos.x, pos.y, pos.z, pos.x+cos(radians(lookDir.x))*(10-sin(radians(lookDir.y))*10), pos.y+sin(radians(lookDir.x))*(10-sin(radians(lookDir.y))*10), pos.z+cos(radians(lookDir.y))*10, 0, 0, -1);
//translate(pos.x+cos(radians(lookDir.x))*(10-sin(radians(lookDir.y))*10), pos.y+sin(radians(lookDir.x))*(10-sin(radians(lookDir.y))*10), pos.z+cos(radians(lookDir.y))*10);
//box(3);
//popMatrix();
}
If anyone can help me with any of this, that would be amazing. Thanks!