OCD Camera library View shakes rapidly somethimes when moving around

I am using the OCD camera library and am trying to make a first person view that you can move around. when i move forwards to far the camera suddenly starts shaking. I don't know how to stop it from doing this and i presume that it is a problem with the point it is looking at. It would be a great help if someone could help me with fixing this problem. This is a 3d project that i am trying to complete here is the code: package explorer;

import processing.core.PApplet; import processing.core.PShape; import damkjer.ocd.*;

public class Explorer extends PApplet { Camera c; PShape w; PShape player; float x = width/2,y = -81,z = 50; float xpos = -PI/6; // float xpos = 0; float yaw = 0; // float xxpos = (float) (width/2.0), ypos = (float) (height/2.0), zpos =(float) ((height/2.0) / tan((float) (PI*30.0 / 180.0))); float xxpos = 0, ypos = 100, zpos = 0; float[] playerhitbox; float[] worldhitbox; float cx = x, cy = y - 10, cz = z;

boolean camup = false, camdown = false, camleft = false, camright = false;
boolean up = false, down = false, left = false, right = false, forward = false, backward = false;
int rotation = 0;
 float k = 10;// Move distance
 float xzLength = 0;
 float dx = 0;
 float dz = 0;
 float dy = 0;
 float test = (float) .1;
public void settings(){
      size(640, 360, P3D);

// fullScreen(1); } public void setup() { w = loadShape("winterfell_detailed.obj"); // w = loadShape("untitled.obj"); player = loadShape("sean_sucks_at_making_people.obj"); w.scale(50); // player.scale(-2); w.rotateX(-87); w.rotateX((float) .1); w.rotateX((float) .1); w.rotateX((float) .1); w.rotateX((float) .1); w.rotateX((float) .1); w.rotateX((float) .1); float fov = (float) (PI/3.0); float cameraZ = (float) ((height/2.0) / tan((float) (fov/2.0))); float nearClippingDistance = (float) 0.01; // default is cameraZ/10.0 perspective(fov, width/height, nearClippingDistance, (float) (cameraZ*10.0)); c = new Camera(this, x, y, z); c.aim(1000,1000,1000); }

public void draw() {
        test = (float) (10 * Math.cos(yaw));
      System.out.println(test);
      c.jump(x, y, z);
      background(10);
      pushMatrix();

// ambientLight(255, 255, 255, x, y, z); lights(); popMatrix(); //rotateY(ry); pushMatrix(); // translate(x,y,z); shape(w); popMatrix(); pushMatrix(); translate(x,y,z); shape(player); popMatrix(); movement(); c.feed(); // c.pan(xpos); // c.tilt(ypos); // System.out.println(x + " " + y + " " + z); // pushMatrix(); // beginCamera(); // camera(x,y,z, xxpos, ypos, zpos, 0, 1, 0); // camera(x,y,z, x, y, z, 0, 1, 0); // translate(x,y,z); // rotateX(xpos); // rotate(ypos); // endCamera(); // popMatrix();

     float[] A = c.attitude();
     yaw = A[0] * 100;

// c.aim(x, y, z); // Update your camera: // if(checkCollision(playerhitbox, worldhitbox)){ //
// }

}

public boolean checkCollision(float[] player, float[] obj){
    /*
     * players x Min is player[0]
     * players x Max is player[1]
     * players y Min is player[2]
     * players y Max is player[3]
     * players z Min is player[4]
     * players z Max is player[5]
     * world objects x Min is obj[0]
     * world objects x Max is obj[1]
     * world objects y Min is obj[2]
     * world objects y Max is obj[3]
     * world objects z Min is obj[4]
     * world objects z Max is obj[5]
    */
    if(
        player[0] < obj[1] && player[1] > obj[0] &&
        player[2] < obj[3] && player[3] > obj[2] &&
        player[4] < obj[5] && player[5] > obj[4]

        )
    {
            return true;    
    }else{
        return false;
    }

}
public void mouseClicked() {
      float[] attitude = c.attitude();
      println("Yaw: " + attitude[0]);
    }
public void mouseMoved() {
      c.pan((float) (radians(mouseX - pmouseX) / 2.0));
      c.tilt((float) (radians(mouseY - pmouseY) / 2.0));
    }
public void keyPressed(){
    if(key == ' '){
        up = true;
    }
    if(keyCode == SHIFT){
        down = true;
    }
    if(key == 'w'){
        forward = true;
    }
    if(key == 'a'){
        left = true;
    }
    if(key == 's'){
        backward = true;
    }
    if(key == 'd'){
        right = true;
    }
    if(keyCode == UP){
        camup = true;
    }
    if(keyCode == DOWN){
        camdown = true;
    }
    if(keyCode == LEFT){
        camleft = true;
    }
    if(keyCode == RIGHT){
        camright = true;
    }
    if(key == 'e'){
        doo = true;
    }
}
boolean doo = false;
public void keyReleased(){
    if(key == ' '){
        up = false;
    }
    if(keyCode == SHIFT){
        down = false;
    }
    if(key == 'w'){
        forward = false;
    }
    if(key == 'a'){
        left = false;
    }
    if(key == 's'){
        backward = false;
    }
    if(key == 'd'){
        right = false;
    }
    if(keyCode == ENTER){

// w.rotateX((float) .1); rotation++; System.out.println(rotation); player.rotateX(1);

    }
    if(keyCode == UP){
        camup = false;
    }
    if(keyCode == DOWN){
        camdown = false;
    }
    if(keyCode == LEFT){
        camleft = false;
    }
    if(keyCode == RIGHT){
        camright = false;
    }
    if(key == 'e'){
        doo = false;
    }
}
public void movement(){
    if(up){
        y -= 10;

// println("up"); } if(down){ y += 10; // println("down"); } if(left){ x -= 10; // println("left");

    }
    if(right){
        x += 10;

// println("right");

    }
    if(forward){

// z -= 10;

// println("forward"); // c.truck(-10); z -= (10 * Math.cos(yaw)); x -= (10 * Math.sin(yaw)); } if(backward){ // z += 10;

// c.pan(10 * Math.cos(yaw)); // println("backward"); x -= 10 * Math.cos(yaw); z -= 10 * Math.sin(yaw); } if(camleft){

        c.pan((float) -.10);

// y += 10 * Math.sin(ypos); } if(camright){

          c.pan((float) .10);
    }
    if(camup){

          c.tilt((float) -0.1);
    }
    if(camdown){


          c.tilt((float) .10);
    }
    if(doo){
        xpos++;
        player.rotateX(1);
    }
}

public static void main(String _args[]) {
    PApplet.main(new String[] { explorer.Explorer.class.getName() });
}

}

Tagged:
Sign In or Register to comment.