Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2011
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.87 KB | None | 0 0
  1. private void DrawMapModel(Model m)
  2.         {
  3.             Matrix[] transforms = new Matrix[m.Bones.Count];
  4.             m.CopyAbsoluteBoneTransformsTo(transforms);
  5.  
  6.             // Initialize an array of indices for the box. 12 lines require 24 indices
  7.             short[] bBoxIndices = {
  8.                     0, 1, 1, 2, 2, 3, 3, 0, // Front edges
  9.                     4, 5, 5, 6, 6, 7, 7, 4, // Back edges
  10.                     0, 4, 1, 5, 2, 6, 3, 7 // Side edges connecting front and back
  11.             };
  12.  
  13.             foreach (ModelMesh mesh in m.Meshes)
  14.             {
  15.                 //This fixes the lighting conditions
  16.                 foreach (Effect e in mesh.Effects)
  17.                 {
  18.                     IEffectLights iel = e as IEffectLights;
  19.                     if (iel != null)
  20.                         iel.EnableDefaultLighting();
  21.                 }
  22.  
  23.                 foreach (BasicEffect effect in mesh.Effects)
  24.                 {
  25.                     effect.TextureEnabled = true;
  26.                     effect.World = transforms[mesh.ParentBone.Index] *
  27.                         Matrix.CreateScale(1.5f);
  28.                         Matrix.CreateTranslation(mapPosition);
  29.                     effect.View = viewMatrix;
  30.                     effect.Projection = projectionMatrix;
  31.                 }
  32.                
  33.                 //TEST - Draw lines around the edges of the bounding
  34.                 //boxes
  35.                 foreach (BasicEffect effect in mesh.Effects)
  36.                 {
  37.                     foreach (BoundingBox box in mapBoxes)
  38.                     {
  39.                         Vector3[] corners = box.GetCorners();
  40.                         VertexPositionColor[] primitiveList = new
  41.                                 VertexPositionColor[corners.Length];
  42.  
  43.                         // Assign the 8 box vertices
  44.                         for (int i = 0; i < corners.Length; i++)
  45.                         {
  46.                             primitiveList[i] = new VertexPositionColor(corners[i], Color.White);
  47.                         }
  48.  
  49.                         /* Set your own effect parameters here */
  50.  
  51.                         effect.World = Matrix.Identity;
  52.                         effect.View = viewMatrix;
  53.                         effect.Projection = projectionMatrix;
  54.                         effect.TextureEnabled = false;
  55.  
  56.                         // Draw thebox with a LineList
  57.                         foreach (EffectPass pass in effect.CurrentTechnique.Passes)
  58.                         {
  59.                             pass.Apply();
  60.  
  61.  
  62.  
  63. // THIS IS WHERE THE ERROR OCCURS:
  64.  
  65.  
  66.                             game.GraphicsDevice.DrawUserIndexedPrimitives(
  67.                                 PrimitiveType.LineList, primitiveList, 0, 8, bBoxIndices, 0, 12);
  68.  
  69.  
  70.  
  71.  
  72.  
  73.                         }
  74.                     }
  75.                 }
  76.                 mesh.Draw();
  77.             }
  78.         }
  79.  
  80.  
  81.  
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement