Ejemplo n.º 1
0
void gkSkeletonLoader::makeManual(gkEntity* ent)
{

	Ogre::Entity* oent = ent->getEntity();
	if (!oent || !oent->hasSkeleton())
		return;


	Ogre::SkeletonInstance* inst = oent->getSkeleton();


	gkBone::BoneList::Iterator it = m_skeleton->getBoneList().iterator();
	while (it.hasMoreElements())
	{
		gkBone* bone = it.getNext();


		if (inst->hasBone(bone->getName()))
		{
			Ogre::Bone* obone = inst->getBone(bone->getName());
			bone->_setOgreBone(obone);

			obone->setManuallyControlled(true);
		}
	}
}
Ejemplo n.º 2
0
//-------------------------------------------------------------------------------------
void AxisLines::initAxis(Ogre::String boneName, Ogre::Entity* entity, Ogre::SceneManager* mSceneManager)
{

	if(isXVisible)	/* red */
	{
		xLine = new DynamicLines(Ogre::RenderOperation::OT_LINE_LIST);
		entity->attachObjectToBone(boneName, xLine);
		xLine->setMaterial(color1);
	}

	if(isYVisible) /* green */
	{
		yLine = new DynamicLines(Ogre::RenderOperation::OT_LINE_LIST);
		entity->attachObjectToBone(boneName, yLine);
		yLine->setMaterial(color2);
	}

	if(isZVisible) /* blue */
	{
		zLine = new DynamicLines(Ogre::RenderOperation::OT_LINE_LIST);
		entity->attachObjectToBone(boneName, zLine);
		zLine->setMaterial(color3);
	}

	Ogre::Bone* bone = entity->getSkeleton()->getBone(boneName);
	Ogre::Quaternion q = bone->getOrientation();
	this->updateLines(q.xAxis(), q.yAxis(), q.zAxis());
}
Ejemplo n.º 3
0
void MyLink::SetBornPosition( int name, float x, float y, float z)
{
	Ogre::Bone *bone = mEntity->getSkeleton()->getBone(name);
	bone->setManuallyControlled(true);
	bone->setPosition(x,y,z);
	
}
Ejemplo n.º 4
0
void PhysicsComponent::receiveEvent(Event* event)
{
    if (event->getType() == Event::PHYSICS_UPDATE) {
        btTransform transform;

        transform.setIdentity();
        Ogre::Vector3 position = parent->getNode()->_getDerivedPosition();
        Ogre::Quaternion orientation = parent->getNode()->_getDerivedOrientation();

        if (this->getParent()->getGraphicComponent()->isAnimated() && false) {
            Ogre::Bone* bone = parent->getOgreEntity()->getSkeleton()->getBone(0);
            Ogre::Vector3 bone_converted_pos = parent->getNode()
                    ->convertLocalToWorldPosition(bone->_getDerivedPosition());
            Ogre::Quaternion bone_converted_or = parent->getNode()
                    ->convertLocalToWorldOrientation(bone->_getDerivedOrientation());

            Ogre::Vector3 bonePos =
                    parent->getNode()->_getDerivedPosition() +
                    parent->getNode()->_getDerivedOrientation() *
                    bone_converted_pos;

            Ogre::Quaternion boneRot = parent->getNode()->_getDerivedOrientation() * (bone
                    ->getInitialOrientation().Inverse() * bone->_getDerivedOrientation());

            position = bone_converted_pos;
            orientation = boneRot;

        }

        transform.setOrigin(BtOgre::Convert::toBullet(position));
        transform.setRotation(BtOgre::Convert::toBullet(orientation));

        state->setKinematicPos(transform);
    }
}
	void CAnimatedEntity::setBoneLocalOrientation(std::string boneName, Quaternion localQuat)
	{
		Ogre::Bone* bone = _entity->getSkeleton()->getBone(boneName);

		bone->setManuallyControlled(true);

		bone->setOrientation(localQuat);
	}
Ejemplo n.º 6
0
Transform GfxBody::getBoneWorldTransform (unsigned n)
{
    checkBone(n);
    Ogre::Bone *bone = skeleton->getBone(n);
    Transform t(from_ogre(bone->_getDerivedPosition()), from_ogre(bone->_getDerivedOrientation()), from_ogre(bone->_getDerivedScale()));
    updateWorldTransform();
    return worldTransform * t;
}
Ejemplo n.º 7
0
void CreatureWeaponAnimation::updatePart(NifOgre::ObjectScenePtr& scene, int slot)
{
    MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr);
    MWWorld::ContainerStoreIterator it = inv.getSlot(slot);

    if (it == inv.end())
    {
        scene.setNull();
        return;
    }
    MWWorld::Ptr item = *it;

    std::string bonename;
    if (slot == MWWorld::InventoryStore::Slot_CarriedRight)
        bonename = "Weapon Bone";
    else
        bonename = "Shield Bone";

    scene = NifOgre::Loader::createObjects(mSkelBase, bonename, mInsert, item.getClass().getModel(item));
    Ogre::Vector3 glowColor = getEnchantmentColor(item);

    setRenderProperties(scene, RV_Actors, RQG_Main, RQG_Alpha, 0,
                        !item.getClass().getEnchantment(item).empty(), &glowColor);

    if(scene->mSkelBase)
    {
        Ogre::SkeletonInstance *skel = scene->mSkelBase->getSkeleton();
        if(scene->mSkelBase->isParentTagPoint())
        {
            Ogre::Node *root = scene->mSkelBase->getParentNode();
            if(skel->hasBone("BoneOffset"))
            {
                Ogre::Bone *offset = skel->getBone("BoneOffset");

                root->translate(offset->getPosition());

                // It appears that the BoneOffset rotation is completely bogus, at least for light models.
                //root->rotate(offset->getOrientation());
                root->pitch(Ogre::Degree(-90.0f));

                root->scale(offset->getScale());
                root->setInitialState();
            }
        }
        updateSkeletonInstance(mSkelBase->getSkeleton(), skel);
    }

    // TODO:
    // type == ESM::PRT_Weapon should get an animation source based on the current offset
    // of the weapon attack animation (from its beginning, or start marker?)
    std::vector<Ogre::Controller<Ogre::Real> >::iterator ctrl(scene->mControllers.begin());
    for(;ctrl != scene->mControllers.end();ctrl++)
    {
        if(ctrl->getSource().isNull())
            ctrl->setSource(Ogre::SharedPtr<NullAnimationTime>(new NullAnimationTime()));
    }
}
Ejemplo n.º 8
0
void MyLink::SetBornScale( const char*name, float sx, float sy, float sz)
{
	if(mEntity->getSkeleton()->hasBone(name) == true)
	{
		Ogre::Bone *bone = mEntity->getSkeleton()->getBone(name);
		bone->setManuallyControlled(true);
		bone->setScale(sx,sy,sz);
	}
}
Ejemplo n.º 9
0
void MyLink::SetBornYaw( const char*name, float ang)
{
	if(mEntity->getSkeleton()->hasBone(name) == true)
	{
		Ogre::Bone *bone = mEntity->getSkeleton()->getBone(name);
		bone->setManuallyControlled(true);
		bone->yaw(Ogre::Degree(ang));
	}
}
Ejemplo n.º 10
0
void MyLink::SetBornOrientation( const char*name, float w, float x, float y, float z)
{
	if(mEntity->getSkeleton()->hasBone(name) == true)
	{
		Ogre::Bone *bone = mEntity->getSkeleton()->getBone(name);
		bone->setManuallyControlled(true);
		bone->setOrientation(w,x,y,z);
	}
}
Ejemplo n.º 11
0
//Bone* createChild(unsigned short handle, const Vector3& translate = Vector3::ZERO, const Quaternion& rotate = Quaternion::IDENTITY);
BoneHandle bone_create_child(BoneHandle obj, unsigned short handle, const coiVector3* t, const coiQuaternion* r)
{
    Ogre::Bone* bone = static_cast<Ogre::Bone*>(obj);

    const Ogre::Vector3 translate(t->x, t->y, t->z);
    const Ogre::Quaternion rotate(r->w, r->x, r->y, r->z);

    Ogre::Bone* child = bone->createChild(handle, translate, rotate);
    return static_cast<BoneHandle>(child);
}
Ejemplo n.º 12
0
	void CAnimatedEntity::setBoneWorldOrientation(std::string boneName, Quaternion worldQuat)
	{
		Ogre::Bone* bone = _entity->getSkeleton()->getBone(boneName);

		bone->setManuallyControlled(true);

		Ogre::Quaternion parentQuat = _entityNode->_getDerivedOrientation(); 
		Ogre::Quaternion boneQuat = worldQuat.Inverse() * parentQuat;

		bone->_setDerivedOrientation(boneQuat);
	}
Ejemplo n.º 13
0
	Quaternion CAnimatedEntity::getBoneWorldOrientation(std::string boneName)
	{
		Ogre::Bone* bone = _entity->getSkeleton()->getBone(boneName);

		Ogre::SceneNode *parent = _entityNode; /*node of the entity that has the skeleton*/;
		Ogre::Quaternion parentQuat = _entityNode->_getDerivedOrientation();
		Ogre::Quaternion boneQuat = bone->_getDerivedOrientation();

		Ogre::Quaternion worldQuat = boneQuat * parentQuat; // actually, it might be parentQuat * boneQuat, I forgot

		return worldQuat;
	}
Ejemplo n.º 14
0
	Vector3 CAnimatedEntity::getBoneWorldPosition(std::string boneName)
	{
		Ogre::Bone* bone = _entity->getSkeleton()->getBone(boneName);

		Ogre::Quaternion parentQuat = _entityNode->_getDerivedOrientation();
		Ogre::Vector3 parentPos = _entityNode->_getDerivedPosition();
		Ogre::Vector3 bonePos = bone->_getDerivedPosition();

		Ogre::Vector3 worldPos = parentQuat * bonePos + parentPos;

		return worldPos;
	}
Ejemplo n.º 15
0
	///Get the orientation of the wrist bone
	Ogre::Quaternion getWristOrientation()
	{
		Ogre::Entity* hand = this->Entity();
		assert(hand);

		Ogre::SkeletonInstance* ske;
		Ogre::Bone* wrist;
		if(ske = hand->getSkeleton())
			if(wrist = ske->getBone("Wrist"))
				return wrist->getOrientation();			
		return Ogre::Quaternion::IDENTITY;
	}
Ejemplo n.º 16
0
void VLogicModel::_updateLocatorPos()
{
    for (VLocatorMap::iterator itr = mLocators.begin(); itr != mLocators.end(); ++itr)
    {
        VLocatorValue &tempValue = itr->second;

        // 只更新创建出来的(已经使用的)locator node
        if (tempValue.mLocatorNode != VNULL)
        {
            if (!tempValue.mBoneName.empty())
            {
                Ogre::Bone *bone = VNULL;
                try
                {
                    bone = mSkeleton->getBone(tempValue.mBoneName);
                }
                catch (const Ogre::Exception &e)
                {
                    Ogre::LogManager::getSingleton().logMessage("LogicModel::_updateLocatorPos " + mName + e.getDescription());
                    continue;
                }

                assert(bone != VNULL);

                Ogre::SceneNode *locatorNode = tempValue.mLocatorNode;
                assert(locatorNode != VNULL);

                locatorNode->setPosition(bone->_getDerivedPosition());
                locatorNode->setOrientation(bone->_getDerivedOrientation());

                if (tempValue.mTranslateFirst)
                {
                    // 先平移,再旋转
                    locatorNode->translate(tempValue.mPosition, Ogre::Node::TS_LOCAL);
                    locatorNode->rotate(tempValue.mOrientation, Ogre::Node::TS_LOCAL);
                }
                else
                {
                    // 先旋转,再平移
                    locatorNode->rotate(tempValue.mOrientation, Ogre::Node::TS_LOCAL);
                    locatorNode->translate(tempValue.mPosition, Ogre::Node::TS_LOCAL);
                }
            }
        }
    }

    if (mLocators.size() != 0)
    {
        mModelMainNode->_update(true, false);
    }
}
Ejemplo n.º 17
0
//This is basically just a time-waster
void NPCCharacter::_actionIdle()
{
	//want the head to point straight ahead when it's idling
	Ogre::Bone* headBone;
	Ogre::Skeleton* skel = static_cast<Ogre::Entity*>(_movableObject)->getSkeleton();
	headBone = skel->getBone("Bip01_Head");
	if(headBone->isManuallyControlled())
	{
		//rotate it to be aligned with the body.

	}

	_isActFinished = true;
}
Ejemplo n.º 18
0
	void CAnimatedEntity::setBoneWorldPosition(std::string boneName, Vector3 worldPos)
	{
		Ogre::Bone* bone = _entity->getSkeleton()->getBone(boneName);

		bone->setManuallyControlled(true);

		Ogre::Vector3 parentPos = _entityNode->_getDerivedPosition(); 
		Ogre::Vector3 parentQuatXbonePos = worldPos - parentPos;

		Ogre::Quaternion parentQuat = _entityNode->_getDerivedOrientation(); 
		Ogre::Vector3 bonePos = parentQuat.Inverse() * parentQuatXbonePos;
		Ogre::Vector3 inverseParentScale = 1.0 / _entityNode->_getDerivedScale();

		bone->_setDerivedPosition(bonePos * inverseParentScale);
	}
Ejemplo n.º 19
0
    /** See Ogre::ParticleEmitter. */
    void _initParticle(Ogre::Particle *particle)
    {
        Ogre::Vector3 xOff, yOff, zOff;

        // Call superclass
        ParticleEmitter::_initParticle(particle);

        xOff = Ogre::Math::SymmetricRandom() * mXRange;
        yOff = Ogre::Math::SymmetricRandom() * mYRange;
        zOff = Ogre::Math::SymmetricRandom() * mZRange;

#if OGRE_VERSION >= (1 << 16 | 10 << 8 | 0)
        Ogre::Vector3& position = particle->mPosition;
        Ogre::Vector3& direction = particle->mDirection;
        Ogre::ColourValue& colour = particle->mColour;
        Ogre::Real& totalTimeToLive = particle->mTotalTimeToLive;
        Ogre::Real& timeToLive = particle->mTimeToLive;
#else
        Ogre::Vector3& position = particle->position;
        Ogre::Vector3& direction = particle->direction;
        Ogre::ColourValue& colour = particle->colour;
        Ogre::Real& totalTimeToLive = particle->totalTimeToLive;
        Ogre::Real& timeToLive = particle->timeToLive;
#endif

        Ogre::Node* emitterBone = mEmitterBones.at(OEngine::Misc::Rng::rollDice(mEmitterBones.size()));

        position = xOff + yOff + zOff +
                 mParticleBone->_getDerivedOrientation().Inverse() * (emitterBone->_getDerivedPosition()
                - mParticleBone->_getDerivedPosition());

        // Generate complex data by reference
        genEmissionColour(colour);

        // NOTE: We do not use mDirection/mAngle for the initial direction.
        Ogre::Radian hdir = mHorizontalDir + mHorizontalAngle*Ogre::Math::SymmetricRandom();
        Ogre::Radian vdir = mVerticalDir + mVerticalAngle*Ogre::Math::SymmetricRandom();
        direction = (mParticleBone->_getDerivedOrientation().Inverse()
                     * emitterBone->_getDerivedOrientation() *
                                Ogre::Quaternion(hdir, Ogre::Vector3::UNIT_Z) *
                               Ogre::Quaternion(vdir, Ogre::Vector3::UNIT_X)) *
                              Ogre::Vector3::UNIT_Z;

        genEmissionVelocity(direction);

        // Generate simpler data
        timeToLive = totalTimeToLive = genEmissionTTL();
    }
Ejemplo n.º 20
0
void IKChain::PushOgreBone(Ogre::Bone* OgreBone)
{
	Ogre::Bone* oBone = OgreBone;
	Ogre::Vector3 vecBonePos = oBone->getPosition();
	oBone->setManuallyControlled(true);
	IKJoint* oJoint = NULL;
	if ( mLastPush == NULL ) 
	{
		// Root
		oJoint = new IKJoint(oBone, NULL, oBone->getPosition().x + mMeshNode->getPosition().x, oBone->getPosition().y + mMeshNode->getPosition().y, oBone->getPosition().z + mMeshNode->getPosition().z);
		mIKRoot = oJoint;
		mJointCount = 1;
	}
	else
	{
		// Not root
		Ogre::Vector3 vecParent = mLastPush->GetOgreBone()->_getDerivedPosition();
		Ogre::Vector3 vecDerived = oBone->_getDerivedPosition();
		Ogre::Vector3 vecJointPos = oBone->_getDerivedPosition() + mMeshNode->getPosition();
		oJoint = new IKJoint(oBone, mLastPush, vecJointPos.x, vecJointPos.y, vecJointPos.z);
		mLastPush->SetChild(oJoint);
		mJointCount++;
		mChainLength += vecParent.distance(oBone->_getDerivedPosition());
	}
	mLastPush = oJoint;
	mIKEffector = oJoint;
	cout << "Joint count " << mJointCount << endl;
}
Ejemplo n.º 21
0
void CAnimatedEntity::moveBone(const std::string &bone, float pitch) {
    Ogre::Bone * entityBone = _entity->getSkeleton()->getBone(bone);
    entityBone->reset();

    Ogre::Skeleton * skel = _entity->getSkeleton();

    //entityBone->setManuallyControlled(true);

    unsigned short boneHandle = entityBone->getHandle();
    Ogre::AnimationStateIterator animStateIt = _entity->getAllAnimationStates()->getAnimationStateIterator();

    while( animStateIt.hasMoreElements() )
    {
        Ogre::AnimationState *pAnimState = animStateIt.getNext();
        // ignore disabled animations
        skel->getAnimation(pAnimState->getAnimationName())->destroyNodeTrack(boneHandle);
    }

    entityBone->pitch(Ogre::Radian(pitch));
}
Ejemplo n.º 22
0
//-------------------------------------------------------------------------------------
void ControllableCharacter::setupBone(const Ogre::String& name,const Ogre::Degree& yaw,const Ogre::Degree& pitch,const Ogre::Degree& roll)
{
    Ogre::Bone* bone = bodyEntity->getSkeleton()->getBone(name);
    bone->setManuallyControlled(true);
    bone->setInheritOrientation(false);

    bone->resetOrientation();

    bone->yaw(yaw);
    bone->pitch(pitch);
    bone->roll(roll);
    bone->setInitialState();
}
Ejemplo n.º 23
0
std::vector<std::wstring> ManipulatorEffect::GetLocatorNames() const
{
	Ogre::Entity* ent = ManipulatorSystem.GetObject().GetSelection();
	assert(ent);

	std::vector<std::wstring> ret;
	//M3模型从max导出时locator命名为Ref_xxx形式
	Ogre::SkeletonPtr skel = ent->getMesh()->getSkeleton();
	Ogre::Skeleton::BoneIterator iter = skel->getBoneIterator();

	while (iter.hasMoreElements())
	{
		Ogre::Bone* pBone = iter.peekNext();
		if(pBone->getName().find("Ref_") != Ogre::String::npos)
			ret.push_back(Utility::EngineToUnicode(pBone->getName()));

		iter.getNext();
	}

	return std::move(ret);
}
bool LIRenAttachmentEntity::create_skeleton ()
{
	Ogre::SkeletonInstance* skeleton = entity->getSkeleton ();
	if (skeleton == NULL)
		return false;

	/* Set the initial bone transformations. */
	/* The mesh may not have set these correctly if it depended on bones
	   in external skeletons. Because of external bones, we need to set
	   the transformations using the pose skeleton of the object. */
	LIRenModelData* model = get_model ();
	if (model != NULL && model->rest_pose_buffer != NULL)
	{
		for (int i = 0 ; i < model->rest_pose_buffer->bones.count ; i++)
		{
			const LIMdlPoseBufferBone* group = model->rest_pose_buffer->bones.array + i;
			if (!group->name)
				continue;
			LIMatTransform t;
			if (!object->get_node_transform (group->name, t))
				continue;
			Ogre::Bone* bone = skeleton->getBone (i);
			bone->setPosition (t.position.x, t.position.y, t.position.z);
			bone->setOrientation (t.rotation.w, t.rotation.x, t.rotation.y, t.rotation.z);
		}
	}

	/* Make all bones manually controlled. */
	for (int i = 0 ; i < skeleton->getNumBones () ; i++)
	{
		Ogre::Bone* bone = skeleton->getBone (i);
		bone->setManuallyControlled (true);
	}

	/* Set the binding pose. */
	skeleton->setBindingPose ();

	return true;
}
Ejemplo n.º 25
0
  void RendererSystemComponent::LinkSkeletons(Ogre::SceneNode* sceneNode, RendererSystemComponent::SkeletonList* skeletons)
  {
    SceneNode::ObjectIterator objects = sceneNode->getAttachedObjectIterator();

    while(objects.hasMoreElements())
    {
      MovableObject* object = objects.getNext();

      if(object->getMovableType() == EntityFactory::FACTORY_TYPE_NAME)
      {
        Entity* entity = m_scene->GetSceneManager()->getEntity(object->getName());

        if (entity->hasSkeleton())
        {
          Ogre::Skeleton::BoneIterator boneIterator = entity->getSkeleton()->getBoneIterator();

          while(boneIterator.hasMoreElements())
          {
            Ogre::Bone* oBone = boneIterator.getNext();
            oBone->setManuallyControlled(true);

            /*Entity *axis = m_scene->GetSceneManager()->createEntity(oBone->getName() + "_axis", "/data/entities/meshes/axes.mesh");
            TagPoint* tagPoint = entity->attachObjectToBone(oBone->getName(), axis);
            tagPoint->setScale(0.005f, 0.005f, 0.005f);*/
          }

          skeletons->push_back(entity->getSkeleton());
        }
      }
    }

    Node::ChildNodeIterator children = sceneNode->getChildIterator();

    while(children.hasMoreElements())
    {
      SceneNode* child = static_cast<SceneNode*>(children.getNext());
      this->LinkSkeletons(child, skeletons);
    }
  }
Ejemplo n.º 26
0
//-------------------------------------------------------------------------------------
void ControllableCharacter::setupBone(const Ogre::String& name, const Ogre::Quaternion& q)
{
    Ogre::Bone* bone = bodyEntity->getSkeleton()->getBone(name);
    bone->setManuallyControlled(true);
    bone->setInheritOrientation(false);

    bone->resetOrientation();
    bone->setOrientation(q);

    bone->setInitialState();
}
Ejemplo n.º 27
0
void NIFSkeletonLoader::buildBones(Ogre::Skeleton *skel, const Nif::Node *node, Ogre::Bone *parent)
{
    Ogre::Bone *bone;
    if(!skel->hasBone(node->name))
        bone = skel->createBone(node->name);
    else
        bone = skel->createBone();
    if(parent) parent->addChild(bone);
    mNifToOgreHandleMap[node->recIndex] = bone->getHandle();

    bone->setOrientation(node->trafo.rotation);
    bone->setPosition(node->trafo.pos);
    bone->setScale(Ogre::Vector3(node->trafo.scale));
    bone->setBindingPose();

    if(!(node->recType == Nif::RC_NiNode || /* Nothing special; children traversed below */
         node->recType == Nif::RC_RootCollisionNode || /* handled in nifbullet (hopefully) */
         node->recType == Nif::RC_NiTriShape || /* Handled in the mesh loader */
         node->recType == Nif::RC_NiBSAnimationNode || /* Handled in the object loader */
         node->recType == Nif::RC_NiBillboardNode || /* Handled in the object loader */
         node->recType == Nif::RC_NiBSParticleNode ||
         node->recType == Nif::RC_NiCamera ||
         node->recType == Nif::RC_NiAutoNormalParticles ||
         node->recType == Nif::RC_NiRotatingParticles
         ))
        warn("Unhandled "+node->recName+" "+node->name+" in "+skel->getName());

    Nif::ControllerPtr ctrl = node->controller;
    while(!ctrl.empty())
    {
        if(!(ctrl->recType == Nif::RC_NiParticleSystemController ||
             ctrl->recType == Nif::RC_NiVisController ||
             ctrl->recType == Nif::RC_NiUVController ||
             ctrl->recType == Nif::RC_NiKeyframeController ||
             ctrl->recType == Nif::RC_NiGeomMorpherController
             ))
            warn("Unhandled "+ctrl->recName+" from node "+node->name+" in "+skel->getName());
        ctrl = ctrl->next;
    }

    const Nif::NiNode *ninode = dynamic_cast<const Nif::NiNode*>(node);
    if(ninode)
    {
        const Nif::NodeList &children = ninode->children;
        for(size_t i = 0;i < children.length();i++)
        {
            if(!children[i].empty())
                buildBones(skel, children[i].getPtr(), bone);
        }
    }
}
Ejemplo n.º 28
0
void ESKOgre::buildBone(unsigned short b, Ogre::Skeleton *ogre_skeleton, Ogre::Bone *parent_bone) {
	ESKBone *bone = bones[b];
	Ogre::Bone *mBone = ogre_skeleton->createBone(bone->name);
  if (parent_bone)
  {
    parent_bone->addChild(mBone);
  }

	Ogre::Matrix4 parent_matrix = Ogre::Matrix4::IDENTITY;

	if (bone->parent_index < bones.size()) {
		ESKBone *pbone = bones[bone->parent_index];

		parent_matrix = Ogre::Matrix4(pbone->transform_matrix[0], pbone->transform_matrix[4], pbone->transform_matrix[8], pbone->transform_matrix[12],
									  pbone->transform_matrix[1], pbone->transform_matrix[5], pbone->transform_matrix[9], pbone->transform_matrix[13],
									  pbone->transform_matrix[2], pbone->transform_matrix[6], pbone->transform_matrix[10], pbone->transform_matrix[14],
									  pbone->transform_matrix[3], pbone->transform_matrix[7], pbone->transform_matrix[11], pbone->transform_matrix[15]);
	}


	Ogre::Matrix4 transform_matrix(bone->transform_matrix[0], bone->transform_matrix[4], bone->transform_matrix[8], bone->transform_matrix[12],
								   bone->transform_matrix[1], bone->transform_matrix[5], bone->transform_matrix[9], bone->transform_matrix[13],
								   bone->transform_matrix[2], bone->transform_matrix[6], bone->transform_matrix[10], bone->transform_matrix[14],
								   bone->transform_matrix[3], bone->transform_matrix[7], bone->transform_matrix[11], bone->transform_matrix[15]);

	transform_matrix = transform_matrix * parent_matrix.inverse();

	Ogre::Vector3 mPos;
	Ogre::Vector3 mScale;
	Ogre::Quaternion mRot;
	transform_matrix.decomposition(mPos, mScale, mRot);

	LOG_DEBUG("Bone %d Setup for %s: %f %f %f %d\n", b, bone->name.c_str(), (float)mPos.x, (float)mPos.y, (float)mPos.z, bone->index_4);

	mBone->setPosition(mPos * -1);
	mBone->setScale(mScale);
	mBone->setOrientation(mRot.Inverse());
	mBone->setInitialState();

	mBone->setManuallyControlled(false);

	for (size_t i = 0; i < bones.size(); i++) {
		if (bones[i]->parent_index == b) {
			buildBone(i, ogre_skeleton, mBone);
		}
	}
}
Ejemplo n.º 29
0
//-------------------------------------------------------------------------------------
void ControllableCharacter::setupBone(const Ogre::String& name, NuiJointIndex idx)
{
    Ogre::Bone* bone = bodyEntity->getSkeleton()->getBone(name);
    bone->setManuallyControlled(true);

    if(name != "WRIST_RIGHT" && name != "WRIST_RIGHT")
        bone->setInheritOrientation(false);

    bone->resetOrientation();

    Ogre::Quaternion q = Ogre::Quaternion::IDENTITY;
    bone->setOrientation(q);

    bone->setInitialState();

    if(showBoneOrientationAxes) axisLines[idx]->initAxis(name, this->bodyEntity, this->mSceneManager);		// debug
}
Ejemplo n.º 30
0
//-------------------------------------------------------------------------------------
void ControllableCharacter::transformBone(Ogre::String boneName, NuiManager::NuiJointIndex jointIdx)
{
    int state = 0;
    state = (int)controller->getJointStatus(jointIdx);

    if(state == 2)
    {
        Ogre::Bone* bone = skeleton->getBone(boneName);
        Ogre::Quaternion qI = bone->getInitialOrientation();
        Ogre::Quaternion newQ = jointCalc->getSkeletonJointOrientation(jointIdx);

        bone->resetOrientation();
        newQ = bone->convertWorldToLocalOrientation(newQ);
        bone->setOrientation(newQ * qI);

        Ogre::Quaternion resQ = bone->getOrientation();
        if(showBoneOrientationAxes) axisLines[jointIdx]->updateLines(resQ.xAxis(), resQ.yAxis(), resQ.zAxis());		// debug
    }
}