Package raytracer.common.object

Source Code of raytracer.common.object.RtObject

package raytracer.common.object;

import java.awt.Color;

import raytracer.common.type.Environnement;
import raytracer.common.type.Ray;
import raytracer.common.type.Vector;

public abstract class RtObject {
  Vector center;
  Color color;
  Vector rotation;

  public RtObject() {
    center = new Vector();
    color = new Color(1, 1, 1);
    rotation = new Vector(0, 0, 0);
  }

  abstract public double[] primitive(Ray ray);

  abstract public Vector normal(Vector inter);

  public Color color(Vector inter){
    return (this.color);
  }

  // abstract public int in(Ray ray, Vector inter);

  // abstract public Color getTexture(Vector pos);

  public Color getColor(Vector pos) {
    // if (texture == true)
    // return (getTexture(pos));
    // else
    return (color);
  }

  public static double near(double[] tab) {
    double result;
    if (tab.length > 0) {
      result = tab[0];
      for (double dist : tab) {
        if (dist > 0 && dist < result)
          result = dist;
      }
    } else
      result = -1;
    return (result);

  }

  public static double searchNear(Ray ray) {
    double result = -1;
    double tmp;

    for (RtObject object : Environnement.LIST_OBJECT) {
      tmp = near(object.primitive(ray));
      if (result == -1 || (tmp > 0. && result > tmp)) {
        result = tmp;
      }
    }
    return (result);
  }
}
TOP

Related Classes of raytracer.common.object.RtObject

TOP
Copyright © 2018 www.massapi.com. 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.