So I'm kind of new to programming and I'm trying to check collision using bounding boxes. I'm currently stuck as to how to call my bounding box within my bounding box function as shown below
public BoundingBox BuildBoundingBox()
{
// Create initial variables to hold min and max xyz values for the mesh
Vector3 meshMax = new Vector3(float.MinValue);
Vector3 meshMin = new Vector3(float.MaxValue);
foreach (ModelMesh mesh in model.Meshes)
{
foreach (ModelMeshPart part in mesh.MeshParts)
{
// The stride is how big, in bytes, one vertex is in the vertex buffer
// We have to use this as we do not know the make up of the vertex
int stride = part.VertexBuffer.VertexDeclaration.VertexStride;
VertexPositionNormalTexture[] vertexData = new VertexPositionNormalTexture[part.NumVertices];
part.VertexBuffer.GetData(part.VertexOffset * stride, vertexData, 0, part.NumVertices, stride);
// Find minimum and maximum xyz values for this mesh part
Vector3 vertPosition = new Vector3();
for (int i = 0; i < vertexData.Length; i++)
{
vertPosition = vertexData[i].Position;
// update our values from this vertex
meshMin = Vector3.Min(meshMin, vertPosition);
meshMax = Vector3.Max(meshMax, vertPosition);
}
}
// transform by mesh bone matrix
meshMin = Vector3.Transform(meshMin, meshTransform);
meshMax = Vector3.Transform(meshMax, meshTransform);
}
// Create the bounding box
BoundingBox box1 = new BoundingBox(meshMin, meshMax);
return box1;
}
I'm trying to call box1 (my bounding box) in my update method to check collision however I can't seem to call box1 as it's not in the context of my class.