Esempio n. 1
0
        public void CalculateAndSaveDistanceMapForPosition(int positionIndex, Bone[] testBones)
        {
            //quick check that we can do this. Don't need our own distance field, just the testBones'
            if (_coloredBone == null)
            {
                return;
            }

            //calculate the relative motion for each bone. Need a transform for each testBone, that will
            //move this bone into its coordinate system
            TransformMatrix[] transforms = new TransformMatrix[testBones.Length];
            if (positionIndex != 0) //in the neutral position, we are in the correct place
            {
                for (int i = 0; i < testBones.Length; i++)
                {
                    transforms[i] = CalculateRelativeMotionFromNeutral(positionIndex, testBones[i]);
                }
            }

            double[] distances = DistanceMaps.createDistanceMap(this, testBones, transforms);
            lock (_computedDistances)
            {
                _computedDistances[positionIndex] = distances;
            }
        }
Esempio n. 2
0
        public void CalculateAndSaveDistanceMapForAnimation(int[] animationOrder, int numFramesPerStep, int absoluteFrameNumber, Bone[] testBones, Bone fixedBone)
        {
            //quick check that we can do this. Don't need our own distance field, just the testBones'
            if (_coloredBone == null)
            {
                return;
            }

            //need to calculate where we are in the whole animation scheme. What two positions are we between?
            int startPositionIndex = absoluteFrameNumber / numFramesPerStep;
            int partialFrame       = absoluteFrameNumber % numFramesPerStep;
            int startPosition      = animationOrder[startPositionIndex];

            //calculate the relative motion for each bone. Need a transform for each testBone, that will
            //move this bone into its coordinate system
            TransformMatrix[] transforms = new TransformMatrix[testBones.Length];
            if (partialFrame == 0)      //no partial frame, we are exactly where we want to be
            {
                if (startPosition != 0) //if we are at absolute neutral, no calculations needed
                {
                    //check for the non
                    for (int i = 0; i < testBones.Length; i++)
                    {
                        transforms[i] = CalculateRelativeMotionFromNeutral(startPosition, testBones[i]);
                    }
                }
            }
            else
            {
                //so we have a partial motion to deal with, first calculate the position of the current bone
                TransformMatrix tmCurrentBone = CalculateInterpolatedMotion(startPosition, animationOrder[startPositionIndex + 1], fixedBone, numFramesPerStep)[partialFrame];
                for (int i = 0; i < testBones.Length; i++)
                {
                    TransformMatrix tmTestBone = testBones[i].CalculateInterpolatedMotion(startPosition, animationOrder[startPositionIndex + 1], fixedBone, numFramesPerStep)[partialFrame];
                    transforms[i] = tmTestBone.Inverse() * tmCurrentBone;
                }
            }

            double[] distances = DistanceMaps.createDistanceMap(this, testBones, transforms);
            lock (this)
            {
                if (_animationComputedDistances == null)
                {
                    _animationComputedDistances = new double[(animationOrder.Length - 1) * numFramesPerStep + 1][];
                }
                _animationComputedDistances[absoluteFrameNumber] = distances;
            }
        }