Exemple #1
0
        public Vector2 getPicking(Point pos, Viewport Viewport)
        {
            Vector3 v1 = new Vector3(pos.X, pos.Y, 1);
            Vector3 v2 = new Vector3(pos.X, pos.Y, 0);
            v1.Unproject(Viewport, m_Projection, m_View, Matrix.Identity);
            v2.Unproject(Viewport, m_Projection, m_View, Matrix.Identity);
            Vector3 v3 = v2 - v1;
            v3.Scale(1.0f/v3.Y);
            Vector3 v4 = v1 - v3 * v1.Y; // Y 값이 0이 되는 방정식 계산.

            return new Vector2(v4.X, v4.Z);
        }
		/// <summary>
		/// Get an intercept for the mesh .
		/// </summary>
		public bool GetMeshIntersect(out Ray foundRay, double WorldRadius,
			Viewport viewPort,
			Matrix pMatrix,
			Matrix vMatrix,
			Matrix wMatrix, int MouseX, int MouseY)
		{
			bool bIntersects = false;
			Vector3 vDirection;
			Vector3 vNear = new Vector3(MouseX, MouseY, 0);
			Vector3 vFar = new Vector3(MouseX, MouseY, 1);
			Vector3 sv = MathEngine.SphericalToCartesian(Angle.FromRadians(m_Lat),
				Angle.FromRadians(m_Lon), WorldRadius + m_Alt*1000 );
			vNear.Unproject(viewPort,
				pMatrix,
				vMatrix,
				Matrix.Translation(sv));

			vFar.Unproject(viewPort,
				pMatrix,
				vMatrix,
				Matrix.Translation(sv));

			foundRay = new Ray();
			vDirection= Vector3.Subtract(vFar,vNear);
			foundRay.origin = vNear;
			foundRay.destination = vFar;
			foundRay.direction =vDirection;
			// Perform ray-box intersection test.
			if (Geometry.BoxBoundProbe(meshBoundingBoxMinValue *m_scale,
				meshBoundingBoxMaxValue*m_scale, vNear, vFar))
			{
				bIntersects = true;
			}
			return bIntersects;
		}
Exemple #3
0
 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);
 }
Exemple #4
0
        /// <summary>
        /// Calculates latitude/longitude for given screen coordinate.
        /// </summary>
        public virtual void PickingRayIntersection(int screenX, int screenY, out Angle latitude, out Angle longitude)
        {
            Vector3 v1 = new Vector3();
            v1.X = screenX;
            v1.Y = screenY;
            v1.Z = viewPort.MinZ;
            v1.Unproject(viewPort, m_absoluteProjectionMatrix, m_absoluteViewMatrix, m_absoluteWorldMatrix);

            Vector3 v2 = new Vector3();
            v2.X = screenX;
            v2.Y = screenY;
            v2.Z = viewPort.MaxZ;
            v2.Unproject(viewPort, m_absoluteProjectionMatrix, m_absoluteViewMatrix, m_absoluteWorldMatrix);

            Point3d p1 = new Point3d(v1.X, v1.Y, v1.Z);
            Point3d p2 = new Point3d(v2.X, v2.Y, v2.Z);

            double a = (p2.X - p1.X)*(p2.X - p1.X) + (p2.Y - p1.Y)*(p2.Y - p1.Y) + (p2.Z - p1.Z)*(p2.Z - p1.Z);
            double b = 2.0*((p2.X - p1.X)*(p1.X) + (p2.Y - p1.Y)*(p1.Y) + (p2.Z - p1.Z)*(p1.Z));
            double c = p1.X*p1.X + p1.Y*p1.Y + p1.Z*p1.Z - _worldRadius*_worldRadius;

            double discriminant = b*b - 4*a*c;
            if (discriminant <= 0) {
                latitude = Angle.NaN;
                longitude = Angle.NaN;
                return;
            }

            //	float t0 = ((-1.0f) * b + (float)Math.Sqrt(b*b - 4 * a * c)) / (2*a);
            double t1 = ((-1.0)*b - Math.Sqrt(b*b - 4*a*c))/(2*a);

            //	Vector3 i0 = new Vector3(p1.X + t0*(p2.X - p1.X), p1.Y + t0*(p2.Y - p1.Y), p1.Z + t0 *(p2.Z - p1.Z));
            Point3d i1 = new Point3d(p1.X + t1*(p2.X - p1.X), p1.Y + t1*(p2.Y - p1.Y), p1.Z + t1*(p2.Z - p1.Z));

            //	Vector3 i0t = MathEngine.CartesianToSpherical(i0.X, i0.Y, i0.Z);
            Point3d i1t = MathEngine.CartesianToSphericalD(i1.X, i1.Y, i1.Z);
            Point3d mousePointer = i1t;

            latitude = Angle.FromRadians(mousePointer.Y);
            longitude = Angle.FromRadians(mousePointer.Z);
        }
Exemple #5
0
 /// <summary>
 /// Check is mouse over a mesh.
 /// </summary>
 /// <param name="mesh">Mesh to check</param>
 /// <param name="dev">device which is ready to render</param>
 private bool IsMouseOver(Mesh mesh, Device dev)
 {
     Vector3 rayPos = new Vector3(DrawArgs.LastMousePosition.X, DrawArgs.LastMousePosition.Y, dev.Viewport.MinZ);
     Vector3 rayDir = new Vector3(DrawArgs.LastMousePosition.X, DrawArgs.LastMousePosition.Y, dev.Viewport.MaxZ);
     rayPos.Unproject(dev.Viewport, dev.Transform.Projection, dev.Transform.View, dev.Transform.World);
     rayDir.Unproject(dev.Viewport, dev.Transform.Projection, dev.Transform.View, dev.Transform.World);
     return mesh.Intersect(rayPos, rayDir);
 }
        public static bool TestIntersectWithMouse(Mesh mshMesh, object objViewport, Matrix mtxProjection, Matrix mtxView, Matrix mtxWorld, int iX, int iY, out IntersectInformation iiInfo)
        {
            // Create ray for intersection test
            Vector3	near = new Vector3(iX, iY, 0);
            Vector3	far = new Vector3(iX, iY, 1);

            //unproject the near and far vectors to 3D space
            near.Unproject(objViewport, mtxProjection, mtxView, mtxWorld);
            far.Unproject(objViewport, mtxProjection, mtxView, mtxWorld);

            //subtract the near vector from the far vector to get our ray
            far.Subtract(near);

            return mshMesh.Intersect(near,far, out iiInfo);
        }
Exemple #7
0
        /// <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;
        }