Package jmt.engine.graphic

Examples of jmt.engine.graphic.Vector4


    vertices[2] = v2;
    return vertices;
  }

  public void updateNormal() {
    Vector4 vv0 = Vector4.createPoint3D(v0.x(), v0.y(), v0.z());
    Vector4 vv1 = Vector4.createPoint3D(v1.x(), v1.y(), v1.z());
    Vector4 vv2 = Vector4.createPoint3D(v2.x(), v2.y(), v2.z());
    vv1.subSelf(vv0);
    vv2.subSelf(vv0);
    vv1.crossSelf(vv2);
    normal = vv1;
    normal.normalize();
  }
View Full Code Here


    else
      return 0;
  }

  public boolean isCoplanar(HullFace face) {
    Vector4 diff = this.normal.clone();
    diff.subSelf(face.normal);
    if (Math.abs(diff.x()) > COPLANAR_EPSILON
        || Math.abs(diff.y()) > COPLANAR_EPSILON
        || Math.abs(diff.z()) > COPLANAR_EPSILON) {
      return false;
    } else {
      return true;
    }
  }
View Full Code Here

    int size = faces.size();
    for (int i = 0; i < size; i++) {
      HullFace face = faces.get(i);

      Vector4 normal = face.getNormal();
      HullEdge[] edges = face.getEdges();
      HullVertex[] vertices = face.getVertices();

      float facing = normal.dot(forward);
      boolean isVisible = (facing <= VISIBILITY_EPSILON);
      if (isVisible) {
        visibleFacesSet.add(face);
      } else {
        hiddenFacesSet.add(face);
      }
      face.setShade(facing);

      // Create unique and visibility sets
      for (int j = 0; j < edges.length; j++) {
        HullEdge e = edges[j];
        if (isVisible) {
          visibleEdgesSet.add(e);

          // Fix edges flagged as hidden but actually visible
          if (hiddenEdgesSet.contains(e)) {
            hiddenEdgesSet.remove(e);
          }
        } else if (!visibleEdgesSet.contains(e)) {
          // Add only if no other faces have already claimed the edge
          // visibility.
          hiddenEdgesSet.add(e);
        }
        if (hullEdgesSet.add(e)) {
        }
      }
      for (int j = 0; j < vertices.length; j++) {
        HullVertex v = vertices[j];
        Vector4 worldPos = Vector4.createPoint3D(v.x(), v.y(), v.z());
        Vector4 screenPos = prj.project(worldPos);
        PointData p = new PointData(worldPos, screenPos, v);
        if (isVisible) {
          visibleVerticesSet.add(p);

          // Fix vertices flagged as hidden but actually visible
          if (hiddenVerticesSet.contains(p)) {
            hiddenVerticesSet.remove(p);
          }
        } else if (!visibleVerticesSet.contains(p)) {
          // Add only if no other faces have already claimed the
          // vertex visibility.
          hiddenVerticesSet.add(p);
        }
        if (p.vertex.getID() >= 0 && hullVerticesSet.add(p)) {
          if (v.x() > max[0]) {
            max[0] = v.x();
          }
          if (v.y() > max[1]) {
            max[1] = v.y();
          }
          if (v.z() > max[2]) {
            max[2] = v.z();
          }
          if (v.x() < min[0]) {
            min[0] = v.x();
          }
          if (v.y() < min[1]) {
            min[1] = v.y();
          }
          if (v.z() < min[2]) {
            min[2] = v.z();
          }
        }
      }
    }

    // Centering and scaling
    centroid.x((max[0] + min[0]) * 0.5f * zoomFactor);
    centroid.y((max[1] + min[1]) * 0.5f * zoomFactor);
    centroid.z((max[2] + min[2]) * 0.5f * zoomFactor);
    max[0] -= min[0];
    max[1] -= min[1];
    max[2] -= min[2];
    maxVertexDistance = 0.5f * (float) Math.sqrt(max[0] * max[0] + max[1]
        * max[1] + max[2] * max[2]);
    centroid.divSelf(maxVertexDistance * zoomFactor);

    // Build the verticesInside set.
    verticesInsideSet.clear();
    for (int i = 0; i < allVerticesArray.length; i++) {
      HullVertex v = allVerticesArray[i];
      PointData p = new PointData(null, null, v); // Dummy PointData, just
                            // to check the HashSet
      if (!hullVerticesSet.contains(p)) {
        Vector4 worldPos = Vector4.createPoint3D(v.x(), v.y(), v.z());
        Vector4 screenPos = prj.project(worldPos);
        p = new PointData(worldPos, screenPos, v);
        verticesInsideSet.add(p);
      }
    }

View Full Code Here

    // Draw hidden faces
    if (enableHiddenFaces) {
      for (int i = 0; i < hiddenFacesArray.length; i++) {
        HullFace f = hiddenFacesArray[i];
        HullVertex v = f.getVertex(0);
        Vector4 worldPos = Vector4.createPoint3D(v.x(), v.y(), v.z());
        Vector4 screenPos = prj.project(worldPos);
        PointData p1 = new PointData(worldPos, screenPos, v);

        v = f.getVertex(1);
        worldPos = Vector4.createPoint3D(v.x(), v.y(), v.z());
        screenPos = prj.project(worldPos);
        PointData p2 = new PointData(worldPos, screenPos, v);

        v = f.getVertex(2);
        worldPos = Vector4.createPoint3D(v.x(), v.y(), v.z());
        screenPos = prj.project(worldPos);
        PointData p3 = new PointData(worldPos, screenPos, v);

        drawFace(g, p1, p2, p3, f);
      }
    }

    // Draw visible faces
    if (enableVisibleFaces) {
      for (int i = 0; i < visibleFacesArray.length; i++) {
        HullFace f = visibleFacesArray[i];
        HullVertex v = f.getVertex(0);
        Vector4 worldPos = Vector4.createPoint3D(v.x(), v.y(), v.z());
        Vector4 screenPos = prj.project(worldPos);
        PointData p1 = new PointData(worldPos, screenPos, v);

        v = f.getVertex(1);
        worldPos = Vector4.createPoint3D(v.x(), v.y(), v.z());
        screenPos = prj.project(worldPos);
        PointData p2 = new PointData(worldPos, screenPos, v);

        v = f.getVertex(2);
        worldPos = Vector4.createPoint3D(v.x(), v.y(), v.z());
        screenPos = prj.project(worldPos);
        PointData p3 = new PointData(worldPos, screenPos, v);

        drawFace(g, p1, p2, p3, f);
      }
    }

    // Draw hidden edges
    if (enableHiddenEdges) {
      for (int i = 0; i < hiddenEdgesArray.length; i++) {
        HullEdge e = hiddenEdgesArray[i];
        HullVertex v = e.getEndPoint(0);
        Vector4 worldPos = Vector4.createPoint3D(v.x(), v.y(), v.z());
        Vector4 screenPos = prj.project(worldPos);
        PointData p1 = new PointData(worldPos, screenPos, v);

        v = e.getEndPoint(1);
        worldPos = Vector4.createPoint3D(v.x(), v.y(), v.z());
        screenPos = prj.project(worldPos);
        PointData p2 = new PointData(worldPos, screenPos, v);

        drawEdge(g, p1, p2, e, false);
      }
    }

    // Draw hidden hull vertices
    for (int i = 0; i < sortedHiddenVertices.length; i++) {
      PointData p = sortedHiddenVertices[i];
      if (p.vertex.getID() >= 0) {
        drawVertex(g, p, false, true);
      }
    }

    // Draws points inside
    for (int i = 0; i < sortedVerticesInside.length; i++) {
      PointData p = sortedVerticesInside[i];
      if (enableInternalVertices || p.vertex.getName().equals(selectedStation) ) {
        drawVertex(g, p, false, false);
      }
    }
   

    drawAxes(g, true);

    // Draw visible hull edges
    if (enableVisibleEdges) {
      for (int i = 0; i < visibleEdgesArray.length; i++) {
        HullEdge e = visibleEdgesArray[i];
        HullVertex v = e.getEndPoint(0);
        Vector4 worldPos = Vector4.createPoint3D(v.x(), v.y(), v.z());
        Vector4 screenPos = prj.project(worldPos);
        PointData p1 = new PointData(worldPos, screenPos, v);

        v = e.getEndPoint(1);
        worldPos = Vector4.createPoint3D(v.x(), v.y(), v.z());
        screenPos = prj.project(worldPos);
View Full Code Here

      boolean xEnable, boolean yEnable, boolean zEnable) {
    // size *= 0.5f;
    float delta = size / numSegments;
    float offset, limit = size;
    numSegments *= 2;
    Vector4 p = new Vector4();
    if (xEnable) {
      final Color lineColor = new Color(1.0f, 0.75f, 0.75f);
      g.setColor(lineColor);
      offset = -limit;
      for (int i = 0; i <= numSegments; i++) {
        p.set(0.0f, offset, -limit, 1.0f);
        Vector4 s1 = prj.project(p);
        p.set(0.0f, offset, limit, 1.0f);
        Vector4 e1 = prj.project(p);
        p.set(0.0f, -limit, offset, 1.0f);
        Vector4 s2 = prj.project(p);
        p.set(0.0f, limit, offset, 1.0f);
        Vector4 e2 = prj.project(p);
        g.drawLine((int) s1.x(), (int) s1.y(), (int) e1.x(),
            (int) e1.y());
        g.drawLine((int) s2.x(), (int) s2.y(), (int) e2.x(),
            (int) e2.y());
        offset += delta;
      }
    }
    if (yEnable) {
      final Color lineColor = new Color(0.75f, 1.0f, 0.75f);
      g.setColor(lineColor);
      offset = -limit;
      for (int i = 0; i <= numSegments; i++) {
        p.set(offset, 0.0f, -limit, 1.0f);
        Vector4 s1 = prj.project(p);
        p.set(offset, 0.0f, limit, 1.0f);
        Vector4 e1 = prj.project(p);
        p.set(-limit, 0.0f, offset, 1.0f);
        Vector4 s2 = prj.project(p);
        p.set(limit, 0.0f, offset, 1.0f);
        Vector4 e2 = prj.project(p);
        g.drawLine((int) s1.x(), (int) s1.y(), (int) e1.x(),
            (int) e1.y());
        g.drawLine((int) s2.x(), (int) s2.y(), (int) e2.x(),
            (int) e2.y());
        offset += delta;
      }
    }
    if (zEnable) {
      final Color lineColor = new Color(0.75f, 0.75f, 1.0f);
      g.setColor(lineColor);
      offset = -limit;
      for (int i = 0; i <= numSegments; i++) {
        p.set(offset, -limit, 0.0f, 1.0f);
        Vector4 s1 = prj.project(p);
        p.set(offset, limit, 0.0f, 1.0f);
        Vector4 e1 = prj.project(p);
        p.set(-limit, offset, 0.0f, 1.0f);
        Vector4 s2 = prj.project(p);
        p.set(limit, offset, 0.0f, 1.0f);
        Vector4 e2 = prj.project(p);
        g.drawLine((int) s1.x(), (int) s1.y(), (int) e1.x(),
            (int) e1.y());
        g.drawLine((int) s2.x(), (int) s2.y(), (int) e2.x(),
            (int) e2.y());
        offset += delta;
      }
    }
  }
View Full Code Here

    g.setColor(visible ? colorVisible : colorHidden);
    g.fillPolygon(x, y, 3);

    if (enableDebugInfo) {
      // Draw normals
      Vector4 wc = new Vector4();
      wc.x(p1.worldPos.x() + p2.worldPos.x() + p3.worldPos.x());
      wc.y(p1.worldPos.y() + p2.worldPos.y() + p3.worldPos.y());
      wc.z(p1.worldPos.z() + p2.worldPos.z() + p3.worldPos.z());
      wc.w(1.0f);
      wc.multSelf(1.0f / 3.0f);
      Vector4 pc = prj.project(wc);
      Vector4 pn = prj.project(wc.add(face.getNormal()));
      g.setColor(Color.BLUE);
      g.drawLine((int) pc.x(), (int) pc.y(), (int) pn.x(), (int) pn.y());
    }
  }
View Full Code Here

  /**
   * Projects 3D points onto the screen and repaints the diagram.
   */
  public void updateProjection() {
    final Vector4 nx = Vector4.createPoint3D(2.0f, 0.0f, 0.0f);
    final Vector4 ny = Vector4.createPoint3D(0.0f, 2.0f, 0.0f);
    final Vector4 nz = Vector4.createPoint3D(0.0f, 0.0f, 2.0f);
    final Vector4 lx = Vector4.createPoint3D(1.7f, 0.0f, 0.0f);
    final Vector4 ly = Vector4.createPoint3D(0.0f, 1.2f, 0.0f);
    final Vector4 lz = Vector4.createPoint3D(0.0f, 0.0f, 1.7f);

    if (zoomFactor > 1.0f) {
      rotXdelta /= zoomFactor;
      rotYdelta /= zoomFactor;
    }

    // Keep pitch rotation between ±90°
    rotX = clamp((float) Math.toRadians(-89), rotX + rotXdelta,
        (float) Math.toRadians(89));

    // Yaw rotation modulo 360°
    rotY -= rotYdelta;
    if (rotY < 0) {
      rotY += (2 * Math.PI);
    }
    rotY %= 2 * Math.PI;

    rotXdelta = 0;
    rotYdelta = 0;

    Dimension size = getSize();
    if (size.width < 32 || size.height < 32) {
      return;
    }
    screenW = size.width;
    screenH = size.height;
    halfW = screenW / 2;
    halfH = screenH / 2;
    aspect = screenW / screenH;
    prj.setScreenSize(size);
    prj.updateProjection();

    Matrix4 mv = prj.getModelView();
    eyeRT = Matrix4.createScale(0.95f * (enableCustomZoom ? zoomFactor
        : 1.0f));
    eyeRT.multSelf(Matrix4.createRotationX(rotX));
    eyeRT.multSelf(Matrix4.createRotationY(rotY));
    eyeRT.multSelf(Matrix4.createTranslation(-centroid.x(), centroid.y(),
        centroid.z()));
    Vector4 eyePos = Vector4.createPoint3D(0.0f, 0.0f, 10.0f);
    prj.lookAt(eyePos, Vector4.ORIGIN, false);
    prj.push(mv.clone());
    prj.push(eyeRT.clone());
    mv.set(eyeRT.mult(mv));

View Full Code Here

TOP

Related Classes of jmt.engine.graphic.Vector4

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.