static public void MouseMove(int x, int y, Color clr) { if ((Halo1_Bsp != null) && (Input.ApplyLightmapPaint)) { Vector3 origin = new Vector3(); Vector3 direction = new Vector3(); MdxRender.CalculatePickRayWorld(x, y, out direction, out origin); Halo1_Bsp.ApplyLightmapColor(origin, direction, clr); } }
public void MouseDown(int MouseX, int MouseY) { //mouse down is only important if there is an active selection in an edit mode if (activeSelection != null) { Vector3 PickRayDirection = new Vector3(); Vector3 PickRayOrigin = new Vector3(); MdxRender.CalculatePickRayWorld(MouseX, MouseY, out PickRayDirection, out PickRayOrigin); if (activeSelection != null) { activeSelection.MouseDown(PickRayOrigin, PickRayDirection); } } }
public void MouseMove(int MouseX, int MouseY) { if (activeSelection != null) { Vector3 PickRayDirection = new Vector3(); Vector3 PickRayOrigin = new Vector3(); MdxRender.CalculatePickRayWorld(MouseX, MouseY, out PickRayDirection, out PickRayOrigin); if (activeSelection != null) { activeSelection.Hover(PickRayOrigin, PickRayDirection); } } if (multiSelectBox.Mode == MultiSelectMode.FindEnd) { multiSelectBox.MouseMove(MouseX, MouseY); multiSelectBox.UpdateFrustumSelection(this); UpdateSelectionLeader(); } }
public void GetFrustumPlanes(int StartX, int StartY, int StopX, int StopY, out Plane[] FrustumPlanes) { FrustumPlanes = new Plane[6]; Vector3 temp = new Vector3(); Vector3 direction = new Vector3(); Vector3 plane_norm = new Vector3(); Vector3 pt = new Vector3(); //make sure StartX < StartY, StopX < StopY if (StartY > StopY) { int tmp = StopY; StopY = StartY; StartY = tmp; } if (StartX > StopX) { int tmp = StopX; StopX = StartX; StartX = tmp; } for (int i = 0; i < 6; i++) { FrustumPlanes[i] = new Plane(); } //near FrustumPlanes[0].A = LookVector.X; FrustumPlanes[0].B = LookVector.Y; FrustumPlanes[0].C = LookVector.Z; FrustumPlanes[0].Normalize(); pt.X = m_PositionVector.X + m_LookVector.X * 0.1f; pt.Y = m_PositionVector.Y + m_LookVector.Y * 0.1f; pt.Z = m_PositionVector.Z + m_LookVector.Z * 0.1f; CalculatePlaneDist(ref FrustumPlanes[0], pt); //far FrustumPlanes[1].A = -LookVector.X; FrustumPlanes[1].B = -LookVector.Y; FrustumPlanes[1].C = -LookVector.Z; FrustumPlanes[1].Normalize(); pt.X = m_PositionVector.X + m_LookVector.X * 30f; pt.Y = m_PositionVector.Y + m_LookVector.Y * 30; pt.Z = m_PositionVector.Z + m_LookVector.Z * 30f; CalculatePlaneDist(ref FrustumPlanes[1], pt); //i think the cross between the direction and up vectors will give the plane normal //but that may only be for a cases where the look vector is right in the center of the //screen //right MdxRender.CalculatePickRayWorld(StartX, 0, out direction, out temp); plane_norm = Vector3.Cross(direction, this.m_UpVector); plane_norm.Normalize(); FrustumPlanes[2].A = plane_norm.X; FrustumPlanes[2].B = plane_norm.Y; FrustumPlanes[2].C = plane_norm.Z; CalculatePlaneDist(ref FrustumPlanes[2], m_PositionVector); //left MdxRender.CalculatePickRayWorld(StopX, 0, out direction, out temp); plane_norm = -Vector3.Cross(direction, this.m_UpVector); plane_norm.Normalize(); FrustumPlanes[3].A = plane_norm.X; FrustumPlanes[3].B = plane_norm.Y; FrustumPlanes[3].C = plane_norm.Z; CalculatePlaneDist(ref FrustumPlanes[3], m_PositionVector); Vector3 left_vec = new Vector3(); left_vec = Vector3.Cross(this.m_UpVector, this.m_LookVector); //top MdxRender.CalculatePickRayWorld(0, StopY, out direction, out temp); plane_norm = Vector3.Cross(direction, left_vec); plane_norm.Normalize(); FrustumPlanes[4].A = plane_norm.X; FrustumPlanes[4].B = plane_norm.Y; FrustumPlanes[4].C = plane_norm.Z; CalculatePlaneDist(ref FrustumPlanes[4], m_PositionVector); //bottom MdxRender.CalculatePickRayWorld(0, StartY, out direction, out temp); plane_norm = -Vector3.Cross(direction, left_vec); plane_norm.Normalize(); FrustumPlanes[5].A = plane_norm.X; FrustumPlanes[5].B = plane_norm.Y; FrustumPlanes[5].C = plane_norm.Z; CalculatePlaneDist(ref FrustumPlanes[5], m_PositionVector); }
public void ProcessSelectionEdit(int MouseX, int MouseY) { //Trace.WriteLine("edit active = " + MdxRender.Input.EditActive.ToString()); //get selected instance if ((activeSelection != null) && (MdxRender.Input.EditActive)) { Vector3 PickRayDirection = new Vector3(); Vector3 PickRayOrigin = new Vector3(); MouseX = MdxRender.Input.MouseX; MouseY = MdxRender.Input.MouseY; MdxRender.CalculatePickRayWorld(MouseX, MouseY, out PickRayDirection, out PickRayOrigin); //use the z-plane of most recent object selected float z_plane = activeSelection.ZPlane; //calculate mouse-movement of selected object Vector3 move_vector = new Vector3(); Vector3 sel_pos = new Vector3(); Vector3 obj_pos = new Vector3(); //use last selected object's reference planes to figure out where to move the object activeSelection.GetTranslation(out obj_pos); if (MdxRender.Input.EditVerticalPlacement) { //do calculation to determine selection plane intersect point for XZ plane if ((PickRayOrigin.Y - PickRayDirection.Y) != 0) { float u = (PickRayOrigin.Y - obj_pos.Y) / (PickRayOrigin.Y - PickRayDirection.Y); sel_pos.X = PickRayOrigin.X + u * (PickRayDirection.X - PickRayOrigin.X); sel_pos.Y = PickRayOrigin.Y + u * (PickRayDirection.Y - PickRayOrigin.Y); sel_pos.Z = PickRayOrigin.Z + u * (PickRayDirection.Z - PickRayOrigin.Z); move_vector.X = 0; move_vector.Y = 0; move_vector.Z = sel_pos.Z - lastSelectionPosition.Z; } } else //X-Y Object Movement { //do calculation to determine selection plane intersect point for XY plane if ((PickRayOrigin.Z - PickRayDirection.Z) != 0) { float u = (PickRayOrigin.Z - obj_pos.Z) / (PickRayOrigin.Z - PickRayDirection.Z); sel_pos.X = PickRayOrigin.X + u * (PickRayDirection.X - PickRayOrigin.X); sel_pos.Y = PickRayOrigin.Y + u * (PickRayDirection.Y - PickRayOrigin.Y); sel_pos.Z = PickRayOrigin.Z + u * (PickRayDirection.Z - PickRayOrigin.Z); move_vector.X = sel_pos.X - lastSelectionPosition.X; move_vector.Y = sel_pos.Y - lastSelectionPosition.Y; move_vector.Z = 0; } } lastSelectionPosition = sel_pos; activeSelection.IncrementTranslation(move_vector); } }
public void MouseUp(int MouseX, int MouseY) { Vector3 PickRayDirection = new Vector3(); Vector3 PickRayOrigin = new Vector3(); MdxRender.CalculatePickRayWorld(MouseX, MouseY, out PickRayDirection, out PickRayOrigin); #region 2D Selection Box //see if we need to do a 2D select box multiSelectBox.MouseUp(MouseX, MouseY); if (multiSelectBox.Mode != MultiSelectMode.Disabled) { if (multiSelectBox.Mode != MultiSelectMode.Disabled) { ArrayList tmp = multiSelectBox.UpdateFrustumSelection(this); bool bFoundDuplicate = false; Instance3D inst, tmp_inst; //add 2d select box selection list to master selection list for (int s = 0; s < tmp.Count; s++) { tmp_inst = (Instance3D)tmp[s]; //check for duplication for (int k = 0; k < selectionList.Count; k++) { inst = (Instance3D)selectionList[k]; if (tmp_inst == inst) { bFoundDuplicate = true; break; } } if (bFoundDuplicate == false) { selectionList.Add(tmp[s]); } } } } #endregion //debug code if (activeSelection == null) { foreach (Instance3D instance in this) { if (instance.MouseUp(PickRayOrigin, PickRayDirection, false) == true) { activeSelection = instance; } } if ((selectionList.Count != 0) && (multiSelectBox.Mode == MultiSelectMode.Disabled)) { foreach (Instance3D item in this) { item.Selected = false; } selectionList.Clear(); } //if(m_DebugObject1.MouseUp(PickRayOrigin, PickRayDirection, false)) // m_ActiveSelection = m_DebugObject1; } else { activeSelection.MakeEditInactive(); if (activeSelection.MouseUp(PickRayOrigin, PickRayDirection, true) == false) { if (activeSelection.EditMode == EditMode.NotSelected) { activeSelection = null; } } } UpdateSelectionLeader(); }