Newer
Older
EPQ-3D-renderer / src / Point3D.java
public class Point3D {
    public double x;
    public double y;
    public double z;

    public Point3D(double _x, double _y, double _z){
        x = _x;
        y = _y;
        z = _z;
    }
    public void set(double[] _new){
        x = _new[0];
        y = _new[1];
        z = _new[2];
    }
    public void translate(Point3D trVec){
        x += trVec.x;
        y += trVec.y;
        z += trVec.z;
    }
    public Point2D project(double fpdis, int scrX, int scrY){
        return new Point2D(
                (int)(((fpdis*y)/z + .5)*scrX),
                (int)(((fpdis*x)/z + .5)*scrY)
                // multiply by scrX both times such that the projected screen always projects points between -1<x<1.
                // this means that there isn't any weird scaling, and the FOV is in terms of horizontal.. ness.
        );
    }
    public void projectOn(double fpdis, int scrX, int scrY, Point2D point){
        point.x = (int)(scrX*((fpdis*y)/z + .5));
        point.y = (int)(scrX*((fpdis*x)/z + .5));
    }
    public double[] get(){
        return new double[]{x, y, z};
    }
}