I’m working on a personal project, and I want to create a camera that follows a box() around. That is however already done. My problem is, I want the box AND camera to rotate with the mouse. (See; every third person game ever made)
int grid = 10;
PVector bpos = new PVector();
float bsize = 20;
float bspeedX, bspeedY, bspeedZ;
boolean input1, input2, input3, input4;
void setup() {
//size(300,300,P3D);
fullScreen(P3D);
}
void draw() {
lights();
camera(width/2.0 + bpos.x, height/2 + bpos.y+30 - bsize*5, (height/2.0) / tan(PI*30.0 / 180.0) + bpos.z-700,
width/2.0 + bpos.x, height/2.0, bpos.z,
0, 1, 0);
//camera(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ) - no parameters
//camera(width/2.0, height/2.0, (height/2.0) / tan(PI*30.0 / 180.0), width/2.0, height/2.0, 0, 0, 1, 0) - default
background(125);
pushMatrix();
translate(width/2, height/2);
for (int i = -width/2; i <width/2; i+=grid) {
for (int j = -height/2; j < height/2; j+=grid) {
float y = bsize/2;
line(i, y, j, i+grid, y, j );
line(i+grid, y, j, i+grid, y, j+grid );
line(i+grid, y, j+grid, i, y, j+grid );
line(i, y, j, i, y, j+grid );
}
}
popMatrix();
noCursor();
pushMatrix();
translate(width/2+bpos.x, height/2+bpos.y, bpos.z);
stroke(255);
fill(0);
box(bsize);
popMatrix();
if (input1 == true && bspeedX >-3)bspeedX-=0.5;
if (input2 == true && bspeedX<3)bspeedX+=0.5;
if (input3 == true && bspeedZ >-3)bspeedZ-=0.5;
if (input4 == true && bspeedZ <3)bspeedZ+=0.5;
//-------------------------------------------//
if (bspeedX!=0)bspeedX*=0.95;
if (bspeedZ!=0)bspeedZ*=0.95;
bpos.x+=bspeedX;
bpos.z+=bspeedZ;
}
void keyPressed()
{
setMove(keyCode, true);
}
void keyReleased()
{
setMove(keyCode, false);
}
boolean setMove(int k, boolean b)
{
switch (k) {
case 'A':
return input1=b;
case 'D':
return input2=b;
case 'W':
return input3=b;
case 'S':
return input4=b;
default:
return b;
}
}
Feel free to ask questions.