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 am use to XNA and starting to learn XNA for Silverlight 5. My Question is that in XNA when you create a Model and load it using content.load you are able to access the models Position, scale etc.. In Silverlight XNA these options are not available. It would be possible to change the Models position using World Translate, but I need the models position for collision detectection using boundingSphere Any Advice??

share|improve this question
add comment

1 Answer 1

XNA should allow you to do something like this to create your BoundingSphere, so long as you get grab the vertex buffer for your model.

List<Vector3> vertices = GetModelVertices(scale);    
BoundingSphere sphere = BoundingSphere.CreateFromPoints(vertices);

// Gets the vertices that make up a model
public List<Vector3> GetModelVertices(float Scale)
{
    List<Vector3> verts = new List<Vector3>();

    VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[numVertices];
    vertexBuffer.GetData(vertices);
    foreach (VertexPositionNormalTexture vertex in vertices)
    {
        verts.Add(vertex.Position * Scale);
    }

    return verts;
}

Alternatively, you should be able to iterate through each ModelMesh part in your model, and each of those have a BoundingSphere that you can query. From that you can call BoundingSphere.CreateMerged(BoundingSphere, BoundingSphere), for each of the bounding spheres on the ModelMesh objects, and combine them to get your final bounding sphere.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.