public void Set(string Id, POINT point, float autoScale = 1f) { this.id = Id; pointStrcut = point; var goLayer = TViewBase.Content.GetLayer(point.C8); if (goLayer != null) { //GenerateLine(); } var p1 = new Vector3((float)point.C10 / autoScale, (float)point.C30 / autoScale, (float)point.C20 / autoScale); transform.localPosition = p1; if (RayTools.GetAixaHD(transform) != null) { transform.forward = RayTools.GetAixaHD(transform).parent.forward; //Debug.LogError(Id + "控制方向" + transform.forward + "父物体的前边" + RayTools.GetAixaHD(transform).parent.forward); //Vector3 targetPos = transform.position - transform.up - transform.forward * 50 + transform.right; //GameObject go = new GameObject(); //go.transform.parent = transform; //go.transform.position = targetPos; } gameObject.name = "Point_" + Id; }
void Update() { base.Update(); mSel = SelType.None; if (mCam == null || !Input.GetMouseButton(0)) { return; } Ray ray = mCam.ScreenPointToRay(Input.mousePosition); Matrix4x4 m = Matrix4x4.TRS(mTarget.position, mTarget.localRotation, Vector3.one); Vector3[] vs = new Vector3[] { new Vector3(0, 0, 0), new Vector3(mR, 0, 0), new Vector3(0, mR, 0), new Vector3(0, 0, mR) }; for (int i = 0; i < 4; ++i) { vs[i] = m.MultiplyPoint(vs[i]); } Bounds xbd = new Bounds((vs [0] + vs [1]) / 2, m.MultiplyVector(new Vector3(mR, mR / 10, mR / 10))); Bounds ybd = new Bounds((vs [0] + vs [2]) / 2, m.MultiplyVector(new Vector3(mR / 10, mR, mR / 10))); Bounds zbd = new Bounds((vs [0] + vs [3]) / 2, m.MultiplyVector(new Vector3(mR / 10, mR / 10, mR))); if (xbd.IntersectRay(ray)) { mSel = SelType.X; } if (ybd.IntersectRay(ray)) { mSel = SelType.Y; } if (zbd.IntersectRay(ray)) { mSel = SelType.Z; } if (RayTools.intersectQuad(ray, m.MultiplyPoint(new Vector3(0.3f * mR, 0, 0)), m.MultiplyPoint(new Vector3(0.5f * mR, 0, 0)), m.MultiplyPoint(new Vector3(0, 0.5f * mR, 0)), m.MultiplyPoint(new Vector3(0, 0.3f * mR, 0)))) { mSel = SelType.XY; } if (RayTools.intersectQuad(ray, m.MultiplyPoint(new Vector3(0.3f * mR, 0, 0)), m.MultiplyPoint(new Vector3(0.5f * mR, 0, 0)), m.MultiplyPoint(new Vector3(0, 0, 0.5f * mR)), m.MultiplyPoint(new Vector3(0, 0, 0.3f * mR)))) { mSel = SelType.XZ; } if (RayTools.intersectQuad(ray, m.MultiplyPoint(new Vector3(0, 0.3f * mR, 0)), m.MultiplyPoint(new Vector3(0, 0.5f * mR, 0)), m.MultiplyPoint(new Vector3(0, 0, 0.5f * mR)), m.MultiplyPoint(new Vector3(0, 0, 0.3f * mR)))) { mSel = SelType.YZ; } if (RayTools.intersectTriangle(ray, m.MultiplyPoint(new Vector3(0.3f * mR, 0, 0)), m.MultiplyPoint(new Vector3(0, 0.3f * mR, 0)), m.MultiplyPoint(new Vector3(0, 0, 0.3f * mR)))) { mSel = SelType.XYZ; } }
void Update() { base.Update(); //显示前半球 Vector3 center = mCam.worldToCameraMatrix.MultiplyPoint(mTarget.position); mMat.SetVector("_Center", center); //======= mSel = SelType.None; Ray ray = mCam.ScreenPointToRay(Input.mousePosition); if (RayTools.intersectSphere(ray, mTarget.position, 1.1f * mR) != 0) { mSel = SelType.N; } float d = RayTools.intersectSphere(ray, mTarget.position, mR); if (d == 0) { return; } mSel = SelType.XYZ; Vector3 p = pos = ray.GetPoint(d); Matrix4x4 m = Matrix4x4.TRS(mTarget.position, mTarget.localRotation, Vector3.one); Plane x = new Plane(m.MultiplyVector(Vector3.left), m.MultiplyPoint(Vector3.zero)); Plane y = new Plane(m.MultiplyVector(Vector3.up), m.MultiplyPoint(Vector3.zero)); Plane z = new Plane(m.MultiplyVector(Vector3.forward), m.MultiplyPoint(Vector3.zero)); if (Mathf.Abs(x.GetDistanceToPoint(p)) < 0.1f) { mSel = SelType.X; } if (Mathf.Abs(y.GetDistanceToPoint(p)) < 0.1f) { mSel = SelType.Y; } if (Mathf.Abs(z.GetDistanceToPoint(p)) < 0.1f) { mSel = SelType.Z; } }