public void clearData()
 {
     observer  = null;
     posBuff   = null;
     scaleBuff = null;
     rotBuff   = null;
     isDirty   = true;
 }
예제 #2
0
    public static bool DistThresh(Vector3 a1, Vector3 a2, Vector3 b1, Vector3 b2, float thresh)
    {
        Vector3Pair points = Dist3DSegToSeg(a1, a2, b1, b2);

        if ((points.a - points.b).magnitude < thresh)
        {
            return(true);
        }
        return(false);
    }
예제 #3
0
 public OpticalSurface(int id,
                       Vector3Pair p,
                       Transform3 transform,
                       Curve curve,
                       Shape shape,
                       Medium left,
                       Medium right) : base(id, p, transform, curve, shape)
 {
     _mat[0] = left;
     _mat[1] = right;
 }
예제 #4
0
 private int IsConnectingFirst(Vector3Pair pair, Vector3 point)
 {
     if (pair.V1 == point)
     {
         return(1);
     }
     if (pair.V2 == point)
     {
         return(2);
     }
     return(0);
 }
예제 #5
0
        public void ProcessSegments()
        {
            if (Segments.Count() == 0)
            {
                return;
            }

            var visited     = new HashSet <Vector3Pair>();
            var result      = new List <Vector3Pair>();
            var afterStart  = new List <Vector3Pair>();
            var beforeStart = new List <Vector3Pair>();

            var currentSegment = Segments[0];

            afterStart.Add(currentSegment);
            visited.Add(currentSegment);

            for (var i = 0; i < Segments.Count; i++)
            {
                Vector3Pair connected      = Vector3Pair.Zero;
                var         foundConnected = FindConnectingPoint(currentSegment, false, ref connected);
                if (!foundConnected)
                {
                    continue;
                }

                if (visited.Contains(connected))
                {
                    IsLoop = true;
                    continue;
                }

                afterStart.Add(connected);
                currentSegment = connected;
            }

            currentSegment = Segments[0];
            for (var i = Segments.Count - 1; i >= 0; i--)
            {
                Vector3Pair connected      = Vector3Pair.Zero;
                var         foundConnected = FindConnectingPoint(currentSegment, true, ref connected);
                if (!foundConnected)
                {
                    continue;
                }

                if (visited.Contains(connected))
                {
                    IsLoop = true;
                    continue;
                }
            }
        }
예제 #6
0
        // From FAR with ferram4 authorisation
        public static MechJebModuleDockingAutopilot.Box3d GetBoundingBox(this Vessel vessel, bool debug = false)
        {
            Vector3 minBounds = new Vector3();
            Vector3 maxBounds = new Vector3();

            if (debug)
            {
                MonoBehaviour.print("[GetBoundingBox] Start " + vessel.vesselName);
            }

            for (int i = 0; i < vessel.parts.Count; i++)
            {
                Part        p       = vessel.parts[i];
                Vector3Pair partBox = p.GetBoundingBox();

                if (debug)
                {
                    MonoBehaviour.print("[GetBoundingBox] " + p.name + " " + (partBox.p1 - partBox.p2).magnitude.ToString("F3"));
                }

                maxBounds.x = Mathf.Max(maxBounds.x, partBox.p1.x);
                minBounds.x = Mathf.Min(minBounds.x, partBox.p2.x);
                maxBounds.y = Mathf.Max(maxBounds.y, partBox.p1.y);
                minBounds.y = Mathf.Min(minBounds.y, partBox.p2.y);
                maxBounds.z = Mathf.Max(maxBounds.z, partBox.p1.z);
                minBounds.z = Mathf.Min(minBounds.z, partBox.p2.z);

                //foreach (var sympart in p.symmetryCounterparts)
                //{
                //    partBox = sympart.GetBoundingBox();

                //    maxBounds.x = Mathf.Max(maxBounds.x, partBox.p1.x);
                //    minBounds.x = Mathf.Min(minBounds.x, partBox.p2.x);
                //    maxBounds.y = Mathf.Max(maxBounds.y, partBox.p1.y);
                //    minBounds.y = Mathf.Min(minBounds.y, partBox.p2.y);
                //    maxBounds.z = Mathf.Max(maxBounds.z, partBox.p1.z);
                //    minBounds.z = Mathf.Min(minBounds.z, partBox.p2.z);
                //}
            }

            if (debug)
            {
                MonoBehaviour.print("[GetBoundingBox] End " + vessel.vesselName);
            }

            MechJebModuleDockingAutopilot.Box3d box = new MechJebModuleDockingAutopilot.Box3d();

            box.center = new Vector3d((maxBounds.x + minBounds.x) / 2, (maxBounds.y + minBounds.y) / 2, (maxBounds.z + minBounds.z) / 2);
            box.size   = new Vector3d(Math.Abs(box.center.x - maxBounds.x), Math.Abs(box.center.y - maxBounds.y), Math.Abs(box.center.z - maxBounds.z));

            return(box);
        }
예제 #7
0
    private void CheckPoints(Dictionary <Vector3Pair, bool> pairs, Vector3 p1, Vector3 p2, Matrix4x4 objectMatrix)
    {
        // Only add a line if the two points haven't been connected yet, so there are no duplicate lines
        var pair1 = new Vector3Pair(p1, p2);
        var pair2 = new Vector3Pair(p2, p1);

        if (!pairs.ContainsKey(pair1) && !pairs.ContainsKey(pair2))
        {
            pairs[pair1] = true;
            pairs[pair2] = true;
            Line(objectMatrix.MultiplyPoint3x4(p1), objectMatrix.MultiplyPoint3x4(p2));
        }
    }
        void InitDocking()
        {
            lastTarget = core.target.Target;

            try
            {
                Vector3Pair vesselBoundingBox = vessel.GetBoundingBox();
                Vector3Pair targetBoundingBox = lastTarget.GetVessel().GetBoundingBox();

                targetSize = Mathf.Max(targetBoundingBox.p1.magnitude, targetBoundingBox.p2.magnitude);

                safeDistance = Mathf.Max(vesselBoundingBox.p1.magnitude, vesselBoundingBox.p2.magnitude) + targetSize;


                if (core.target.Target is ModuleDockingNode)
                {
                    acquireRange = ((ModuleDockingNode)core.target.Target).acquireRange * 0.5;
                }
                else
                {
                    acquireRange = 0.25;
                }
            }
            catch (Exception e)
            {
                print(e);
            }

            if (zSep < 0)  //we're behind the target
            {
                dockingStep = DockingStep.WRONG_SIDE_BACKING_UP;
            }
            else if (lateralSep.magnitude > dockingcorridorRadius) // in front but far from docking axis
            {
                if (zSep < targetSize)
                {
                    dockingStep = DockingStep.BACKING_UP;
                }
                else
                {
                    dockingStep = DockingStep.MOVING_TO_START;
                }
            }
            else
            {
                dockingStep = DockingStep.DOCKING;
            }
        }
예제 #9
0
        /*
         *
         * intersection d'un plan defini par :
         *
         * P(Px, Py, Pz) appartenant au plan
         * N(Px, Py, Pz) normal au plan
         *
         * avec une droite AB definie par l'ensemble des points tel que:
         *
         * A + * t B
         *
         * on a :
         *
         * t=(Nz*Pz+Ny*Py+Nx*Px-Az*Nz-Ay*Ny-Ax*Nx)/(Bz*Nz+By*Ny+Bx*Nx)
         *
         */


        override public Vector3 intersect(Vector3Pair ray)
        {
            double s = ray.direction().z();

            if (s == 0)
            {
                return(null);
            }
            double a = -ray.origin().z() / s;

            if (a < 0)
            {
                return(null);
            }
            return(ray.origin().plus(ray.direction().times(a)));
        }
예제 #10
0
    private void WriteLineToFile()
    {
        var path = EditorUtility.SaveFilePanelInProject("Save " + (useVector2? "Vector2" : "Vector3") + " Line", objectTransform.name + "Vector.bytes", "bytes",
                                                        "Please enter a file name for the line data");

        if (path == "")
        {
            return;
        }

        var fileBytes = new byte[(useVector2? linePoints.Count * 16 : linePoints.Count * 24)];

        idx = 0;
        for (int i = 0; i < linePoints.Count; i++)
        {
            Vector3Pair v = linePoints[i];
            Vector3     p = v.p1 - objectTransform.position;
            ConvertFloatToBytes(p.x, fileBytes);
            ConvertFloatToBytes(p.y, fileBytes);
            if (!useVector2)
            {
                ConvertFloatToBytes(p.z, fileBytes);
            }
            p = v.p2 - objectTransform.position;
            ConvertFloatToBytes(p.x, fileBytes);
            ConvertFloatToBytes(p.y, fileBytes);
            if (!useVector2)
            {
                ConvertFloatToBytes(p.z, fileBytes);
            }
        }

        try {
            File.WriteAllBytes(path, fileBytes);
            AssetDatabase.Refresh();
        }
        catch (System.Exception err) {
            message = err.Message;
            return;
        }
        message = "File written successfully";
    }
예제 #11
0
        private bool FindConnectingPoint(Vector3Pair pair, bool reverseCheck, ref Vector3Pair result)
        {
            /*
             * foreach (var segment in GetSegments(reverseCheck))
             * {
             *  if (segment == pair)
             *  {
             *      continue;
             *  }
             *
             *  if (pair.V1 == segment.V1 || pair.V1 == segment.V2 ||
             *      pair.V2 == segment.V1 || pair.V2 == semgnet.V2)
             *  {
             *      result = segment;
             *      return true;
             *  }
             * }
             */

            return(false);
        }
예제 #12
0
        /**
         * Swap the given element between the member vectors and return a new pair
         */
        public static Vector3Pair swapElement(Vector3Pair p, int j)
        {
            double[] n0 = new double[3];
            double[] n1 = new double[3];

            for (int i = 0; i < 3; i++)
            {
                if (i == j)
                {
                    // swap
                    n0[i] = p.v1.v(i);
                    n1[i] = p.v0.v(i);
                }
                else
                {
                    // retain original
                    n0[i] = p.v0.v(i);
                    n1[i] = p.v1.v(i);
                }
            }

            return(new Vector3Pair(new Vector3(n0[0], n0[1], n0[2]), new Vector3(n0[0], n0[1], n0[2])));
        }
예제 #13
0
 public override Image.Builder position(Vector3Pair position)
 {
     return((Image.Builder)base.position(position));
 }
예제 #14
0
 public override OpticalSurface.Builder position(Vector3Pair position)
 {
     return((OpticalSurface.Builder)base.position(position));
 }
예제 #15
0
 public void AddPair(Vector3Pair pair)
 {
     Pairs.Add(pair);
 }
예제 #16
0
 public override Stop.Builder position(Vector3Pair position)
 {
     return((Stop.Builder)base.position(position));
 }
예제 #17
0
 public override MirrorSurface.Builder position(Vector3Pair position)
 {
     return((MirrorSurface.Builder)base.position(position));
 }
예제 #18
0
 public void AddPair(Vector3Pair pair)
 {
     Pairs.Add(pair);
 }
예제 #19
0
 static void CheckPairPoints(Dictionary<Vector3Pair, bool> pairs, Vector3 p1, Vector3 p2, List<Vector3> linePoints)
 {
     var pair1 = new Vector3Pair(p1, p2);
     var pair2 = new Vector3Pair(p2, p1);
     if (!pairs.ContainsKey(pair1) && !pairs.ContainsKey(pair2)) {
         pairs[pair1] = true;
         pairs[pair2] = true;
         linePoints.Add(p1);
         linePoints.Add(p2);
     }
 }
예제 #20
0
 public void AddPair(Vector3Pair pair)
 {
     Segments.Add(pair);
 }
예제 #21
0
 public Vector3 pl_ln_intersect(Vector3Pair line)
 {
     return(line.v0.plus(line.v1.times(pl_ln_intersect_scale(line))));
 }
예제 #22
0
 public double pl_ln_intersect_scale(Vector3Pair line)
 {
     // See https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection
     return((origin().dot(normal()) - normal().dot(line.origin())) /
            (line.normal().dot(normal())));
 }
예제 #23
0
 public bool isEquals(Vector3Pair other, double tolerance)
 {
     return(v0.isEqual(other.v0, tolerance) && v1.isEqual(other.v1, tolerance));
 }
예제 #24
0
	//Distance formula borrowed from:
	//http://softsurfer.com/Archive/algorithm_0106/algorithm_0106.htm
	public static Vector3Pair Dist3DSegToSeg(Vector3 a1, Vector3 a2, Vector3 b1, Vector3 b2) {
		//Debug.Log("dist between (" + a1 + " - " + a2 + ") and (" + b1 + ", " + b2 + ")");
		Vector3Pair result = new Vector3Pair();
		Vector3 u = a2 - a1;
		Vector3 v = b2 - b1;
		Vector3 w = a1 - b1;
		float a = Vector3.Dot(u, u);
		float b = Vector3.Dot(u, v);
		float c = Vector3.Dot(v, v);
		float d = Vector3.Dot(u, w);
		float e = Vector3.Dot(v, w);
		float D = a * c - b * b;
		float sc, sN, sD = D;
		float tc, tN, tD = D;

		if(D < Mathf.Epsilon) {	//Lines almost parallel
			sN = 0;
			sD = 1;
			tN = e;
			tD = c;
		} else {
			sN = b * e - c * d;
			tN = a * e - b * d;
			if(sN < 0) {
				sN = 0;
				tN = e;
				tD = e;
			} else if(sN > sD) {
				sN = sD;
				tN = e + b;
				tD = c;
			}
		}

		if(tN < 0) {
			tN = 0;
			if(-d < 0)
				sN = 0;
			else if(-d > a)
				sN = sD;
			else {
				sN = -d + b;
				sD = a;
			}
		} else if(tN > tD) {      // tc > 1 => the t=1 edge is visible
			tN = tD;
			// recompute sc for this edge
			if((-d + b) < 0.0)
				sN = 0;
			else if((-d + b) > a)
				sN = sD;
			else {
				sN = (-d + b);
				sD = a;
			}
		}
		sc = Mathf.Abs(sN) < Mathf.Epsilon ? 0 : sN / sD;
		tc = Mathf.Abs(tN) < Mathf.Epsilon ? 0 : tN / tD;
		result.a = a1 + sc * u;
		result.b = b1 + tc * v;
		return result;
	}
예제 #25
0
 public Image(int id, Vector3Pair p, Transform3 transform, Curve curve, Shape shape) : base(id, p, transform,
                                                                                            curve, shape)
 {
 }
예제 #26
0
 public void AddPair(Vector3Pair pair)
 {
     Segments.Add(pair);
 }
예제 #27
0
        private bool FindConnectingPoint(Vector3Pair pair, bool reverseCheck, ref Vector3Pair result)
        {
            /*
            foreach (var segment in GetSegments(reverseCheck))
            {
                if (segment == pair)
                {
                    continue;
                }

                if (pair.V1 == segment.V1 || pair.V1 == segment.V2 ||
                    pair.V2 == segment.V1 || pair.V2 == semgnet.V2)
                {
                    result = segment;
                    return true;
                }
            }
            */

            return false;
        }
예제 #28
0
 public Stop(int id, Vector3Pair p, Transform3 transform, Curve curve, Shape shape) :
     base(id, p, transform, curve, shape)
 {
     _external_radius = shape.max_radius() * 2.0;
 }
예제 #29
0
 private int IsConnectingFirst(Vector3Pair pair, Vector3 point)
 {
     if (pair.V1 == point)
     {
         return 1;
     }
     if (pair.V2 == point)
     {
         return 2;
     }
     return 0;
 }
예제 #30
0
 public MirrorSurface(int id, Vector3Pair p, Transform3 transform, Curve curve, Shape shape, Medium left,
                      Medium right) : base(id, p, transform, curve, shape, left, right)
 {
 }
예제 #31
0
 public LightRay(Vector3Pair ray) : this(ray, 1.0, SpectralLine.d)
 {
 }
예제 #32
0
    //Distance formula borrowed from:
    //http://softsurfer.com/Archive/algorithm_0106/algorithm_0106.htm
    public static Vector3Pair Dist3DSegToSeg(Vector3 a1, Vector3 a2, Vector3 b1, Vector3 b2)
    {
        //Debug.Log("dist between (" + a1 + " - " + a2 + ") and (" + b1 + ", " + b2 + ")");
        Vector3Pair result = new Vector3Pair();
        Vector3     u = a2 - a1;
        Vector3     v = b2 - b1;
        Vector3     w = a1 - b1;
        float       a = Vector3.Dot(u, u);
        float       b = Vector3.Dot(u, v);
        float       c = Vector3.Dot(v, v);
        float       d = Vector3.Dot(u, w);
        float       e = Vector3.Dot(v, w);
        float       D = a * c - b * b;
        float       sc, sN, sD = D;
        float       tc, tN, tD = D;

        if (D < Mathf.Epsilon)          //Lines almost parallel
        {
            sN = 0;
            sD = 1;
            tN = e;
            tD = c;
        }
        else
        {
            sN = b * e - c * d;
            tN = a * e - b * d;
            if (sN < 0)
            {
                sN = 0;
                tN = e;
                tD = e;
            }
            else if (sN > sD)
            {
                sN = sD;
                tN = e + b;
                tD = c;
            }
        }

        if (tN < 0)
        {
            tN = 0;
            if (-d < 0)
            {
                sN = 0;
            }
            else if (-d > a)
            {
                sN = sD;
            }
            else
            {
                sN = -d + b;
                sD = a;
            }
        }
        else if (tN > tD)                 // tc > 1 => the t=1 edge is visible
        {
            tN = tD;
            // recompute sc for this edge
            if ((-d + b) < 0.0)
            {
                sN = 0;
            }
            else if ((-d + b) > a)
            {
                sN = sD;
            }
            else
            {
                sN = (-d + b);
                sD = a;
            }
        }
        sc       = Mathf.Abs(sN) < Mathf.Epsilon ? 0 : sN / sD;
        tc       = Mathf.Abs(tN) < Mathf.Epsilon ? 0 : tN / tD;
        result.a = a1 + sc * u;
        result.b = b1 + tc * v;
        return(result);
    }
예제 #33
0
 public LightRay(Vector3Pair ray, double intensity, double wavelen)
 {
     this._ray       = ray;
     this._intensity = intensity;
     this._wavelen   = wavelen;
 }
예제 #34
0
파일: Road.cs 프로젝트: Sprunth/RoadTraffic
    void UpdateBoundPoints()
    {
        // pushback
        Pushback(node1, pushback1);
        Pushback(node2, pushback2);

        //var p1 = node1.transform.position;
        //var p2 = node2.transform.position;

        var p1 = end1;
        var p2 = end2;

        var diff = p2 - p1;
        var angle = (float) Math.Atan2(diff.z, diff.x);
        const float rightAngle = (float) Math.PI/2;
        var width = 1f;
        var elevation = 0.02f;

        var p1_1 = new Vector3(width * (float)Math.Cos(angle - rightAngle), elevation,
            width * (float)Math.Sin(angle - rightAngle));
        var p1_2 = new Vector3(width * (float)Math.Cos(angle + rightAngle), elevation,
            width * (float)Math.Sin(angle + rightAngle));
        var p2_1 = new Vector3(width * (float)Math.Cos(angle - rightAngle) + diff.x, elevation,
            diff.z + width * (float)Math.Sin(angle - rightAngle));
        var p2_2 = new Vector3(width * (float)Math.Cos(angle + rightAngle) + diff.x, elevation,
            diff.z + width * (float)Math.Sin(angle + rightAngle));

        nodeCorners.Clear();
        Assert.AreNotEqual(node1, node2);
        var pair1 = new Vector3Pair(p1_1, p1_2);
        var pair2 = new Vector3Pair(p2_1, p2_2);
        Assert.AreNotEqual(pair1, pair2);
        nodeCorners.Add(node1, pair1);
        nodeCorners.Add(node2, pair2);
        Assert.AreNotEqual(nodeCorners[node1], nodeCorners[node2]);

        var randColor = new Color(UnityEngine.Random.Range(0.1f, 0.9f),
            UnityEngine.Random.Range(0.1f, 0.9f),
            UnityEngine.Random.Range(0.1f, 0.9f));

        Func<Vector3, Color, GameObject> CreateCornerPoint = (pos, col) =>
        {
            var point = GameObject.CreatePrimitive(PrimitiveType.Cube);
            point.transform.localScale = new Vector3(0.3f, 0.5f, 0.3f);
            point.transform.position = pos;
            point.transform.parent = transform;
            point.GetComponent<Renderer>().material.color = col;
            return point;
        };

        foreach (var cornerPoint in cornerPoints)
        {
            Destroy(cornerPoint.Value.First);
            Destroy(cornerPoint.Value.Second);
        }
        cornerPoints.Clear();
        cornerPoints.Add(nodeCorners[node1], new GeneralHelpers.Tuple<GameObject, GameObject>(CreateCornerPoint(p1_1, randColor), CreateCornerPoint(p1_2, randColor)));
        cornerPoints.Add(nodeCorners[node2], new GeneralHelpers.Tuple<GameObject, GameObject>(CreateCornerPoint(p2_1, randColor), CreateCornerPoint(p2_2, randColor)));
    }