Ejemplo n.º 1
0
        public MotionPath(string pathdescriptor)
        {
            //Abuse the Lua runtime to parse the path descriptor for us
            var  rt             = new LuaRunner(env);
            var  path           = (LuaTable)(rt.DoString("path = {" + pathdescriptor + "}")["path"]);
            bool hasOrientation = true;
            var  type           = (int)path[0];

            loop = type == CLOSED;
            //detect if orientations are present
            var orient = (LuaTable)path[2];

            if (orient.Capacity < 4)
            {
                hasOrientation = false;
            }
            //Construct path

            for (int i = 1; i < path.Capacity; i++)
            {
                if (hasOrientation && i % 2 == 0)
                {
                    quaternions.Add(GetQuat(path[i]));
                }
                else
                {
                    points.Add(GetVec(path[i]));
                }
            }
            if (points.Count > 2)
            {
                curve = true;
            }
        }
Ejemplo n.º 2
0
        public MotionPath(string pathdescriptor)
        {
            //Abuse the Lua runtime to parse the path descriptor for us
            var rt   = new LuaRunner(env);
            var path = (LuaTable)(rt.DoString("path = {" + pathdescriptor + "}")["path"]);
            var type = (int)path[0];

            loop = type == CLOSED;
            //detect if orientations are present
            var orient = (LuaTable)path[2];

            if (orient.Capacity >= 4)
            {
                HasOrientation = true;
            }
            var points      = new List <Vector3>();
            var quaternions = new List <Quaternion>();

            //Construct path
            for (int i = 1; i < path.Capacity; i++)
            {
                if (HasOrientation && i % 2 == 0)
                {
                    quaternions.Add(GetQuat(path[i]));
                }
                else
                {
                    points.Add(GetVec(path[i]));
                }
            }
            if (loop)
            {
                quaternions.Add(quaternions[0]);
            }
            if (points.Count < 2)
            {
                throw new Exception("Path does not have minimum two points");
            }
            if (points.Count > 2)
            {
                curve      = true;
                curveQuats = quaternions.ToArray();
            }

            startPoint = points[0];
            endPoint   = points[points.Count - 1];
            startQuat  = quaternions[0];
            endQuat    = quaternions[quaternions.Count - 1];
            //
            if (curve)
            {
                BuildSegments(points);
            }
        }