Example #1
0
    private void saveTriangleIndexToFile(string fileName)
    {
        float[] shoulderL = planes.getControlPlane("shoulderLeft");
        float[] shoulderR = planes.getControlPlane("shoulderRight");
        //float[] back = planes.getControlPlane ("back");

        int[] tri = clothMesh.triangles;
        //Vector3[] vertices = clothMesh.vertices;
        Vector3[] vertices = clothVertices;
        string    data     = "";
        int       index    = 0;

        for (int i = 0; i < tri.Length; i += 3, index++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (!AuxMath.isAbovePlane(vertices [tri [i + j]], shoulderL) &&
                    !AuxMath.isAbovePlane(vertices [tri [i + j]], shoulderR)
                    )
                {
                    data += index.ToString() + " ";
                    break;
                }
            }
        }
        FileOperator.SaveDataToFile(fileName, data);
    }
Example #2
0
        public static float GetFieldOfView(this HeadsetModel headset, Axis axis)
        {
            float vertical;

            switch (headset)
            {
            case HeadsetModel.Fove:         vertical = 95;  break;

            case HeadsetModel.VivePro:      vertical = 110; break;

            case HeadsetModel.None60:       vertical = 60;  break;

            case HeadsetModel.None120:      vertical = 120; break;

            case HeadsetModel.FHD60:        vertical = 60;  break;

            default:                                        throw new Exception();
            }

            switch (axis)
            {
            case Axis.Horizontal:   return(AuxMath.HorizontalFoV(vertical, headset.GetAspectRatio()));

            case Axis.Vertical:             return(vertical);

            default:                                throw new Exception();
            }
        }
Example #3
0
    // 臀围
    private void scaleHipGrith(float scale)
    {
        Vector3[] old    = sizedMesh.vertices;
        Vector3[] tmp    = templateMesh.vertices;
        Vector3[] tmpLen = templateLenMesh.vertices;
        ArrayList vertex = templateBody.vertexIndexsPerBone [HumanBone.Pelvis];
        float     top    = planes.getPlaneHeight("PlaneHipTop");

        float[] topPlane = planes.getControlPlane("PlaneHipTop");
        float   hip      = planes.getPlaneHeight("PlaneHip");
        float   bottom   = planes.getPlaneHeight("PlaneHipBottom");
        float   height   = top - bottom;
        float   std      = ControlPoints.hipBezier.getBezierPoint((hip - bottom) / height).z;

        for (int i = 0; i < vertex.Count; ++i)
        {
            if (!AuxMath.isAbovePlane(tmp [(int)vertex [i]], topPlane) && tmp [(int)vertex [i]].y > bottom)
            {
                float   ratio         = (tmp [(int)vertex [i]].y - bottom) / height;
                float   p             = (ControlPoints.hipBezier.getBezierPoint(ratio).z - std) / 5.0f + 1.0f;
                Vector3 projectNormal = AuxMath.projectOnPlane(templateMesh.normals [(int)vertex [i]], Vector3.up);
                float   cosAngel      = Vector3.Dot(projectNormal.normalized, Vector3.back);
                float   k             = (scale - 1.0f) * cosAngel +
                                        Mathf.Sqrt((scale - 1.0f) * (scale - 1.0f) * cosAngel * cosAngel + 2 * scale - 1);
                old [(int)vertex [i]] = tmpLen [(int)vertex [i]] +
                                        (templateMesh.normals [(int)vertex [i]] * (k - 1.0f) * measurement [HumanSize.Hip_Grith] * p);
            }
        }
        sizedMesh.vertices = old;
    }
Example #4
0
    // 胸围
    private void scaleBustGrith(float scale)
    {
        Vector3[] old    = sizedMesh.vertices;
        Vector3[] tmp    = templateMesh.vertices;
        Vector3[] tmpLen = templateLenMesh.vertices;
        ArrayList vertex = templateBody.vertexIndexsPerBone [HumanBone.Spine2];

        float[] top         = planes.getControlPlane("PlaneBustTop");
        float[] topL        = planes.getControlPlane("PlaneBustTopLeft");
        float[] topR        = planes.getControlPlane("PlaneBustTopRight");
        float[] bust        = planes.getControlPlane("PlaneBust");
        float[] bottom      = planes.getControlPlane("PlaneBustBottom");
        Vector3 busthNormal = new Vector3(bust [0], bust [1], bust [2]);

        // Scale the left thigh
        for (int i = 0; i < vertex.Count; ++i)
        {
            if (AuxMath.isAbovePlane(tmp [(int)vertex [i]], top) !=
                AuxMath.isAbovePlane(tmp [(int)vertex [i]], bottom))
            {
                if (!AuxMath.isAbovePlane(tmp [(int)vertex [i]], topL) &&
                    !AuxMath.isAbovePlane(tmp [(int)vertex [i]], topR))
                {
                    Vector3 projectNormal = AuxMath.projectOnPlane(templateMesh.normals [(int)vertex [i]],
                                                                   busthNormal);
                    float cosAngel = Vector3.Dot(projectNormal.normalized, Vector3.forward);
                    float k        = (scale - 1.0f) * cosAngel +
                                     Mathf.Sqrt((scale - 1.0f) * (scale - 1.0f) * cosAngel * cosAngel + 2 * scale - 1);
                    old [(int)vertex [i]] = tmpLen [(int)vertex [i]] +
                                            (templateMesh.normals [(int)vertex [i]] * (k - 1.0f) * measurement [HumanSize.Bust_Grith]);
                }
            }
        }
        sizedMesh.vertices = old;
    }
Example #5
0
    // 腰围
    private void scaleWaistGrith(float scale)
    {
        Vector3[] old    = sizedMesh.vertices;
        Vector3[] tmp    = templateMesh.vertices;
        Vector3[] tmpLen = templateLenMesh.vertices;
        ArrayList vertex = templateBody.vertexIndexsPerBone [HumanBone.Pelvis];
        float     top    = planes.getPlaneHeight("PlaneWaistTop");
        float     waist  = planes.getPlaneHeight("PlaneWaist");
        float     bottom = planes.getPlaneHeight("PlaneWaistBottom");
        float     height = top - bottom;
        float     std    = ControlPoints.wasitBezier.getBezierPoint((waist - bottom) / height).z;

        for (int i = 0; i < vertex.Count; ++i)
        {
            if (tmp [(int)vertex [i]].y <top && tmp [(int)vertex [i]].y> bottom)
            {
                float   ratio         = (tmp [(int)vertex [i]].y - bottom) / height;
                float   p             = (ControlPoints.wasitBezier.getBezierPoint(ratio).z - std) / 5.0f + 1.0f;
                Vector3 projectNormal = AuxMath.projectOnPlane(templateMesh.normals [(int)vertex [i]], Vector3.up);
                float   cosAngel      = Vector3.Dot(projectNormal.normalized, Vector3.forward);
                //float sinAngel_square = 1.0f - cosAngel * cosAngel;
                float k = (scale - 1.0f) * cosAngel +
                          Mathf.Sqrt((scale - 1.0f) * (scale - 1.0f) * cosAngel * cosAngel + 2 * scale - 1);
                old [(int)vertex [i]] = tmpLen [(int)vertex [i]] +
                                        (templateMesh.normals [(int)vertex [i]] * (k - 1.0f) * measurement [HumanSize.Waist_Grith] * p);
            }
        }
        sizedMesh.vertices = old;
    }
Example #6
0
        private static Color AddRandomSeeds(Color pixel)
        {
            var random = new System.Random((int)AuxMath.CantorPair(pixel.r, pixel.g));

            pixel.b = (float)random.NextDouble();
            pixel.a = (float)random.NextDouble();

            return(pixel);
        }
Example #7
0
        public static float CalculateC(float phi0)
        {
            var c = 0f;

            if (IsSuperior(phi0))
            {
                c = 1.9f + 1.4f * AuxMath.Tanh((phi0 - 121) / 14);
            }
            else
            {
                c = 1.0f + .5f * AuxMath.Tanh((-phi0 - 90) / 25);
            }

            return(c);
        }
Example #8
0
    // 大腿围
    private void scaleThighGrith(float scale)
    {
        Vector3[] old    = sizedMesh.vertices;
        Vector3[] tmp    = templateMesh.vertices;
        Vector3[] tmpLen = templateLenMesh.vertices;
        ArrayList vertex = templateBody.vertexIndexsPerBone [HumanBone.L_Thigh];

        float[] top         = planes.getControlPlane("PlaneThighTopLeft");
        float[] thigh       = planes.getControlPlane("PlaneThigh");
        float[] bottom      = planes.getControlPlane("PlaneThighBottom");
        Vector3 thighNormal = new Vector3(thigh [0], thigh [1], thigh [2]);

        // Scale the left thigh
        for (int i = 0; i < vertex.Count; ++i)
        {
            if (AuxMath.isAbovePlane(tmp [(int)vertex [i]], top) !=
                AuxMath.isAbovePlane(tmp [(int)vertex [i]], bottom))
            {
                Vector3 projectNormal = AuxMath.projectOnPlane(templateMesh.normals [(int)vertex [i]],
                                                               thighNormal);
                float cosAngel = Vector3.Dot(projectNormal.normalized, Vector3.back);
                float k        = (scale - 1.0f) * cosAngel +
                                 Mathf.Sqrt((scale - 1.0f) * (scale - 1.0f) * cosAngel * cosAngel + 2 * scale - 1);
                old [(int)vertex [i]] = tmpLen [(int)vertex [i]] +
                                        (templateMesh.normals [(int)vertex [i]] * (k - 1.0f) * measurement [HumanSize.Thigh_Grith]);
            }
        }
        // Scale the Right Thigh
        vertex = templateBody.vertexIndexsPerBone [HumanBone.R_Thigh];
        top    = planes.getControlPlane("PlaneThighTopRight");
        for (int i = 0; i < vertex.Count; ++i)
        {
            if (AuxMath.isAbovePlane(tmp [(int)vertex [i]], top) !=
                AuxMath.isAbovePlane(tmp [(int)vertex [i]], bottom))
            {
                Vector3 projectNormal = AuxMath.projectOnPlane(templateMesh.normals [(int)vertex [i]],
                                                               thighNormal);
                float cosAngel = Vector3.Dot(projectNormal.normalized, Vector3.back);
                float k        = (scale - 1.0f) * cosAngel +
                                 Mathf.Sqrt((scale - 1.0f) * (scale - 1.0f) * cosAngel * cosAngel + 2 * scale - 1);
                old [(int)vertex [i]] = tmpLen [(int)vertex [i]] +
                                        (templateMesh.normals [(int)vertex [i]] * (k - 1.0f) * measurement [HumanSize.Thigh_Grith]);
            }
        }
        sizedMesh.vertices = old;
    }
Example #9
0
    private void initGrith(string planeName, HumanSize grithKey, HumanBone planeInBone)
    {
        float[] plane = { 0.0f, 0.0f, 0.0f, 0.0f };
        planes.getControlPlane(planeName, plane);
        ArrayList grithList = new ArrayList();
        ArrayList edgeList  = templateBody.edgeIndexsPerBone [planeInBone];

        for (int i = 0; i < edgeList.Count; i++)
        {
            Edge e = edgeList [i] as Edge;
            if (AuxMath.isAbovePlane(templateMesh.vertices [e.e1], plane) !=
                AuxMath.isAbovePlane(templateMesh.vertices [e.e2], plane))
            {
                Vector3 intersectPoint = AuxMath.intersectPlane(templateMesh.vertices [e.e1],
                                                                templateMesh.vertices [e.e2],
                                                                plane);
                if (intersectPoint != AuxMath.nullVector)
                {
                    if (HumanSize.Thigh_Grith == grithKey)
                    {
                        if (intersectPoint.x < 0.0f)
                        {
                            grithList.Add(intersectPoint);
                        }
                    }
                    else
                    {
                        grithList.Add(intersectPoint);
                    }
                }
            }
        }
        if (grithList.Count > 0)
        {
            ArrayList grithIndex = new ArrayList();
            AuxMath.convexInPlane(new Vector3(plane [0], plane [1], plane [2]),
                                  grithList, grithIndex);
            initMeasurements [(int)grithKey - 1] = AuxMath.getLength(grithIndex, grithList);
            measurement [grithKey] = initMeasurements [(int)grithKey - 1] / (2.0f * Mathf.PI);
        }
    }
Example #10
0
        private static float ClosestPhi0(Vector2 polar, float from, float to, int resolution)
        {
            var increment = (to - from) / resolution;

            var closestPhi0 = float.MaxValue;
            var closestPhi  = float.MaxValue;

            for (int i = 0; i < resolution; i++)
            {
                var estPhi0 = from + increment * i;
                estPhi0 = AuxMath.Overflow(estPhi0, -180, 180);

                var estPhi = AxonModel.CalculatePhi(estPhi0, polar.x);
                if (Mathf.Abs(polar.y - estPhi) < Mathf.Abs(polar.y - closestPhi))
                {
                    closestPhi  = estPhi;
                    closestPhi0 = estPhi0;
                }
            }

            return(closestPhi0);
        }
Example #11
0
        public static float CalculateB(float phi0)
        {
            float lnB;

            if (IsSuperior(phi0))
            {
                lnB = -1.9f + 3.9f * AuxMath.Tanh(-(phi0 - 121) / 14);
            }
            else
            {
                lnB = .5f + 1.5f * AuxMath.Tanh(-(-phi0 - 90) / 25);
            }

            var b = Mathf.Exp(lnB);

            if (IsInferior(phi0))
            {
                b = -b;
            }

            return(b);
        }
Example #12
0
 void Update()
 {
     uiElement.sizeDelta *= 1 + Input.GetAxis("Mouse ScrollWheel") * _zoomSpeed;
     uiElement.sizeDelta  = AuxMath.Clamp(uiElement.sizeDelta, StartingSize * _minZoom, StartingSize * _maxZoom);
 }
Example #13
0
        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            lock (this.MyBody)
            {
                if (e.KeyData == Keys.Up)
                {
                    this.MyBody.Velocity = new LM.Senac.BouncingBall.Physics.Vector2d(this.MyBody.Velocity.X, this.MyBody.Velocity.Y - 30);
                }
                if (e.KeyData == Keys.Down)
                {
                    this.MyBody.Velocity = new LM.Senac.BouncingBall.Physics.Vector2d(this.MyBody.Velocity.X, this.MyBody.Velocity.Y + 30);
                }
                if (e.KeyData == Keys.Left)
                {
                    this.MyBody.Velocity = new LM.Senac.BouncingBall.Physics.Vector2d(this.MyBody.Velocity.X - 5, this.MyBody.Velocity.Y);
                }
                if (e.KeyData == Keys.Right)
                {
                    this.MyBody.Velocity = new LM.Senac.BouncingBall.Physics.Vector2d(this.MyBody.Velocity.X + 5, this.MyBody.Velocity.Y);
                }
            }

            lock (this.MainGame.MyPlanet.Bodies)
            {
                if (e.KeyData == Keys.L)
                {
                    Body bd = new Body();
                    bd.UseGravity = true;
                    bd.Color      = Brushes.Black;
                    bd.Position   = new LM.Senac.BouncingBall.Physics.Vector2d(400, 400);
                    bd.Velocity   = AuxMath.AngleDegreesToVector(85, -135);
                    bd.Size       = new Size2d(12, 12);
                    this._mainGame.MyPlanet.AddBody(bd);
                }
                if (e.KeyData == Keys.K)
                {
                    Body bd = new Body();
                    bd.UseGravity = true;
                    bd.Color      = Brushes.Black;
                    bd.Position   = new LM.Senac.BouncingBall.Physics.Vector2d(30, 400);
                    bd.Velocity   = AuxMath.AngleDegreesToVector(85, -45);
                    bd.Size       = new Size2d(12, 12);
                    this._mainGame.MyPlanet.AddBody(bd);
                }
                if (e.KeyData == Keys.J)
                {
                    Body bd = new Body();
                    bd.UseGravity = true;
                    bd.Color      = Brushes.Black;
                    bd.Position   = new LM.Senac.BouncingBall.Physics.Vector2d(70, 400);
                    bd.Velocity   = AuxMath.AngleDegreesToVector(85, -90);
                    bd.Size       = new Size2d(12, 12);
                    this._mainGame.MyPlanet.AddBody(bd);
                }
            }

            if (e.KeyData == Keys.Add)
            {
                this.MainGame.MyPlanet.Gravity += 5d;
            }

            if (e.KeyData == Keys.Subtract)
            {
                this.MainGame.MyPlanet.Gravity -= 5d;
            }

            if (e.KeyData == Keys.C)
            {
                this.Clear();
            }

            if (e.KeyData == Keys.R)
            {
                this.InitializeBodies();
            }

            if (e.KeyData == Keys.P)
            {
                this._mainGame.Paused();
            }
        }