Package org.ode4j.math

Examples of org.ode4j.math.DVector3C


   
    while (iter.hasNext()) {
      Node<BodyPart> node = iter.next();
      BodyPart bp = node.getContent();
     
      DVector3C prePos;
      if (node.getPredecessor() != null) {
        prePos = node.getPredecessor().getContent().getBody().getPosition();
      }
      else {
        prePos = new DVector3(0, 0, 10);
      }
      DVector3 relPos = bp.getPosition();
      DVector3 size = bp.getSize();
      DVector3 newPos;
      if (node.getPredecessor() == null) {
        newPos = new DVector3(
            prePos.get0(),
            prePos.get1(),
            prePos.get2());
      }
      else {
        newPos = new DVector3(
            prePos.get0() + relPos.get0()*size.get0()/2,
            prePos.get1() + relPos.get1()*size.get1()/2,
            prePos.get2() + relPos.get2()*size.get2()/2);
      }
      DBody b = OdeHelper.createBody(env.getWorld());
      bp.setBody(b);
      DGeom g = OdeHelper.createBox(
          env.getSpace(),
View Full Code Here


    double y = 0;
    double z = 0;
    int size = bodies.size();
    Iterator<DBody> iter = bodies.iterator();
    while (iter.hasNext()) {
      DVector3C pos = iter.next().getPosition();
      x += pos.get0();
      y += pos.get1();
      z += pos.get2();
    }
    DVector3 vec = new DVector3(x/size, y/size, z/size);
    return vec;
  }
View Full Code Here

   *
   * @param g
   *            Geometry to be drawn.
   */
  public static void drawGeom(DGeom g) {
    DVector3C pos = g.getPosition();
    DMatrix3C R = g.getRotation();

    if (g instanceof DBox) {
      DVector3C sides = ((DBox) g).getLengths();
      dsDrawBox(pos, R, sides);
    } else if (g instanceof DCylinder) {
      double r = ((DCylinder) g).getRadius();
      double l = ((DCylinder) g).getLength();
      dsDrawCylinder(pos, R, (float) l, (float) r);
View Full Code Here

    FloatBuffer pos = BufferUtils.createFloatBuffer(bodymatrix.length
        * bodymatrix.length * 3);

    for (int i = 0; i < bodymatrix.length; i++) {
      for (int j = 0; j < bodymatrix.length; j++) {
        DVector3C vec0 = bodymatrix[i][j].getPosition();
        float[] f0 = vec0.toFloatArray();
        pos.put(f0);
      }
    }
    pos.rewind();

View Full Code Here

    FloatBuffer pos = BufferUtils.createFloatBuffer(bodymatrix.length
        * bodymatrix.length * 3);

    for (int i = 0; i < bodymatrix.length; i++) {
      for (int j = 0; j < bodymatrix.length; j++) {
        DVector3C vec0 = bodymatrix[i][j].getPosition();
        float[] f0 = vec0.toFloatArray();
        pos.put(f0);
      }
    }
    pos.rewind();

View Full Code Here

    GL11.glEnable(GL11.GL_NORMALIZE);
    GL11.glBegin(GL11.GL_TRIANGLES);
    for (int i = 0; i < bodies.length - 1; ++i) {
      for (int j = 0; j < bodies[i].length - 1; ++j) {

        DVector3C vec0 = bodies[i][j].getPosition();
        DVector3C vec1 = bodies[i + 1][j].getPosition();
        DVector3C vec2 = bodies[i][j + 1].getPosition();
        DVector3C vec3 = bodies[i + 1][j + 1].getPosition();

        DVector3C temp1 = new DVector3(vec1.get0() - vec0.get0(),
            vec1.get1() - vec0.get1(), vec1.get2() - vec0.get2());
        DVector3C temp2 = new DVector3(vec2.get0() - vec0.get0(),
            vec2.get1() - vec0.get1(), vec2.get2() - vec0.get2());

        DVector3C temp3 = new DVector3(vec1.get0() - vec2.get0(),
            vec1.get1() - vec2.get1(), vec1.get2() - vec2.get2());
        DVector3C temp4 = new DVector3(vec3.get0() - vec2.get0(),
            vec3.get1() - vec2.get1(), vec3.get2() - vec2.get2());

        DVector3C normal = new DVector3(temp1.get1() * temp2.get2()
            - temp1.get2() * temp2.get1(), temp1.get2()
            * temp2.get0() - temp1.get0() * temp2.get2(),
            temp1.get0() * temp2.get1() - temp1.get1()
                * temp2.get0());
        DVector3C normal2 = new DVector3(temp3.get1() * temp4.get2()
            - temp3.get2() * temp4.get1(), temp3.get2()
            * temp4.get0() - temp3.get0() * temp4.get2(),
            temp3.get0() * temp4.get1() - temp3.get1()
                * temp4.get0());

        DVector3C norm0 = normal.clone();
        DVector3C norm1 = normal.clone();
        DVector3C norm2 = normal.clone();
        DVector3C norm3 = normal.clone();

        norm1 = new DVector3(norm1.get0() + normal2.get0(),
            norm1.get1() + normal2.get1(), norm1.get2()
                + normal2.get2());
        norm2 = new DVector3(norm2.get0() + normal2.get0(),
            norm2.get1() + normal2.get1(), norm2.get2()
                + normal2.get2());
        norm3 = new DVector3(norm3.get0() + normal2.get0(),
            norm3.get1() + normal2.get1(), norm3.get2()
                + normal2.get2());

        GL11.glNormal3d(norm0.get0(), norm0.get1(), norm0.get2());
        GL11.glVertex3d(vec0.get0(), vec0.get1(), vec0.get2());
        GL11.glNormal3d(norm1.get0(), norm1.get1(), norm1.get2());
        GL11.glVertex3d(vec1.get0(), vec1.get1(), vec1.get2());
        GL11.glNormal3d(norm2.get0(), norm2.get1(), norm2.get2());
        GL11.glVertex3d(vec2.get0(), vec2.get1(), vec2.get2());

        GL11.glNormal3d(norm2.get0(), norm2.get1(), norm2.get2());
        GL11.glVertex3d(vec2.get0(), vec2.get1(), vec2.get2());
        GL11.glNormal3d(norm1.get0(), norm1.get1(), norm1.get2());
        GL11.glVertex3d(vec1.get0(), vec1.get1(), vec1.get2());
        GL11.glNormal3d(norm3.get0(), norm3.get1(), norm3.get2());
        GL11.glVertex3d(vec3.get0(), vec3.get1(), vec3.get2());
      }
    }
    GL11.glEnd();
    GL11.glDisable(GL11.GL_NORMALIZE);

    GL11.glDisable(GL11.GL_LIGHTING);
    // GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glLightModeli(GL11.GL_LIGHT_MODEL_TWO_SIDE, GL11.GL_FALSE);

    // / GRID
    GL11.glDisable(GL11.GL_LIGHTING);
    GL11.glLineWidth(2);
    GL11.glEnable(GL11.GL_LINE_STIPPLE);
    // GL11.glShadeModel(GL11.GL_FLAT);
    GL11.glColor3f(.085f, .085f, .085f);
    GL11.glBegin(GL11.GL_LINES);

    for (int i = 0; i < bodies.length - 1; ++i) {
      for (int j = 0; j < bodies[i].length - 1; ++j) {
        DVector3C vec0 = bodies[i][j].getPosition();
        DVector3C vec1 = bodies[i][j + 1].getPosition();
        DVector3C vec2 = bodies[i + 1][j].getPosition();
        GL11.glVertex3d(vec0.get0(), vec0.get1(), vec0.get2());
        GL11.glVertex3d(vec1.get0(), vec1.get1(), vec1.get2());

        GL11.glVertex3d(vec0.get0(), vec0.get1(), vec0.get2());
        GL11.glVertex3d(vec2.get0(), vec2.get1(), vec2.get2());
      }
    }
    for (int i = 0; i < bodies.length - 1; i++) {
      DVector3C vec0 = bodies[i][bodies[i].length - 1].getPosition();
      DVector3C vec1 = bodies[i + 1][bodies[i + 1].length - 1]
          .getPosition();
      GL11.glVertex3d(vec0.get0(), vec0.get1(), vec0.get2());
      GL11.glVertex3d(vec1.get0(), vec1.get1(), vec1.get2());
    }
    for (int i = 0; i < bodies.length - 1; i++) {
      DVector3C vec0 = bodies[bodies[i].length - 1][i].getPosition();
      DVector3C vec1 = bodies[bodies[i + 1].length - 1][i + 1]
          .getPosition();
      GL11.glVertex3d(vec0.get0(), vec0.get1(), vec0.get2());
      GL11.glVertex3d(vec1.get0(), vec1.get1(), vec1.get2());
    }
    GL11.glEnd();
  }
View Full Code Here

TOP

Related Classes of org.ode4j.math.DVector3C

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.