/// <summary> /// Display the name label(s) of the models in screen space. /// </summary> public void DrawModelNames(Scene debugScene, Camera debugCamera) { spriteBatch.Begin(); // If the cursor is over a model, we'll draw its name. Ray cursorRay = CalculateCursorRay(debugCamera.projection, debugCamera.view); Matrix instanceMatrix = Matrix.Identity; BoundingSphere bSphere; foreach (Meteor.Resources.Model staticModel in debugScene.sceneModels.Values) { // Check for cursor picking intersection if (RayIntersectsModel(cursorRay, staticModel, out instanceMatrix, out bSphere)) { String foundMeshName = "Model"; foreach (String meshName in staticModel.MeshInstanceGroups.Keys) { foundMeshName = meshName; break; } // Project from world space to screen space Vector3 screenSpace = graphicsDevice.Viewport.Project(Vector3.Zero, debugCamera.projection, debugCamera.view, instanceMatrix); // we want to draw the text a little bit above that, so we'll use the screen space position. Vector2 textPosition = new Vector2((int)screenSpace.X, (int)screenSpace.Y - 60); // Calculate string's center and draw using that as the origin. Vector2 stringCenter = font.MeasureString(foundMeshName) / 2; spriteBatch.Draw(nullTexture, new Vector2(textPosition.X - stringCenter.X - 8, textPosition.Y - (int)stringCenter.Y - 2), new Rectangle( (int)(textPosition.X - stringCenter.X - 8), (int)(textPosition.Y - (int)stringCenter.Y - 2), (int)(stringCenter.X * 2 + 16), font.LineSpacing + 4), new Color(0, 0, 0, 120)); // first draw the shadow... Vector2 shadowOffset = new Vector2(1, 1); spriteBatch.DrawString(font, foundMeshName, textPosition + shadowOffset, Color.Black, 0.0f, stringCenter, 1.0f, SpriteEffects.None, 0.0f); // ...and then the real text on top. spriteBatch.DrawString(font, foundMeshName, textPosition, Color.White, 0.0f, stringCenter, 1.0f, SpriteEffects.None, 0.0f); // Add debug shapes around the highlighted object ShapeRenderer.AddBoundingSphere(bSphere, Color.LawnGreen); ShapeRenderer.Draw(debugCamera.view, debugCamera.projection); // We can stop here if just one model is needed. //break; } } spriteBatch.End(); }