示例#1
0
        internal void update(bool parentUpdated)
        {
            if (HasControlsToSolve) //Control solve
            {
                if (BeforeUpdate != null)
                {
                    BeforeUpdate.Invoke(this);
                }

                //Seed needupdate, will be true if there are external controls or the parent was updated
                bool needUpdate = externalControls.Count > 0 || parentUpdated;

                foreach (var control in controls)
                {
                    //See if any controls moved
                    needUpdate           |= control.MovedThisTick;
                    control.MovedThisTick = false;
                    control.syncPosition();
                }

                //Something requires us to update
                if (needUpdate)
                {
                    ikSolver.Solve(solveControls);
                    parentUpdated   = true;
                    updatedThisTick = true;
                }
            }
            else if (AutosolveOnParentUpdate && parentUpdated) //Solve bones if parent updated and no controls
            {
                if (BeforeUpdate != null)
                {
                    BeforeUpdate.Invoke(this);
                }

                ikSolver.Solve(solveBones);

                updatedThisTick = true;
            }

            foreach (var child in childSolvers)
            {
                child.update(parentUpdated);
            }
        }
示例#2
0
        protected override void Step()
        {
            solver.Solve(controls);

            foreach (var bone in bones)
            {
                bone.Entity.Position        = bone.Bone.Position;
                bone.Entity.Orientation     = Quaternion.Concatenate(bone.LocalRotationBoneToEntity, bone.Bone.Orientation);
                bone.Entity.AngularVelocity = new Vector3();
                bone.Entity.LinearVelocity  = new Vector3();
            }
        }
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public InverseKinematicsTestDemo2(DemosGame game)
            : base(game)
        {
            game.Camera.Position = new Vector3(0, 3, 5);
            Box ground = new Box(new Vector3(0, -3, 0), 30, 1, 30);

            Space.Add(ground);
            Space.ForceUpdater.Gravity = new Vector3(0, -9.81m, 0);

            var solver = new IKSolver();

            solver.ActiveSet.UseAutomass = true;
            //solver.AutoscaleControlImpulses = true;
            //solver.AutoscaleControlMaximumForce = Fix64.MaxValue;
            solver.ControlIterationCount     = 20;
            solver.FixerIterationCount       = 0;
            solver.VelocitySubiterationCount = 3;


            List <Bone>   bones;
            List <Entity> boneEntities;
            int           boneCount = 10;

            BuildStick(new Vector3(0, 0.5m, 0), boneCount, out bones, out boneEntities);

            DragControl dragger = new DragControl {
                TargetBone = bones[boneCount - 1], MaximumForce = Fix64.MaxValue
            };

            dragger.LinearMotor.Rigidity       = 16;
            dragger.LinearMotor.LocalOffset    = new Vector3(0, 0.5m, 0);
            dragger.LinearMotor.TargetPosition = new Vector3(10, 0, 0);


            bones[0].Pinned = true;

            var controls = new List <Control>();

            controls.Add(dragger);

            solver.Solve(controls);

            var tipLocation = bones[boneCount - 1].Position + Matrix3x3.CreateFromQuaternion(bones[boneCount - 1].Orientation).Up * 0.5m;

            for (int i = 0; i < bones.Count; ++i)
            {
                boneEntities[i].Position    = bones[i].Position;
                boneEntities[i].Orientation = bones[i].Orientation;
                Space.Add(boneEntities[i]);
            }
        }
示例#4
0
 void LateUpdate()
 {
     IKSolver.Solve(false, 1f, 1f, 0f, -1, -1, upperLimb, lowerLimb, endLimb, elbowForward, target.position, Vector3.zero, target.rotation);
 }