Projects

Computer Graphics Projects for Under Graduate  Students.

I am presenting you some of the Computer Graphics Projects that will be helpful to all the undergraduate students of Computer Engineering or any Information Technology related Students. These are the Computer graphics Projects made in different Platforms like JAVA , C++ Builder, C++ using OPEN GL Or SDL, C# projects.
Get mediafire links to download all the stuffs……………………….

1.     3d – modeling of a bridge.(In JAVA)
The object contains 2  walls with bulged structure and a floor. Use the navigation keys to rotate the object.  It implements the basic knowledge of the Computer Graphics, i.e
a.      Rotation
b.     Translation
c.      Shearing
d.     scaling
e.     Illumination
f.       View co-ordinates
The keys are the four arrow keys. As normal the respective keys changes the position of the camera or the eye, let’s say the view point. Then the object moves correspondingly. Don’t get surprised that when you press left key, the object will move right. Actually the camera is moving,  When you move your eye-point to the left , then the object will move to the right.
Use  W,A,S,D to rotate the object in either clock wise or anti-clock wise direction in horizontal or vertical axis.
Project Dissection
The Snapshot of the file system of the project is:
This project contains of 14 classes wrapped up in 6 packages. They are:
1.     Hidden Surface
A.     Visibility.java
2.     Rendering
A.     CosineLambert.java
3.     bridge.view
A.     Bridge.java
B.     Main.java
C.     MainFrame.java
4.     Core
A.     Edge.java
B.     Surface.java
C.     Vertex.java
5.     geometry
A.     Projection.java
B.     Translation.java
C.     ViewCordinate.java
6.     Math
A.     MyMath.java
B.     MyMatrix.java
C.     MyVectot.java


Each Classes are described below::


Bridge.java
package bridge.view;
import core.*;
import core.Vertex;
import java.util.ArrayList;
import java.util.Vector;
import math.*;
public class Bridge {
    private Vertex[][] vertex = new Vertex[1524][4]; //20+36+36+36+36+1+36+18+18+36
    private Edge[][] edge = new Edge[1524][4];
    private Surface surface;
    private Vector<Surface> bridge = new Vector<Surface>();
    private int zposition;
    private int endingZ;
    private int yposition;
    private int xposition;
    private int vertexIndex;
    private int side;
    private int width;
    private int height;
    private final int STRIPWIDTH = 10;
    public Bridge() {
        vertexIndex = 0;
        init();
    }
    public void init() {
        zposition = 100;
        xposition=-160;
        yposition=165;
        width=320;
        height=390;     
        drawFloor(xposition,yposition,zposition, width,height);
        System.out.println("bridge vertices" + vertexIndex);
        xposition = -160;
        zposition = 100;
        endingZ = 490;
        side = 0;
        drawBackWall(xposition, zposition, endingZ, side);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 100;
        endingZ = 210;
        drawLeftWall(zposition, endingZ);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 210;
        drawLeftWallBack(zposition);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 210;
        endingZ = 240;
        drawLeftWallBulged(zposition, endingZ);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 240;
        drawLeftWallFront(zposition);
        System.out.println("bridge vertices" + vertexIndex);       
        zposition = 240;
        endingZ = 350;
        drawLeftWall(zposition, endingZ);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 350;
        drawLeftWallBack(zposition);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 350;
        endingZ = 380;
        drawLeftWallBulged(zposition, endingZ);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 380;
        drawLeftWallFront(zposition);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 380;
        endingZ = 490;
        drawLeftWall(zposition, endingZ);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 100;
        endingZ = 210;
        drawLeftWallTop(zposition, endingZ, 15);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 210;
        endingZ = 240;
        drawLeftWallTop(zposition, endingZ, 25);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 240;
        endingZ = 350;
        drawLeftWallTop(zposition, endingZ, 15);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 350;
        endingZ = 380;
        drawLeftWallTop(zposition, endingZ, 25);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 380;
        endingZ = 490;
        drawLeftWallTop(zposition, endingZ, 15);
        System.out.println("bridge vertices" + vertexIndex);
        xposition = -160;
        zposition = 490;
        side = 0;
        drawFrontWall(xposition, zposition, side);
        System.out.println("bridge vertices" + vertexIndex);
        xposition = 160;
        zposition = 100;
        endingZ = 490;
        side = 1;
        drawBackWall(xposition, zposition, endingZ, side);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 100;
        endingZ = 210;
        drawRightWall(zposition, endingZ);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 210;
        drawRightWallBack(zposition);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 210;
        endingZ = 240;
        drawRightWallBulged(zposition, endingZ);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 240;
        drawRightWallFront(zposition);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 240;
        endingZ = 350;
        drawRightWall(zposition, endingZ);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 350;
        drawRightWallBack(zposition);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 350;
        endingZ = 380;
        drawRightWallBulged(zposition, endingZ);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 380;
        drawRightWallFront(zposition);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 380;
        endingZ = 490;
        drawRightWall(zposition, endingZ);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 100;
        endingZ = 210;
        drawRightWallTop(zposition, endingZ, 15);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 210;
        endingZ = 240;
        drawRightWallTop(zposition, endingZ, 25);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 240;
        endingZ = 350;
        drawRightWallTop(zposition, endingZ, 15);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 350;
        endingZ = 380;
        drawRightWallTop(zposition, endingZ, 25);
        System.out.println("bridge vertices" + vertexIndex);
        zposition = 380;
        endingZ = 490;
        drawRightWallTop(zposition, endingZ, 15);
        System.out.println("bridge vertices" + vertexIndex);
        xposition = 160;
        zposition = 490;
        side = 1;       
        drawFrontWall(xposition, zposition, side);
        System.out.println("bridge vertices" + vertexIndex);
        xposition = -160;
        zposition = 490;
        yposition = 165;
        height = 10;
        width = 320;
        drawBase(xposition,yposition, zposition, width, height);
        System.out.println("bridge vertices" + vertexIndex);
    }
    public Surface getSurface(int index) {
        return bridge.get(index);
    }
    public void drawBase(int x,int y, int sz, int width, int height) {
                        int numberOfDivisons = width/STRIPWIDTH;
        for (int i = 0; i < numberOfDivisons; i++) {       
        vertex[vertexIndex][0] = new Vertex(x + i*STRIPWIDTH, y, sz);
        vertex[vertexIndex][1] = new Vertex(x + i*STRIPWIDTH , y + height, sz);
        vertex[vertexIndex][2] = new Vertex(x + (i+1)*STRIPWIDTH, y + height, sz);
        vertex[vertexIndex][3] = new Vertex(x + (i+1)*STRIPWIDTH, y, sz);
        edge[vertexIndex][0] = new Edge(vertex[vertexIndex][0], vertex[vertexIndex][1]);
        edge[vertexIndex][1] = new Edge(vertex[vertexIndex][1], vertex[vertexIndex][2]);
        edge[vertexIndex][2] = new Edge(vertex[vertexIndex][2], vertex[vertexIndex][3]);
        edge[vertexIndex][3] = new Edge(vertex[vertexIndex][3], vertex[vertexIndex][0]);
        //creating surface
        surface = new Surface();
        for (int j = 0; j < 4; j++) {
            surface.addEdge(edge[vertexIndex][j]);
        }
        surface.setNormal(MyVector.normalVector(surface));
        surface.setCenter(MyMath.midPoint(vertex[vertexIndex][0], vertex[vertexIndex][2]));
        //adding surface to the bridge
        bridge.add(surface);
        vertexIndex++;
        }
    }
    public void drawFrontWall(int x, int sz, int side) {
        if (side == 0) {
            vertex[vertexIndex][0] = new Vertex(x, 165, sz);
            vertex[vertexIndex][1] = new Vertex(x + 15, 165, sz);
            vertex[vertexIndex][2] = new Vertex(x + 15, 105, sz);
            vertex[vertexIndex][3] = new Vertex(x, 105, sz);
        } else if (side == 1) {
            vertex[vertexIndex][0] = new Vertex(x, 165, sz);
            vertex[vertexIndex][1] = new Vertex(x, 105, sz);
            vertex[vertexIndex][2] = new Vertex(x - 15, 105, sz);
            vertex[vertexIndex][3] = new Vertex(x - 15, 165, sz);
        }
        //defining edge
        edge[vertexIndex][0] = new Edge(vertex[vertexIndex][0], vertex[vertexIndex][1]);
        edge[vertexIndex][1] = new Edge(vertex[vertexIndex][1], vertex[vertexIndex][2]);
        edge[vertexIndex][2] = new Edge(vertex[vertexIndex][2], vertex[vertexIndex][3]);
        edge[vertexIndex][3] = new Edge(vertex[vertexIndex][3], vertex[vertexIndex][0]);
        //creating surface
        surface = new Surface();
        for (int j = 0; j < 4; j++) {
            surface.addEdge(edge[vertexIndex][j]);
        }
        surface.setNormal(MyVector.normalVector(surface));
        surface.setCenter(MyMath.midPoint(vertex[vertexIndex][0], vertex[vertexIndex][2]));
        //adding surface to the bridge
        bridge.add(surface);
        vertexIndex++;
    }
    public void drawBackWall(int x, int sz, int ez, int side) {
        int numberOfStrips = (ez - sz) / STRIPWIDTH;
        for (int i = 0; i < numberOfStrips; i++) {

            if (side == 0) {
                vertex[vertexIndex][0] = new Vertex(x, 105, sz + STRIPWIDTH * i);
                vertex[vertexIndex][1] = new Vertex(x, 165, sz + STRIPWIDTH * i);
                vertex[vertexIndex][2] = new Vertex(x, 165, sz + STRIPWIDTH * (i + 1));
                vertex[vertexIndex][3] = new Vertex(x, 105, sz + STRIPWIDTH * (i + 1));
            } else if (side == 1) {
                vertex[vertexIndex][0] = new Vertex(x, 165, sz + STRIPWIDTH * i);
                vertex[vertexIndex][1] = new Vertex(x, 105, sz + STRIPWIDTH * i);
                vertex[vertexIndex][2] = new Vertex(x, 105, sz + STRIPWIDTH * (i + 1));
                vertex[vertexIndex][3] = new Vertex(x, 165, sz + STRIPWIDTH * (i + 1));
            }
            //defining edge
            edge[vertexIndex][0] = new Edge(vertex[vertexIndex][0], vertex[vertexIndex][1]);
            edge[vertexIndex][1] = new Edge(vertex[vertexIndex][1], vertex[vertexIndex][2]);
            edge[vertexIndex][2] = new Edge(vertex[vertexIndex][2], vertex[vertexIndex][3]);
            edge[vertexIndex][3] = new Edge(vertex[vertexIndex][3], vertex[vertexIndex][0]);
            //creating surface
            surface = new Surface();
            for (int j = 0; j < 4; j++) {
                surface.addEdge(edge[vertexIndex][j]);
            }
            surface.setNormal(MyVector.normalVector(surface));
            surface.setCenter(MyMath.midPoint(vertex[vertexIndex][0], vertex[vertexIndex][2]));
            //adding surface to the bridge
            bridge.add(surface);
            vertexIndex++;
        }
    }
    public void drawLeftWall(int sz, int ez) {
        int numberOfStrips = (ez - sz) / STRIPWIDTH;
        for (int i = 0; i < numberOfStrips; i++) {
            vertex[vertexIndex][0] = new Vertex(-145, 165, sz + STRIPWIDTH * i);
            vertex[vertexIndex][1] = new Vertex(-145, 105, sz + STRIPWIDTH * i);
            vertex[vertexIndex][2] = new Vertex(-145, 105, sz + STRIPWIDTH * (i + 1));
            vertex[vertexIndex][3] = new Vertex(-145, 165, sz + STRIPWIDTH * (i + 1));
            //defining edge
            edge[vertexIndex][0] = new Edge(vertex[vertexIndex][0], vertex[vertexIndex][1]);
            edge[vertexIndex][1] = new Edge(vertex[vertexIndex][1], vertex[vertexIndex][2]);
            edge[vertexIndex][2] = new Edge(vertex[vertexIndex][2], vertex[vertexIndex][3]);
            edge[vertexIndex][3] = new Edge(vertex[vertexIndex][3], vertex[vertexIndex][0]);
            //creating surface
            surface = new Surface();
            for (int j = 0; j < 4; j++) {
                surface.addEdge(edge[vertexIndex][j]);
            }
            surface.setNormal(MyVector.normalVector(surface));
            surface.setCenter(MyMath.midPoint(vertex[vertexIndex][0], vertex[vertexIndex][2]));
            //adding surface to the bridge
            bridge.add(surface);
            vertexIndex++;
        }
    }
    public void drawLeftWallBulged(int sz, int ez) {
        int numberOfStrips = (ez - sz) / STRIPWIDTH;
        for (int i = 0; i < numberOfStrips; i++) {
            vertex[vertexIndex][0] = new Vertex(-135, 165, sz + STRIPWIDTH * i);
            vertex[vertexIndex][1] = new Vertex(-135, 105, sz + STRIPWIDTH * i);
            vertex[vertexIndex][2] = new Vertex(-135, 105, sz + STRIPWIDTH * (i + 1));
            vertex[vertexIndex][3] = new Vertex(-135, 165, sz + STRIPWIDTH * (i + 1));
            //defining edge
            edge[vertexIndex][0] = new Edge(vertex[vertexIndex][0], vertex[vertexIndex][1]);
            edge[vertexIndex][1] = new Edge(vertex[vertexIndex][1], vertex[vertexIndex][2]);
            edge[vertexIndex][2] = new Edge(vertex[vertexIndex][2], vertex[vertexIndex][3]);
            edge[vertexIndex][3] = new Edge(vertex[vertexIndex][3], vertex[vertexIndex][0]);
            //creating surface
            surface = new Surface();
            for (int j = 0; j < 4; j++) {
                surface.addEdge(edge[vertexIndex][j]);
            }
            surface.setNormal(MyVector.normalVector(surface));
            surface.setCenter(MyMath.midPoint(vertex[vertexIndex][0], vertex[vertexIndex][2]));
            //adding surface to the bridge
            bridge.add(surface);
            vertexIndex++;
        }
    }
    public void drawLeftWallBack(int sz) {
        vertex[vertexIndex][0] = new Vertex(-145, 165, sz);
        vertex[vertexIndex][1] = new Vertex(-145, 105, sz);
        vertex[vertexIndex][2] = new Vertex(-135, 105, sz);
        vertex[vertexIndex][3] = new Vertex(-135, 165, sz);
        //defining edge
        edge[vertexIndex][0] = new Edge(vertex[vertexIndex][0], vertex[vertexIndex][1]);
        edge[vertexIndex][1] = new Edge(vertex[vertexIndex][1], vertex[vertexIndex][2]);
        edge[vertexIndex][2] = new Edge(vertex[vertexIndex][2], vertex[vertexIndex][3]);
        edge[vertexIndex][3] = new Edge(vertex[vertexIndex][3], vertex[vertexIndex][0]);
        //creating surface
        surface = new Surface();
        for (int j = 0; j < 4; j++) {
            surface.addEdge(edge[vertexIndex][j]);
        }
        surface.setNormal(MyVector.normalVector(surface));
        surface.setCenter(MyMath.midPoint(vertex[vertexIndex][0], vertex[vertexIndex][2]));
        bridge.add(surface);
        vertexIndex++;
    }
    public void drawLeftWallFront(int sz) {
        vertex[vertexIndex][0] = new Vertex(-135, 165, sz);
        vertex[vertexIndex][1] = new Vertex(-135, 105, sz);
        vertex[vertexIndex][2] = new Vertex(-145, 105, sz);
        vertex[vertexIndex][3] = new Vertex(-145, 165, sz);
        //defining edge
        edge[vertexIndex][0] = new Edge(vertex[vertexIndex][0], vertex[vertexIndex][1]);
        edge[vertexIndex][1] = new Edge(vertex[vertexIndex][1], vertex[vertexIndex][2]);
        edge[vertexIndex][2] = new Edge(vertex[vertexIndex][2], vertex[vertexIndex][3]);
        edge[vertexIndex][3] = new Edge(vertex[vertexIndex][3], vertex[vertexIndex][0]);
        //creating surface
        surface = new Surface();
        for (int j = 0; j < 4; j++) {
            surface.addEdge(edge[vertexIndex][j]);
        }
        surface.setNormal(MyVector.normalVector(surface));
        surface.setCenter(MyMath.midPoint(vertex[vertexIndex][0], vertex[vertexIndex][2]));
        //adding surface to the bridge
        bridge.add(surface);
        vertexIndex++;
    }
    public void drawLeftWallTop(int sz, int ez, int width) {
        int numberOfStrips = (ez - sz) / STRIPWIDTH;
        for (int i = 0; i < numberOfStrips; i++) {
            vertex[vertexIndex][0] = new Vertex(-160 + width, 105, sz + STRIPWIDTH * i);
            vertex[vertexIndex][1] = new Vertex(-160, 105, sz + STRIPWIDTH * i);
            vertex[vertexIndex][2] = new Vertex(-160, 105, sz + STRIPWIDTH * (i + 1));
            vertex[vertexIndex][3] = new Vertex(-160 + width, 105, sz + STRIPWIDTH * (i + 1));
            //defining edge
            edge[vertexIndex][0] = new Edge(vertex[vertexIndex][0], vertex[vertexIndex][1]);
            edge[vertexIndex][1] = new Edge(vertex[vertexIndex][1], vertex[vertexIndex][2]);
            edge[vertexIndex][2] = new Edge(vertex[vertexIndex][2], vertex[vertexIndex][3]);
            edge[vertexIndex][3] = new Edge(vertex[vertexIndex][3], vertex[vertexIndex][0]);
            //creating surface
            surface = new Surface();
            for (int j = 0; j < 4; j++) {
                surface.addEdge(edge[vertexIndex][j]);
            }
            surface.setNormal(MyVector.normalVector(surface));
            surface.setCenter(MyMath.midPoint(vertex[vertexIndex][0], vertex[vertexIndex][2]));
            //adding surface to the bridge
            bridge.add(surface);
            vertexIndex++;
        }
    }
    public void drawRightWall(int sz, int ez) {
        int numberOfStrips = (ez - sz) / STRIPWIDTH;
        for (int i = 0; i < numberOfStrips; i++) {
            vertex[vertexIndex][0] = new Vertex(145, 105, sz + STRIPWIDTH * i);
            vertex[vertexIndex][1] = new Vertex(145, 165, sz + STRIPWIDTH * i);
            vertex[vertexIndex][2] = new Vertex(145, 165, sz + STRIPWIDTH * (i + 1));
            vertex[vertexIndex][3] = new Vertex(145, 105, sz + STRIPWIDTH * (i + 1));
            //defining edge
            edge[vertexIndex][0] = new Edge(vertex[vertexIndex][0], vertex[vertexIndex][1]);
            edge[vertexIndex][1] = new Edge(vertex[vertexIndex][1], vertex[vertexIndex][2]);
            edge[vertexIndex][2] = new Edge(vertex[vertexIndex][2], vertex[vertexIndex][3]);
            edge[vertexIndex][3] = new Edge(vertex[vertexIndex][3], vertex[vertexIndex][0]);
            //creating surface
            surface = new Surface();
            for (int j = 0; j < 4; j++) {
                surface.addEdge(edge[vertexIndex][j]);
            }
            surface.setNormal(MyVector.normalVector(surface));
            surface.setCenter(MyMath.midPoint(vertex[vertexIndex][0], vertex[vertexIndex][2]));
            //adding surface to the bridge
            bridge.add(surface);
            vertexIndex++;
        }
    }
    public void drawRightWallBulged(int sz, int ez) {
        int numberOfStrips = (ez - sz) / STRIPWIDTH;
        for (int i = 0; i < numberOfStrips; i++) {
            vertex[vertexIndex][0] = new Vertex(135, 105, sz + STRIPWIDTH * i);
            vertex[vertexIndex][1] = new Vertex(135, 165, sz + STRIPWIDTH * i);
            vertex[vertexIndex][2] = new Vertex(135, 165, sz + STRIPWIDTH * (i + 1));
            vertex[vertexIndex][3] = new Vertex(135, 105, sz + STRIPWIDTH * (i + 1));
            //defining edge
            edge[vertexIndex][0] = new Edge(vertex[vertexIndex][0], vertex[vertexIndex][1]);
            edge[vertexIndex][1] = new Edge(vertex[vertexIndex][1], vertex[vertexIndex][2]);
            edge[vertexIndex][2] = new Edge(vertex[vertexIndex][2], vertex[vertexIndex][3]);
            edge[vertexIndex][3] = new Edge(vertex[vertexIndex][3], vertex[vertexIndex][0]);
            //creating surface
            surface = new Surface();
            for (int j = 0; j < 4; j++) {
                surface.addEdge(edge[vertexIndex][j]);
            }
            surface.setNormal(MyVector.normalVector(surface));
            surface.setCenter(MyMath.midPoint(vertex[vertexIndex][0], vertex[vertexIndex][2]));
            //adding surface to the bridge
            bridge.add(surface);
            vertexIndex++;
        }
    }
    public void drawRightWallBack(int sz) {
        vertex[vertexIndex][0] = new Vertex(145, 105, sz);
        vertex[vertexIndex][1] = new Vertex(145, 165, sz);
        vertex[vertexIndex][2] = new Vertex(135, 165, sz);
        vertex[vertexIndex][3] = new Vertex(135, 105, sz);
        //defining edge
        edge[vertexIndex][0] = new Edge(vertex[vertexIndex][0], vertex[vertexIndex][1]);
        edge[vertexIndex][1] = new Edge(vertex[vertexIndex][1], vertex[vertexIndex][2]);
        edge[vertexIndex][2] = new Edge(vertex[vertexIndex][2], vertex[vertexIndex][3]);
        edge[vertexIndex][3] = new Edge(vertex[vertexIndex][3], vertex[vertexIndex][0]);
        //creating surface
        surface = new Surface();
        for (int j = 0; j < 4; j++) {
            surface.addEdge(edge[vertexIndex][j]);
        }
        surface.setNormal(MyVector.normalVector(surface));
        surface.setCenter(MyMath.midPoint(vertex[vertexIndex][0], vertex[vertexIndex][2]));
        //adding surface to the bridge
        bridge.add(surface);
        vertexIndex++;
    }
    public void drawRightWallFront(int sz) {
       vertex[vertexIndex][0] = new Vertex(145, 105, sz);
        vertex[vertexIndex][1] = new Vertex(135, 105, sz);
        vertex[vertexIndex][2] = new Vertex(135, 165, sz);
        vertex[vertexIndex][3] = new Vertex(145, 165, sz);
        //defining edge
        edge[vertexIndex][0] = new Edge(vertex[vertexIndex][0], vertex[vertexIndex][1]);
        edge[vertexIndex][1] = new Edge(vertex[vertexIndex][1], vertex[vertexIndex][2]);
        edge[vertexIndex][2] = new Edge(vertex[vertexIndex][2], vertex[vertexIndex][3]);
        edge[vertexIndex][3] = new Edge(vertex[vertexIndex][3], vertex[vertexIndex][0]);
        //creating surface
        surface = new Surface();
        for (int j = 0; j < 4; j++) {
            surface.addEdge(edge[vertexIndex][j]);
        }
        surface.setNormal(MyVector.normalVector(surface));
        surface.setCenter(MyMath.midPoint(vertex[vertexIndex][0], vertex[vertexIndex][2]));
        //adding surface to the bridge
        bridge.add(surface);
        vertexIndex++;
    }
    public void drawRightWallTop(int sz, int ez, int width) {
        int numberOfStrips = (ez - sz) / STRIPWIDTH;
        for (int i = 0; i < numberOfStrips; i++) {
            vertex[vertexIndex][0] = new Vertex(160, 105, sz + STRIPWIDTH * i);
            vertex[vertexIndex][1] = new Vertex(160 - width, 105, sz + STRIPWIDTH * i);
            vertex[vertexIndex][2] = new Vertex(160 - width, 105, sz + STRIPWIDTH * (i + 1));
            vertex[vertexIndex][3] = new Vertex(160, 105, sz + STRIPWIDTH * (i + 1));
            //defining edge
            edge[vertexIndex][0] = new Edge(vertex[vertexIndex][0], vertex[vertexIndex][1]);
            edge[vertexIndex][1] = new Edge(vertex[vertexIndex][1], vertex[vertexIndex][2]);
            edge[vertexIndex][2] = new Edge(vertex[vertexIndex][2], vertex[vertexIndex][3]);
            edge[vertexIndex][3] = new Edge(vertex[vertexIndex][3], vertex[vertexIndex][0]);
            //creating surface
            surface = new Surface();
            for (int j = 0; j < 4; j++) {
                surface.addEdge(edge[vertexIndex][j]);
            }
            surface.setNormal(MyVector.normalVector(surface));
            surface.setCenter(MyMath.midPoint(vertex[vertexIndex][0], vertex[vertexIndex][2]));
            //adding surface to the bridge
            bridge.add(surface);
            vertexIndex++;
        }
    }
    public void drawFloor(int x, int y,int z,int width,int height) {
        int numberOfStrips = height / STRIPWIDTH;
        int numberOfDivisons = width/STRIPWIDTH;
        for (int i = 0; i < numberOfStrips; i++) {
            for(int j=0;j<numberOfDivisons;j++){
            vertex[vertexIndex][0] = new Vertex(x+STRIPWIDTH*j, y, z + STRIPWIDTH *  (i + 1));
            vertex[vertexIndex][1] = new Vertex(x+STRIPWIDTH*(j+1), y, z + STRIPWIDTH  * (i + 1));
            vertex[vertexIndex][2] = new Vertex(x+STRIPWIDTH*(j+1), y, z + STRIPWIDTH * i);
            vertex[vertexIndex][3] = new Vertex(x+STRIPWIDTH*j, y, z + STRIPWIDTH * i);
            //defining edge
            edge[vertexIndex][0] = new Edge(vertex[vertexIndex][0], vertex[vertexIndex][1]);
            edge[vertexIndex][1] = new Edge(vertex[vertexIndex][1], vertex[vertexIndex][2]);
            edge[vertexIndex][2] = new Edge(vertex[vertexIndex][2], vertex[vertexIndex][3]);
            edge[vertexIndex][3] = new Edge(vertex[vertexIndex][3], vertex[vertexIndex][0]);
            //creating surface
            surface = new Surface();
            for (int k = 0; k < 4; k++) {
                surface.addEdge(edge[vertexIndex][k]);
            }
            surface.setNormal(MyVector.normalVector(surface));
            surface.setCenter(MyMath.midPoint(vertex[vertexIndex][0], vertex[vertexIndex][2]));
            //adding surface to the bridge
            bridge.add(surface);
            vertexIndex++;
            }
        }
    }
}

Main.java
package bridge.view;
import java.awt.Color;
import javax.swing.JFrame;
public class Main extends JFrame{
    public static void main(String[] args) {
        Thread thread;
        MainFrame sniper=new MainFrame();
        thread =new Thread(sniper);
        Main application=new Main();
        application.add(sniper);
        sniper.setRedrawCanvas(false);
        thread.start();
        application.setVisible(true);
        application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        application.setSize(1024, 768);   
    }
}

MainFrame.java
package bridge.view;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseListener;
import java.awt.Canvas;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import java.awt.RenderingHints;
import java.awt.image.BufferStrategy;
import java.awt.event.MouseEvent;
import java.awt.Toolkit;
import math.MyMath;
import math.MyVector;
import core.Surface;
import core.Vertex;
import geometry.Projection;
public class MainFrame extends Canvas implements KeyListener, MouseListener, Runnable {
    public static MyVector viewingDirection = new MyVector(0, 0, 1);
    public static MyVector lightSource = new MyVector(0, 0, -1);
    double[] unitNormal = new double[3];
    private BufferStrategy bufferStrategy;
    private boolean runAnimation;
    private boolean redrawCanvas;
    private RenderingHints hintForSpeedProcessing;
    private RenderingHints hintForQualityProcessing;
    private Bridge bridge;
    private Projection projection = new Projection();
    int left;
    int right;
    private boolean isSniperOn = false;
    private boolean condition1 = false;
    private double visible1 = 0.1;
    private double visible2 = 0;
    private double snipeVisible1 = 0.5;
    double[] mapPointX;
    double[] mapPointY;
    double[] mapPointZ;
    private boolean wireframe = false;
    private boolean step1 = true;
    private boolean step3 = false;
    public MainFrame() {
        mapPointX = new double[1];
        mapPointY = new double[1];
        mapPointZ = new double[1];

        setHintForSpeedProcessing(new RenderingHints(null));        getHintForSpeedProcessing().put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);        getHintForSpeedProcessing().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
        setHintForQualityProcessing(new RenderingHints(null));        getHintForQualityProcessing().put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);        getHintForQualityProcessing().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        runAnimation = true;
        redrawCanvas = false;
        bridge = new Bridge();
        this.addKeyListener(this);
        this.addMouseListener(this);
    }
    public void refreshCanvas() {
        redrawCanvas = true;
    }
    public void run() {
        while (runAnimation) {
            if (isRedrawCanvas()) {
                this.createBufferStrategy(2);
                bufferStrategy = this.getBufferStrategy();
                Graphics g = null;
                g = bufferStrategy.getDrawGraphics();
                Graphics2D g2 = (Graphics2D) g;
                /**
                 * NOTE: the the graphics operations become slow, switch to
                 * hints for speed processing
                 * g2.setRenderingHints(getHintForSpeedProcessing());
                 */
               g2.setRenderingHints(getHintForSpeedProcessing());

                this.paint(g2);
//                *******************
                g.dispose();
                bufferStrategy.show();
                setRedrawCanvas(false);
            }
        }
    }
    //Methods override for MouseListener
    public void mouseClicked(MouseEvent e) {
        if (step1) {
            System.out.println("clicked");
            step1 = false;
            step3 = true;
            repaint();
            setRedrawCanvas(true);
        }
    }
    public void mouseExited(MouseEvent e) {
    }
    public void mouseEntered(MouseEvent e) {
    }
    public void mousePressed(MouseEvent e) {
    }
    public void mouseReleased(MouseEvent e) {
    }
    public boolean isRunAnimation() {
        return runAnimation;
    }
    public void setRunAnimation(boolean runAnimation) {
        this.runAnimation = runAnimation;
    }
    public boolean isRedrawCanvas() {
        return redrawCanvas;
    }
    public void setRedrawCanvas(boolean redrawCanvas) {
        this.redrawCanvas = redrawCanvas;
    }
    public RenderingHints getHintForSpeedProcessing() {
        return hintForSpeedProcessing;
    }
    public void setHintForSpeedProcessing(RenderingHints hintForSpeedProcessing) {
        this.hintForSpeedProcessing = hintForSpeedProcessing;
    }
    public RenderingHints getHintForQualityProcessing() {
        return hintForQualityProcessing;
    }
    public void setHintForQualityProcessing(RenderingHints hintForQualityProcessing) {
        this.hintForQualityProcessing = hintForQualityProcessing;
    }
    public void keyTyped(KeyEvent event) {
    }
    public void keyReleased(KeyEvent event) {
    }
    public void keyPressed(KeyEvent event) {
        if (!step1) {
            setRedrawCanvas(false);
            Vertex lookup = projection.getLook();
            Vertex eye = projection.getEye();
            int xdirection = lookup.getX() - eye.getX();
            int zdirection = lookup.getZ() - eye.getZ();
            MyVector direction = new MyVector(xdirection, 0, zdirection);
            direction = MyVector.unitVector(direction);
            int x = (int) (direction.getXcomponent() * 10);
            int z = (int) (direction.getZcomponent() * 10);
            if (event.getKeyCode() == KeyEvent.VK_LEFT) {
                projection.setEye(eye.getX() + z, eye.getY(), eye.getZ() - x);
                projection.updateLook(z, 0, -x);
            }
            if (event.getKeyCode() == KeyEvent.VK_RIGHT) {
                projection.setEye(eye.getX() - z, eye.getY(), eye.getZ() + x);
                projection.updateLook(-z, 0, x);
            }
            if (event.getKeyCode() == KeyEvent.VK_UP) {
                projection.setEye(eye.getX() + x, eye.getY(), eye.getZ() + z);
            }
            if (event.getKeyCode() == KeyEvent.VK_DOWN) {
                projection.setEye(eye.getX() - x, eye.getY(), eye.getZ() - z);
            }
            if (!isSniperOn) {
                if (event.getKeyCode() == KeyEvent.VK_A) {
                    projection.setEye(eye.getX() - z, eye.getY(), eye.getZ() + x);
                }
                if (event.getKeyCode() == KeyEvent.VK_D) {
                    projection.setEye(eye.getX() + z, eye.getY(), eye.getZ() - x);
                }
                if (event.getKeyCode() == KeyEvent.VK_W) {
                    projection.updateLook(0, -10, 0);
                }
                if (event.getKeyCode() == KeyEvent.VK_S) {
                    projection.updateLook(0, 10, 0);
                }
                if (event.getKeyCode() == KeyEvent.VK_F1) {
                    boolean view = projection.getView();
                    projection.setView(!view);
                    projection.setEyeY(-1000);
                    System.out.println("projection view" + projection.getView() + projection.getEye().getY());
                }
                if (event.getKeyCode() == KeyEvent.VK_F2) {
                    wireframe = !wireframe;
                }
            }
            if (event.getKeyCode() == KeyEvent.VK_ESCAPE) {
                System.exit(0);
            }
            System.out.println("Eye Point " + projection.getEye().getX() + ", " + projection.getEye().getY() + ", " + projection.getEye().getZ());
            System.out.println("Look Point " + projection.getLook().getX() + ", " + projection.getLook().getY() + ", " + projection.getLook().getZ());
            setRedrawCanvas(true);
        }
    }
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        Graphics2D graphics = (Graphics2D) g;
        graphics.setColor(new Color(100, 100, 100));
        int width = Toolkit.getDefaultToolkit().getScreenSize().width;
        int height = Toolkit.getDefaultToolkit().getScreenSize().height;
        graphics.fillRect(0, 0, width, height);
        try {
            int[][] point;
//            //rendering for the floor
            for (int i = 0; i < 1248; i++) {
                Surface surface = bridge.getSurface(i);
                MyVector normal = surface.getNormal();
                MyVector lookVector = MyVector.unitVector(MyVector.calculateVector(projection.getEye(), projection.getLook()));
                MyVector viewToSurface = MyVector.unitVector(MyVector.calculateVector(projection.getEye(), surface.getCenter()));
                double isVisible1 = MyMath.dotProduct(lookVector, viewToSurface);
                double isVisible2 = MyMath.dotProduct(MyVector.negate(viewToSurface), normal);
                if (!isSniperOn) {
                    if (isVisible1 > visible1) {
                        condition1 = true;
                    } else {
                        condition1 = false;
                    }
                } else {
                    if (isVisible1 >= snipeVisible1) {
                        condition1 = true;
                    } else {
                        condition1 = false;
                    }
                }
                if (condition1 && isVisible2 > visible2) {
                    point = projection.project(surface);
                    graphics.setColor(new Color((int) (100 + isVisible2 * 30), (int) (100 + isVisible2 * 30), (int) (50 + isVisible2 * 80))); //floor
                    if (!wireframe) {
                        graphics.fillPolygon(point[0], point[1], 4);
                    } else {
                        graphics.setColor(new Color(10, 230, 10));
                        graphics.drawPolygon(point[0], point[1], 4);
                    }
                }
            }

            //Rendering for the Bridge walls
            for (int i = 1248; i < 1524; i++) {
                Surface surface = bridge.getSurface(i);
                MyVector normal = surface.getNormal();
                MyVector lookVector = MyVector.unitVector(MyVector.calculateVector(projection.getEye(), projection.getLook()));
                MyVector viewToSurface = MyVector.unitVector(MyVector.calculateVector(projection.getEye(), surface.getCenter()));
                double isVisible1 = MyMath.dotProduct(lookVector, viewToSurface);
                double isVisible2 = MyMath.dotProduct(MyVector.negate(viewToSurface), normal);
                if (!isSniperOn) {
                    if (isVisible1 > visible1) {
                        condition1 = true;
                    } else {
                        condition1 = false;
                    }
                } else {
                    if (isVisible1 >= snipeVisible1) {
                        condition1 = true;
                    } else {
                        condition1 = false;
                    }
                }
                if (condition1 && isVisible2 > visible2) {
                    point = projection.project(surface);
                    if (i >= 1248 && i < 1287) {
                        graphics.setColor(new Color((int) (70 + isVisible2 * 50), (int) (60 + isVisible2 * 50), (int) (60 + isVisible2 * 50))); //left backwall
                    } else if (i >= 1287 && i < 1330) {
                        graphics.setColor(new Color((int) (70 + isVisible2 * 50), (int) (60 + isVisible2 * 50), (int) (60 + isVisible2 * 50))); //left wall
                    } else if (i >= 1330 && i < 1370) {
                        graphics.setColor(new Color((int) (120 + isVisible2 * 50), (int) (90 + isVisible2 * 50), (int) (90 + isVisible2 * 70))); //left wall top
                    } else if (i >= 1370 && i < 1409) {
                        graphics.setColor(new Color((int) (70 + isVisible2 * 50), (int) (60 + isVisible2 * 50), (int) (60 + isVisible2 * 50))); //right backwall
                    } else if (i >= 1409 && i < 1452) {
                        graphics.setColor(new Color((int) (70 + isVisible2 * 50), (int) (60 + isVisible2 * 50), (int) (60 + isVisible2 * 50))); //right wall
                    } else if (i >= 1452 && i < 1524) {
                        graphics.setColor(new Color((int) (120 + isVisible2 * 50), (int) (90 + isVisible2 * 50), (int) (90 + isVisible2 * 70))); //left wall top
                    }

                    if (!wireframe) {
                        graphics.fillPolygon(point[0], point[1], 4);
                    } else {
                        graphics.setColor(new Color(100, 190, 50));
                        graphics.drawPolygon(point[0], point[1], 4);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Edge.java
package core;
public class Edge {
    private Vertex v1;
    private Vertex v2;
    public Edge() {
        v1 = new Vertex();
        v2 = new Vertex();
    }
    public Edge(Vertex v1,Vertex v2){
        this.v1=v1;
        this.v2=v2;
    }
    public Edge(Edge edge){
        this.v1=edge.getV1();
        this.v2=edge.getV2();
    }
    public void setV1(Vertex v1){
        this.v1=v1;
    }
    public void setV2(Vertex v2){
        this.v2=v2;
    }
    public Vertex getV1(){
        return v1;
    }
    public Vertex getV2(){
        return v2;
    }
    public Edge getEdge(){
        return this;
    }
}

Surface.java
package core;
import java.util.ArrayList;
import math.MyVector;
public class Surface {   
    private ArrayList<Edge> surface;
    private MyVector normal;
    private Vertex center;
    public Surface(){
        surface = new ArrayList<Edge>(10);
        normal = new MyVector();
        center = new Vertex();
    }
    public Surface(ArrayList<Edge> surface){
        this.surface = surface;
        //normal = MyVector.normalVector(surface);
    }
    public Surface(Surface surface){
        for(int i=0;i<surface.size();i++){
            this.addEdge(surface.getEdge(i));
        }
    }
    public Edge getEdge(int index){
        return surface.get(index);
    }
    public void addEdge(Edge edge){
        surface.add(edge);
    }
    public int size(){
       return surface.size();
    }
    public void setNormal(MyVector vector){
        normal=vector;
    }
    public MyVector getNormal(){
        return normal;
    }
    public void setCenter(Vertex vertex){
        center=vertex;
    }
    public Vertex getCenter(){
        return center;
    }
}

Vertex.java
package core;
public class Vertex {
private int x;
private int y;
private int z;
public Vertex(){
    x=0;
    y=0;
    z=0;
}
public Vertex(int x,int y,int z){
    this.x=x;
    this.y=y;
    this.z=z;
}
public Vertex(Vertex vertex){
    x=vertex.getX();
    y=vertex.getY();
    z=vertex.getZ();
}
public int getX(){
    return x;
}
public int getY(){
    return y;
}
public int getZ(){
    return z;
}
public void setX(int x){
    this.x=x;
}
public void setY(int y){
    this.y=y;
}
public void setZ(int z){
    this.z=z;
}
}

Projection.java

package geometry;
import core.*;
import java.awt.Point;
import math.*;
public class Projection {
    private Vertex lookup;
    private Vertex eye;
    private double near = 0.1;
    private double far = 1000;
    private MyVector upVector;
    private MyVector r;
    private MyVector u;
    private MyVector n;
    private double k;
    private double W = 1024;
    private double H = 600;
    private double aspectRatio;
    private boolean helicopterView=false;
    private boolean snipeView=false;
    public Projection() {
        aspectRatio = H / W;       
        k= near/far;     
        lookup = new Vertex();
        eye = new Vertex();
        lookup.setX(0);
        lookup.setY(0);
        lookup.setZ(0);
        eye.setX(0);
        eye.setY(-50);
        eye.setZ(555);
        n = new MyVector();
        n = MyVector.calculateVector(lookup, eye);
        n = MyVector.unitVector(n);
        upVector = new MyVector(0, 1, 0);
        r = MyMath.crossProduct(upVector, n);
        r = MyVector.unitVector(r);
        u = MyMath.crossProduct(n, r);
    }
    public void setView(boolean view){
        helicopterView=view;
    }
    public boolean getView(){
        return helicopterView;
    }
    public void setSnipeView(boolean view){
        snipeView=view;
    }
    public boolean getSnipeView(){
        return snipeView;
    }   
    public void setEye(int x, int y, int z) {       
            eye.setX(x);
        eye.setY(y);
        eye.setZ(z);
        if(eye.getX()<-420)    {
            eye.setX(-420);
        }
        if(eye.getX()>420)    {
            eye.setX(420);
        }
        if(eye.getY()!=(-50) && (!helicopterView))    {
            eye.setY(-50);
        }else if(helicopterView){
            if(eye.getY()>=-100)
                eye.setY(-100);
        }           
        if(eye.getZ()<244 && (!snipeView))    {
            eye.setZ(244);
        }else if(snipeView){
            if(eye.getZ()<110)
                eye.setZ(110);
        }  
          }
    public Vertex getEye() {
        return eye;
    }
    public void setLook(int x, int y, int z) {
        lookup.setX(x);
        lookup.setY(y);
        lookup.setZ(z);
        if(lookup.getX()<-800)    {
            lookup.setX(-800);
        }
        if(lookup.getX()>800)    {
            lookup.setX(800);
        }
        if(lookup.getY()>165)    {
            lookup.setY(165);
        }
        if(lookup.getY()<-405)    {
            lookup.setY(-405);
        }
        if(lookup.getZ()!=0)    {
            lookup.setZ(0);
        }
    }
    public Vertex getLook() {
        return lookup;
    }
    public void updateLook(int x, int y, int z) {
        int x1=lookup.getX();
        int y1=lookup.getY();
        int z1=lookup.getZ();
        lookup.setX(x1 + x);
        lookup.setY(y1 + y);
        lookup.setZ(z1 + z);
    }
    public void perspective(double[] x1, double[] y1, double[] z1, int size) {
        for (int i = 0; i <= size; i++) {
            z1[i] =-z1[i];// (z1[i] + k) / (k - 1);
        }
    }
    public void scale(double[] x1, double[] y1, double[] z1, int size) {
        for (int i = 0; i <= size; i++) {
            x1[i] = x1[i] * (aspectRatio / far);
            y1[i] = y1[i] * (1 / far);
            z1[i] = z1[i] * (1 / far);
        }
    }
    public void rotation(double[] x1, double[] y1, double[] z1, int size) {
        n = MyVector.calculateVector(lookup, eye);
        n = MyVector.unitVector(n);
        r = MyMath.crossProduct(upVector, n);
        r = MyVector.unitVector(r);
        u = MyMath.crossProduct(n, r);
        double tempx;
        double tempy;
        double tempz;
        for (int i = 0; i <= size; i++) {
            tempx = x1[i];
            tempy = y1[i];
            tempz = z1[i];
            x1[i] = tempx * r.getXcomponent() + tempy * r.getYcomponent() + tempz * r.getZcomponent();
            y1[i] = tempx * u.getXcomponent() + tempy * u.getYcomponent() + tempz * u.getZcomponent();
            z1[i] = tempx * n.getXcomponent() + tempy * n.getYcomponent() + tempz * n.getZcomponent();
        }
    }
    public void translation(double[] x1, double[] y1, double[] z1, int size) {
        for (int i = 0; i <= size; i++) {
            x1[i] = x1[i] - eye.getX();
            y1[i] = y1[i] - eye.getY();
            z1[i] = z1[i] - eye.getZ();
        }
    }
    public void transformToImageSpace(double[] x1, double[] y1, double[] z1, int size) {
        for (int i = 0; i <= size; i++) {
            x1[i] = (W * ((x1[i] / z1[i]) + 1) / 2);
            y1[i] = (H * ((y1[i] / z1[i]) + 1) / 2);
        }
    }
    public void map(double[] x1, double[] y1, double[] z1, int size) {
        translation(x1, y1, z1, size);
        rotation(x1, y1, z1, size);
        scale(x1, y1, z1, size);
        perspective(x1, y1, z1, size);
        transformToImageSpace(x1, y1, z1, size);
    }
    public void setEyeY(int y){
        eye.setY(y);
        if(eye.getY()!=-50 && (!helicopterView))    {
            eye.setY(-50);
        }else if(helicopterView){
            if(eye.getY()>=-100)
                eye.setY(-100);
        }
    }
    public int[][] project(Surface surface) {
        int[][] point;
        double[] x = new double[surface.size() + 1];
        double[] y = new double[surface.size() + 1];
        double[] z = new double[surface.size() + 1];
        int size = surface.size();
        point = new int[2][size + 1];
        for (int i = 0; i <= size; i++) {
            x[i] = surface.getEdge(i % (size)).getV1().getX();
            y[i] = surface.getEdge(i % (size)).getV1().getY();
            z[i] = surface.getEdge(i % (size)).getV1().getZ();
        }
        map(x, y, z, size);
        for (int i = 0; i <= size; i++) {
            point[0][i] = (int) x[i];
            point[1][i] = (int) y[i];
        }
        return point;
    }
}

Translation.java

package geometry;
import core.*;
public class Translation {
    public Translation(){       
    }
    public void translate(Surface surface){
        for(int i =0;i<4;i++){
//            surface.getEdge(i).getV1()
        }   
    }
}

ViewCordinate.java
package geometry;
import core.Vertex;
import java.awt.Point;
import math.*;
public class ViewCordinate {
    private Vertex lookup;
    private Vertex eye;
    private double near=0.1;
    private double far=1000;
    private MyVector lookVector;
    private MyVector viewplaneX;
    private MyVector upVector;   
    private MyVector r;
    private MyVector u;
    private MyVector n;   
    private double k;
    private double W=1024;
    private double H=768;
    private double aspectRatio=H/W;
    private double temp[]=new double[3];      
    public ViewCordinate(){
        lookup=new Vertex();
        eye=new Vertex();       
        lookup.setX(0);
        lookup.setY(0);
        lookup.setZ(600);       
        eye.setX(0);
        eye.setY(150);
        eye.setZ(900);       
        // z part of viewing plane
        lookVector=new MyVector();
        lookVector = MyVector.calculateVector(lookup, eye);
        lookVector = MyVector.unitVector(lookVector);       
        lookVector = MyVector.unitVector(lookVector);       
        //y part of viewing plane
        upVector=new MyVector(0,-1,0);            
       
        //z part of view plane
        viewplaneX=MyMath.crossProduct(upVector, lookVector);
        viewplaneX = MyVector.unitVector(viewplaneX);       
        k=near/far;     
        n=MyVector.negate(lookVector);            
        r=MyMath.crossProduct(upVector,n);
        r=MyVector.unitVector(r);
        u=MyMath.crossProduct(n, r);             
    }
    public double perspective(double x,double y,double z){      
        temp[2]=(z+k)/(k-1);
        return z;
    }
    public double[] scale(double x,double y,double z){      
            temp[0]=x*(aspectRatio/far);
            temp[1]=y*(1/far);
            temp[2]=z*(1/far);
            return temp;
    }
    public double[] rotation(double x,double y,double z){    
        double tempx,tempy,tempz;
        tempx=x*r.getXcomponent()+y*r.getYcomponent()+z*r.getZcomponent();
        tempy=x*u.getXcomponent()+y*u.getYcomponent()+z*u.getZcomponent();
        tempz=x*n.getXcomponent()+y*n.getYcomponent()+z*n.getZcomponent();      
        temp[0]=tempx;
        temp[1]=tempy;
        temp[2]=tempz;
        return temp;      
    }
    public double[] translation(double x,double y,double z){    
        temp[0]=x-eye.getX();
        temp[1]=y-eye.getY();
        temp[2]=z-eye.getZ();       
        return temp;      
    }
    public void transformToImageSpace(double x,double y,double z) {
        temp[0]=(W*((x/z)+1)/2);
        temp[1]=(H*((y/z)+1)/2);       
    }
    public Point map(double x,double y,double z){        
        translation(x,y,z);
        System.out.println("After translation");
        System.out.println(temp[0]+","+temp[1]+","+temp[2]);       
        rotation(temp[0],temp[1],temp[2]);
        System.out.println("After rotation");
        System.out.println(x+","+y+","+z);       
        scale(temp[0],temp[1],temp[2]);
        System.out.println("After scale");
        System.out.println(x+","+y+","+z);
       
        perspective(temp[0],temp[1],temp[2]);
        System.out.println("After perspective");
        System.out.println(x+","+y+","+z);              
        transformToImageSpace(temp[0],temp[1],temp[2]);
        System.out.println("After imagespace");
        System.out.println(x+","+y+","+z);       
        System.out.println("------------------points here---------------------");
        return new Point((int)temp[0],(int)temp[1]);
    }
}

Visibility.java
package HiddenSurface;
import math.*;
import bridge.view.MainFrame;
public class Visibility {   
    /** Creates a new instance of Visibility */
    public Visibility() {
    }
    public static boolean isVisible(MyVector surfaceNormal){       
//        MyVector viewingDirection = new MyVector(0, 0, -1);
        double dotProduct = MyMath.dotProduct(surfaceNormal, MainFrame.viewingDirection);       
        if(dotProduct<0)
            return true;
        else
            return false;
    }
}

MyMath.java
package math;
import core.Vertex;
public class MyMath {
    public static MyVector crossProduct(MyVector v1,MyVector v2){
        double i,j,k;       
        i = ((v1.getYcomponent()*v2.getZcomponent())-v1.getZcomponent()*v2.getYcomponent());
        j = -((v1.getXcomponent()*v2.getZcomponent())-v1.getZcomponent()*v2.getXcomponent());
        k = ((v1.getXcomponent()*v2.getYcomponent())-v1.getYcomponent()*v2.getXcomponent());      
        return new MyVector(i,j,k);//product;
    }
    public static double dotProduct(MyVector v1,MyVector v2){
        double i,j,k;//,product;
        i = v1.getXcomponent()*v2.getXcomponent();
        //System.out.println("In dotProduct i: " + i);
        j = v1.getYcomponent()*v2.getYcomponent();
        k = v1.getZcomponent()*v2.getZcomponent();
        //product = i+j+k;
        //System.out.println("In dotProduct : " + product);
        return i+j+k;//product;
      
    }
    public static Vertex midPoint(Vertex v1,Vertex v2){
        Vertex result = new Vertex();
        result.setX((v1.getX()+v2.getX())/2);
        result.setY((v1.getY()+v2.getY())/2);
        result.setZ((v1.getZ()+v2.getZ())/2);
        return result;
    }
    public static Vertex centeroid(Vertex v1,Vertex v2,Vertex v3){
        Vertex result = new Vertex();
        result.setX((v1.getX()+v2.getX()+v3.getX())/3);
        result.setY((v1.getY()+v2.getY()+v3.getY())/3);
        result.setZ((v1.getZ()+v2.getZ()+v3.getZ())/3);
        return result;
    }
}

MyMatrix.java
package math;
import core.Vertex;
public class MyMatrix {
    private double[] matrix;
    public MyMatrix(){
        matrix=new double[4];
        for(int i=0;i<4;i++)
            matrix[i]=0;
    }
    public MyMatrix(double[] elements){
        matrix=new double[4];
        matrix=elements;
    }
    public MyMatrix(Vertex vertex){
        matrix=new double[4];
        matrix[0]=vertex.getX();
        matrix[1]=vertex.getY();
        matrix[2]=vertex.getZ();
        matrix[3]=1;
    }
    //for 4X4 and 4X1 matrix multiplication
    public static double[] matrixMultiplication(double [][]matrix1,double []matrix2){
        double[] resultant=new double[4];
        for(int i=0;i<matrix1.length;i++){
            for(int k=0;k<matrix2.length;k++)
               resultant[i]+=matrix1[i][k]*matrix2[k];
        }
        return resultant;
    }
    public double[] getMatrix(){
        return matrix;
    }
    public double get1(){
        return matrix[0];
    }
    public double get2(){
        return matrix[1];
    }
    public double get3(){
        return matrix[2];
    }
    public double get4(){
        return matrix[3];
    }
}

MyVector.java
package math;
import core.Vertex;
import core.*;
public class MyVector {
    private double i;
    private double j;
    private double k;   
    public MyVector(){
        i=0;
        j=0;
        k=0;
    }
    public MyVector(double i,double j,double k){
        this.i = i;
        this.j = j;
        this.k = k;
    }
    public MyVector(MyVector vector){
        i = vector.getXcomponent();
        j = vector.getYcomponent();
        k = vector.getZcomponent();
    }
    public void setXcomponent(double x){
        this.i = x;
    }
    public void setYcomponent(double y){
        this.j = y;
    }
    public void setZcomponent(double z){
        this.k = z;
    }
    public void setVector(MyVector vector){
        this.i = vector.getXcomponent();
        this.j = vector.getYcomponent();
        this.k = vector.getXcomponent();
    }
    public double getXcomponent(){
        return i;
    }
    public double getYcomponent(){
        return j;
    }
    public double getZcomponent(){
        return k;
    }
    public MyVector getVector(){
        return this;
    }
    public static MyVector calculateVector(Vertex v1,Vertex v2){
        double i=v2.getX()-v1.getX();
        double j=v2.getY()-v1.getY();
        double k=v2.getZ()-v1.getZ();
        return new MyVector(i, j, k);
    }
    public static MyVector unitVector(MyVector v){
        double magnitude;
        magnitude = Math.pow(v.getXcomponent(), 2)+Math.pow(v.getYcomponent(), 2)+Math.pow(v.getZcomponent(), 2);
        magnitude = Math.pow(magnitude, 0.5);
        double i=v.getXcomponent()/magnitude;
        double j=v.getYcomponent()/magnitude;
        double k=v.getZcomponent()/magnitude;
        return new MyVector(i, j, k);
    }
    public static MyVector normalVector(Surface surface){
        MyVector vector1,vector2,normal;
        Vertex v1,v2,v3;
        v1= surface.getEdge(0).getV1();
        v2= surface.getEdge(1).getV1();
        v3= surface.getEdge(2).getV1();      
        vector1 = calculateVector(v2,v1);
        vector2 = calculateVector(v2,v3);       
        normal = MyMath.crossProduct(vector1,vector2);
        normal = unitVector(normal);
        return normal;
    }
    public static MyVector negate(MyVector vector){
        return new MyVector(vector.getXcomponent()*-1,vector.getYcomponent()*-1,vector.getZcomponent()*-1);
    }
   
    public static double distance(Vertex first, Vertex second){
        int xdiff = first.getX() - second.getX();
        int ydiff = first.getY() - second.getY();
        int zdiff = first.getZ() - second.getZ();               
        return Math.abs(Math.sqrt(Math.pow(xdiff,2) + Math.pow(ydiff,2) + Math.pow(zdiff, 2)));
    }
}

CosineLambert.java
package Rendering;
import math.*;
import bridge.view.MainFrame;
public class CosineLambert {   
    /** Creates a new instance of CosineLambert */
    public CosineLambert() {
    }   
    public static double getIntensity(MyVector surfaceNormal){
        return -MyMath.dotProduct(surfaceNormal, MainFrame.lightSource);
    }
   
}