Exemplo n.º 1
0
        /**
         *      this method is used to rotate the character about the vertical axis, so that it's default heading has the value that is given as a parameter
         */
        public void recenter()
        {
            ArrayList             state = getState();
            ReducedCharacterState chS   = new ReducedCharacterState(state);
            Vector3 currPos             = chS.getPosition();

            currPos.x = currPos.z = 0;
            chS.setPosition(currPos);
            setState(state);
        }
Exemplo n.º 2
0
        /**
         *      This method populates the state of the current character with the values that are passed
         *      in the dynamic array. The same conventions as for the getState() method are assumed.
         */
        public void setState(ArrayList state, int start = 0, bool hackFlag = true)
        {
            //updateJointOrdering();
            ReducedCharacterState rs = new ReducedCharacterState(state, start);

            //kinda ugly code....
            root.setCMPosition(rs.getPosition());
            root.setOrientation(rs.getOrientation());
            root.setCMVelocity(rs.getVelocity());
            root.setAngularVelocity(rs.getAngularVelocity());

            //now each joint introduces one more rigid body, so we'll only record its state relative to its parent.
            //we are assuming here that each joint is revolute!!!
            Quaternion qRel;
            Vector3    wRel;

            //Vector3 r;
            //Vector3 d;
            //Vector3 vRel;

            CWJoint joint;

            //	root->updateToWorldTransformation();
            for (int j = 0; j < joints.Count; j++)
            {
                qRel = rs.getJointRelativeOrientation(j);
                wRel = rs.getJointRelativeAngVelocity(j);
                //transform the relative angular velocity to world coordinates
                joint = joints[j] as CWJoint;
                wRel  = joint.getParent().getOrientation() * wRel;

                //now that we have this information, we need to restore the state of the rigid body.

                //set the proper orientation
                //int orderedJ = j;
                //if( hackFlag )
                //orderedJ = (int)jointOrder[j];

                //	joint = joints[orderedJ] as CWJoint;
                joint.getChild().setOrientation(joint.getParent().getOrientation() * qRel);
                //and the proper angular velocity
                joint.getChild().setAngularVelocity(joint.getParent().getAngularVelocity() + wRel);

                //Debug.Log("111111 "+joint.name+" "+qRel+" "+wRel);
                //and now set the linear position and velocity
                joint.fixJointConstraints(false, true, false);
                //		joints[j]->child->updateToWorldTransformation();
            }
        }