Welcome, Guest! Log In | Create Account

Changeset 1676

Show
Ignore:
Timestamp:
06/30/09 12:46:53 (4 months ago)
Author:
borrillis
Message:

Ticket #26
- Fixed WireBoundingBox? being larger than actual entity.

This is not the implementation provided by andris11, but an update from the OGRE code.
Checked against the test included in this patch to verify.
Color changing to implemented

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/Projects/Axiom/Source/Engine/Core/WireBoundingBox.cs

    r1663 r1676  
    4848    public sealed class WireBoundingBox : SimpleRenderable 
    4949    { 
    50         #region Member variables 
     50        #region Field and Properties 
    5151 
    5252        private float radius; 
    5353 
    54         #endregion Member variables 
     54        #endregion Field and Properties 
    5555 
    5656        #region Constants 
    5757 
    5858        const int POSITION = 0; 
    59         const int COLOR = 1; 
    60  
     59  
    6160        #endregion Constants 
    6261 
     
    7877            // add elements for position and color only 
    7978            decl.AddElement( POSITION, 0, VertexElementType.Float3, VertexElementSemantic.Position ); 
    80             decl.AddElement( COLOR, 0, VertexElementType.Color, VertexElementSemantic.Diffuse ); 
    8179 
    8280            // create a new hardware vertex buffer for the position data 
     
    9088            binding.SetBinding( POSITION, buffer ); 
    9189 
    92             // create a new hardware vertex buffer for the color data 
    93             buffer = HardwareBufferManager.Instance.CreateVertexBuffer( 
    94                 decl.GetVertexSize( COLOR ), 
    95                 vertexData.vertexCount, 
    96                 BufferUsage.StaticWriteOnly ); 
    97  
    98             // bind the color buffer 
    99             binding.SetBinding( COLOR, buffer ); 
    100  
    101                         this.Material = (Material)MaterialManager.Instance[ "BaseWhite" ]; 
    102  
    103                         //Material mat = MaterialManager.Instance[ "Core/WireBB" ]; 
    104  
    105                         //if ( mat == null ) 
    106                         //{ 
    107                         //    mat = MaterialManager.Instance[ "BaseWhite" ]; 
    108                         //    mat = mat.Clone( "Core/WireBB", "" ); 
    109                         //    mat.Lighting = false; 
    110                         //} 
    111  
    112                         //this.Material = mat; 
     90                        this.Material = (Material)MaterialManager.Instance[ "BaseWhiteNoLighting" ]; 
     91 
    11392        } 
    11493 
     
    123102        public override void GetWorldTransforms( Matrix4[] matrices ) 
    124103        { 
     104            // return identity matrix to prevent parent transforms 
    125105            matrices[ 0 ] = Matrix4.Identity; 
    126106        } 
     
    129109        { 
    130110            SetupAABBVertices( box ); 
    131  
    132             // get a reference to the color buffer 
    133             HardwareVertexBuffer buffer = 
    134                 vertexData.vertexBufferBinding.GetBuffer( COLOR ); 
    135  
    136             // lock the buffer 
    137             IntPtr colPtr = buffer.Lock( BufferLocking.Discard ); 
    138  
    139             // load the color buffer with the specified color for each element 
    140             unsafe 
    141             { 
    142                 int* pCol = (int*)colPtr.ToPointer(); 
    143  
    144                 for ( int i = 0; i < vertexData.vertexCount; i++ ) 
    145                     pCol[ i ] = Root.Instance.ConvertColor( ColorEx.Red ); 
    146             } 
    147  
    148             // unlock the buffer 
    149             buffer.Unlock(); 
    150111 
    151112            // store the bounding box locally 
     
    162123            radius = Utility.Sqrt( lengthSquared ); 
    163124 
    164             float maxx = max.x + 1.0f; 
    165             float maxy = max.y + 1.0f; 
    166             float maxz = max.z + 1.0f; 
    167  
    168             float minx = min.x - 1.0f; 
    169             float miny = min.y - 1.0f; 
    170             float minz = min.z - 1.0f; 
     125            float maxx = max.x; 
     126            float maxy = max.y; 
     127            float maxz = max.z; 
     128 
     129            float minx = min.x; 
     130            float miny = min.y; 
     131            float minz = min.z; 
    171132 
    172133            int i = 0; 
    173134 
    174             HardwareVertexBuffer buffer = 
    175                 vertexData.vertexBufferBinding.GetBuffer( POSITION ); 
     135            HardwareVertexBuffer buffer = vertexData.vertexBufferBinding.GetBuffer( POSITION ); 
    176136 
    177137            IntPtr posPtr = buffer.Lock( BufferLocking.Discard ); 
     
    282242            min = box.Minimum; 
    283243            max = box.Maximum; 
    284             mid = ( ( min - max ) * 0.5f ) + min; 
     244            mid = ( ( max - min ) * 0.5f ) + min; 
    285245            dist = camera.DerivedPosition - mid; 
    286246