Giter VIP home page Giter VIP logo

maze's Introduction

Maze Project

A project Developed in webGL by Kevin Lin

Running Project

Run in Firefox, Internet Edge and any other webGL supported browser. The only browser with a bug at the moment is Google Chrome

Aspects of the project

Built on top of the textbook's provided MV.js file.

Lighting & Shading

The Phong model is used for lighting and shading. The player which is currently a ball has a light source that is used to calculated color of the nearby objects. The code was based off the textbook's example.

Vertex Shader

varying vec3 N, L, E, H;

E = normalize(-pos);
N = normalize( (normalMatrix*vNormal).xyz);
H = normalize(L + E);

vec4 ambient = vec4(0,0,0,1);

float Kd = max( dot(L, N), 0.0 );
vec4  diffuse = Kd*diffuseProduct;
float Ks = pow( max(dot(N, H), 0.0), shininess );
vec4  specular = Ks * specularProduct;
if( dot(L, N) < 0.0 )
    specular = vec4(0.0, 0.0, 0.0, 1.0);
fColor = ambient + diffuse +specular;

Fragment Shader

uniform vec4 ambientProduct;
uniform vec4 diffuseProduct;
uniform vec4 specularProduct;
varying vec3 N, L, E, H;

vec4 fColorTemp;
vec4 ambient = ambientProduct;
float Kd = max( dot(L, N), 0.0 );
vec4  diffuse = Kd*diffuseProduct;
float Ks = pow( max(dot(N, H), 0.0), shininess );
vec4  specular = Ks * specularProduct;
if( dot(L, N) < 0.0 )
    specular = vec4(0.0, 0.0, 0.0, 1.0);
fColorTemp = ambient + diffuse +specular;
fColorTemp.a = 1.0;
gl_FragColor = fColorTemp;

Texturing

The objects that are textured are the walls and the skybox. The skybox uses a generic light blue with white and the walls are stones. The texture image were embedded into the html file with the hidden flag. This allowed proper import of the jpg files

Vertex Shader

attribute vec2 vTexCoord;
varying vec2 fTexCoord;

fTexCoord = 1.0 * vTexCoord;

Fragment Shader

uniform sampler2D texture;
varying vec4 fColor;
varying vec2 fTexCoord;
if (distance < 3.5){
    float coef = 1.0 / pow(distance,3.0);
    if(coef > 1.0)
        coef = 1.0;
    gl_FragColor = coef * texture2D(texture, fTexCoord);
}
else if(distance > 50.0)
    gl_FragColor = texture2D(texture, fTexCoord);
else
    gl_FragColor = vec4(0.0,0.0,0.0,1.0);

Collision Detection

Collisions were detected by using the sphere's speed and calculating the future position of the sphere on each side of the sphere while keeping the maximum width of the sphere in the calculations

sphere.collisionDetection = function(){
    ...

     if (sToFront <= sToBack && sToFront <= sToLeft && sToFront <= sToRight ) {
	if ((sphereFuturePosition[2] - frontPoint[2] ) <= sphere.radius) {
		sphere.speed[2] = -sphere.speed[2];
		collideStatus =  true;
        }
    }
    if (sToBack <= sToFront && sToBack <= sToLeft && sToBack <= sToRight ) {
	if((backPoint[2] - sphereFuturePosition[2] ) <= sphere.radius){
		sphere.speed[2] = -sphere.speed[2];
		collideStatus =  true;
        }
    }

    if (sToLeft <= sToBack && sToLeft <= sToFront && sToLeft <= sToRight ) {
	if((leftPoint[0] - sphereFuturePosition[0] ) <= sphere.radius) {
		sphere.speed[0] = -sphere.speed[0];
		collideStatus =  true;
        }
    }

    if (sToRight < sToBack && sToRight < sToFront && sToRight < sToLeft ) {
	if((sphereFuturePosition[0] - rightPoint[0] ) <= sphere.radius) {
		sphere.speed[0] = -sphere.speed[0];
		collideStatus =  true;
        }
    }
    return collideStatus;
};

Playing the Maze

Controls

W : Forward
A : Left
S : Backward
D : Right
T : Top-view
<-: Turn Right
->: Turn Left

maze's People

Contributors

kevinlin6543 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.