Exemple #1
0
        /**
         *      This method is used to compute the torques that are to be applied at the next step.
         */
        override public void computeTorques()
        {
            ReducedCharacterState rs = new ReducedCharacterState(desiredPose);

            for (int i = 0; i < jointCount; i++)
            {
                CWJoint joint = character.getJoint(i);
                if (!joint.getRelToRootFrame())
                {
                    targetOrientation[i] = rs.getJointRelativeOrientation(i);
                }
                else
                {
                    targetOrientation[i] = Quaternion.Inverse(joint.getParent().getOrientation()) * (currentHeading * rs.getJointRelativeOrientation(i));
                }
            }
        }
Exemple #2
0
        public PoseController(Character ch) : base(ch)
        {
            //copy the current state of the character into the desired pose - makes sure that it's the correct size
            //Debug.Log("PoseController===================================================");
            desiredPose    = ch.getState();
            characterFrame = Quaternion.identity;
            currentHeading = Quaternion.identity;
            desiredHeading = Quaternion.identity;

            //set initial values
            ReducedCharacterState rs = new ReducedCharacterState(desiredPose);

            rs.setPosition(Vector3.zero);
            rs.setVelocity(Vector3.zero);
            rs.setOrientation(Quaternion.identity);
            rs.setAngularVelocity(Vector3.zero);

            for (int i = 0; i < jointCount; i++)
            {
                //Debug.Log(ch.getJoint(i).name + "+++++++++++++++++++++++++++++++ "+i);
                rs.setJointRelativeAngVelocity(Vector3.zero, i);
                rs.setJointRelativeOrientation(Quaternion.identity, i);
            }
        }
Exemple #3
0
        public void evaluateJointTargets()
        {
            ReducedCharacterState poseRS = new ReducedCharacterState(desiredPose);

            //d and v are specified in the rotation (heading) invariant coordinate frame
            updateDAndV();

            //there are two stages here. First we will compute the pose (i.e. relative orientations), using the joint trajectories for the current state
            //and then we will compute the PD torques that are needed to drive the links towards their orientations - here the special case of the
            //swing and stance hips will need to be considered

            //always start from a neutral desired pose, and build from there...
            root.setExternalForce(Vector3.zero);
            root.setExternalTorque(Vector3.zero);
            CWJoint j;

            for (int i = 0; i < jointCount; i++)
            {
                j = character.getJoint(i);
                j.getChild().setExternalForce(Vector3.zero);
                j.getChild().setExternalTorque(Vector3.zero);
                poseRS.setJointRelativeOrientation(Quaternion.identity, i);
                poseRS.setJointRelativeAngVelocity(Vector3.zero, i);
            }

            float phiToUse = phi;

            //make sure that we only evaluate trajectories for phi values between 0 and 1
            if (phiToUse > 1)
            {
                phiToUse = 1;
            }

            Vector3 force  = Vector3.zero;
            Vector3 torque = Vector3.zero;

            // First compute external forces
            for (int i = 0; i < currentState.getExternalForceCount(); i++)
            {
                ExternalForce ef  = currentState.getExternalForce(i);
                CWRigidBody   arb = character.getArticulatedRigidBody(ef.getARBIndex(stance));

                force  = Vector3.zero;
                force += character.getLocalFrontAxis() * ef.forceX.evaluate_catmull_rom(phiToUse);
                force += character.getLocalUpAxis() * ef.forceY.evaluate_catmull_rom(phiToUse);
                force += character.getLocalLeftAxis() * ef.forceZ.evaluate_catmull_rom(phiToUse);
                force  = characterFrame * force;
                arb.addExternalForce(force);

                torque  = Vector3.zero;
                torque += character.getLocalFrontAxis() * ef.torqueX.evaluate_catmull_rom(phiToUse);
                torque += character.getLocalUpAxis() * ef.torqueY.evaluate_catmull_rom(phiToUse);
                torque += character.getLocalLeftAxis() * ef.torqueZ.evaluate_catmull_rom(phiToUse);
                torque  = characterFrame * torque;
                arb.addExternalTorque(torque);
            }
            //Debug.Log(Random.value + "ffffffffffff  "+curState.getTrajectoryCount());
            for (int i = 0; i < currentState.getTrajectoryCount(); i++)
            {
                Trajectory tra = currentState.getTrajectory(i);
                //now we have the desired rotation angle and axis, so we need to see which joint this is intended for
                int jIndex = tra.getJointIndex(stance, isLeftReverseStance);
                //Debug.Log(Random.value + "00000000000  "+(curState.sTraj[i] as Trajectory).getJointName());
                j = character.getJoint(jIndex);

                //get the desired joint orientation to track - include the feedback if necessary/applicable
                Vector3 d0 = new Vector3();
                Vector3 v0 = new Vector3();
                computeD0(phiToUse, ref d0);
                computeV0(phiToUse, ref v0);

                //if the index is -1, it must mean it's the root's trajectory. Otherwise we should give an error
                if (jIndex == -1)
                {
                    qRootD = tra.evaluateTrajectory(this, j, stance, phiToUse, d - d0, v - v0);
                }
                else
                {
                    Quaternion newOrientation = tra.evaluateTrajectory(this, j, stance, phiToUse, d - d0, v - v0);
                    j.setRelToRootFrame(tra.relToCharFrame);
                    poseRS.setJointRelativeOrientation(newOrientation, jIndex);
                }

                if (tra.hitFeedback != null)
                {
                    CWRigidBody arb = character.getArticulatedRigidBody(tra.hitFeedback.hitARBIndex);
                    if (phiToUse > tra.hitFeedback.minTime && arb.contactPoints.Count > 0)
                    {
                        ContactPointInfo cp = (ContactPointInfo)arb.contactPoints[0];
                        onHitOtherSBCharacter(tra.hitFeedback, cp);
                    }
                }
            }
        }