Drawing graphics in BEPU Matrix's

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
AMG
Posts: 3
Joined: Fri Apr 20, 2012 5:46 pm

Drawing graphics in BEPU Matrix's

Post by AMG »

Hello all,

Im working on a little project and am running into some bother was hoping for some help. i am new to this kind of project and am struggling somewhat.

I am trying to load in a height-map terrain and a vehicle to a map and drive around - which i have done successfully.
for example...

Code: Select all

           //Read the world file and load terrainmap.
            mWorld = new World("testMap.wld");

            //Create the terrain.
            int xLength = 127;
            int zLength = 127;
            float xSpacing = 10f;
            float zSpacing = 10f;
            var heights = new float[xLength, zLength];

            heights = mWorld.myTerrain.getHeights();

            var terrain = new Terrain(heights, new AffineTransform(
            new Vector3(xSpacing, 1, zSpacing),
                    Quaternion.Identity,
                    new Vector3(-xLength * xSpacing / 2, 0, -zLength * zSpacing / 2)));

            terrain.Thickness = 5; //Uncomment this and shoot some things at the bottom of the terrain! They'll be sucked up through the ground.
            space.Add(terrain);
            ModelDrawer.Add(terrain);
            ModelDrawer.IsWireframe = true;
This results in me successfully loading my world and having the ability to drive around on it.

what i am having difficulty with is getting my terrain to be drawn in my own method. if i remove the ModelDrawer.Add(terrain);

Code: Select all

     public void DrawTerrain()
        {
            RasterizerState rs = new RasterizerState();
            rs.CullMode = CullMode.None;
            rs.FillMode = FillMode.WireFrame;
            GraphicsDevice.RasterizerState = rs;
  
            effect.CurrentTechnique = effect.Techniques["ColoredNoShading"];
            effect.Parameters["xView"].SetValue(Camera.ViewMatrix);
            effect.Parameters["xProjection"].SetValue(Camera.ProjectionMatrix);
            effect.Parameters["xWorld"].SetValue(Camera.WorldMatrix);

            //Set our terrain vertex buffer objects.
            device.Indices = mWorld.myTerrain.iBuf;
            device.SetVertexBuffer(mWorld.myTerrain.vBuf);

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, mWorld.myTerrain.Vertices.Length, 0, (mWorld.myTerrain.Indices.Length / 3));
            }

        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);
            ModelDrawer.Draw(Camera.ViewMatrix, Camera.ProjectionMatrix);
          
            //DRAW OUR OWN TERRAIN
            DrawTerrain();

            base.Draw(gameTime);
        }

I cant find my terrain anywhere. can anyone shed some light as to where i am going wrong ?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Drawing graphics in BEPU Matrix's

Post by Norbo »

At a glance, I don't see anything wrong with it. It may help to debug through the code looking at the actual values for matrices and vertices to ensure they are where you expect them to be.

However, the physics engine has no concept of visuals- the BEPUphysicsDrawer is just a debug helper, separate from the engine. For graphics-related help, you'd likely have better luck on the XNA website. Those forums and samples generally focus on graphics more.
AMG
Posts: 3
Joined: Fri Apr 20, 2012 5:46 pm

Re: Drawing graphics in BEPU Matrix's

Post by AMG »

Thanks for your quick response !.

I will ask over there to see if i have any luck.
AMG
Posts: 3
Joined: Fri Apr 20, 2012 5:46 pm

Re: Drawing graphics in BEPU Matrix's

Post by AMG »

Well after a little perseverance i have solved it! So I thought I would share incase someone else has this problem.

Code: Select all

   var terrain = new Terrain(heights, new AffineTransform(
             new Vector3(xSpacing, 1, zSpacing),
                    Quaternion.Identity,
                    new Vector3(0, 0, 0)));
                    // new Vector3(-xLength * xSpacing / 2, 0, -zLength * zSpacing / 2)));

           //terrain.Thickness = 5; //Uncomment this and shoot some things at the bottom of the terrain! They'll be sucked up through the ground.
            space.Add(terrain);
I have moved the world to 0,0,0;

And changed my draw method.

Code: Select all

effect.Parameters["xWorld"].SetValue(Matrix.Identity);
Thanks again for your prompt reply. :D
Post Reply