예제 #1
0
            public ArcPoint(ArcPoint original, double angleOffset)
            {
                this.Parent     = original.Parent;
                this.Point      = original.Point;
                this.RightEnd   = original.RightEnd;
                this.EdgeFacing = original.EdgeFacing;

                this.Angle = original.Angle + angleOffset;
            }
예제 #2
0
    public ArcPoint WorldToArc(Vector3 world)
    {
        float      t      = NormalizeAngle(GetAngle(new Vector3(world.x, 0.0f, world.z) - new Vector3(center.x, 0.0f, center.z)));
        float      d      = (new Vector3(world.x, 0.0f, world.z) - new Vector3(center.x, 0.0f, center.z)).magnitude;
        GameObject obj2   = new GameObject();
        ArcPoint   newArc = obj2.AddComponent <ArcPoint>();

        newArc.Arcarcpoint(t, d);
        return(newArc);
    }
예제 #3
0
    public Vector3 ArcToWorld(ArcPoint arcPoint)
    {
        float tr = arcPoint.t * Mathf.Deg2Rad;
        float d  = arcPoint.d;

        if (flipped)
        {
            tr = (-arcPoint.t + 180) * Mathf.Deg2Rad;
        }
        return(new Vector3(d * Mathf.Cos(tr), 0, d * Mathf.Sin(tr)) + center);
    }
예제 #4
0
    public Vector3 ArcToLocal(ArcPoint arcPoint)
    {
        float tr = arcPoint.t * Mathf.Deg2Rad;
        float d  = arcPoint.d;

        if (flipped)
        {
            tr = (-arcPoint.t + 180) * Mathf.Deg2Rad;
        }
        return(new Vector3(d * Mathf.Cos(tr), 0, d * Mathf.Sin(tr)) + center - transform.position);
    }
예제 #5
0
    /* this method is adapted from http://www.jakecaspick.com/post/endlessroad/?fbclid=IwAR3z_UHz15fQohIkY6tSgBI6VLrnCgbXhqNJS6u6vl8Rl6A8P3y2pC-mDmQ
     */
    public bool ContainsPoint(Vector3 point, float margin)
    {
        ArcPoint p  = WorldToArc(point);
        float    rp = NormalizeAngle(p.t - startAngle);

        if (rp >= 0 && rp <= angle && p.d <= radius + width / 2 + margin && p.d >= radius - width / 2 - margin)
        {
            return(true);
        }
        return(false);
    }
예제 #6
0
            public ArcInterval(Arc parent)
            {
                var points = parent.Points.ToArray();

                this.Left  = points[1];
                this.Right = points[0];

                if (this.Right.Angle > this.Left.Angle)
                {
                    this.Right = new ArcPoint(this.Right, -4);
                }
            }
예제 #7
0
    public Vector3[] ArcArray()
    {
        List <Vector3> output = new List <Vector3>(); //Vector3[resolution + 1];

        angleRadians = Mathf.Deg2Rad * (flipped ? -angle : angle);
        float maxDist = (velocity * velocity * Mathf.Sin(2 * angleRadians)) / g;

        flag = false;
        for (int i = 0; i < resolution + 20; i++)
        {
            float t  = (float)i / (float)resolution;
            float t2 = ((float)i + 1) / (float)resolution;

            TransitionTest(frog.position + ArcPoint(t, maxDist), frog.position + ArcPoint(t2, maxDist));

            ArcPoint point = TestGroundHit(frog.position + ArcPoint(t, maxDist), frog.position + ArcPoint(t2, maxDist));
            if (i < resolution + 10)
            {
                if (!point.hitGround)
                {
                    output.Add(point.point);
                }
                else
                {
                    output.Add(point.point);
                    output.Add(point.hitPoint);
                    hitPoint = point.hitPoint;
                    break;
                }
            }
            else
            {
                output.Add(point.point);
                hitPoint = point.point;
            }
        }
        Vector3 avg = Vector3.zero;

        foreach (Vector3 point in output)
        {
            avg += point;
        }
        if (!flag)
        {
            transition = false;
        }
        avgPosition      = avg / output.Count;
        lr.positionCount = output.Count;
        frog.GetComponent <FrogScript>().expectedLandingPoint = hitPoint;
        return(output.ToArray());
    }
예제 #8
0
    /* this method is adapted from http://www.jakecaspick.com/post/endlessroad/?fbclid=IwAR3z_UHz15fQohIkY6tSgBI6VLrnCgbXhqNJS6u6vl8Rl6A8P3y2pC-mDmQ
     */
    public void Initialize()
    {
        if (!flipped)
        {
            startAngle = NormalizeAngle(startAngle);
            endAngle   = NormalizeAngle(startAngle + angle);
        }
        else
        {
            startAngle = NormalizeAngle(-startAngle);
            endAngle   = NormalizeAngle(-startAngle - angle);
        }
        center        = GetCenter();
        totalDistance = angle / 180 * Mathf.PI * radius;
        GameObject obj    = new GameObject();
        ArcPoint   newArc = obj.AddComponent <ArcPoint>();

        newArc.Arcarcpoint(angle + startAngle, radius);


        endPos = ArcToWorld(newArc);
    }
 public Arc(ParticleSystem.Particle[] particles, int start, int count)
 {
     this.start = start;
     this.end = start + count;
     this.particles = particles;
     points = new ArcPoint[pointsPerArc];
     for (int i = 0; i < pointsPerArc; i++) {
         points[i] = new ArcPoint();
     }
     initPoints();
 }
예제 #10
0
    /* this method is adapted from http://www.jakecaspick.com/post/endlessroad/?fbclid=IwAR3z_UHz15fQohIkY6tSgBI6VLrnCgbXhqNJS6u6vl8Rl6A8P3y2pC-mDmQ
     */
    public void GenerateMesh()
    {
        GetComponent <MeshFilter>().mesh = mesh = new Mesh();
        vertices = new Vector3[(arcDivisions + 1) * (widthDivisions + 1)];
        uv       = new Vector2[vertices.Length];
        float      arcStep    = angle / arcDivisions;
        float      widthStep  = width / widthDivisions;
        GameObject obj1       = new GameObject();
        ArcPoint   nextVertex = obj1.AddComponent <ArcPoint>();

        nextVertex.Arcarcpoint(0, 0);
        Vector2 nextUV = Vector2.zero;

        if (!flipped)
        {
            for (int t = 0; t <= arcDivisions; t++)
            {
                for (int w = 0; w <= widthDivisions; w++)
                {
                    nextVertex.Set(t * arcStep + startAngle, (w * widthStep - width / 2) + radius);
                    vertices[t * (widthDivisions + 1) + w] = ArcToLocal(nextVertex);
                    nextUV.Set((float)w / widthDivisions / textureScale, (float)t / arcDivisions * totalDistance / textureScale + uvOffset);
                    uv[t * (widthDivisions + 1) + w] = nextUV;
                }
            }
        }
        else
        {
            for (int t = 0; t <= arcDivisions; t++)
            {
                for (int w = 0; w <= widthDivisions; w++)
                {
                    nextVertex.Set(t * arcStep + startAngle, (w * -widthStep + width / 2) + radius);
                    vertices[t * (widthDivisions + 1) + w] = ArcToLocal(nextVertex);
                    nextUV.Set((float)w / widthDivisions / textureScale, (float)t / arcDivisions * totalDistance / textureScale + uvOffset);
                    uv[t * (widthDivisions + 1) + w] = nextUV;
                }
            }
        }
        mesh.vertices = vertices;
        mesh.uv       = uv;
        triangles     = new int[arcDivisions * widthDivisions * 6];
        for (int ti = 0, vi = 0, t = 0; t < arcDivisions; t++, vi++)
        {
            for (int w = 0; w < widthDivisions; w++, ti += 6, vi++)
            {
                triangles[ti]     = vi;
                triangles[ti + 3] = triangles[ti + 2] = vi + 1;
                triangles[ti + 4] = triangles[ti + 1] = vi + widthDivisions + 1;
                triangles[ti + 5] = vi + widthDivisions + 2;
                mesh.triangles    = triangles;
            }
        }
        mesh.RecalculateNormals();


        //Mesh collider needs  to be added after creating mesh or else
        //    collider will be in the shape of the initial plane
        gameObject.AddComponent <MeshCollider>();
        gameObject.GetComponent <MeshCollider>().sharedMesh = mesh;
    }
예제 #11
0
    public void GenerateMesh()
    {
        GetComponent <MeshFilter>().mesh = mesh = new Mesh();

        vertices = new Vector3[(arcDivisions + 1) * (widthDivisions + 1)];
        uv       = new Vector2[vertices.Length];

        float    arcStep    = angle / arcDivisions;
        float    widthStep  = width / widthDivisions;
        ArcPoint nextVertex = new ArcPoint(0, 0);
        Vector2  nextUV     = Vector2.zero;

        if (!flipped)
        {
            for (int t = 0; t <= arcDivisions; t++)
            {
                for (int w = 0; w <= widthDivisions; w++)
                {
                    nextVertex.Set(t * arcStep + startAngle, (w * widthStep - width / 2) + radius);
                    vertices[t * (widthDivisions + 1) + w] = ArcToLocal(nextVertex);

                    nextUV.Set((float)w / widthDivisions / textureScale, (float)t / arcDivisions * totalDistance / textureScale + uvOffset);
                    uv[t * (widthDivisions + 1) + w] = nextUV;
                }
            }
        }
        else
        {
            for (int t = 0; t <= arcDivisions; t++)
            {
                for (int w = 0; w <= widthDivisions; w++)
                {
                    nextVertex.Set(t * arcStep + startAngle, (w * -widthStep + width / 2) + radius);
                    vertices[t * (widthDivisions + 1) + w] = ArcToLocal(nextVertex);

                    nextUV.Set((float)w / widthDivisions / textureScale, (float)t / arcDivisions * totalDistance / textureScale + uvOffset);
                    uv[t * (widthDivisions + 1) + w] = nextUV;
                }
            }
        }

        mesh.vertices = vertices;
        mesh.uv       = uv;

        triangles = new int[arcDivisions * widthDivisions * 6];

        for (int ti = 0, vi = 0, t = 0; t < arcDivisions; t++, vi++)
        {
            for (int w = 0; w < widthDivisions; w++, ti += 6, vi++)
            {
                triangles[ti]     = vi;
                triangles[ti + 3] = triangles[ti + 2] = vi + 1;
                triangles[ti + 4] = triangles[ti + 1] = vi + widthDivisions + 1;
                triangles[ti + 5] = vi + widthDivisions + 2;

                mesh.triangles = triangles;
            }
        }

        mesh.RecalculateNormals();
    }
예제 #12
0
 public ArcInterval(ArcPoint left, ArcPoint right)
 {
     this.Left  = left;
     this.Right = right;
 }
예제 #13
0
        private void multipleArcVertices(ArcPoint point, Vector2D facing, List <float> outputData)
        {
            var circle = point.Parent.Parent;
            var left   = point.EdgeFacing * circle.Radius;
            var right  = point.EdgeFacing * point.EdgeFacing.Dot(point.Point);
            var top    = point.Parent.Parent.Radius * (point.RightEnd ?
                                                       point.EdgeFacing.PerpendicularRight :
                                                       point.EdgeFacing.PerpendicularLeft);

            var endShape = new LinkedList <Vector2D>(new[] {
                right + top,
                right,
                left,
                left + top,
            });

            var facingNormal = point.RightEnd ? facing.PerpendicularRight : facing.PerpendicularLeft;

            for (var current = endShape.First; current != null; /* no step */)
            {
                var next  = current.Next ?? endShape.First;
                var added = false;
                if ((current.Value.Dot(facingNormal) < DotLimit) != (next.Value.Dot(facingNormal) < DotLimit))
                {
                    var line   = next.Value - current.Value;
                    var height = current.Value.Dot(facingNormal);
                    var speed  = -height / line.Dot(facingNormal);
                    endShape.AddAfter(current, current.Value + line * speed);
                    added = true;
                }

                if (current.Value.Dot(facingNormal) < DotLimit)
                {
                    var realNext = current.Next;
                    endShape.Remove(current);
                    current = realNext;
                }
                else
                {
                    current = current.Next;
                }

                if (added)
                {
                    current = current.Next;
                }
            }

            var triangles = new List <Vector2D[]>();

            for (var current = endShape.First.Next.Next; current != null; current = current.Next)
            {
                triangles.Add(makeTriangle(endShape.First.Value, current.Previous.Value, current.Value));
            }

            var facingSide = facing.Cross(point.EdgeFacing);

            if (point.RightEnd && facingSide < 0 || !point.RightEnd && facingSide > 0)
            {
                triangles.Add(makeTriangle(new Vector2D(0, 0), facing * circle.Radius * 1.5f, point.EdgeFacing * circle.Radius * 1.5f));
            }

            outputData.AddRange(triangles.SelectMany(x => x).SelectMany(x => orbitVertex(x)));
        }