GithubHelp home page GithubHelp logo

webgl-flightsim's Introduction

Running the code

The code should be able to run without any setup given that 1. The demo is being run in a browser that supports WebGL (such as Chromium) 2. The computer has a graphics card that is currently supported by WebGL

Keys

A/D - roll left/right
W/S - pitch up/down
-/+ - decrease/increase velocity

Terrain Generator

I created my own terrain generator which makes use of Perlin Noise (or Coherent Noise). Terrain Size - the size of the terrain in model coordinate. # Data Points - the number of noise data points to generate. More samples generally means more spikes/mountains. # Noise Samples - the number of samples to take from the linearly interpolated noise data. (More means more polygons) Max Mountain Height - the maximum height of the mountains in model coordinates.

UFO mode is a surprise.

Sources

webgl-flightsim's People

Contributors

keunhong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

jhuang314 dgzzhb

webgl-flightsim's Issues

Plane and ground

The plane can fly through the ground, however iv'e made a bit of code that only works if the max mountain height is 0.1.
In mp2.js you can replace the tick() function with this

function tick(){
    requestAnimFrame(tick);
    display();
	
	$("#up>span").html("x:"+up[0]+"<br/>y:"+up[1]+"<br/>z:"+up[2]);
	$("#forward>span").html("x:"+forward[0]+"<br/>y:"+forward[1]+"<br/>z:"+forward[2]);
	$("#position>span").html("x:"+position[0]+"<br/>y:"+position[1]+"<br/>z:"+position[2]);
	$('#velocity>span').html(velocity);

    var now = new Date().getTime();
    if(last != 0){

        var delta = (now - last)/1000

        groundHeight = 0.3;

        if (position[2] > groundHeight) {
            
    		// Move forward
    		position[0] += delta * velocity * forward[0];
    		position[1] += delta * velocity * forward[1];
    		position[2] += delta * velocity * forward[2];
    		
    		// Rotate based on roll
    		// normal vector of forward-z plane
    		var n_fz = vec3.create();
    		vec3.cross(forward, vec3.create([0,0,1]), n_fz);
    		vec3.normalize(n_fz);
    		var roll = vec3.dot(n_fz, up); // both vectors are unit so cosB = dot(n_fz, up)
    		
    		// Turn according to roll
    		var rotateMatrix = mat4.create();
    		mat4.identity(rotateMatrix);
    		mat4.rotate(rotateMatrix, -1 * delta * Math.tan(roll), up);
    		mat4.multiplyVec3(rotateMatrix, forward);
		
        
    		// Pitch up or down
    		var right = vec3.create();
    		vec3.cross(forward, up, right);
    		mat4.identity(rotateMatrix);
    		mat4.rotate(rotateMatrix, delta * vertical_angular_velocity, right);
    		mat4.multiplyVec3(rotateMatrix, up);
    		mat4.multiplyVec3(rotateMatrix, forward);
    	
    		// Roll sideways
    		mat4.identity(rotateMatrix);
    		mat4.rotate(rotateMatrix, delta * roll_angular_velocity, forward);
    		mat4.multiplyVec3(rotateMatrix, up);
        } else {
            if (velocity > 0) {

                position[0] += delta * velocity * forward[0]; 
                position[1] += delta * velocity * forward[2];
                position[2] = groundHeight;     

            } else {

                angle = 0;

            } ;
        } 
    }
    last = now;
}

But the groundHeight variable dose not change based on the ground

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.