public static string GetCellById(int id)
    {
        int space    = MathU.PowOfTen(GetInfoLength("type"));
        int typesCnt = CellType2Name.Length;
        int index    = Mathf.FloorToInt(id / ((float)space / typesCnt));

        return(CellType2Name[index]);
    }
Example #2
0
        private static object Get()
        {
            if (_math != null)
            {
                return(_math);
            }

            Type   t = typeof(T);
            object m;

            if (t == typeof(sbyte))
            {
                m = new MathI8();
            }
            else if (t == typeof(byte))
            {
                m = new MathU8();
            }
            else if (t == typeof(short))
            {
                m = new MathI16();
            }
            else if (t == typeof(ushort))
            {
                m = new MathU16();
            }
            else if (t == typeof(int))
            {
                m = new MathI();
            }
            else if (t == typeof(uint))
            {
                m = new MathU();
            }
            else if (t == typeof(long))
            {
                m = new MathL();
            }
            else if (t == typeof(ulong))
            {
                m = new MathUL();
            }
            else if (t == typeof(float))
            {
                m = new MathF();
            }
            else if (t == typeof(double))
            {
                m = new MathD();
            }
            else
            {
                m = null;              // TODO: search open assemblies for INumTraits<T> via reflection?
            }
            return(_math = m);
        }
Example #3
0
        protected override void ApplyRotation(float delta, Physics2DDirectBodyState state)
        {
            if (Vel.Length() > 0f || RotateBy != 0)
            {
                Transform2D xform = state.Transform.Rotated(MathU.LerpAngle(state.Transform.Rotation, RotateBy == 0 ? LinearVelocity.Angle() + Mathf.Deg2Rad(90) : RotateBy,
                                                                            Type.RotationSpeed * delta * (Speed / Type.MaxSpeed) + Mathf.Abs(RotateBy / Mathf.Tau)) - state.Transform.Rotation);

                state.Transform = xform;
            }
        }
Example #4
0
    public Transform[] bezierPoint;     // 4 points

    public override void UpdateVertex(int i)
    {
        MDSmelt mdsmelt = (MDSmelt)baseMD;

        if (limit.localPosition.z > baseMD.displacedVertices[i].z)
        {
            float t = (mdsmelt.deltaXZ[i] + 1) * 0.5f;             // [-1;1] -> [0,1]

            Vector3 targetPos = MathU.CalculateCubicBezierPoint(t,
                                                                bezierPoint[0].localPosition,
                                                                bezierPoint[1].localPosition,
                                                                bezierPoint[2].localPosition,
                                                                bezierPoint[3].localPosition);
            targetPos.x = baseMD.originalVertices[i].x;

            baseMD.displacedVertices[i] = Vector3.Lerp(baseMD.displacedVertices[i], targetPos, baseMD.value);
        }
    }
Example #5
0
    private void PopulateCellMatrix(ref CellType[,] CellMatrix)
    {
        List <Gene> Genes = DNA.GetGenes();

        Point pos = BaseU.GetMatrixMid(CellMatrix);

        foreach (Gene gene in Genes)
        {
            CellType            type   = gene.GetCellType();
            PhysicsU.Directions dir    = gene.GetDirection();
            Vector2             dirVec = PhysicsU.Dir2Vec(dir);

            pos.x += (int)dirVec.x;
            pos.y += (int)dirVec.y;

            pos.x = MathU.MinMax(pos.x, 0, CellMatrix.GetLength(0) - 1);
            pos.y = MathU.MinMax(pos.y, 0, CellMatrix.GetLength(1) - 1);

            CellMatrix[pos.x, pos.y] = type;
        }
    }
    protected override void UpdateMeshFunc()
    {
        bool flag = this.Width != 0f && this.Length != 0f && this.Height != 0f;

        if (flag)
        {
            this.mMesh.name = "Pyramid";
            Vector3[] array  = new Vector3[8 + this.HeightSegments * 2 * 4];
            Vector2[] array2 = new Vector2[array.Length];
            int[]     array3 = new int[18 + (this.HeightSegments - 1) * 6 * 4];
            float     num    = this.Width * 0.5f;
            float     num2   = this.Length * 0.5f;
            float     num3   = this.Height / (float)this.HeightSegments;
            int       num4   = 0;
            int       num5   = 0;
            array[0]  = new Vector3(-num, 0f, -num2);
            array[1]  = new Vector3(-num, 0f, num2);
            array[2]  = new Vector3(num, 0f, num2);
            array[3]  = new Vector3(num, 0f, -num2);
            array2[0] = new Vector2(0f, 0f);
            array2[1] = new Vector2(1f, 0f);
            array2[2] = new Vector2(1f, 1f);
            array2[3] = new Vector2(0f, 1f);
            array3[0] = 3;
            array3[1] = 2;
            array3[2] = 1;
            array3[3] = 1;
            array3[4] = 0;
            array3[5] = 3;
            num5     += 6;
            array[4]  = new Vector3(0f, this.Height, 0f);
            array[5]  = new Vector3(0f, this.Height, 0f);
            array[6]  = new Vector3(0f, this.Height, 0f);
            array[7]  = new Vector3(0f, this.Height, 0f);
            array2[4] = new Vector2(0.5f, 1f);
            array2[5] = new Vector2(0.5f, 1f);
            array2[6] = new Vector2(0.5f, 1f);
            array2[7] = new Vector2(0.5f, 1f);
            num4     += 8;
            int num6 = num4;
            for (int i = 0; i < this.HeightSegments; i++)
            {
                float num7 = MathU.scale((float)i, 0f, (float)this.HeightSegments, num, 0f);
                float y    = num3 * (float)i;
                float z    = MathU.scale((float)i, 0f, (float)this.HeightSegments, num2, 0f);
                array[num4]      = new Vector3(-num7, y, z);
                array[num4 + 1]  = new Vector3(num7, y, z);
                array2[num4]     = new Vector2(1f - (float)i / (float)this.HeightSegments * 0.5f, (float)i / (float)this.HeightSegments);
                array2[num4 + 1] = new Vector2((float)i / (float)this.HeightSegments * 0.5f, (float)i / (float)this.HeightSegments);
                num4            += 2;
            }
            for (int i = 0; i < this.HeightSegments - 1; i++)
            {
                array3[num5]     = num6 + 2;
                array3[num5 + 1] = num6;
                array3[num5 + 2] = num6 + 1;
                array3[num5 + 3] = num6 + 3;
                array3[num5 + 4] = num6 + 2;
                array3[num5 + 5] = num6 + 1;
                num5            += 6;
                num6            += 2;
            }
            array3[num5]     = num4 - 2;
            array3[num5 + 1] = num4 - 1;
            array3[num5 + 2] = 4;
            num5            += 3;
            num6             = num4;
            for (int i = 0; i < this.HeightSegments; i++)
            {
                float num8 = MathU.scale((float)i, 0f, (float)this.HeightSegments, num, 0f);
                float y2   = num3 * (float)i;
                float z2   = MathU.scale((float)i, 0f, (float)this.HeightSegments, -num2, 0f);
                array[num4]      = new Vector3(-num8, y2, z2);
                array[num4 + 1]  = new Vector3(num8, y2, z2);
                array2[num4]     = new Vector2((float)i / (float)this.HeightSegments * 0.5f, (float)i / (float)this.HeightSegments);
                array2[num4 + 1] = new Vector2(1f - (float)i / (float)this.HeightSegments * 0.5f, (float)i / (float)this.HeightSegments);
                num4            += 2;
            }
            for (int i = 0; i < this.HeightSegments - 1; i++)
            {
                array3[num5]     = num6 + 3;
                array3[num5 + 1] = num6 + 1;
                array3[num5 + 2] = num6;
                array3[num5 + 3] = num6;
                array3[num5 + 4] = num6 + 2;
                array3[num5 + 5] = num6 + 3;
                num5            += 6;
                num6            += 2;
            }
            array3[num5]     = num4 - 1;
            array3[num5 + 1] = num4 - 2;
            array3[num5 + 2] = 5;
            num5            += 3;
            num6             = num4;
            for (int i = 0; i < this.HeightSegments; i++)
            {
                float x    = MathU.scale((float)i, 0f, (float)this.HeightSegments, num, 0f);
                float y3   = num3 * (float)i;
                float num9 = MathU.scale((float)i, 0f, (float)this.HeightSegments, num2, 0f);
                array[num4]      = new Vector3(x, y3, -num9);
                array[num4 + 1]  = new Vector3(x, y3, num9);
                array2[num4]     = new Vector2((float)i / (float)this.HeightSegments * 0.5f, (float)i / (float)this.HeightSegments);
                array2[num4 + 1] = new Vector2(1f - (float)i / (float)this.HeightSegments * 0.5f, (float)i / (float)this.HeightSegments);
                num4            += 2;
            }
            for (int i = 0; i < this.HeightSegments - 1; i++)
            {
                array3[num5]     = num6;
                array3[num5 + 1] = num6 + 2;
                array3[num5 + 2] = num6 + 3;
                array3[num5 + 3] = num6 + 3;
                array3[num5 + 4] = num6 + 1;
                array3[num5 + 5] = num6;
                num5            += 6;
                num6            += 2;
            }
            array3[num5]     = num4 - 1;
            array3[num5 + 1] = num4 - 2;
            array3[num5 + 2] = 6;
            num5            += 3;
            num6             = num4;
            for (int i = 0; i < this.HeightSegments; i++)
            {
                float x2    = MathU.scale((float)i, 0f, (float)this.HeightSegments, -num, 0f);
                float y4    = num3 * (float)i;
                float num10 = MathU.scale((float)i, 0f, (float)this.HeightSegments, num2, 0f);
                array[num4]      = new Vector3(x2, y4, -num10);
                array[num4 + 1]  = new Vector3(x2, y4, num10);
                array2[num4]     = new Vector2(1f - (float)i / (float)this.HeightSegments * 0.5f, (float)i / (float)this.HeightSegments);
                array2[num4 + 1] = new Vector2((float)i / (float)this.HeightSegments * 0.5f, (float)i / (float)this.HeightSegments);
                num4            += 2;
            }
            for (int i = 0; i < this.HeightSegments - 1; i++)
            {
                array3[num5]     = num6 + 1;
                array3[num5 + 1] = num6 + 3;
                array3[num5 + 2] = num6 + 2;
                array3[num5 + 3] = num6 + 2;
                array3[num5 + 4] = num6;
                array3[num5 + 5] = num6 + 1;
                num5            += 6;
                num6            += 2;
            }
            array3[num5]         = num4 - 2;
            array3[num5 + 1]     = num4 - 1;
            array3[num5 + 2]     = 7;
            this.mMesh.vertices  = array;
            this.mMesh.uv        = array2;
            this.mMesh.triangles = array3;
            this.mMesh.RecalculateNormals();
            this.mMesh.RecalculateBounds();
        }
    }
Example #7
0
    protected override void UpdateMeshFunc()
    {
        bool flag = this.Radius != 0f && this.Height != 0f;

        if (flag)
        {
            this.mMesh.name = "Capsule";
            int   num  = this.Rings + 1;
            float num2 = this.Height * 0.5f;
            float num3 = this.Height - this.Radius * 2f;
            float num4 = num3 * 0.5f;
            float num5 = (this.Height - num3) * 0.5f;
            int   num6 = this.HeightSegments + 1;
            float num7 = num3 / (float)this.HeightSegments;
            this.Sides++;
            int       num8   = this.Rings * 2 + 1;
            Vector3[] array  = new Vector3[(num8 + 1) * this.Sides + num6 * this.Sides];
            Vector2[] array2 = new Vector2[array.Length];
            Vector3[] array3 = new Vector3[array.Length];
            int[]     array4 = new int[this.Rings * 2 * (this.Sides - 1) * 6 + this.HeightSegments * (this.Sides - 1) * 6];
            float     num9   = 1f / (float)(num8 - 1);
            float     num10  = 1f / (float)(this.Sides - 1);
            int       num11  = 0;
            int       num12  = 0;
            int       num13  = num11;
            for (int i = 0; i < num6; i++)
            {
                for (int j = 0; j < this.Sides; j++)
                {
                    float f     = (float)j / (float)(this.Sides - 1) * 6.28318548f;
                    float num14 = -num4 + num7 * (float)i;
                    float num15 = Mathf.Cos(f);
                    float num16 = Mathf.Sin(f);
                    array[num11]  = new Vector3(this.Radius * num15, num14, this.Radius * num16);
                    array3[num11] = new Vector3(num15, 0f, num16);
                    array2[num11] = new Vector2((float)j * num10, MathU.scale(num14, -(num4 + num5), num4 + num5, 0f, 1f));
                    num11++;
                }
            }
            for (int i = 0; i < num6 - 1; i++)
            {
                for (int j = 0; j < this.Sides - 1; j++)
                {
                    int num17 = num13 + i * this.Sides + j;
                    int num18 = num13 + i * this.Sides + (j + 1);
                    int num19 = num13 + (i + 1) * this.Sides + (j + 1);
                    int num20 = num13 + (i + 1) * this.Sides + j;
                    array4[num12]     = num17;
                    array4[num12 + 1] = num19;
                    array4[num12 + 2] = num18;
                    array4[num12 + 3] = num19;
                    array4[num12 + 4] = num17;
                    array4[num12 + 5] = num20;
                    num12            += 6;
                }
            }
            this.Sides--;
            this.mMesh.vertices  = array;
            this.mMesh.uv        = array2;
            this.mMesh.triangles = array4;
            this.mMesh.normals   = array3;
            this.mMesh.RecalculateBounds();
        }
    }