package jomodel;


import java.util.*;


/**
 * Vertex contains an xyz position, and a list of neighboring
 * triangles.  Normals and texture coordinates are stored in the
 * GL_Triangle object, since each face may have different normals and
 * texture coords for the same vertex.
 *
 * The "neighbor" triangle list holds all triangles that contains
 * this vertex.  Not to be confused with the GL_Triangle.neighborsP1,
 * GL_Triangle.neighborsP2, etc. that contain only neighbors that should
 * be smoothed into the given triangle.
 *
 * jun 2006: added makeClone()
 */
public class JOVertex {
    
    public JOVector pos = new JOVector();   // xyz coordinate of vertex
    public JOVector posS = new JOVector();  // xyz Screen coords of projected vertex
    public int ID;  // index into parent objects vertexData vector
    public ArrayList<JOTriangle> neighborTris = new ArrayList<JOTriangle>();  // Neighbor triangles of this vertex
    

    public JOVertex() {
        pos = new JOVector(0f, 0f, 0f);
    }

    public JOVertex(float xpos, float ypos, float zpos) {
        pos = new JOVector(xpos, ypos, zpos);
    }

    public JOVertex(float xpos, float ypos, float zpos, float u, float v) {
        pos = new JOVector(xpos, ypos, zpos);
    }

    public JOVertex(JOVector ppos) {
        pos = ppos.getClone();
    }

    /**
     * add a neighbor triangle to this vertex
     */
    void addNeighborTri(JOTriangle triangle) {
        if (!neighborTris.contains(triangle)) {
        	neighborTris.add(triangle);
        }
    }

    /**
     * clear the neighbor triangle list
     */
    void resetNeighbors() {
    	neighborTris.clear();
    }

    public JOVertex makeClone() {
        JOVertex newVertex = new JOVertex();
        newVertex.pos = pos.getClone();
        newVertex.posS = posS.getClone();
        newVertex.ID = ID;
        return newVertex;
    }

    public String toString() {
        return new String("<vertex  x=" + pos.x + " y=" + pos.y + " z=" + pos.z + ">\r\n");
    }
}