@dan850 as you requested, here i post the new updates on this code!
import com.jogamp.newt.opengl.GLWindow;
float x, y, z, xp = 0, yp = 0, zp = 0, anguloXY = 45, anguloZ = 180;
boolean Movements[] = new boolean[5], flag = true;
void setup()
{
size(200,200,P3D);
//fullScreen(P3D);
surface.setLocation((displayWidth / 2) - (width / 2), (displayHeight / 2) - (height / 2));
x = 100;
y = 100;
z = 0;
noCursor();
}
void draw()
{
((GLWindow)getSurface().getNative()).warpPointer(width / 2, height / 2);
background(180);
lights();
noFill();
//translate(width / 2, height / 2, 0);
//box(200, 200, 200);
displayBox(100, 100, -80, 200);
fill(255);
displayBox((width / 2) - 35, (height / 2) - 35, 0, 40);
displayBox((width / 2) + 35, (height / 2) + 35, 0, 40);
//box(40, 40, 40);
fill(0);
line(0, 0, 0, 50, 0, 0);
text("X", 50, 0, 0);
line(0, 0, 0, 0, 50, 0);
text("Y", 0, 50, 0);
line(0, 0, 0, 0, 0, 50);
text("Z", 0, 0, 50);
println("anguloXY: " + anguloXY + " anguloZ: " + anguloZ + " | x: " + x + " y: " + y + " z: " + z);
camera(xp, yp, zp, x, y, z, 0, 0, 1);
if(Movements[0]) //forward (w)
{
xp += sin(map(anguloXY, 0, 360, 0, TWO_PI));
yp += cos(map(anguloXY, 0, 360, 0, TWO_PI));
x += sin(map(anguloXY, 0, 360, 0, TWO_PI));
y += cos(map(anguloXY, 0, 360, 0, TWO_PI));
}
if(Movements[1]) //backwards (s)
{
xp -= sin(map(anguloXY, 0, 360, 0, TWO_PI));
yp -= cos(map(anguloXY, 0, 360, 0, TWO_PI));
x += sin(map(anguloXY, 0, 360, 0, TWO_PI));
y += cos(map(anguloXY, 0, 360, 0, TWO_PI));
}
if(Movements[2]) //left (a)
{
xp += sin(map(anguloXY + 90, 0, 360, 0, TWO_PI));
yp += cos(map(anguloXY + 90, 0, 360, 0, TWO_PI));
x += sin(map(anguloXY + 90, 0, 360, 0, TWO_PI));
y += cos(map(anguloXY + 90, 0, 360, 0, TWO_PI));
}
if(Movements[3]) //right (d)
{
xp += sin(map(anguloXY - 90, 0, 360, 0, TWO_PI));
yp += cos(map(anguloXY - 90, 0, 360, 0, TWO_PI));
x += sin(map(anguloXY - 90, 0, 360, 0, TWO_PI));
y += cos(map(anguloXY - 90, 0, 360, 0, TWO_PI));
}
if(Movements[4])
{
if(flag)
{
zp += 20;
z += 20;
flag = false;
}
}
else
{
if(flag)
{
zp -= 20;
z -= 20;
flag = false;
}
}
if(mouseY > (height / 2) + 1)
{
//z += mouseY - (height / 2);
//z = z>100?100:z;
anguloZ += mouseY - (height / 2);
anguloZ = anguloZ>90?90:anguloZ;
}
else if(mouseY < (height / 2) - 1)
{
//z += mouseY - (height / 2);
//z = z<-100?-100:z;
anguloZ += mouseY - (height / 2);
anguloZ = anguloZ<-90?-90:anguloZ;
}
if(mouseX > (width / 2) + 1)
{
anguloXY += mouseX - (width / 2);
anguloXY = anguloXY>360?0:anguloXY;
}
else if(mouseX < (width / 2) - 1)
{
anguloXY += mouseX - (width / 2);
anguloXY = anguloXY<0?360:anguloXY;
}
xp = constrain(xp, -((width * 2) + 1), ((width * 2) - 1));
yp = constrain(yp, -((width * 2) + 1), (width * 2) - 1);
x = (width / 2) + sin(map(anguloXY, 0, 360, 0, TWO_PI)) * (width / 2);
x = constrain(x, -(width * 2), width * 2);
y = (width / 2) + cos(map(anguloXY, 0, 360, 0, TWO_PI)) * (width / 2);
y = constrain(y, -(width * 2), width * 2);
z = -100 + sin(map(anguloZ, -90, 360, -PI/2, TWO_PI)) * 300;
z = constrain(z, -100, 200);
//text();
}
void keyPressed()
{
if(key == 'w')
{
Movements[0] = true;
}
if(key == 's')
{
Movements[1] = true;
}
if(key == 'd')
{
Movements[2] = true;
}
if(key == 'a')
{
Movements[3] = true;
}
if(key == ' ')
{
Movements[4] = true;
flag = true;
}
}
void keyReleased()
{
if(key == 'w')
{
Movements[0] = false;
}
if(key == 's')
{
Movements[1] = false;
}
if(key == 'd')
{
Movements[2] = false;
}
if(key == 'a')
{
Movements[3] = false;
}
if(key == ' ')
{
Movements[4] = false;
flag = true;
}
}
void displayBox(float x, float y, float z, float r)
{
pushMatrix();
translate(x, y, z);
box(r);
popMatrix();
}
i’m open to any suggestions!