Example #1
0
        private void UpdatePath(int pathID)
        {
            EntityManager em = World.Active.GetOrCreateManager <EntityManager>();

            // Debug.Log("Updating Path: ID-" + pathEntity.Index + "-" + pathEntity.Version);

            var pathCurvesBuffer = em.GetBufferFromEntity <CurveElement>()[Database.worldPaths[pathID]];

            //int curvesCount = em.GetBufferFromEntity<CurveElement>()[Database.worldPaths[pathID]].Length;
            //float3[] pathPoints = new float3[curvesCount * (BootStrap.Settings.pathResolution + 1)];
            //int pathPointer = 0;

            float4 lastWeight = new float4(0f, 0f, 0f, 1f); // (x,y,z,w)

            DualQuaternion[] pathsCDH = new DualQuaternion[pathCurvesBuffer.Length * (BootStrap.Settings.pathResolution + 1)];
            DualQuaternion[] temp     = { new DualQuaternion(new float4(), new float4()) }; // dummy object

            int index = 0;

            for (int i = 0; i < pathCurvesBuffer.Length; i++)
            {
                Entity curveEntity = pathCurvesBuffer[i];
                // Dep on Curve Type: // Calc Deltas // Calc Weigth
                DualQuaternion[] curveCDH  = temp;
                byte             curveType = em.GetComponentData <CurveInfo>(curveEntity).type;
                if (curveType == CurveTypes.p5)
                {
                    curveCDH = Calc5pCurveParams.GenerateCurvePoints(lastWeight, curveEntity);
                }
                else if (curveType == CurveTypes.p3v2)
                {
                    curveCDH = CalcVecCurveParams.GenerateCurvePoints(lastWeight, curveEntity);
                }

                for (int j = 1; j <= curveCDH.Length; j++)
                {
                    pathsCDH[index++] = curveCDH[j - 1]; // ATEITI GAL DETI I ENTITY.Buffer
                    //Debug.Log(pathsCDH[i * j].Wt + " " + pathsCDH[i * j].Ft);
                    // Debug.Log((index) + " " + (j - 1));
                }

                lastWeight = em.GetComponentData <LastWeight>(curveEntity).Value;
                //foreach (var v in curve) pathPoints[pathPointer++] = v;
            }

            if (Database.PathsDisplacementQuaternions.ContainsKey(pathID))
            {
                Database.PathsDisplacementQuaternions[pathID] = pathsCDH;
            }
            else
            {
                Database.PathsDisplacementQuaternions.Add(pathID, pathsCDH);
            }
            //Debug.Log(Database.PathsDisplacementQuaternions.ContainsKey(pathID));
            //LineRendererSystem.SetPolygonPoints(pathID, pathPoints);
        }
Example #2
0
        private static float4 DisplacementRotation(DualQuaternion c, float4 x)
        {
            // c=[p;q] atitinka [Wt,Ft] ; x=[0, x,y,z]
            // c:x -> p*x*inv(p); just rotation
            float4 p = c.Wt, q = c.Ft;                           // p - tik su svoriais, q - su taskai+svoriais
                                                                 //Vector4 newPoint = H.Mult(H.Mult(p, x) + 1.0f*q, H.Invers(p));
            //float4 newPoint = H.Mult(H.Mult(p, x), H.Invers(p)); // tik posukis
            float4 newPoint = H.Mult(H.Mult(p, x), H.Invers(p)); // tik posukis

            return(newPoint);
        }
Example #3
0
        private static float4 DisplacementMovement(DualQuaternion c)
        {
            // c=[p;q]; x=[0, x,y,z]
            // c:x -> (q*x - 2*p)*Inv(q);
            //float4 p = c[0], q = c[1];
            //float4 newPoint = H.Mult(H.Mult(p, x) + 1.0f * q, H.Invers(p));

            // TAIP IRGI VEIKIA
            float4 curvePoint = H.Mult(c.Ft, H.Invers(c.Wt)); //H.Mult(Ft, H.Invers(Wt)) = making path of movement

            return(curvePoint);
        }
        public static DualQuaternion[] GenerateCurve(float4[] points, float4[] weights)
        {
            float[]          timePath = CalculateTimeListSystem.timePath;
            DualQuaternion[] cDHarr   = new DualQuaternion[timePath.Length];
            // qt-pwf(t); pt-wf(t);
            // Visis C(t) bus Img(H)
            float3[] curve = new float3[timePath.Length];
            float4   Ft, Wt;

            for (int t = 0; t < timePath.Length; t++)
            {
                Ft = new float4(0, 0, 0, 0); // q(t)
                Wt = new float4(0, 0, 0, 0); // p(t)

                List <float> fiList = getFiList(timePath[t]);

                for (int i = 0; i < BootStrap.Settings.TList.Length; i++)
                {
                    //t yra rezoliucijos delta step
                    if (points.Length == 5)
                    {
                        Ft += H.Mult(points[i * 2], weights[i]) * fiList[i];
                    }
                    else
                    {
                        Ft += H.Mult(points[i], weights[i]) * fiList[i];
                    }
                    Wt += weights[i] * fiList[i];
                }
                //Debug.Log(Wt +" ... "+ Ft);
                cDHarr[t] = new DualQuaternion(Wt, Ft); // Movement & Rotation Quaternions

                // float4 curvePoint= H.Mult(Ft, H.Invers(Wt)); // making path of movement
                //curve[t] = new float3(curvePoint.x, curvePoint.y, curvePoint.z);
            }
            return(cDHarr);
        }