Hi all,
I'll get right to the point. My camera is defined using the following code...
cameraworld =
Matrix.CreateTranslation(xplane, yplane, 0) * Matrix.CreateScale(zoom) * Matrix.CreateRotationZ(angle);view = cameraworld *
Matrix.CreateLookAt(new Vector3(0, 0, 100), Vector3.Zero, Vector3.Up);projection =
Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45),(float)graphics.GraphicsDevice.Viewport.Width / (float)graphics.GraphicsDevice.Viewport.Height,1.0f, 1000f);effect.View = view;
effect.Projection = projection;
I've also got code to allow me to place objects in the game world, after unprojecting the mouse points and finding the point of intersection with my XY plane. Only problem is, it doesn't work after I translate the camera, controlled via keyboard input into the xplane/yplane variables above. The mouse unprojection seems to take no account of any translation. Scaling and rotation works just fine.
Relevant mouse code here - I've left out the ray generation etc for brevity, but :
mState =
Mouse.GetState(); int mouseX = mState.X; int mouseY = mState.Y; Vector3 nearsource = new Vector3((float)mouseX, (float)mouseY, 0f); Vector3 farsource = new Vector3((float)mouseX, (float)mouseY, 1f);Matrix
world = Matrix.CreateTranslation(0,0,0); Vector3 nearPoint = graphics.GraphicsDevice.Viewport.Unproject(nearsource, camera.effect.Projection, camera.effect.View, world); Vector3 farPoint = graphics.GraphicsDevice.Viewport.Unproject(farsource, camera.effect.Projection, camera.effect.View, world);
What is going wrong here with the unprojection Why does my code seem to ignore translation, when rotation and scaling is accounted for In other words, if I translate the camera position, new objects are placed when I click as though no translation had taken place. Yet scale and rotation works as intended...