Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have some .X models loaded via self-written AssetManager that has Lists with models in it. I also apply a diffuse shader to my models. All the models are "self-drawing" in a BasicModel class.

effect.CurrentTechnique = effect.Techniques["DiffuseLight"];

// Begin our effect
effect.Begin();
// obvious renderstates
//graphics.GraphicsDevice.RenderState.DepthBufferEnable = true;
//graphics.GraphicsDevice.RenderState.DepthBufferWriteEnable = true;

// A shader can have multiple passes, be sure to loop trough each of them.
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
     // Begin current pass
     pass.Begin();
     foreach (ModelMesh mesh in model.Meshes)
     {
           foreach (ModelMeshPart part in mesh.MeshParts)
           {
                // calculate our worldMatrix..
                world = GetWorld() * mesh.ParentBone.Transform;
                // .. and pass it into our shader.
                // To access a parameter defined in our shader file ( Shader.fx ), use effectObject.Parameters["variableName"]
                Matrix worldInverse = Matrix.Invert(world);
                Vector4 vLightDirection = new Vector4(0.0f, 0.0f, 1.0f, 1.0f);
                effect.Parameters["matWorldViewProj"].SetValue(world * camera.view * camera.projection);
                effect.Parameters["matInverseWorld"].SetValue(worldInverse);
                effect.Parameters["vLightDirection"].SetValue(vLightDirection);
                // Render our meshpart
                graphics.Vertices[0].SetSource(mesh.VertexBuffer, part.StreamOffset, part.VertexStride);
                graphics.Indices = mesh.IndexBuffer;
                graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList,
                    part.BaseVertex, 0, part.NumVertices,
                    part.StartIndex, part.PrimitiveCount);
            }
      }
      // Stop current pass
      pass.End();
}

Now I checked out this tutorial on how to create BoundingBoxes. Of course it doesn't work.

The render method needs a view and a projection matrix. Are those the view and projection matrices I use in my camera class, or what are they supposed to be? I just guessed that those are matrices from my camera class. So I had to call the BoundingBoxRenderer.render() function in Game1.Update(). It looks like this:

if (assetManager._modelsOnscreen.Count != 0)
{
    foreach (BasicModel model in assetManager._modelsOnscreen)
    {
         foreach(ModelMesh mesh in model._model.Meshes){
              sphere = mesh.BoundingSphere;
              BoundingBoxRenderer.Render(BoundingBox.CreateFromSphere(sphere),this.GraphicsDevice,camera.view,camera.projection,Color.Red);
          }
     }
}

As you can see I also had to generate my BoundingBox out of the meshes BoundingSphere. If I just leave the code as it is there are no BoundingBoxes drawn at all. But as far as I can see no more shaders are applied to the models. They are drawn with BasicEffect. I guess it somehow is caused by the BasicEffect that is used for the BoundingBoxRenderer.

Another issue that could be of interest is, that I also tried to draw some Spritefonts on the gamescreen. It had the same effect. Shaders were not applied to the meshes.

Is it possible that it somehow has to do with the order in which Shaders/Meshes, Spritefonts, Colored vetices...are drawn? I use the BasicEffect in order to draw the BoundingBox (Vertices) and the Meshes are also being drawn with the BasicEffect applied, although they should be drawn with my Diffuse Shader.

I sence some kind of connection there

Perhaps somebody experienced similar problems? I use XNA 3.1 if it is important.

share|improve this question

put on hold as off-topic by Josh Petrie 2 days ago

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about debugging a problem in your project must present a concise selection of code and context so as to allow a reader to diagnose the issue without needing to read all of your code or to engage in extensive back-and-forth dialog. For more information, see this meta thread." – Josh Petrie
If this question can be reworded to fit the rules in the help center, please edit the question.

    
First of all you really shouldn't be calling any render code from the update method. I would need to see the BondingBoxRenderer.Render method to figure out your problem. –  Ken Jan 26 '12 at 12:55
    
    
Moved render code to draw method. Now I at least see the BB. Still some issues. 1. Shaders still not working properly, like described above. 2. The BB-lines behind the Model tend to be drawn in front of the model for a split moment. –  bodycountPP Jan 27 '12 at 15:35

Browse other questions tagged or ask your own question.