Skip to content

Instantly share code, notes, and snippets.

@edgarberm
Created October 9, 2013 11:39
Show Gist options
  • Save edgarberm/6899903 to your computer and use it in GitHub Desktop.
Save edgarberm/6899903 to your computer and use it in GitHub Desktop.
Basic Vector3 class
function Vector3( x, y, z )
{
this.x = x;
this.y = y;
this.z = z;
this.tx = 0;
this.ty = 0;
this.tz = 0;
this.sinRX = 0;
this.cosRX = 0;
this.cosRY = 0;
this.sinRY = 0;
this.rotateX = function( angle )
{
this.ty = this.y;
this.tz = this.z;
cosRX = Math.cos( angle );
sinRX = Math.sin( angle );
this.y = ( this.ty * cosRX ) + ( this.tz * sinRX );
this.z = ( this.ty * -sinRX ) + ( this.tz * cosRX );
}
this.rotateY = function( angle )
{
this.tx = this.x;
this.tz = this.z;
cosRY = Math.cos( angle );
sinRY = Math.sin( angle );
this.x = ( this.tx * cosRY ) + ( this.tz * sinRY );
this.z = ( this.tx * -sinRY ) + ( this.tz * cosRY );
}
this.reset = function( x, y, z )
{
this.x = x;
this.y = y;
this.z = z;
}
this.plusEq = function ( v )
{
this.x += v.x;
this.y += v.y;
this.z += v.z;
}
this.multiplyEq = function( s )
{
this.x *= s;
this.y *= s;
this.z *= s;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment