/******************************************************************************************
 * Surface Plotter version 1.20                                               Nov  8 1996 *
 *                                                                                        *
 * SurfaceVertex.java: Vertices of Surface version 1.0                                    *
 *                                                                                        *
 * Copyright (c) 1996 Yanto Suryono. All Rights Reserved.                                 *
 *                                                                                        *
 * Permission to use, copy, and distribute this software for NON-COMMERCIAL purposes      *
 * and without fee is hereby granted, provided that this copyright notice appears in all  *
 * copies and this software is not modified in any way                                    *
 *                                                                                        *
 * Please send bug reports and/or corrections/suggestions to                              *
 * Yanto Suryono <d0771@cranesv.egg.kushiro-ct.ac.jp>                                     *
 ******************************************************************************************/

//import java.awt.*;
import javax.swing.*;
import java.awt.Point;

public class SurfaceVertex {
    float x,y,z;
    private Point projection;
    private int project_index;
    private static Projector projector;
    
    private static float zmin, zmax;
    private static float zfactor;
    private static int   master_project_index = 0;  // needs over 4 billion times to reset
    
    // x and y are always stored in normalized form (i.e. in the range of -10..10)
    
    SurfaceVertex(float ix, float iy, float iz) {
	x = ix; y = iy; z = iz;
	project_index = -1;
    }
    
    public boolean isInvalid() {
	return Float.isNaN(z); 
    }
    
    public Point projection() {
	if (project_index != master_project_index) {
	    projection = projector.project(x,y,(z-zmin)*zfactor-10);
	    project_index = master_project_index;
	}
	return projection;
    }
    
    // this routine is only used for transforming center of projection
    // in Surface Plotter application
    
    public void transform() {
	x = x / projector.getXScaling();
	y = y / projector.getYScaling();
	z = (zmax-zmin)*(z/projector.getZScaling()+10)/20 + zmin;
    }
    
    static void invalidate() {
	master_project_index++;
    }
    
    static void setProjector(Projector projector) {
	SurfaceVertex.projector = projector;
    }
    
    static void setZRange(float zmin, float zmax) {
	SurfaceVertex.zmin = zmin; SurfaceVertex.zmax = zmax;
	zfactor = 20/(zmax-zmin);
    }
}























































































































