Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Mogre;
  6. using Quickstart2010.Modules;
  7. using Quickstart2010.Render.Entities;
  8.  
  9. namespace Quickstart2010.Render.Entities {
  10.     public class PhaserBeam : BaseEntity {
  11.  
  12.         protected BillboardChain mBbc;
  13.         protected BillboardSet _frontFlare;
  14.         protected BillboardSet _backFlare;
  15.         protected SceneNode mTarget;
  16.         protected SceneNode mParent;
  17.         public Vector3 OffsetParent;
  18.         public Vector3 OffsetTarget;
  19.         protected float mWidth;
  20.  
  21.         protected const float DEFAULT_SIZE = 40;
  22.        
  23.         public PhaserBeam( float width, String material, SceneNode target, SceneNode parent )
  24.             : base( )
  25.         {
  26.             // LogManager.Singleton.LogMessage( "phaser beam " + parent.Name + " to " + target.Name );
  27.             mWidth = width;
  28.             mTarget = target;
  29.             mParent = parent;
  30.            
  31.             mBbc = OgreManager.Singleton.SceneMgr.CreateBillboardChain();
  32.             mBbc.Dynamic = true;
  33.             mBbc.NumberOfChains = 1;
  34.             mBbc.MaxChainElements = 2;
  35.  
  36.             mBbc.AddChainElement( 0, BillboardChain.Element_NativePtr.Create(
  37.                 parent.ConvertLocalToWorldPosition( OffsetParent ), 5, 0.0f, ColourValue.White )
  38.             );
  39.  
  40.             mBbc.AddChainElement( 0, BillboardChain.Element_NativePtr.Create(
  41.                 target.ConvertLocalToWorldPosition( OffsetTarget ), 0, 1.0f, ColourValue.White )
  42.             );
  43.  
  44.             // Try head / tail with round conrners ( ending ) of phaser fire
  45.  
  46.             mBbc.SetMaterialName( material );
  47.  
  48.             this.SceneNode = OgreManager.Singleton.SceneMgr.RootSceneNode.CreateChildSceneNode();
  49.             this.SceneNode.AttachObject( mBbc );
  50.  
  51.             SceneNode node;
  52.  
  53.             _frontFlare = OgreManager.Singleton.SceneMgr.CreateBillboardSet( 1 );
  54.             _frontFlare.SetDefaultDimensions( DEFAULT_SIZE, DEFAULT_SIZE );
  55.             _frontFlare.CreateBillboard( Vector3.ZERO);
  56.             _frontFlare.SetMaterialName( material + "/Flare" );
  57.             node = this.SceneNode.CreateChildSceneNode();
  58.             node.Scale( Vector3.UNIT_SCALE * 0.1f );
  59.             node.Position = target.ConvertLocalToWorldPosition( OffsetTarget );
  60.             node.AttachObject(_frontFlare);
  61.  
  62.             _backFlare = OgreManager.Singleton.SceneMgr.CreateBillboardSet( 1 );
  63.             _backFlare.SetDefaultDimensions( DEFAULT_SIZE, DEFAULT_SIZE );
  64.             _backFlare.CreateBillboard( Vector3.ZERO);
  65.             _backFlare.SetMaterialName( material + "/Flare" );
  66.             node = this.SceneNode.CreateChildSceneNode();
  67.             node.Scale( Vector3.UNIT_SCALE * 0.1f );
  68.             node.Position = parent.ConvertLocalToWorldPosition( OffsetParent );
  69.             node.AttachObject( _backFlare );
  70.  
  71.  
  72.             // parent.AttachObject( mBbc );
  73.             this.TimeToLive = 1;
  74.         }
  75.  
  76.         public override void OnBeforeDestroyed() {
  77.             if ( mBbc.ParentSceneNode != null ) {
  78.                 mBbc.ParentSceneNode.Creator.DestroyBillboardChain( this.mBbc );
  79.             }
  80.  
  81.             if ( _frontFlare.ParentSceneNode != null ) {
  82.                 _frontFlare.ParentSceneNode.Creator.DestroyBillboardSet( this._frontFlare );
  83.             }
  84.  
  85.             if ( _backFlare.ParentSceneNode != null ) {
  86.                 _backFlare.ParentSceneNode.Creator.DestroyBillboardSet( this._backFlare );
  87.             }
  88.  
  89.             mBbc.Dispose();
  90.             mBbc = null;
  91.  
  92.             _frontFlare.Dispose();
  93.             _backFlare.Dispose();
  94.         }
  95.  
  96.         public override void Update( float elapsed ) {
  97.             base.Update( elapsed );
  98.  
  99.             float widthFactor = 1;
  100.             if ( this.TimeToLive > 0.5f) {
  101.                 widthFactor = 2* ( 1.0f - this.TimeToLive );
  102.             } else if ( this.TimeToLive < 0.3f ) {
  103.                 widthFactor = this.TimeToLive * 3;
  104.             }
  105.  
  106.             BillboardChain.Element_NativePtr element;
  107.  
  108.             if ( mParent != null && mParent.IsInSceneGraph ) {
  109.                 element = mBbc.GetChainElement( 0, 0 );
  110.                 element.position =  mParent.ConvertLocalToWorldPosition( OffsetParent );
  111.                 _backFlare.ParentSceneNode.Position = element.position;
  112.                 element.width = mWidth * widthFactor;
  113.                 mBbc.UpdateChainElement( 0, 0, element );
  114.             }
  115.  
  116.             if ( mTarget != null && mTarget.IsInSceneGraph ) {
  117.                 element = mBbc.GetChainElement( 0, 1 );
  118.                 element.position = mTarget.ConvertLocalToWorldPosition( OffsetTarget );
  119.                 _frontFlare.ParentSceneNode.Position = element.position;
  120.                 element.width = mWidth * widthFactor;
  121.                 mBbc.UpdateChainElement( 0, 1, element );
  122.             }
  123.         }
  124.  
  125.     }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement