Package jinngine.math

Examples of jinngine.math.Vector3


//    vertices.add(new Vector3(-1,-1, 1).normalize());
//    vertices.add(new Vector3(-1, 1,-1).normalize());
//    vertices.add(new Vector3( 1,-1,-1).normalize());
    // point on icosahedron
    final double t = (1.0 + Math.sqrt(5.0))/ 2.0;
    vertices.add(new Vector3(-1,  t,  0).normalize());
    vertices.add( new Vector3( 1,  t,  0).normalize());
    vertices.add( new Vector3(-1, -t,  0).normalize());
    vertices.add( new Vector3( 1, -t,  0).normalize());
    vertices.add( new Vector3( 0, -1,  t).normalize());
    vertices.add( new Vector3( 01,  t).normalize());
    vertices.add( new Vector3( 0, -1, -t).normalize());
    vertices.add( new Vector3( 01, -t).normalize());
    vertices.add( new Vector3( t,  0, -1).normalize());
    vertices.add( new Vector3( t,  01).normalize());
    vertices.add( new Vector3(-t,  0, -1).normalize());
    vertices.add( new Vector3(-t,  01).normalize());

    int n = 0;
    while (true) {
      ConvexHull hull = new ConvexHull(vertices);

      if (n>=depth)
        return hull;

      // for each face, add a new sphere support
      // point in direction of the face normal
      Iterator<Vector3[]> iter = hull.getFaces();
      while(iter.hasNext()) {
        Vector3[] face = iter.next();
        Vector3 normal =face[1].sub(face[0]).cross(face[2].sub(face[1])).normalize();
        vertices.add(new Vector3(normal));
      }
     
      // depth level done
      n++;
    }
View Full Code Here


      Iterator<Vector3[]> i = shape.getFaces();
      while (i.hasNext()) {
        gl.glBegin(GL.GL_POLYGON);
        Vector3[] face = i.next();
        //compute normal
        Vector3 n =face[1].sub(face[0]).cross(face[2].sub(face[1])).normalize();
       
        for ( Vector3 v: face) {
          gl.glNormal3d(n.x, n.y, n.z);
          //gl.glTexCoord2f(1.0f, 1.0f);
          //gl.glColor3d(v.a1, v.a2, v.a3);
          gl.glVertex3d(v.x, v.y, v.z);
          gl.glTexCoord2f(0.0f, 1.0f);
        }
        gl.glEnd();
      }
     
     
      gl.glPolygonMode( GL.GL_FRONT, GL.GL_LINE );
      gl.glLineWidth(1.7f);
      gl.glDisable(GL.GL_LIGHTING);
      gl.glScaled(1.01, 1.01, 1.01);
      i = shape.getFaces();
      while (i.hasNext()) {
        gl.glBegin(GL.GL_POLYGON);
        Vector3[] face = i.next();
        //compute normal
        Vector3 n =face[1].sub(face[0]).cross(face[2].sub(face[1])).normalize();
       
        for ( Vector3 v: face) {
          gl.glNormal3d(n.x, n.y, n.z);
          //gl.glTexCoord2f(1.0f, 1.0f);
          gl.glColor3d(0.2,0.2, 0.2);
          gl.glVertex3d(v.x, v.y, v.z);
          gl.glTexCoord2f(0.0f, 1.0f);
        }
        gl.glEnd();
      }

   
      gl.glEnable(GL.GL_LIGHTING);

     
      gl.glPopMatrix();
      gl.glPopAttrib();
    }
   
    //draw shadows
   
   
    gl.glLoadIdentity();

   
    gl.glDisable(GL.GL_LIGHTING);
    // Set camera transform
    glu.gluLookAt(cameraFrom.x, cameraFrom.y, cameraFrom.z,
        cameraTo.x, cameraTo.y, cameraTo.z,
        0, 1, 0);

   
    gl.glMultMatrixd(shadowProjectionMatrix(new Vector3(75,350,-75), new Vector3(0,-20 + 0.0,0), new Vector3(0,-1,0)), 0);
   
    gl.glColor3d(0.85, 0.85, 0.85);
   
    for ( DrawShape shape: toDraw) {
      gl.glPushMatrix();
View Full Code Here

    return new Matrix4(proj);
  }
 
  public void getPointerRay(Vector3 p, Vector3 d, double x, double y) {
    // clipping planes
    Vector3 near = new Vector3(2*x/(double)width-1,-2*(y-((height-drawHeight)*0.5))/(double)drawHeight+1, 0.7);
    Vector3 far = new Vector3(2*x/(double)width-1,-2*(y-((height-drawHeight)*0.5))/(double)drawHeight+1, 0.9);

    //inverse transform
    Matrix4 T = getProjectionMatrix().multiply(getCameraMatrix()).inverse();
 
    Vector3 p1 = new Vector3();
    Vector3 p2 = new Vector3();
   
    Matrix4.multiply(T,near,p1);
    Matrix4.multiply(T,far,p2);
   
    p.assign(p1);
    d.assign(p2.sub(p1).normalize());
  }
View Full Code Here

   
  }

  @Override
  public void mousePressed(MouseEvent e) {
    Vector3 p = new Vector3();
    Vector3 d = new Vector3();
    getPointerRay(p, d, e.getX(), e.getY());   
    mouseCallback.mousePressed((double)e.getX(), (double)e.getY(), p, d );
  }
View Full Code Here

    mouseCallback.mouseReleased();
  }

  @Override
  public void mouseDragged(MouseEvent e) {
    Vector3 p = new Vector3();
    Vector3 d = new Vector3();
    getPointerRay(p, d, e.getX(), e.getY());   
    mouseCallback.mouseDragged((double)e.getX(), (double)e.getY(), p, d );
  }
View Full Code Here

    leavingPairs.clear();
  }
 
  private static final boolean overlap( BoundingBox i , BoundingBox j) {

    Vector3 bi = i.getMinBounds();
    Vector3 ei = i.getMaxBounds();
    Vector3 bj = j.getMinBounds();
    Vector3 ej = j.getMaxBounds();
   
    double bix = bi.x;
    double biy = bi.y;
    double biz = bi.z;
    double eix = ei.x;
View Full Code Here

    public double value;
    public boolean delete = false;

    public final void updateValue() {
      //get the correct axis bounds for each body's AABB
      Vector3 thisBounds;
      if ( this.begin ) {
        thisBounds = this.aabb.getMinBounds();
      } else {
        thisBounds = this.aabb.getMaxBounds();
      }

      this.value = thisBounds.get(this.axis);
      //thisBounds.print();
      //System.out.println("Sweep point value: " + value);

    }
View Full Code Here

    Sphere s1 = new Sphere(1);
    Body b1 = new Body("default", s1);
   
    // pick a point outside the sphere, and let the direction point towards
    // the centre of the sphere.
    Vector3 point = new Vector3(-4, 6, 9);
    Vector3 direction = point.multiply(-1);
   
    // do the raycast
    double lambda = raycast.run(s1, null, point, direction, new Vector3(), new Vector3(), 0, envelope, epsilon, false );
   
    // we know the exact intersection point
    Vector3 expected = point.normalize();
   
    // calculate the deviation of the returned point and the reference point
    double error = point.add(direction.multiply(lambda)).sub(expected).norm();
   
    // deviation from expected hitpoint should be lower than envelope+epsilon
View Full Code Here

    Body b1 = new Body("default", s1);
    b1.setPosition(2,-3,-1);
   
    // pick a point outside the sphere, and let the direction point towards
    // the centre of the sphere.
    Vector3 point = new Vector3(-4, 6, 9);
    Vector3 direction = b1.getPosition().sub(point);
   
    // do the raycast
    double lambda = raycast.run(s1, null, point, direction, new Vector3(), new Vector3(), 0, envelope, epsilon, false );
   
    // we know the exact intersection point ( go from the centre of the sphere
    // to the boundary along the oposite ray direction )
    Vector3 expected = b1.getPosition().sub(direction.normalize());
   
    // calculate the deviation of the returned point and the reference point
    double error = point.add(direction.multiply(lambda)).sub(expected).norm();
   
    System.out.println("error" + error);
View Full Code Here

    // setup sphere geometry
    Sphere s1 = new Sphere(1);
    Body b1 = new Body("default", s1);

    // select a point (5,1,0) and the raydirection (-1,0,0)
    Vector3 point = new Vector3(5, 1, 0);
    Vector3 direction = new Vector3(-1,0,0);
   
    System.out.println("*********************************************************************");
   
    // do the raycast
    double lambda = raycast.run(s1, null, point, direction, new Vector3(), new Vector3(), 0, envelope, epsilon, false );
   
    // calculate the  point
    Vector3 p = point.add(direction.multiply(lambda));
   
    System.out.println("p norm="+p.norm());
   
    // the hitpoint must be within the envelope
    assertTrue( Math.abs(p.norm()-1) < envelope+epsilon);
   
    // move the sphere a bit downwards
    b1.setPosition(0,-envelope-2*epsilon, 0);
   
    // do the raycast
    lambda = raycast.run(s1, null, point, direction, new Vector3(), new Vector3(), 0, envelope, epsilon, false );
   
    System.out.println("returned lambda="+lambda);
   
    assertTrue( lambda == Double.POSITIVE_INFINITY);
   
View Full Code Here

TOP

Related Classes of jinngine.math.Vector3

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.