topical media & game development
mobile-query-three-plugins-md2character-tquery.md2character.ratamahatta.js / js
implement Ratamahatta character.
TODO seems to have issue with multilple characters. it may be about material
caching. seems typically a microcache issue.
@name tQuery.RatamahattaMD2Character
@augments tQuery.MD2Character
@constructor
tQuery.registerStatic('RatamahattaMD2Character', function(opts){
// call parent ctor
var parent = tQuery.RatamahattaMD2Character.parent;
parent.constructor.call(this)
// handle parameters
opts = tQuery.extend(opts, {
baseUrl : tQuery.RatamahattaMD2Character.baseUrl+'/models/ratamahatta/'
});
// handle the attachedWorld
this._attachedWorld = null;
this._
inherit from tQuery.MD2Character
tQuery.inherit(tQuery.RatamahattaMD2Character, tQuery.MD2Character);
// make it pluginable
tQuery.pluginsInstanceOn(tQuery.RatamahattaMD2Character);
tQuery.RatamahattaMD2Character.prototype.destroy = function(){
// call parent ctor
var parent = tQuery.RatamahattaMD2Character.parent;
parent.destroy.call(this)
}
////////////////////////////////////////////////////////////////////////////
// //
////////////////////////////////////////////////////////////////////////////
tQuery.RatamahattaMD2Character.prototype.attach = function(world){
if( this._attachedWorld ) this.detacheFrom(this.attachedWorld);
world = world || tQuery.world;
this._attachedWorld = world;
world.add( this.container() )
world.loop().hook(this._loopCb);
return this; // for chained API
};
tQuery.RatamahattaMD2Character.prototype.detach = function(){
world = world || this._attachedWorld;
world.remove(this.container())
world.loop().unhook(this._
Turn left
parameter: {Number} angle angle to turn to in radian
tQuery.RatamahattaMD2Character.prototype.turnLeft = function(angle){
if( angle === undefined ) angle = 0.1;
return this.turn(+angle)
};
Turn right
parameter: {Number} angle angle to turn to in radian
tQuery.RatamahattaMD2Character.prototype.turnRight = function(angle){
if( angle === undefined ) angle = 0.1;
return this.turn(-angle)
};
Turn to an angle
parameter: {Number} angle angle to turn to in radian
tQuery.RatamahattaMD2Character.prototype.turn = function(angle){
var character = this;
if( angle === undefined, "angle MUST be defined" );
if( this.isLoaded() === false ) return this;
var container = character.container();
container.rotation.y += angle;
return this; // for chained API
};
////////////////////////////////////////////////////////////////////////////
// .go() //
////////////////////////////////////////////////////////////////////////////
go forward to a distance
parameter: {Number} angle angle to turn to in radian
tQuery.RatamahattaMD2Character.prototype.goForward = function(distance){
if( this.isLoaded() === false ) return this;
distance = distance !== undefined ? distance : 0.05;
var container = this.container();
var angle = container.rotation.y;
var speed = new THREE.Vector3(0, 0, distance);
var matrix = new THREE.Matrix4().makeRotationY(angle);
speed.applyMatrix4( matrix );
container.position.add(speed);
return this; // for chained API
};
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.