public void Begin() { Vector3 pos = new Vector3(); Vector3 dir = new Vector3(); Vector3 point_in_plane = new Vector3(); pos = MdxRender.Camera.Position; dir = MdxRender.Camera.LookVector; intersectPlane.A = dir.X; intersectPlane.B = dir.Y; intersectPlane.C = dir.Z; intersectPlane = Plane.Normalize(intersectPlane); //calculate the coordinate that is 20 units directly in front of camera point_in_plane.X = pos.X + dir.X * 20; point_in_plane.Y = pos.Y + dir.Y * 20; point_in_plane.Z = pos.Z + dir.Z * 20; Trace.WriteLine("cam_loc = " + pos.ToString()); Trace.WriteLine("cam_dir = " + dir.ToString()); Trace.WriteLine("point in plane = " + point_in_plane.ToString()); //distance here is from the point to the origin, not the nearest distance from plane to origin...need to fix intersectPlane.D = (point_in_plane.X * intersectPlane.A + point_in_plane.Y * intersectPlane.B + point_in_plane.Z * intersectPlane.C); Trace.WriteLine("intersect plane = " + intersectPlane.ToString()); //todo: get the optimal intersect plane based on camera orientation currentState = SelectionBoxState.FindPlane; }
public void Click(Vector3 origin, Vector3 dir) { switch (currentState) { case SelectionBoxState.FindPlane: if (PMath.RayIntersectPlane(origin, dir, intersectPlane, out startCorner)) { basePlane.D = startCorner.Z; currentState = SelectionBoxState.FindStartCorner; } break; case SelectionBoxState.FindStartCorner: PMath.RayIntersectPlane(origin, dir, basePlane, out startCorner); currentState = SelectionBoxState.FindEndCorner; break; case SelectionBoxState.FindEndCorner: PMath.RayIntersectPlane(origin, dir, basePlane, out endCorner); currentState = SelectionBoxState.FindHeight; break; case SelectionBoxState.FindHeight: Vector3 temp = new Vector3(); if (PMath.RayIntersectPlane(origin, dir, intersectPlane, out temp)) { boxHeight = temp.Z - startCorner.Z; } //todo: calc new vertical intersectPlane based on endCorner currentState = SelectionBoxState.Active; break; case SelectionBoxState.Active: //todo: if clicked outside of bounding box model, deselect it currentState = SelectionBoxState.Inactive; break; } Trace.WriteLine(string.Format("Selection Box State: {0}", currentState)); Trace.WriteLine(string.Format("start: {0} {1} {2}", startCorner.X, startCorner.Y, startCorner.Z)); Trace.WriteLine(string.Format("end : {0} {1} {2}", endCorner.X, endCorner.Y, endCorner.Z)); }