private void Form1_MouseMove(object sender, MouseEventArgs e) { Coordinates.Coordinate projCoord = new MOBMAP.Coordinates.Coordinate(new Geometry.Point(e.X,e.Y),false); Vector3 position = new Vector3(0,0,0); position.Project(map.device.Viewport, map.device.Transform.Projection, map.device.Transform.View, map.device.Transform.World); position.X = e.X; position.Y = e.Y; position.Unproject(map.device.Viewport, map.device.Transform.Projection, map.device.Transform.View, map.device.Transform.World); }
private void PrintString(string text,float x,float y,float z,Color color,Microsoft.DirectX.Direct3D.Font printFont) { Vector3 screenPoint=new Vector3(x,y,z); screenPoint.Project(device.Viewport,device.Transform.Projection,device.Transform.View,device.Transform.World); printFont.DrawText(null,text,new Point((int)Math.Ceiling(screenPoint.X),(int)Math.Floor(screenPoint.Y)),color); }
/// <summary> /// Projects a point from world to screen coordinates. /// </summary> /// <param name="point">Point in world space</param> /// <returns>Point in screen space</returns> public Vector3 Project(Vector3 point) { point.Project(viewPort, m_ProjectionMatrix, m_ViewMatrix, m_WorldMatrix); return point; }
/// <summary> /// This projection results to initial velocity of non-engine objects, which parents move in some velocity /// We want to add only forward speed of the parent to the forward direction of the object, and if parent /// is going backward, no speed is added. /// </summary> /// <param name="forwardVector"></param> /// <param name="projectedVector"></param> /// <returns></returns> public static Vector3 ForwardVectorProjection(Vector3 forwardVector, Vector3 projectedVector) { Vector3 forwardVelocity = forwardVector; if (Vector3.Dot(projectedVector, forwardVector) > 0) { //going forward forwardVelocity = forwardVector.Project(projectedVector + forwardVector); return forwardVelocity; } return Vector3.Zero; }
/// <summary> /// The mark 3 d cursor position. /// </summary> /// <param name="x">The x.</param> /// <param name="y">The y.</param> /// <param name="m">The m.</param> /// <returns></returns> /// <remarks></remarks> public Vector3 Mark3DCursorPosition(float x, float y, Matrix m) { Vector3 tempV3 = new Vector3(); tempV3.Project(device.Viewport, device.Transform.Projection, device.Transform.View, m); tempV3.X = x; tempV3.Y = y; tempV3.Unproject(device.Viewport, device.Transform.Projection, device.Transform.View, m); return tempV3; }