Advertisement
snake5

SGRX TestEntity

Feb 12th, 2016
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. global TestEntity = { __getindex = mm_getindex_router, __setindex = mm_setindex_router };
  2.  
  3. function TestEntity.UpdateMatrix()
  4. {
  5.     mtx = mat4()
  6.         .rotate_quat( this._rotation )
  7.         .rotateZ( this.t * M_PI )
  8.         .translate_v3( this._position + vec3(0,0,sin(this.t*M_PI)*0.25) );
  9.     this.SetMatrix( mtx );
  10. }
  11.  
  12. function TestEntity.__get_position(){ return this._position; }
  13. function TestEntity.__set_position( p ){ this._position = p; this.UpdateMatrix(); }
  14. function TestEntity.__get_rotation(){ return this._rotation; }
  15. function TestEntity.__set_rotation( q ){ this._rotation = q; this.UpdateMatrix(); }
  16.  
  17. function TestEntity.Init()
  18. {
  19.     this._position = vec3(0);
  20.     this._rotation = quat();
  21.     this.t = 0;
  22.     this.pstimeout = 0;
  23.     this.MICreate( 0, "meshes/woodbox1.ssm" );
  24.     this.PSCreate( 0, "psys/spark_faulty.psy" );
  25.     this.PSSetMatrix( 0, mat4().translate( 0, 0, 0.3 ).rotateX( M_PI * 0.5 ) );
  26.     this.UpdateMatrix();
  27. }
  28.  
  29. function TestEntity.Update( dt )
  30. {
  31.     this.t += dt;
  32.     this.UpdateMatrix();
  33.    
  34.     this.pstimeout -= dt;
  35.     if( this.pstimeout <= 0 )
  36.     {
  37.         this.PSTrigger( 0 );
  38.         this.pstimeout += 0.1;
  39.     }
  40. }
  41.  
  42. function ENTCREATE_TestEntity()
  43. {
  44.     E = CreateEntityExt( "scripted_entity", "TestEntity" );
  45.     E.Init();
  46.     return E;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement