using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Physics
{
///
/// An abstract class for a bounding volume.
/// A bounding volume has a transformation matrix that determines the orientation of the volume.
/// Futhermore it has an intersect funtion that checks whether this bounding volume intersects with an other bounding volume.
/// There is also a draw method by which the bounding volume is drawn.
///
public abstract class BoundingVolume
{
#region Field: graphicsDevice
///
/// The graphicsDevice of this volume.
///
protected GraphicsDevice graphicsDevice;
#endregion
#region Field: vertexBuffer
///
/// The vertex buffer of this volume.
///
protected VertexBuffer vertexbuffer;
#endregion
#region Field: indexBuffer
///
/// The index buffer of this volume.
///
protected IndexBuffer indexBuffer;
#endregion
#region Field: numberOfPrimitives
///
/// The number of primitives of this volume.
///
protected int numberOfPrimitive;
#endregion
#region Field: numberOfVertices
///
/// The number of vertices of this volume.
///
protected int numberOfVertices;
#endregion
#region Property: TransformationMatrix
///
/// The transformation matrix of this bounding volume.
///
protected Matrix transformationMatrix;
///
/// The transformation matrix of this bounding volume.
///
public Matrix TransformationMatrix
{
get
{
return this.transformationMatrix;
}
}
#endregion
#region Property: Color
///
/// The color of this bounding volume.
///
private Color color;
///
/// The color of this bounding volume.
///
public Color Color
{
get
{
return color;
}
set
{
color = value;
}
}
#endregion
#region Constructor: BoundingVolume(Color color, GraphicsDevice graphicsDevice)
///
/// Create a new bounding volume.
///
/// The color of this volume.
/// The device used to render.
public BoundingVolume(Color color, GraphicsDevice graphicsDevice)
{
this.color = color;
this.transformationMatrix = Matrix.Identity;
this.graphicsDevice = graphicsDevice;
}
#endregion
#region Method: Intersects(BoundingVolume volume)
///
/// This method must be implemented.
/// It checks whether this bounding volume intersects with the given bounding volume.
///
/// The volume to check with.
/// True if the bounding volumes intersect, false otherwise.
public abstract bool Intersects(BoundingVolume volume);
#endregion
#region Method: Draw()
///
/// Draw this bounding volume to the screen.
///
public void Draw()
{
this.graphicsDevice.RenderState.CullMode = CullMode.None;
this.graphicsDevice.Indices = this.indexBuffer;
this.graphicsDevice.VertexDeclaration = new VertexDeclaration(graphicsDevice, VertexPositionColor.VertexElements);
this.graphicsDevice.Vertices[0].SetSource(this.vertexbuffer, 0, VertexPositionColor.SizeInBytes);
this.graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, this.numberOfVertices, 0, this.numberOfPrimitive);
}
#endregion
#region Method: TranslateWorld(Vector3 translation)
///
/// Translate this bounding volume relative to the world axis.
///
/// The translation to make.
public void TranslateWorld(Vector3 translation)
{
this.transformationMatrix *= Matrix.CreateTranslation(translation);
}
#endregion
}
}