Package nu3a.geometry

Examples of nu3a.geometry.N3Point3D


   *            Punto origen del rayo.
   * @param dest
   *            Punto destino del rayo.
   */
  public N3Ray(N3Point3D src, N3Point3D dest) {
    this.src = new N3Point3D(src.x, src.y, src.z);
    this.dest = new N3Point3D(dest.x, dest.y, dest.z);
    d = new N3Vector3D(dest.x - src.x, dest.y - src.y, dest.z - src.z);
    d.normalize();
  }
View Full Code Here


    // Punto en el interior del poligono proyectado.
    N3Point2D inside;
    // Obtenemos el plano del poligono representado de la forma Ax + By +Cz
    // +D = 0
    N3Vector3D polyNormal = poly.getPolygonNormal();
    N3Point3D v = (N3Point3D) poly.getVertex(0);
    float polyD = -(polyNormal.x * v.x + polyNormal.y * v.y + polyNormal.z
        * v.z);
    // Primero comprobamos si hay intersecci�n entre el rayo y el plano
    // Substituimos (x,y,z)=(px,py,pz) + t(dx,dy,dz) en la ecuacion del
    // plano.
    // despejamos t = -(Apx + Bpy + Cpz + D)/(Adx + Bdy + Cdz)
    float s = (polyNormal.x * d.x + polyNormal.y * d.y + polyNormal.z * d.z);
    if (s == 0)
      return false;
    float t = -(polyNormal.x * src.x + polyNormal.y * src.y + polyNormal.z
        * src.z + polyD)
        / s;
    if (t <= 0)
      return false;

    // Ahora hay que comprobar si el punto de corte del rayo con el plano,
    // esta dentro del poligono.
    // Obtenemos el punto de corte con el plano.
    N3Point3D p3D = new N3Point3D(src.x + t * d.x, src.y + t * d.y, src.z
        + t * d.z);

    // Utilizamos el metodo de los half-spaces proyectando el pol�gono y el
    // punto ortograficamente en 2D,
    // seleccionando como plano de proyecci�n aquel en el que el pol�gono
    // tenga un mayor �rea.
    // El �rea es proporcional al las componentes A,B,C del vector normal
    // del pol�gono.
    N3Point2D p2D;
    // Indica en que plano hemos proyectado. 0 = yz, 1 = zx, 2 = xy.
    int plane;
    if (Math.abs(polyNormal.x) > Math.abs(polyNormal.y)
        && Math.abs(polyNormal.x) > Math.abs(polyNormal.z)) {
      // Si es |A| proyectamos en el plano yz.
      p2D = new N3Point2D(p3D.y, p3D.z);
      plane = 0;
    } else if (Math.abs(polyNormal.y) > Math.abs(polyNormal.x)
        && Math.abs(polyNormal.y) > Math.abs(polyNormal.z)) {
      // Si es |B| proyectamos en el plano zx.
      p2D = new N3Point2D(p3D.z, p3D.x);
      plane = 1;
    } else {
      // Si es |C| proyectamos en el plano xy.
      p2D = new N3Point2D(p3D.x, p3D.y);
      plane = 2;
    }

    // Para cada arista del poligono calculamos la ecuaci�n e(u,v)= au + bv
    // + c = 0 que representa un divisi�n del espacio en 2
    // partes, "half-space", el pol�gono queda definido por la intersecci�n
    // de todos ellos.
    // Para un poligono definido en sentido antihorario un punto esta dentro
    // de el si para todos las aristas
    // e < 0.
    for (int i = 0; i < poly.getSides(); i++) {
      // Proyectamos los puntos de la arista actual.
      N3Point3D v13D = (N3Point3D) poly.getVertex(i);
      N3Point3D v23D;
      N3Point2D v1, v2;
      if (i == poly.getSides() - 1)
        v23D = (N3Point3D) poly.getVertex(0);
      else
        v23D = (N3Point3D) poly.getVertex(i + 1);
View Full Code Here

   */
  public N3AABB() {
    maxX = minX = 0;
    maxY = minY = 0;
    maxZ = minZ = 0;
    v1 = new N3Point3D();
    v2 = new N3Point3D();
    v3 = new N3Point3D();
    v4 = new N3Point3D();
    v5 = new N3Point3D();
    v6 = new N3Point3D();
    v7 = new N3Point3D();
    v8 = new N3Point3D();
    firstAdd = true;
  }
View Full Code Here

   *            colisi�n.
   */
  public N3AABB(N3GeometryData geometryData) {
    this.geometryData = geometryData;

    v1 = new N3Point3D();
    v2 = new N3Point3D();
    v3 = new N3Point3D();
    v4 = new N3Point3D();
    v5 = new N3Point3D();
    v6 = new N3Point3D();
    v7 = new N3Point3D();
    v8 = new N3Point3D();
  }
View Full Code Here

    // Calculamos la caja AABB a partir de la geometria

    for (int i = 0; i < geometryData.polygonCount(); i++) {
      N3Polygon poly = geometryData.getPolygon(i);
      for (int j = 0; j < poly.getSides(); j++) {
        N3Point3D vertex = (N3Point3D) poly.getVertex(j);
        N3Point3D v = new N3Point3D(vertex.x, vertex.y, vertex.z);
        v = m.mult(v);
        if (first) {
          maxX = minX = v.x;
          maxY = minY = v.y;
          maxZ = minZ = v.z;
View Full Code Here

   * @param p
   *            Punto que transformar por la matriz.
   * @return El punto transformado por la matriz.
   */
  public N3Point3D mult(N3Point3D p) {
    N3Point3D res = new N3Point3D();
    res.x = matrix[0] * p.x + matrix[4] * p.y + matrix[8] * p.z
        + matrix[12];
    res.y = matrix[1] * p.x + matrix[5] * p.y + matrix[9] * p.z
        + matrix[13];
    res.z = matrix[2] * p.x + matrix[6] * p.y + matrix[10] * p.z
 
View Full Code Here

   * espacio 3D.
   *
   * @return Posición
   */
  public N3Point3D getPosition() {
    return new N3Point3D(matrix[12], matrix[13], matrix[14]);
  }
View Full Code Here

    c.clearToColor(color);
    c.paint();
  }

  public void run() {
    N3Point3D vertexP = new N3Point3D(0, 0, 0);
    N3Point3D vertexL1 = new N3Point3D(0, 0, 0);
    N3Point3D vertexL2 = new N3Point3D(0, 0, 0);
    N3Point3D vertexT1 = new N3Point3D(0, 0, 0);
    N3Point3D vertexT2 = new N3Point3D(0, 0, 0);
    N3Point3D vertexT3 = new N3Point3D(0, 0, 0);
    N3ColorRGBA color = new N3ColorRGBA(0, 0, 0);
    N3ColorRGBA colorG1 = new N3ColorRGBA(0, 0, 0);
    N3ColorRGBA colorG2 = new N3ColorRGBA(0, 0, 0);
    N3ColorRGBA colorG3 = new N3ColorRGBA(0, 0, 0);
    double t = System.currentTimeMillis();
    int i = 0;
    boolean flatVertex = true;
    boolean flatHLine = true;
    boolean flatVLine = true;
    boolean flatLine = true;
    boolean goraudHLine = true;
    boolean goraudVLine = true;
    boolean goraudLine = true;
    boolean flatTriangle = true;
    boolean goraudTriangle = true;
    while (true) {
      c.beginDrawingMode(N3SoftwareRenderContext.N3_POINTS);
      /* Dibujamos un punto */
      if (flatVertex) {
        color.setR((float) Math.random());
        color.setG((float) Math.random());
        color.setB((float) Math.random());
        c.setColor(color);
        vertexP.setX((float) (Math.random() * c.getWidth()));
        vertexP.setY((float) (Math.random() * c.getHeight()));
        vertexP.setZ((float) Math.random());
        c.setVertex(vertexP);
      }
      c.endDrawingMode();

      /* Vamos a dibjuar líneas... */
      c.beginDrawingMode(N3SoftwareRenderContext.N3_LINES);
      /* Dibujamos una línea horizontal flat */
      if (flatHLine) {
        color.setR((float) Math.random());
        color.setG((float) Math.random());
        color.setB((float) Math.random());
        c.setColor(color);
        vertexL1.setX((float) (Math.random() * c.getWidth()));
        vertexL1.setY((float) (Math.random() * c.getHeight()));
        vertexL1.setZ((float) Math.random());
        c.setVertex(vertexL1);
        vertexL2.setX((float) (Math.random() * c.getWidth()));
        vertexL2.setY(vertexL1.getY());
        vertexL2.setZ((float) Math.random());
        c.setVertex(vertexL2);
      }

      /* Dibujamos una línea vertical flat */
      if (flatVLine) {
        color.setR((float) Math.random());
        color.setG((float) Math.random());
        color.setB((float) Math.random());
        c.setColor(color);
        vertexL1.setX((float) (Math.random() * c.getWidth()));
        vertexL1.setY((float) (Math.random() * c.getHeight()));
        vertexL1.setZ((float) Math.random());
        c.setVertex(vertexL1);
        vertexL2.setX(vertexL1.getX());
        vertexL2.setY((float) (Math.random() * c.getHeight()));
        vertexL2.setZ((float) Math.random());
        c.setVertex(vertexL2);
      }

      /* Dibujamos una línea cualquiera flat */
      if (flatLine) {
        color.setR((float) Math.random());
        color.setG((float) Math.random());
        color.setB((float) Math.random());
        c.setColor(color);
        vertexL1.setX((float) (Math.random() * c.getWidth()));
        vertexL1.setY((float) (Math.random() * c.getHeight()));
        vertexL1.setZ((float) Math.random());
        c.setVertex(vertexL1);
        vertexL2.setX((float) (Math.random() * c.getWidth()));
        vertexL2.setY((float) (Math.random() * c.getHeight()));
        vertexL2.setZ((float) Math.random());
        c.setVertex(vertexL2);
      }

      /* Dibujamos una línea horizontal goraud */
      if (goraudHLine) {
        colorG1.setR((float) Math.random());
        colorG1.setG((float) Math.random());
        colorG1.setB((float) Math.random());
        c.setColor(colorG1);
        vertexL1.setX((float) (Math.random() * c.getWidth()));
        vertexL1.setY((float) (Math.random() * c.getHeight()));
        vertexL1.setZ((float) Math.random());
        c.setVertex(vertexL1);
        colorG2.setR((float) Math.random());
        colorG2.setG((float) Math.random());
        colorG2.setB((float) Math.random());
        c.setColor(colorG2);
        vertexL2.setX((float) (Math.random() * c.getWidth()));
        vertexL2.setY(vertexL1.getY());
        vertexL2.setZ((float) Math.random());
        c.setVertex(vertexL2);
      }

      /* Dibujamos una línea vertical goraud */
      if (goraudVLine) {
        colorG1.setR((float) Math.random());
        colorG1.setG((float) Math.random());
        colorG1.setB((float) Math.random());
        c.setColor(colorG1);
        vertexL1.setX((float) (Math.random() * c.getWidth()));
        vertexL1.setY((float) (Math.random() * c.getHeight()));
        vertexL1.setZ((float) Math.random());
        c.setVertex(vertexL1);
        colorG2.setR((float) Math.random());
        colorG2.setG((float) Math.random());
        colorG2.setB((float) Math.random());
        c.setColor(colorG2);
        vertexL2.setX(vertexL1.getX());
        vertexL2.setY((float) (Math.random() * c.getHeight()));
        vertexL2.setZ((float) Math.random());
        c.setVertex(vertexL2);
      }

      /* Dibujamos una línea goraud */
      if (goraudLine) {
        colorG1.setR((float) Math.random());
        colorG1.setG((float) Math.random());
        colorG1.setB((float) Math.random());
        c.setColor(colorG1);
        vertexL1.setX((float) (Math.random() * c.getWidth()));
        vertexL1.setY((float) (Math.random() * c.getHeight()));
        vertexL1.setZ((float) Math.random());
        c.setVertex(vertexL1);
        colorG2.setR((float) Math.random());
        colorG2.setG((float) Math.random());
        colorG2.setB((float) Math.random());
        c.setColor(colorG2);
        vertexL2.setX((float) (Math.random() * c.getWidth()));
        vertexL2.setY((float) (Math.random() * c.getHeight()));
        vertexL2.setZ((float) Math.random());
        c.setVertex(vertexL2);
      }

      c.endDrawingMode();

      c.beginDrawingMode(N3SoftwareRenderContext.N3_TRIANGLES);
      /* Dibujamos un triángulo plano */
      if (flatTriangle) {
        color.setR((float) Math.random());
        color.setG((float) Math.random());
        color.setB((float) Math.random());
        c.setColor(color);
        vertexT1.setX((float) (Math.random() * c.getWidth() + 10));
        vertexT1.setY((float) (Math.random() * c.getHeight() - 10));
        vertexT1.setZ((float) Math.random());
        c.setVertex(vertexT1);
        vertexT2.setX((float) (Math.random() * c.getWidth() - 10));
        vertexT2.setY((float) (Math.random() * c.getHeight() + 10));
        vertexT2.setZ((float) Math.random());
        c.setVertex(vertexT2);
        vertexT3.setX((float) (Math.random() * c.getWidth() + 10));
        vertexT3.setY((float) (Math.random() * c.getHeight() - 10));
        vertexT3.setZ((float) Math.random());
        c.setVertex(vertexT3);
      }

      /* Dibujamos un triángulo goraud */
      if (goraudTriangle) {
        colorG1.setR((float) Math.random());
        colorG1.setG((float) Math.random());
        colorG1.setB((float) Math.random());
        c.setColor(colorG1);
        vertexT1.setX((float) (Math.random() * c.getWidth()));
        vertexT1.setY((float) (Math.random() * c.getHeight()));
        vertexT1.setZ((float) Math.random());
        c.setVertex(vertexT1);
        colorG2.setR((float) Math.random());
        colorG2.setG((float) Math.random());
        colorG2.setB((float) Math.random());
        c.setColor(colorG2);
        vertexT2.setX((float) (Math.random() * c.getWidth()));
        vertexT2.setY((float) (Math.random() * c.getHeight()));
        vertexT2.setZ((float) Math.random());
        c.setVertex(vertexT2);
        colorG3.setR((float) Math.random());
        colorG3.setG((float) Math.random());
        colorG3.setB((float) Math.random());
        c.setColor(colorG3);
        vertexT3.setX((float) (Math.random() * c.getWidth()));
        vertexT3.setY((float) (Math.random() * c.getHeight()));
        vertexT3.setZ((float) Math.random());
        c.setVertex(vertexT3);
      }

      c.endDrawingMode();

View Full Code Here

    // /Optimizaciones
    vect1 = new N3Vector3D();
    vect2 = new N3Vector3D();
    d = new N3Vector3D();
    v1 = new N3Point3D();
    v2 = new N3Point3D();
    v3 = new N3Point3D();
    c1 = new N3ColorRGBA();
    c2 = new N3ColorRGBA();
    c3 = new N3ColorRGBA();
    cV1 = new N3Point3D();
    cV2 = new N3Point3D();
    cV3 = new N3Point3D();
    normal = new N3Vector3D();
    renderContext.setTextureMode(renderContext.N3_SWR_MODULATE);
  }
View Full Code Here

    if (vertexData.hasNext()) {
      clip = false;
      renderContext
          .beginDrawingMode(N3SoftwareRenderContext.N3_TRIANGLES);
      while (vertexData.hasNext()) {
        N3Point3D t1 = (N3Point3D) vertexData.next();
        N3Point3D t2 = (N3Point3D) vertexData.next();
        N3Point3D t3 = (N3Point3D) vertexData.next();
        v1.x = t1.x;
        v1.y = t1.y;
        v1.z = t1.z;
        v2.x = t2.x;
        v2.y = t2.y;
View Full Code Here

TOP

Related Classes of nu3a.geometry.N3Point3D

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.