Hello.
I started with Processing yesterday, I was trying to modify ZNear because when an object comes to close to the camera it disappears.
I have tried with different values but nothing seems to work.
Do you have a clue? I have read in the ALPHA forum that this is normal, but I wonder if it has been solved for the BETA.
In my code, if you move the cube very close to the camera it disappears. You can move it with WASD
Code:
float myZ=0, myX=0;
boolean pressW, pressA, pressS, pressD;
float step=0.5, nextX, nextZ, eyeX=0, eyeZ=20;
float camdegree=90;
MobileThing theBox = new MobileThing(0, 0, 0);
void setup() {
size(700, 500, P3D);
fill(204);
float fov = PI/3.0;
float cameraZ = (height/2.0) / tan(PI * fov / 360.0);
perspective(fov, float(width)/float(height),
cameraZ/10.0, cameraZ*10.0);
}
void draw() {
//calculateCamera();
lights();
background(0);
theBox.calculateWalk();
keyControl();
// Change height of the camera with mouseY
camera(eyeX, 3, eyeZ, // eyeX, eyeY, eyeZ
0.0, 0.0, 0.0, // centerX, centerY, centerZ
0.0, 0.0, 1.0); // upX, upY, upZ
stroke(255,0,0);
line(-100, 0, 0, 100, 0, 0);//X
stroke(0,255,0);
line(0, -100, 0, 0, 100, 0);//Y
stroke(0,0,255);
line(0, 0, -100, 0, 0, 100);//Z
line (theBox.nextX, -2, theBox.nextZ, theBox.posX, -2, theBox.posZ);
pushMatrix();
translate(theBox.posX,0,theBox.posZ);
rotateY (-radians(theBox.degree));
box(2);
popMatrix();
pushMatrix();
sphere(0.1);
popMatrix();
}
void keyControl()
{
if (pressW==true) theBox.walk(true);
if (pressA==true) theBox.turn(false);
if (pressS==true) theBox.walk(false);
if (pressD==true) theBox.turn(true);
}
void keyPressed()
{
if (key=='w') pressW=true;
if (key=='a') pressA=true;
if (key=='s') pressS=true;
if (key=='d') pressD=true;
}
void keyReleased()
{
if (key=='w') pressW=false;
if (key=='a') pressA=false;
if (key=='s') pressS=false;
if (key=='d') pressD=false;
}
class MobileThing
{
float posX, posY, posZ, nextX, nextZ, prevX, prevZ, speed=0.3, degree=0;
MobileThing (float x, float y, float z)
{
posX = x;
posY = y;
posZ = z;
}
void calculateWalk()
{
nextX = posX + cos (radians(degree))*speed;
nextZ = posZ + sin (radians(degree))*speed;
prevX = posX - cos (radians(degree))*speed;
prevZ = posZ - sin (radians(degree))*speed;
}
void walk(boolean d)
{
if (d==true)
{
posX=nextX;
posZ=nextZ;
}
else
{
posX=prevX;
posZ=prevZ;
}
}
void turn (boolean a)
{
if (a==true) degree=degree-5;
else degree=degree+5;
}
}