global TestEntity = { __getindex = mm_getindex_router, __setindex = mm_setindex_router };
function TestEntity.UpdateMatrix()
{
mtx = mat4()
.rotate_quat( this._rotation )
.rotateZ( this.t * M_PI )
.translate_v3( this._position + vec3(0,0,sin(this.t*M_PI)*0.25) );
this.SetMatrix( mtx );
}
function TestEntity.__get_position(){ return this._position; }
function TestEntity.__set_position( p ){ this._position = p; this.UpdateMatrix(); }
function TestEntity.__get_rotation(){ return this._rotation; }
function TestEntity.__set_rotation( q ){ this._rotation = q; this.UpdateMatrix(); }
function TestEntity.Init()
{
this._position = vec3(0);
this._rotation = quat();
this.t = 0;
this.pstimeout = 0;
this.MICreate( 0, "meshes/woodbox1.ssm" );
this.PSCreate( 0, "psys/spark_faulty.psy" );
this.PSSetMatrix( 0, mat4().translate( 0, 0, 0.3 ).rotateX( M_PI * 0.5 ) );
this.UpdateMatrix();
}
function TestEntity.Update( dt )
{
this.t += dt;
this.UpdateMatrix();
this.pstimeout -= dt;
if( this.pstimeout <= 0 )
{
this.PSTrigger( 0 );
this.pstimeout += 0.1;
}
}
function ENTCREATE_TestEntity()
{
E = CreateEntityExt( "scripted_entity", "TestEntity" );
E.Init();
return E;
}
Comments