package com.srbenoit.render;

import com.srbenoit.geom.Point3;
import com.srbenoit.geom.Vector3;

/**
 * A vertex in view coordinates.
 */
public class ViewVertex extends Point3 {

    /** the index of this vertex in the scene where it is contained */
    private int indexInScene;

    /** the vertex normal */
    private final Vector3 normal;

    /**
     * Constructs a new <code>ViewVertex</code>.
     */
    public ViewVertex() {

        super();

        this.normal = new Vector3();
    }

    /**
     * Gets the index of this face in the scene.
     *
     * @return  the index
     */
    public int getIndexInScene() {

        return this.indexInScene;
    }

    /**
     * Gets the vertex normal.
     *
     * @return  the normal vector
     */
    public Vector3 getNormal() {

        return this.normal;
    }

    /**
     * Copies a world-coordinate vertex object into a view-coordinate vertex object.
     *
     * @param  camera  the camera to use to transform points and vectors
     * @param  world   the world-space vertex from which to copy
     */
    public void transformFrom(final Camera camera, final WorldVertex world) {

        this.indexInScene = world.getIndexInScene();

        // Transform the vertex position
        camera.transformPoint(world, this);

        // Build and transform the vertex normal
        world.buildNormal(this.normal);
        camera.transformVec(this.normal, this.normal);
    }
}
