Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Mogre;
- using Quickstart2010.Modules;
- using Quickstart2010.Render.Entities;
- namespace Quickstart2010.Render.Entities {
- public class PhaserBeam : BaseEntity {
- protected BillboardChain mBbc;
- protected BillboardSet _frontFlare;
- protected BillboardSet _backFlare;
- protected SceneNode mTarget;
- protected SceneNode mParent;
- public Vector3 OffsetParent;
- public Vector3 OffsetTarget;
- protected float mWidth;
- protected const float DEFAULT_SIZE = 40;
- public PhaserBeam( float width, String material, SceneNode target, SceneNode parent )
- : base( )
- {
- // LogManager.Singleton.LogMessage( "phaser beam " + parent.Name + " to " + target.Name );
- mWidth = width;
- mTarget = target;
- mParent = parent;
- mBbc = OgreManager.Singleton.SceneMgr.CreateBillboardChain();
- mBbc.Dynamic = true;
- mBbc.NumberOfChains = 1;
- mBbc.MaxChainElements = 2;
- mBbc.AddChainElement( 0, BillboardChain.Element_NativePtr.Create(
- parent.ConvertLocalToWorldPosition( OffsetParent ), 5, 0.0f, ColourValue.White )
- );
- mBbc.AddChainElement( 0, BillboardChain.Element_NativePtr.Create(
- target.ConvertLocalToWorldPosition( OffsetTarget ), 0, 1.0f, ColourValue.White )
- );
- // Try head / tail with round conrners ( ending ) of phaser fire
- mBbc.SetMaterialName( material );
- this.SceneNode = OgreManager.Singleton.SceneMgr.RootSceneNode.CreateChildSceneNode();
- this.SceneNode.AttachObject( mBbc );
- SceneNode node;
- _frontFlare = OgreManager.Singleton.SceneMgr.CreateBillboardSet( 1 );
- _frontFlare.SetDefaultDimensions( DEFAULT_SIZE, DEFAULT_SIZE );
- _frontFlare.CreateBillboard( Vector3.ZERO);
- _frontFlare.SetMaterialName( material + "/Flare" );
- node = this.SceneNode.CreateChildSceneNode();
- node.Scale( Vector3.UNIT_SCALE * 0.1f );
- node.Position = target.ConvertLocalToWorldPosition( OffsetTarget );
- node.AttachObject(_frontFlare);
- _backFlare = OgreManager.Singleton.SceneMgr.CreateBillboardSet( 1 );
- _backFlare.SetDefaultDimensions( DEFAULT_SIZE, DEFAULT_SIZE );
- _backFlare.CreateBillboard( Vector3.ZERO);
- _backFlare.SetMaterialName( material + "/Flare" );
- node = this.SceneNode.CreateChildSceneNode();
- node.Scale( Vector3.UNIT_SCALE * 0.1f );
- node.Position = parent.ConvertLocalToWorldPosition( OffsetParent );
- node.AttachObject( _backFlare );
- // parent.AttachObject( mBbc );
- this.TimeToLive = 1;
- }
- public override void OnBeforeDestroyed() {
- if ( mBbc.ParentSceneNode != null ) {
- mBbc.ParentSceneNode.Creator.DestroyBillboardChain( this.mBbc );
- }
- if ( _frontFlare.ParentSceneNode != null ) {
- _frontFlare.ParentSceneNode.Creator.DestroyBillboardSet( this._frontFlare );
- }
- if ( _backFlare.ParentSceneNode != null ) {
- _backFlare.ParentSceneNode.Creator.DestroyBillboardSet( this._backFlare );
- }
- mBbc.Dispose();
- mBbc = null;
- _frontFlare.Dispose();
- _backFlare.Dispose();
- }
- public override void Update( float elapsed ) {
- base.Update( elapsed );
- float widthFactor = 1;
- if ( this.TimeToLive > 0.5f) {
- widthFactor = 2* ( 1.0f - this.TimeToLive );
- } else if ( this.TimeToLive < 0.3f ) {
- widthFactor = this.TimeToLive * 3;
- }
- BillboardChain.Element_NativePtr element;
- if ( mParent != null && mParent.IsInSceneGraph ) {
- element = mBbc.GetChainElement( 0, 0 );
- element.position = mParent.ConvertLocalToWorldPosition( OffsetParent );
- _backFlare.ParentSceneNode.Position = element.position;
- element.width = mWidth * widthFactor;
- mBbc.UpdateChainElement( 0, 0, element );
- }
- if ( mTarget != null && mTarget.IsInSceneGraph ) {
- element = mBbc.GetChainElement( 0, 1 );
- element.position = mTarget.ConvertLocalToWorldPosition( OffsetTarget );
- _frontFlare.ParentSceneNode.Position = element.position;
- element.width = mWidth * widthFactor;
- mBbc.UpdateChainElement( 0, 1, element );
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement