Drawing graphics in BEPU Matrix's
Posted: Fri Apr 20, 2012 6:40 pm
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...
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);
I cant find my terrain anywhere. can anyone shed some light as to where i am going wrong ?
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;
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);
}