/* ps4, 11/23/98
	Created by: Prof. McMillan
	Modified by: Andrew Galland
	Modification History
		AJG001	Changed null constructor to initialize all to 0
	*/

import java.awt.Color;

 

public class Vertex3D {

    public float x, y, z, w;           // coordinate of vertex

    public float nx, ny, nz;        // vertex normal

    public boolean hasNormal;



    public Vertex3D()

    {
		/* AJG001+ */
		x = y = z = w =0;
		/* AJG001- */

        nx = ny = nz = 0;

        hasNormal = false;

    }



    public Vertex3D(float xval, float yval, float zval)

    {

        x = xval;

        y = yval;

        z = zval;

        w = 1;

        nx = ny = nz = 0;

        hasNormal = false;

    }

    

    public void copy(Vertex3D v)

    {

        x = v.x;        y = v.y;        z = v.z;    w = v.w;

        nx = v.nx;      ny = v.ny;      nz = v.nz;

        hasNormal = v.hasNormal;

    }



    public void setNormal(float xval, float yval, float zval) {

        float l = (float) (1 / Math.sqrt(xval*xval + yval*yval + zval*zval));

        xval *= l;

        yval *= l;

        zval *= l;

        nx = xval;

        ny = yval;

        nz = zval;

        hasNormal = true;

    }



    public void normalize( )

    {

        if (w != 1) {

            w = 1 / w;

            x *= w;

            y *= w;

            z *= w;

            w = 1;

        }

    }

    

    public String toString()

    {

        return new String(" ["+x+", "+y+", "+z+", "+w+"]");

    }

}