Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Turret.rotateTo( dir, dt )
- {
- dir = dir.normalized;
- // do not let it rotate too quickly
- axis = vec3_cross( dir, this.direction ).normalized;
- angle = acos( min( 1, vec3_dot( dir, this.direction ) ) );
- maxmove = dt;
- if( angle > maxmove )
- dir = mat3().rotate_axis_angle_v3( axis, maxmove ).transform( this.direction ).normalized;
- // limit rotation
- axis = vec3_cross( dir, this.orig_direction ).normalized;
- angle = acos( min( 1, vec3_dot( dir, this.orig_direction ) ) );
- if( angle > this.maxangle )
- angle = this.maxangle;
- // rotate
- this.rotation = this.orig_rotation.normalized.rotate_axis_angle_v3( axis, angle ).normalized;
- this.direction = this.rotation.transform( vec3( 1, 0, 0 ) );
- this.mesh_inst.matrix = mat4().scale_v3( this.scale ).rotate_quat( this.rotation ).translate_v3( this.position );
- this.body.orientation = this.rotation.invert();
- lt = this.light;
- lt.direction = this.direction;
- lt.position = this.position + this.direction;
- lt.updir = this.rotation.transform( vec3(0,0,1) );
- lt.genSpotLightMatrices();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement