Exemplo n.º 1
0
 public GenericTrajectory(GenericTrajectory <T> other)
 {
     tValues   = new ArrayList();
     values    = new ArrayList();
     lastIndex = 0;
     copy(other);
 }
Exemplo n.º 2
0
        /**
         *      Simplify the curve by iteratively adding knots
         */
        public void simplify_catmull_rom(float maxError, int nbSamples = 100)
        {
            if (getKnotCount() < 3)
            {
                return;
            }

            float startTime = (float)tValues[0];
            float endTime   = (float)tValues[tValues.Count - 1];

            GenericTrajectory <T> result = new GenericTrajectory <T>();

            result.addKnot(startTime, (T)values[0]);
            result.addKnot(endTime, (T)values[values.Count - 1]);

            while (true)
            {
                float currError     = 0;
                float currErrorTime = -1000000;

                for (int i = 0; i < nbSamples; ++i)
                {
                    float interp = (float)i / (nbSamples - 1.0f);
                    float time   = startTime * (1 - interp) + endTime * interp;
                    float error  = 0;

                    if (typeof(T) == typeof(Vector3))
                    {
                        error = trajectoryAbs((Vector3)(object)result.evaluate_catmull_rom(time) - (Vector3)(object)evaluate_catmull_rom(time));
                    }
                    else if (typeof(T) == typeof(float))
                    {
                        error = trajectoryAbs((float)(object)result.evaluate_catmull_rom(time) - (float)(object)evaluate_catmull_rom(time));
                    }

                    if (error > currError)
                    {
                        currError     = error;
                        currErrorTime = time;
                    }
                }

                if (currError <= maxError)
                {
                    break;
                }

                result.addKnot(currErrorTime, evaluate_catmull_rom(currErrorTime));
            }

            copy(result);
        }
Exemplo n.º 3
0
        public void copy(GenericTrajectory <T> other)
        {
            if (other == this)
            {
                return;
            }

            tValues.Clear();
            values.Clear();
            int size = other.getKnotCount();

            for (int i = 0; i < size; ++i)
            {
                tValues.Add(other.tValues[i]);
                values.Add(other.values[i]);
            }
        }