public float Hover(Vector3 PickRayOrigin, Vector3 PickRayDirection) { Vector3 intersect_pt = new Vector3(); bool bIntersected = false; float proximity = -1; switch (m_Mode) { case ArcMode.Pitch: bIntersected = PMath.RayIntersectPlane(PickRayOrigin, PickRayDirection, new Plane(1, 0, 0, 0), out intersect_pt); break; case ArcMode.Roll: bIntersected = PMath.RayIntersectPlane(PickRayOrigin, PickRayDirection, new Plane(0, 1, 0, 0), out intersect_pt); break; case ArcMode.Yaw: bIntersected = PMath.RayIntersectPlane(PickRayOrigin, PickRayDirection, new Plane(0, 0, 1, 0), out intersect_pt); break; } if (bIntersected) { proximity = (float)Math.Abs(RadiusScale - intersect_pt.Length()); } return(proximity); }
public void Hover(Vector3 origin, Vector3 dir) { switch (currentState) { case SelectionBoxState.FindPlane: if (PMath.RayIntersectPlane(origin, dir, intersectPlane, out startCorner)) { basePlane.D = startCorner.Z; } Trace.WriteLine(string.Format("findplane: {0} {1} {2}", startCorner.X, startCorner.Y, startCorner.Z)); UpdatePrimitives(); break; case SelectionBoxState.FindStartCorner: if (PMath.RayIntersectPlane(origin, dir, basePlane, out startCorner) == false) { startCorner.X = 0; startCorner.Y = 0; startCorner.Z = 0; } Trace.WriteLine(string.Format("start corner: {0} {1} {2}", startCorner.X, startCorner.Y, startCorner.Z)); UpdatePrimitives(); break; case SelectionBoxState.FindEndCorner: if (PMath.RayIntersectPlane(origin, dir, basePlane, out endCorner) == false) { endCorner.X = 0; endCorner.Y = 0; endCorner.Z = 0; } UpdateBox(startCorner, endCorner, 0.005f); boxOutline.min[0] = startCorner.X; boxOutline.min[1] = startCorner.Y; boxOutline.min[2] = startCorner.Z; boxOutline.max[0] = endCorner.X; boxOutline.max[1] = endCorner.Y; boxOutline.max[2] = endCorner.Z + 0.005f; break; case SelectionBoxState.FindHeight: Vector3 temp = new Vector3(); if (PMath.RayIntersectPlane(origin, dir, intersectPlane, out temp)) { boxHeight = temp.Z - startCorner.Z; } UpdateBox(startCorner, endCorner, boxHeight); boxOutline.min[0] = startCorner.X; boxOutline.min[1] = startCorner.Y; boxOutline.min[2] = startCorner.Z; boxOutline.max[0] = endCorner.X; boxOutline.max[1] = endCorner.Y; boxOutline.max[2] = endCorner.Z + boxHeight; break; } }
protected float GetCurrentAngle(Vector3 PickRayOrigin, Vector3 PickRayDirection) { Vector3 intersect_pt = new Vector3(); bool bIntersected = false; float angle = 0; float a = 0; float b = 0; switch (m_Mode) { case ArcMode.Pitch: //blue bIntersected = PMath.RayIntersectPlane(PickRayOrigin, PickRayDirection, new Plane(1, 0, 0, 0), out intersect_pt); a = intersect_pt.Z; b = intersect_pt.Y; break; case ArcMode.Roll: //green bIntersected = PMath.RayIntersectPlane(PickRayOrigin, PickRayDirection, new Plane(0, 1, 0, 0), out intersect_pt); a = intersect_pt.X; b = intersect_pt.Z; break; case ArcMode.Yaw: //red bIntersected = PMath.RayIntersectPlane(PickRayOrigin, PickRayDirection, new Plane(0, 0, 1, 0), out intersect_pt); a = intersect_pt.Y; b = intersect_pt.X; break; } if (bIntersected) { m_IntersectPoint[1].X = a; m_IntersectPoint[1].Y = b; angle = GetQuadrantAngle(b, a); } while (angle < 0) { angle += (float)Math.PI * 2; } while (angle > Math.PI * 2) { angle -= (float)Math.PI * 2; } return(angle); }
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)); }
public void HoverEdit(Vector3 origin, Vector3 direction, out Vector3 trans_delta, out BindingAngle3 rot_delta) { Vector3 t_org = new Vector3(); Vector3 t_dir = new Vector3(); //transform pick ray into model space (only for rotation) if (ModeIsRotation() == true) { Matrix inv = new Matrix(); inv = m_WorldSpaceTransform; inv.Invert(); t_org = origin; t_dir = direction; t_org.TransformCoordinate(inv); t_dir.TransformNormal(inv); } Vector3 intersect_point = new Vector3(); BindingAngle3 rotation_edit = new BindingAngle3(); BindingAngle3 temp = new BindingAngle3(); rot_delta = temp; trans_delta.X = 0; trans_delta.Y = 0; trans_delta.Z = 0; rot_delta.Pitch = 0; rot_delta.Roll = 0; rot_delta.Yaw = 0; switch (m_Mode) { case EditMode.Pitch: rotation_edit.Pitch = m_PitchHandle.HoverEdit(t_org, t_dir); rot_delta.Pitch = rotation_edit.Pitch - m_EditRotationStart.Pitch; m_EditRotationStart.Pitch = rotation_edit.Pitch; //rotation_edit.Roll = m_PitchHandle.HoverEdit(t_org, t_dir); //rot_delta.Roll = rotation_edit.Roll - m_EditRotationStart.Roll; //m_EditRotationStart.Roll = rotation_edit.Roll; break; case EditMode.Roll: rotation_edit.Roll = m_RollHandle.HoverEdit(t_org, t_dir); rot_delta.Roll = rotation_edit.Roll - m_EditRotationStart.Roll; m_EditRotationStart.Roll = rotation_edit.Roll; //rotation_edit.Pitch = m_RollHandle.HoverEdit(t_org, t_dir); //rot_delta.Pitch = rotation_edit.Pitch - m_EditRotationStart.Pitch; //m_EditRotationStart.Pitch = rotation_edit.Pitch; break; case EditMode.Yaw: rotation_edit.Yaw = m_YawHandle.HoverEdit(t_org, t_dir); rot_delta.Yaw = rotation_edit.Yaw - m_EditRotationStart.Yaw; // if(Math.Abs(rot_delta.Yaw) > 0.5) // { // int j=0; // } m_EditRotationStart.Yaw = rotation_edit.Yaw; break; case EditMode.MoveDX: PMath.RayIntersectPlane(origin, direction, m_EditAxisTestPlane, out intersect_point); intersect_point.Y = m_EditTranslationStart.Y; intersect_point.Z = m_EditTranslationStart.Z; trans_delta = intersect_point - m_EditTranslationStart; m_EditTranslationStart = intersect_point; break; case EditMode.MoveDY: PMath.RayIntersectPlane(origin, direction, m_EditAxisTestPlane, out intersect_point); intersect_point.X = m_EditTranslationStart.X; intersect_point.Z = m_EditTranslationStart.Z; trans_delta = intersect_point - m_EditTranslationStart; m_EditTranslationStart = intersect_point; break; case EditMode.MoveDZ: PMath.RayIntersectPlane(origin, direction, m_EditAxisTestPlane, out intersect_point); intersect_point.X = m_EditTranslationStart.X; intersect_point.Y = m_EditTranslationStart.Y; trans_delta = intersect_point - m_EditTranslationStart; m_EditTranslationStart = intersect_point; break; case EditMode.MoveXY: PMath.RayIntersectPlane(origin, direction, m_EditAxisTestPlane, out intersect_point); intersect_point.Z = m_EditTranslationStart.Z; trans_delta = intersect_point - m_EditTranslationStart; m_EditTranslationStart = intersect_point; break; case EditMode.MoveXZ: PMath.RayIntersectPlane(origin, direction, m_EditAxisTestPlane, out intersect_point); intersect_point.Y = m_EditTranslationStart.Y; trans_delta = intersect_point - m_EditTranslationStart; m_EditTranslationStart = intersect_point; break; case EditMode.MoveYZ: PMath.RayIntersectPlane(origin, direction, m_EditAxisTestPlane, out intersect_point); intersect_point.X = m_EditTranslationStart.X; trans_delta = intersect_point - m_EditTranslationStart; m_EditTranslationStart = intersect_point; break; } //if((Math.Abs(rot_delta.Pitch) > 0.001)||(Math.Abs(rot_delta.Roll) > 0.001)||(Math.Abs(rot_delta.Yaw) > 0.5)) // Trace.WriteLine(string.Format("droll={0} dpitch={1} dyaw={2}", // rot_delta.Pitch, // rot_delta.Roll, // rot_delta.Yaw)); }
public void MouseDown_StartEdit(Matrix WorldTransform, Vector3 origin, Vector3 direction, bool bLog) { Vector3 t_org = new Vector3(); Vector3 t_dir = new Vector3(); //transform pick ray into model space (only for rotation) if (ModeIsRotation() == true) { Matrix inv = new Matrix(); inv = m_WorldSpaceTransform; inv.Invert(); t_org = origin; t_dir = direction; t_org.TransformCoordinate(inv); t_dir.TransformNormal(inv); } //select best test plane if we are using x,y,z direct movement //larger dot product indicates larger incidence angle Vector3 look = MdxRender.Camera.LookVector; float xplane_score = (float)Math.Abs(Vector3.Dot(look, new Vector3(1, 0, 0))); float yplane_score = (float)Math.Abs(Vector3.Dot(look, new Vector3(0, 1, 0))); float zplane_score = (float)Math.Abs(Vector3.Dot(look, new Vector3(0, 0, 1))); switch (m_Mode) { case EditMode.Pitch: m_EditRotationStart.Pitch = m_PitchHandle.MouseDown_StartEdit(t_org, t_dir); m_MouseDownAngle.Pitch = m_EditRotationStart.Pitch; break; case EditMode.Roll: m_EditRotationStart.Roll = m_RollHandle.MouseDown_StartEdit(t_org, t_dir); m_MouseDownAngle.Roll = m_EditRotationStart.Roll; break; case EditMode.Yaw: m_EditRotationStart.Yaw = m_YawHandle.MouseDown_StartEdit(t_org, t_dir); m_MouseDownAngle.Yaw = m_EditRotationStart.Yaw; break; case EditMode.MoveDX: if (yplane_score > zplane_score) { m_EditAxisTestPlane = new Plane(0, 1, 0, m_ModelSpaceTransform.M42); } else { m_EditAxisTestPlane = new Plane(0, 0, 1, m_ModelSpaceTransform.M43); } PMath.RayIntersectPlane(origin, direction, m_EditAxisTestPlane, out m_EditTranslationStart); break; case EditMode.MoveDY: if (xplane_score > zplane_score) { m_EditAxisTestPlane = new Plane(1, 0, 0, m_ModelSpaceTransform.M41); } else { m_EditAxisTestPlane = new Plane(0, 0, 1, m_ModelSpaceTransform.M43); } PMath.RayIntersectPlane(origin, direction, m_EditAxisTestPlane, out m_EditTranslationStart); break; case EditMode.MoveDZ: if (xplane_score > yplane_score) { m_EditAxisTestPlane = new Plane(1, 0, 0, m_ModelSpaceTransform.M41); } else { m_EditAxisTestPlane = new Plane(0, 1, 0, m_ModelSpaceTransform.M42); } PMath.RayIntersectPlane(origin, direction, m_EditAxisTestPlane, out m_EditTranslationStart); break; case EditMode.MoveXY: m_EditAxisTestPlane = new Plane(0, 0, 1, m_ModelSpaceTransform.M43); PMath.RayIntersectPlane(origin, direction, m_EditAxisTestPlane, out m_EditTranslationStart); break; case EditMode.MoveXZ: m_EditAxisTestPlane = new Plane(0, 1, 0, m_ModelSpaceTransform.M42); PMath.RayIntersectPlane(origin, direction, m_EditAxisTestPlane, out m_EditTranslationStart); break; case EditMode.MoveYZ: m_EditAxisTestPlane = new Plane(1, 0, 0, m_ModelSpaceTransform.M41); PMath.RayIntersectPlane(origin, direction, m_EditAxisTestPlane, out m_EditTranslationStart); break; } Trace.WriteLine(string.Format("sPitch = {0:N3} sRoll = {1:N3} sYaw = {2:N3}", m_EditRotationStart.Pitch, m_EditRotationStart.Roll, m_EditRotationStart.Yaw)); }