Newer
Older
EPQ-3D-renderer / src / main / java / uk / org / floop / epq3d / PointComp.java
@cory cory on 7 Feb 2023 1 KB Minor Changes
package uk.org.floop.epq3d;

public class PointComp {
    public Point3D point = new Point3D(0,0,0);
    private final Point3D rotatedPoint = new Point3D(0,0,0);
    private boolean isRotatedPointValid = true;
    private final Point2D projectedPoint = new Point2D(0,0);
    private boolean isProjectedPointValid = true;
    public PointComp(double _x, double _y, double _z){
        point.x = _x;
        point.y = _y;
        point.z = _z;
    }

    public PointComp() {
    }
    public void invalidate(){
        isProjectedPointValid = false; isRotatedPointValid = false;
    }
    public Point3D getRotatedPoint(){
        if(!isRotatedPointValid){
            throw new RuntimeException("Rotated point not initialised");
        }
        return rotatedPoint;
    }
    public Point2D getProjectedPoint(){
        if(!isRotatedPointValid){
            throw new RuntimeException("Projected point not initialised");
        }
        return projectedPoint;
    }
    public void setRotatedPoint(Matrix camMatrix){
        if(!isRotatedPointValid) {
            camMatrix.multiplyPoint3to(point, rotatedPoint);
            isRotatedPointValid = true;
        }
    }
    public void setRotatedPoint(Point3D newRotatedPoint){
        rotatedPoint.x = newRotatedPoint.x;
        rotatedPoint.y = newRotatedPoint.y;
        rotatedPoint.z = newRotatedPoint.z;
        isRotatedPointValid = true;
    }
    public void setProjectedPoint(drawData drawData){
        if(!isProjectedPointValid) {
            rotatedPoint.projectOn(drawData, projectedPoint);
            projectedPoint.z = rotatedPoint.z;
            isProjectedPointValid = true;
        }
    }
}