protected void drawWAll(Color c, IDrawOperation op, Point3D[] wall, int dx, int dy, int dz) {

    Point3D a = new Point3D(0, 0, 0);
    Point3D b = new Point3D(0, 0, 0);
    int[] xs = new int[4];
    int[] ys = new int[4];

    for (int i = 0; i < 4; i++) {
      int j = (i == 3) ? 0 : i + 1;

      a.x = wall[i].x + dx;
      a.y = wall[i].y + dy;
      a.z = wall[i].z + dz;
      b.x = wall[j].x + dx;
      b.y = wall[j].y + dy;
      b.z = wall[j].z + dz;

      checkPoint(a);
      checkPoint(b);

      xs[i] = sx + a.x;
      ys[i] = sy - a.y;
    }

    op.fillPolygone(c, xs, ys, 1.0f);
    op.drawPolygone(Color.black, xs, ys, 1.0f);
  }
Beispiel #2
0
 public Point3D getCenterX(int order) {
   Point3D point = new Point3D();
   Point3D center = new Point3D();
   int offset = order * 4;
   for (int p = 0; p < 4; p++) {
     this.getPoint(p + offset, point);
     center.set(center.x() + point.x(), center.y() + point.y(), center.z() + point.z());
   }
   center.set(center.x() * 0.25, center.y() * 0.25, center.z() * 0.25);
   return center;
 }
Beispiel #3
0
 /**
  * @param a
  * @param b
  * @return
  */
 public static Point3D fois(Point3D a, double b) {
   Point3D c = new Point3D(a.x, a.x, a.x);
   c.x = a.x * b;
   c.y = a.y * b;
   c.z = a.z * b;
   return c;
 }
Beispiel #4
0
 /**
  * @param a
  * @param b
  * @return
  */
 public static Point3D div(Point3D a, double b) {
   Point3D c = new Point3D(a.x, a.x, a.x);
   c.x = a.x / b;
   c.y = a.y / b;
   c.z = a.z / b;
   return c;
 }
Beispiel #5
0
 /**
  * @param a
  * @param b
  * @return
  */
 public static Point3D plus(Point3D a, Point3D b) {
   Point3D c = new Point3D(a.x, a.x, a.x);
   c.x = a.x + b.x;
   c.y = a.y + b.y;
   c.z = a.z + b.z;
   return c;
 }
Beispiel #6
0
 /**
  * @param a
  * @param b
  * @return
  */
 public static Point3D moins(Point3D a, Point3D b) {
   Point3D c = new Point3D((a.x - b.x), (a.y - b.y), (a.z - b.z));
   c.x = a.x - b.x;
   c.y = a.y - b.y;
   c.z = a.z - b.z;
   return c;
 }
  public Point3D update(float time) {
    elapsedTime += time;
    if (elapsedTime == 0) {
      returnPos = pos1;
    } else if (elapsedTime >= 10) // traveling to a planet will take 10 seconds
    {
      returnPos.set(pos4.x, pos4.y, pos4.z);
    } else {
      float t = elapsedTime / 10f;

      returnPos.x =
          (1.0f - t) * (1.0f - t) * (1.0f - t) * pos1.x
              + 3 * (1.0f - t) * (1.0f - t) * t * pos2.x
              + 3 * (1.0f - t) * t * t * pos3.x
              + t * t * t * pos4.x;
      returnPos.y =
          (1.0f - t) * (1.0f - t) * (1.0f - t) * pos1.y
              + 3 * (1.0f - t) * (1.0f - t) * t * pos2.y
              + 3 * (1.0f - t) * t * t * pos3.y
              + t * t * t * pos4.y;
      returnPos.z =
          (1.0f - t) * (1.0f - t) * (1.0f - t) * pos1.z
              + 3 * (1.0f - t) * (1.0f - t) * t * pos2.z
              + 3 * (1.0f - t) * t * t * pos3.z
              + t * t * t * pos4.z;
    }

    return returnPos;
  }
Beispiel #8
0
 @Override
 public void rotateZ(double angle) {
   Point3D point = new Point3D();
   for (int p = 0; p < this.meshPoints.length; p += 3) {
     point.set(meshPoints[p], meshPoints[p + 1], meshPoints[p + 2]);
     point.rotateZ(angle);
     meshPoints[p] = (float) point.x();
     meshPoints[p + 1] = (float) point.y();
     meshPoints[p + 2] = (float) point.z();
   }
 }
Beispiel #9
0
  /** Returns XYZ coordinates of the point. Z will be set to 0 if Z is missing. */
  Point3D getXYZ() {
    if (isEmptyImpl())
      throw new GeometryException("This operation should not be performed on an empty geometry.");

    Point3D pt = new Point3D();
    pt.x = m_attributes[0];
    pt.y = m_attributes[1];
    if (m_description.hasZ()) pt.z = m_attributes[2];
    else pt.z = VertexDescription.getDefaultValue(Semantics.Z);

    return pt;
  }
  @Override
  public Point3D convertToCameraCoordinateSystem(Point3D point3D) {
    Point3D converted = super.convertToCameraCoordinateSystem(point3D);

    double focalLength = cameraSettings.getFocalLength();
    double ratio = focalLength / converted.z;

    double x = ratio * converted.x;
    double y = ratio * converted.y;
    double z = converted.z;

    converted.x = x;
    converted.y = y;
    converted.z = z;

    return converted;
  }
  private void checkPoint(Point3D p) {
    //		double cos = Math.cos(Math.PI/8);
    //		double sin = Math.sin(Math.PI/8);
    //		Point3D p2 = new Point3D(0,0,0);

    // sur l'axe z
    //		p2.x = (int) (p.x*cos+p.y*sin);
    //		p2.y = (int) (-p.x*sin+p.y*cos);
    //		p2.z = p.z;
    //		vx = (int) (pointFuite.x*cos+pointFuite.y*sin);
    //		vy = (int) (-pointFuite.x*sin+pointFuite.y*cos);
    //		vz = (int) (pointFuite.z);

    //		p2.x = (int) (p.x*cos-p.z*sin);
    //		p2.y = (int) (p.y);
    //		p2.z = (int) (-p.x*sin+p.z*cos);

    //		p2.x = (int) (p.x);
    //		p2.y = (int) (p.y*cos-p.z*sin);
    //		p2.z = (int) (p.y*sin+p.z*cos);
    //		vx = (int) (pointFuite.x);
    //		vy = (int) (pointFuite.y*cos-pointFuite.z*sin);
    //		vz = (int) (pointFuite.y*sin+pointFuite.z*cos);

    //		double a = (vy-p2.y) / (vx-p2.x);
    //		double z = Math.min(vz, p2.z);
    //
    //		double var = z / vz;
    //		double yy = 1 - 1/(1+var*1.5);
    //		double d = yy * (vx-p2.x);

    double a = (vy - p.y) / (vx - p.x);
    double z = Math.min(vz, p.z);

    double var = z / vz;
    double yy = 1 - 1 / (1 + var * 1.5);
    double d = yy * (vx - p.x);

    //		p.x = p2.x;
    //		p.y = p2.y;
    //		p.z = p2.z;

    p.x += (int) d;
    p.y += (int) (a * d);
  }
Beispiel #12
0
  private Color Brightness(Point3D lightPoint, Point3D p1, Point3D p2, Point3D p3, Color c) {

    Point3D normal, vec;
    normal = new Point3D(0, 0, 0);
    vec = new Point3D(0, 0, 0);
    normal.setNormal(p1, p2, p3);
    vec.x = p1.x - lightPoint.x;
    vec.y = p1.y - lightPoint.y;
    vec.z = p1.z - lightPoint.z;
    double cosa = ((normal.x * vec.x) + (normal.y * vec.y) + (normal.z * vec.z));
    cosa /=
        (Math.sqrt(normal.x * normal.x + normal.y * normal.y + normal.z * normal.z)
            * Math.sqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z));

    if (cosa < 0) cosa = 0;
    if (cosa > 1) cosa = 1;
    float[] hsb = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null);
    return Color.getHSBColor(hsb[0], hsb[1], (float) (hsb[2] + 0.3 * cosa));
  }
Beispiel #13
0
 public Point3D getCenterZ(int order) {
   Point3D point = new Point3D();
   Point3D center = new Point3D();
   int offset = order * 4;
   if (order == 0) {
     this.getPoint(0, point);
     center.set(center.x() + point.x(), center.y() + point.y(), center.z() + point.z());
     this.getPoint(1, point);
     center.set(center.x() + point.x(), center.y() + point.y(), center.z() + point.z());
     this.getPoint(4, point);
     center.set(center.x() + point.x(), center.y() + point.y(), center.z() + point.z());
     this.getPoint(5, point);
     center.set(center.x() + point.x(), center.y() + point.y(), center.z() + point.z());
   } else {
     this.getPoint(2, point);
     center.set(center.x() + point.x(), center.y() + point.y(), center.z() + point.z());
     this.getPoint(3, point);
     center.set(center.x() + point.x(), center.y() + point.y(), center.z() + point.z());
     this.getPoint(6, point);
     center.set(center.x() + point.x(), center.y() + point.y(), center.z() + point.z());
     this.getPoint(7, point);
     center.set(center.x() + point.x(), center.y() + point.y(), center.z() + point.z());
   }
   center.set(center.x() * 0.25, center.y() * 0.25, center.z() * 0.25);
   return center;
 }
 private void updatePos(double off) {
   pos.x -= UNIT * Math.sin(Math.toRadians(rotAngle + off));
   pos.z += UNIT * Math.cos(Math.toRadians(rotAngle + off));
 }