Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void DrawMapModel(Model m)
- {
- Matrix[] transforms = new Matrix[m.Bones.Count];
- m.CopyAbsoluteBoneTransformsTo(transforms);
- // Initialize an array of indices for the box. 12 lines require 24 indices
- short[] bBoxIndices = {
- 0, 1, 1, 2, 2, 3, 3, 0, // Front edges
- 4, 5, 5, 6, 6, 7, 7, 4, // Back edges
- 0, 4, 1, 5, 2, 6, 3, 7 // Side edges connecting front and back
- };
- foreach (ModelMesh mesh in m.Meshes)
- {
- //This fixes the lighting conditions
- foreach (Effect e in mesh.Effects)
- {
- IEffectLights iel = e as IEffectLights;
- if (iel != null)
- iel.EnableDefaultLighting();
- }
- foreach (BasicEffect effect in mesh.Effects)
- {
- effect.TextureEnabled = true;
- effect.World = transforms[mesh.ParentBone.Index] *
- Matrix.CreateScale(1.5f);
- Matrix.CreateTranslation(mapPosition);
- effect.View = viewMatrix;
- effect.Projection = projectionMatrix;
- }
- //TEST - Draw lines around the edges of the bounding
- //boxes
- foreach (BasicEffect effect in mesh.Effects)
- {
- foreach (BoundingBox box in mapBoxes)
- {
- Vector3[] corners = box.GetCorners();
- VertexPositionColor[] primitiveList = new
- VertexPositionColor[corners.Length];
- // Assign the 8 box vertices
- for (int i = 0; i < corners.Length; i++)
- {
- primitiveList[i] = new VertexPositionColor(corners[i], Color.White);
- }
- /* Set your own effect parameters here */
- effect.World = Matrix.Identity;
- effect.View = viewMatrix;
- effect.Projection = projectionMatrix;
- effect.TextureEnabled = false;
- // Draw thebox with a LineList
- foreach (EffectPass pass in effect.CurrentTechnique.Passes)
- {
- pass.Apply();
- // THIS IS WHERE THE ERROR OCCURS:
- game.GraphicsDevice.DrawUserIndexedPrimitives(
- PrimitiveType.LineList, primitiveList, 0, 8, bBoxIndices, 0, 12);
- }
- }
- }
- mesh.Draw();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement