I am having a hard time understanding how to go about this. I have a 2D game with some 3D models in it. I want to move a 3D model to where the mouse cursor is currently at in every frame (In other words, center a 3D model in a specific Point(x,y)).
This is my drawing code to position the model in the center of the screen:
Matrix transforms = new Matrix[Model.Bones.Count]; Model.CopyAbsoluteBoneTransformsTo(transforms); ModelMesh mesh = Model.Meshes; BasicEffect effect = (BasicEffect)mesh.Effects; Vector3 modelPosition = new Vector3(0, 0, 0); effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up); effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f); effect.EnableDefaultLighting(); effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(modelPosition); mesh.Draw();
I suppose I would need a formula to convert the (camera position,model position, aspect ratio, field of view) into pixels ? Does anyone know how it works ?