Hi, i tried this... but is there a way to use this with the standartcamera?
If I try this, i get a negative X and Y-Coordinate
protected override void Update(GameTime gameTime)
{
// Create a total bounding sphere for the mesh
BoundingSphere totalbounds = new BoundingSphere();
foreach (ModelMesh mesh in player.model.Meshes)
{
totalbounds = BoundingSphere.CreateMerged(totalbounds, mesh.BoundingSphere);
}
// Project the center of the 3D object to the screen, and center the
// sprite there
Vector3 center = GraphicsDevice.Viewport.Project(totalbounds.Center,
cameraProjectionMatrix, cameraViewMatrix, Matrix.Identity);
player.boundingRectangle.X = (int)center.X;
player.boundingRectangle.Y = (int)center.Y;
// Create a bounding box from the bounding sphere, and find the corner
// that is farthest away from the center using Project
BoundingBox extents = BoundingBox.CreateFromSphere(totalbounds);
float maxdistance = 0;
float distance;
Vector3 screencorner;
foreach (Vector3 corner in extents.GetCorners())
{
screencorner = GraphicsDevice.Viewport.Project(corner,
cameraProjectionMatrix, cameraViewMatrix, Matrix.Identity);
distance = Vector3.Distance(screencorner, center);
if (distance > maxdistance)
maxdistance = distance;
}
UpdateMouse();
UpdateMovement();
base.Update(gameTime);
}
Thanks for helping,
Robin