I am working with threedimensional spaces lately. This is my Code:
//The Main Programm:
Figur figur1;
void setup()
{
size(1300,750,P3D);
figur1=new Figur(650,375,0);
}
void draw()
{
println(mousey);
background(#FFFFFF);
figur1.drawFigur();
figur1.moveFigur();
figur1.kamera();
}
void keyPressed()
{
figur1.pressedkeys();
}
void keyReleased()
{
figur1.releasedkeys();
}
void mouseMoved()
{
figur1.movedmouse();
}
//The Figur class tab:
float a1=0;
float b1=0;
float c1=0;
float mousey=0;
float cam=0;
class Figur
{
float xPos;
float yPos;
float zPos;
Figur(float x,float y,float z)
{
xPos=x;
yPos=y;
zPos=z;
}
void drawFigur()
{
pushMatrix();
fill(#0000FF);
translate(xPos,yPos,zPos);
if(mouseX<1300&mouseX>0)
{rotateY(mousey);}
sphere(20);
popMatrix();
pushMatrix();
translate(xPos,yPos+50,zPos);
if(mouseX<1300&mouseX>0)
{rotateY(mousey);}
box(15,60,15);
popMatrix();
}
void pressedkeys()
{
if(key==‘w’)
{c1=5;}
if(key==‘s’)
{c1=-5;}
if(key==‘c’)
{cam=5;}
}
void releasedkeys()
{
if(key==‘w’)
{c1=0;}
if(key==‘s’)
{c1=0;}
if(key==‘c’)
{cam=0;}
}
void movedmouse()
{
if(mouseX<650)
{mousey=-(-mouseX+650)*0.01;}
if(mouseX>650)
{mousey=(mouseX-650)*0.01;}
}
void moveFigur()
{
if(c1>0)
{
zPos=zPos+5;
}
if(c1<0)
{
zPos=zPos-5;
}
}
void kamera()
{
camera(xPos,yPos,zPos+200,xPos,yPos,zPos,0,1,1);
if(cam>0)
{
camera(xPos,yPos,zPos+10,xPos,yPos,zPos,0,1,1);
}
}
}
My Problem is, that I want the movement directions to rotate, too.
As far only the Figur rotates, but when I move her, the figur does not change her directions of movement. I tried it with PVectors, but I am not very good with them, because I never used them before. Can someone please explain me how I can fullfill my goal? Thank you.