void OnMouseDrag() { if (Lerping) { return; } float MouseY = Input.mousePosition.y - _mouseOffsetY; float NewAngle; float AngleIncrement; if (_dragHandle == "L") { AngleIncrement = -Mathf.Atan2(MouseY, Screen.width / 2) * Mathf.Rad2Deg; } else { AngleIncrement = Mathf.Atan2(MouseY, Screen.width / 2) * Mathf.Rad2Deg; } NewAngle = _startAngle + AngleIncrement; Bez.CtrlPts[Mrkr.Index].BankAngle = NewAngle; //Rotate the marker - We do this by rotating the transform about the kerb pivot Vector3 _markerPos = Bez.CtrlPts[Mrkr.Index].Pos; AttachedTransform.position = _startPos; AttachedTransform.rotation = _startRot; AttachedTransform.RotateAround(_pivot, AttachedTransform.forward, AngleIncrement); //this function was depreciated but I really struggled to do it any other way Bez.CtrlPts[Mrkr.Index].Pos = AttachedTransform.position; Bez.Interp(Mrkr.Index - 1); Bez.Interp(Mrkr.Index); Bez.Interp(Mrkr.Index + 1); Bez.DrawLine(); }
void OnMouseDrag() { if (Lerping) { return; } r = FPCam.ScreenPointToRay(Input.mousePosition); float entry; Vector3 newpos; if (_dragDirection == "xz") { DragPlane.Raycast(r, out entry); d = entry; newpos = r.GetPoint(d) - _mouseOffset; } else { DragPlane.Raycast(r, out entry); d = entry; newpos = new Vector3(GizmoStartPos.x, r.GetPoint(d).y - _mouseOffset.y, GizmoStartPos.z); } AttachedTransform.position = newpos - AttachedTransform.up * _hoverHeight; if (Mrkr.Index == 1 && Road.Instance.IsCircular) { Bez.CtrlPts[Bez.CtrlPts.Count - 2].Pos = Mrkr.transform.position; //Bez.CtrlPts[Bez.CtrlPts.Count - 2].goRdMkr.transform.position = Mrkr.transform.position; Bez.Interp(Bez.CtrlPts.Count - 2); } Bez.CtrlPts[Mrkr.Index].Pos = Mrkr.transform.position; Bez.Interp(Mrkr.Index - 1); Bez.Interp(Mrkr.Index); Bez.Interp(Mrkr.Index + 1); //Bez.DrawLine(); }
void OnMouseDrag() { if (Lerping) { return; } float NewAngle; float MouseAngle = Mathf.Atan2(Input.mousePosition.y - Screen.height / 2, Input.mousePosition.x - Screen.width / 2) * Mathf.Rad2Deg; //Signed angle measured anticlockwise from the right MouseAngle = MouseAngle - _mouseOffsetAngle; if (MouseAngle > 180) { MouseAngle = MouseAngle - 360; } if (MouseAngle < -180) { MouseAngle = MouseAngle + 360; } if (_viewFromFront) { MouseAngle = -MouseAngle; } NewAngle = _startAngle + MouseAngle; if (_hand == "R") { if (NewAngle > 0) { transform.localRotation = Quaternion.Euler(0, 0, NewAngle); _oppositeGizmoBank.localRotation = Quaternion.identity; } else { _oppositeGizmoBank.localRotation = Quaternion.Euler(0, 0, NewAngle); transform.localRotation = Quaternion.identity; } } else { if (NewAngle > 0) { _oppositeGizmoBank.localRotation = Quaternion.Euler(0, 0, NewAngle); transform.localRotation = Quaternion.identity; } else { transform.localRotation = Quaternion.Euler(0, 0, NewAngle); _oppositeGizmoBank.localRotation = Quaternion.identity; } } Bez.CtrlPts[Mrkr.Index].BankAngle = NewAngle; //transform.RotateAround(_pivot, AttachedTransform.forward, AngleIncrement); //Bez.CtrlPts[Mrkr.Index].Pos = AttachedTransform.position; Bez.Interp(Mrkr.Index - 1); Bez.Interp(Mrkr.Index); Bez.Interp(Mrkr.Index + 1); Bez.DrawLine(); }
void OnMouseDrag() { if (Lerping) { return; } float MouseY = Input.mousePosition.y - _mouseOffsetY; float NewAngle; if (_hand == "L") { NewAngle = _startAngle + Mathf.Atan2(MouseY, Screen.width / 2); } else { NewAngle = _startAngle - Mathf.Atan2(MouseY, Screen.width / 2); } NewAngle = NewAngle * Mathf.Rad2Deg; //Debug.Log("New angle = " + NewAngle); Vector3 NewPos; Vector3 _bankDirection = AttachedTransform.forward * NewAngle; NewPos = VectGeom.RotatePointAroundPivot(_untiltedPos, OtherHandGizmo.position, _bankDirection); Bez.CtrlPts[Mrkr.Index].Pos = (NewPos + _otherHandStartPos) / 2; AttachedTransform.position = Bez.CtrlPts[Mrkr.Index].Pos; Bez.CtrlPts[Mrkr.Index].BankAngle = NewAngle; Bez.Interp(Mrkr.Index - 1); Bez.Interp(Mrkr.Index); Bez.Interp(Mrkr.Index + 1); Bez.DrawLine(); AttachedTransform.rotation = Quaternion.identity; try { AttachedTransform.LookAt(BezierLine.Instance.Path[Bez.CtrlPts[Mrkr.Index].SegStartIdx + 1]); AttachedTransform.Rotate(Vector3.forward, NewAngle); } catch (System.Exception e) { //Todo Find something for it to look at } transform.position = NewPos; OtherHandGizmo.position = _otherHandStartPos; transform.LookAt(OtherHandGizmo, AttachedTransform.up); OtherHandGizmo.LookAt(transform, AttachedTransform.up); }
public void AddSection(Vector3 Point) //We add the section but we can't say how many segments it has //So we add the Xsecs and Segs for the previous section { if (Road.Instance.IsCircular) { return; } if (Bez.CtrlPts.Count > 3 && Vector3.Distance(Point, Bez.CtrlPts[Bez.CtrlPts.Count - 2].Pos) > 80) { Tut.gameObject.SetActive(true); Tut.ShowSpeech("This cone is too far from the last", 5); return; } int NewIdx = Road.Instance.Sectns.Count; int SegCount; Point = Bez.LimitSlope(Point, 0.33f); if (Bez.CtrlPts.Count == 2) { SegCount = 0; } else { SegCount = Mathf.CeilToInt(Vector3.Distance(Point, Bez.CtrlPts[Bez.CtrlPts.Count - 2].Pos) / 0.84f); } Bez.AddControlPoint(Point, 0, SegCount); Bez.Interp(NewIdx - 1); Bez.DrawLine(); RoadSectn Sectn = new RoadSectn(); Sectn.Idx = NewIdx; Sectn.name = "RoadSection" + (NewIdx); Rd.Sectns[NewIdx - 1].Chargeable = true; Rd.Sectns[NewIdx - 1].AddXSecs(SegCount); //Add XSecs to the PREVIOUS Section Sectn.CreateGameObjects(); Road.Instance.Sectns.Add(Sectn); // Section1 comes after RoadMarker1 Bez.CtrlPts[NewIdx].CreateRoadMarker(); Bez.AlignAllRoadMarkers(); XSecCalculator.CalcXSecs(NewIdx - 1, RoadWidth); //calculates for the section up to the previous marker for (int Idx = Bez.CtrlPts[NewIdx - 1].SegStartIdx; Idx < Bez.CtrlPts[NewIdx].SegStartIdx; Idx++) //create the segs ahead of the marker but don't mesh them { RoadSegment seg = new RoadSegment(); seg.Idx = Idx; seg.SectnIdx = NewIdx - 1; Rd.Sectns[NewIdx - 1].Segments.Add(seg); seg.CreateGameObjects(); seg.goSeg.name = "RoadSeg" + Idx; Rd.Segments.Add(seg); seg.SetMaterial(RoadMat); seg.LFenceType = LFenceType; seg.RFenceType = RFenceType; seg.goSeg.transform.SetParent(Rd.Sectns[NewIdx - 1].goSectn.transform); } Rd.Sectns[NewIdx].SetMaterial(RoadMat); Rd.Sectns[NewIdx - 1].LFenceType = LFenceType; Rd.Sectns[NewIdx - 1].RFenceType = RFenceType; Rd.Sectns[NewIdx - 1].SetMaterial(RoadMat); XSecCalculator.AdjustHairpin(Bez, NewIdx - 2); if (NewIdx > 3) { Road.Instance.Sectns[NewIdx - 3].CalcVisibleFenceVerts(); } BuildQueue.Enqueue(NewIdx - 3); Bez.CtrlPts[NewIdx].goRdMkr.GetComponent <RoadMarker>().Select(); //Update the tutorial if (SaveLoadModel.savedGames.Count < 3) { Tutorial Tut = _canvas.transform.Find("pnlTutorialBuild2(Clone)").GetComponent <Tutorial>(); int _roadCost = BillOfRoadMaterials.Items.Sum(i => i.Cost); int _sceneryCost = BillOfSceneryMaterials.Items.Sum(i => i.Opt.Cost); int conesLeft = (UserDataManager.Instance.Data.Coins - _roadCost - _sceneryCost) / 5; Tut.ShowSpeech(string.Format("You have money for {0:0.} more cones\n\nThe track must be a loop", conesLeft), 3); } }