本文整理汇总了C++中ogre::Entity::getSkeleton方法的典型用法代码示例。如果您正苦于以下问题:C++ Entity::getSkeleton方法的具体用法?C++ Entity::getSkeleton怎么用?C++ Entity::getSkeleton使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::Entity
的用法示例。
在下文中一共展示了Entity::getSkeleton方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AttachMeshToBone
bool EC_Mesh::AttachMeshToBone(QObject* targetMesh, const QString& boneName)
{
if (!entity_)
return false;
// First make sure that the target mesh is valid, and the bone can be found
EC_Mesh* targetMeshPtr = dynamic_cast<EC_Mesh*>(targetMesh);
if (!targetMeshPtr)
return false;
Ogre::Entity* targetEntity = targetMeshPtr->GetEntity();
if (!targetEntity)
return false;
std::string boneNameStd = boneName.toStdString();
Ogre::SkeletonInstance* skeleton = targetEntity->getSkeleton();
if (!skeleton)
return false;
if (!skeleton->hasBone(boneNameStd))
return false;
// We are ready to go. Detach the entity from its normal scene node first
DetachMeshFromBone();
DetachEntity();
bone_tagpoint_ = targetEntity->attachObjectToBone(boneNameStd, entity_);
bone_parent_mesh_ = targetMeshPtr;
bone_parent_mesh_->bone_attached_mesh_ = this;
attached_to_bone_ = true;
// Force the adjustment for the tagpoint now
OnAttributeUpdated(&nodeTransformation);
return true;
}
示例2: makeManual
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);
}
}
}
示例3: createScene
//-------------------------------------------------------------------------------------
void DeltaControl::createScene(void) {
mSceneMgr->setSkyBox(true, "StormySkyBox");
mControlCenter = new ControlCenter(mSceneMgr);
/* *********************************************************
* ENTITIES
* *********************************************************/
// Telephone* phone = new Telephone(mSceneMgr, "phone1");
// phone->init();
// Create entity from mesh and attach it to a scene node.
Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
Ogre::Entity* ent = mSceneMgr->createEntity("Sinbad", "Sinbad.mesh");
node->attachObject(ent);
node->setPosition(0,50,0);
node->scale(10,10,10);
// Set animation blend mode to additive / cumulative.
ent->getSkeleton()->setBlendMode(Ogre::ANIMBLEND_CUMULATIVE);
// Get the two halves of the idle animation
Ogre::AnimationState* baseAnim = ent->getAnimationState("IdleBase");
Ogre::AnimationState* topAnim = ent->getAnimationState("IdleTop");
// Enable both of them and set them to loop.
baseAnim->setLoop(true);
topAnim->setLoop(true);
baseAnim->setEnabled(true);
topAnim->setEnabled(true);
}
示例4: getWristOrientation
///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;
}
示例5: OnTimer
void CBlendingAnimationsView::OnTimer(UINT_PTR nIDEvent)
{
CEngine *Engine = ((CBlendingAnimationsApp*)AfxGetApp())->m_Engine;
Ogre::Root *Root = Engine->GetRoot();
Ogre::SceneNode *RobotNode = Root->getSceneManager("Walking")->getSceneNode("Robot");
Ogre::Entity *RobotEntity = Root->getSceneManager("Walking")->getEntity("Robot");
Ogre::Skeleton *Skeleton = RobotEntity->getSkeleton();
if (m_WeightDlg->m_IsAverage)
{
Skeleton->setBlendMode(Ogre::SkeletonAnimationBlendMode::ANIMBLEND_AVERAGE);
}
else
{
Skeleton->setBlendMode(Ogre::SkeletonAnimationBlendMode::ANIMBLEND_CUMULATIVE);
}
double WalkWeight;
double SlumpWeight;
switch(nIDEvent)
{
case 1:
WalkWeight = m_WeightDlg->m_WalkWeight.GetPos() / 10.0;
SlumpWeight = m_WeightDlg->m_SlumpWeight.GetPos() / 10.0;
m_WalkAnimation->setWeight(WalkWeight);
m_SlumpAnimation->setWeight(SlumpWeight);
m_WalkAnimation->addTime(0.01);
m_SlumpAnimation->addTime(0.01);
break;
case 2:
m_WalkAnimation->addTime(0.01);
break;
case 3:
m_SlumpAnimation->addTime(0.01);
break;
}
Root->renderOneFrame();
CView::OnTimer(nIDEvent);
}
开发者ID:southerlies,项目名称:OGRE-3D-1.7-Application-Development-Cookbook-Code,代码行数:52,代码来源:BlendingAnimationsView.cpp
示例6: OnTimer
void CSceletalAnimationView::OnTimer(UINT_PTR nIDEvent)
{
CEngine *Engine = ((CSceletalAnimationApp*)AfxGetApp())->m_Engine;
Ogre::Root *Root = Engine->GetRoot();
Ogre::SceneManager *SceneManager = Root->getSceneManager("Animation");
Ogre::Entity *Entity = SceneManager->getEntity("Animation");
Ogre::Skeleton *Skeleton = Entity->getSkeleton();
m_AnimationState->addTime(0.1);
Root->renderOneFrame();
CView::OnTimer(nIDEvent);
}
开发者ID:southerlies,项目名称:OGRE-3D-1.7-Application-Development-Cookbook-Code,代码行数:13,代码来源:SceletalAnimationView.cpp
示例7: CharacterController
OgreCharacterController::OgreCharacterController(Ogre::Camera * Camera, const Ogre::String& name, const Ogre::Vector3& position)
: CharacterController(Camera, position, name, "Sinbad.mesh", Ogre::Vector3(3, 3, 3)), lastTop(0), lastBase(0),
mSword1(0), mSword2(0), swordsOut(false), sliceDir(false), animTimer(0)
{
Ogre::SceneManager * smgr = Camera->getSceneManager();
Ogre::Entity * ent = getEntity();
ent->getSkeleton()->setBlendMode(Ogre::ANIMBLEND_CUMULATIVE);
mSword1 = smgr->createEntity("Sword1", "Sword.mesh");
mSword2 = smgr->createEntity("Sword2", "Sword.mesh");
ent->attachObjectToBone("Sheath.L", mSword1);
ent->attachObjectToBone("Sheath.R", mSword2);
getTargetNode()->setFixedYawAxis(true);
}
示例8: updateParts
Ogre::Vector3 NpcAnimation::runAnimation(float timepassed)
{
if(mTimeToChange <= 0.0f)
{
mTimeToChange = 0.2f;
updateParts();
}
mTimeToChange -= timepassed;
Ogre::Vector3 ret = Animation::runAnimation(timepassed);
const Ogre::SkeletonInstance *skelsrc = mEntityList.mSkelBase->getSkeleton();
for(size_t i = 0;i < sPartListSize;i++)
{
Ogre::Entity *ent = mEntityParts[i].mSkelBase;
if(!ent) continue;
updateSkeletonInstance(skelsrc, ent->getSkeleton());
ent->getAllAnimationStates()->_notifyDirty();
}
return ret;
}
示例9: checkMesh
void BoneCollisionManager::checkMesh(Ogre::String outFileName, Ogre::SceneNode* node)
{
std::ofstream file(outFileName.c_str());
if (file)
{
Ogre::Entity* ent = (Ogre::Entity*)node->getAttachedObject(0);
Ogre::SkeletonInstance* skeletonInst = ent->getSkeleton();
Ogre::Skeleton::BoneIterator boneI=skeletonInst->getBoneIterator();
//file<<"Creating bone length information from:\n";
file<<"Mesh name: "<<ent->getMesh()->getName()<<"\n";
file<<"Skeleton name: "<<skeletonInst->getName()<<"\n\n";
while(boneI.hasMoreElements())
{
Ogre::Bone* bone=boneI.getNext();
Ogre::String bName=bone->getName();
if (bone->getChild(0))
{
Ogre::Vector3 curr = bone->_getDerivedPosition();
Ogre::Vector3 next = bone->getChild(0)->_getDerivedPosition();
Ogre::Vector3 difference = next-curr;
//length of bone
Ogre::Real lenght = difference.length();
file<<bName<<":\nLength\t\t\t=\t"<<Ogre::StringConverter::toString(lenght,3)<<"\n"<<
"Position"<<"\t\t=\t"<<Ogre::StringConverter::toString(curr.x,1)<<", "<<
Ogre::StringConverter::toString(curr.y,1)<<", "<<
Ogre::StringConverter::toString(curr.z,1)<<"\n";
if (!bone->getParent())
file<<bName<<" is a Root Bone!\n\n";
else
file<<"\n\n";
}
}
}
}
示例10: while
//!
//! Clones an Ogre::MovableObject.
//!
//! Is needed because OGRE does not provide clone functions for cameras and
//! lights.
//!
//! \param movableObject The object to clone.
//! \param name The name to use for the object.
//! \param sceneManager The scene manager to use for creating the object.
//! \return The cloned object.
//!
Ogre::MovableObject * OgreTools::cloneMovableObject ( Ogre::MovableObject *movableObject, const QString &name, Ogre::SceneManager *sceneManager /* = 0 */ )
{
// make sure the given object is valid
if (!movableObject) {
Log::error("The given movable object is invalid.", "OgreTools::cloneMovableObject");
return 0;
}
// make sure a valid scene manager is available
if (!sceneManager)
sceneManager = movableObject->_getManager();
if (!sceneManager) {
Log::error("No valid scene manager available.", "OgreTools::cloneMovableObject");
return 0;
}
Ogre::MovableObject *result = 0;
Ogre::String typeName = movableObject->getMovableType();
if (typeName == "Entity") {
// clone entity
Ogre::Entity *entity = dynamic_cast<Ogre::Entity *>(movableObject);
//movableObjectCopy = entity->clone(name.toStdString());
Ogre::Entity *entityCopy = sceneManager->createEntity(name.toStdString(), entity->getMesh()->getName());
Ogre::AnimationStateSet *animationStateSet = entity->getAllAnimationStates();
Ogre::AnimationStateSet *animationStateSetCopy = entityCopy->getAllAnimationStates();
// set the same blend mode on entity copy
if (entity && entityCopy) {
if (entity->hasSkeleton() && entityCopy->hasSkeleton()) {
Ogre::Skeleton *skeleton = entity->getSkeleton();
Ogre::Skeleton *skeletonCopy = entityCopy->getSkeleton();
skeletonCopy->setBlendMode(skeleton->getBlendMode());
}
}
// copy all animation states
if (animationStateSet && animationStateSetCopy) {
Ogre::AnimationStateIterator animationStateIter = animationStateSet->getAnimationStateIterator();
Ogre::AnimationStateIterator animationStateCopyIter = animationStateSetCopy->getAnimationStateIterator();
while (animationStateIter.hasMoreElements()) {
if (!animationStateCopyIter.hasMoreElements())
break;
Ogre::AnimationState *animationState = animationStateIter.getNext();
Ogre::AnimationState *animationStateCopy = animationStateCopyIter.getNext();
animationStateCopy->setLoop(animationState->getLoop());
//bool enabled = animationState->getEnabled();
//animationStateCopy->setEnabled(animationState->getEnabled());
animationStateCopy->setEnabled(true);
animationStateCopy->setTimePosition(animationState->getTimePosition());
}
}
// create a new container for the cloned entity
OgreContainer *entityCopyContainer = new OgreContainer(entityCopy);
entityCopy->setUserAny(Ogre::Any(entityCopyContainer));
if (!entity->getUserAny().isEmpty()) {
OgreContainer *entityContainer = Ogre::any_cast<OgreContainer *>(entity->getUserAny());
if (entityContainer) {
QObject::connect(entityContainer, SIGNAL(animationStateUpdated(const QString &, double)), entityCopyContainer, SLOT(updateAnimationState(const QString &, double)));
QObject::connect(entityContainer, SIGNAL(boneTransformUpdated(const QString &, double, double, double, double, double, double)), entityCopyContainer, SLOT(updateBoneTransform(const QString &, double, double, double, double, double, double)));
}
}
result = dynamic_cast<Ogre::MovableObject *>(entityCopy);
} else if (typeName == "Light") {
// clone light
Ogre::Light *light = dynamic_cast<Ogre::Light *>(movableObject);
Ogre::Light *lightCopy = sceneManager->createLight(name.toStdString());
lightCopy->setType(light->getType());
lightCopy->setDiffuseColour(light->getDiffuseColour());
lightCopy->setSpecularColour(light->getSpecularColour());
lightCopy->setAttenuation(light->getAttenuationRange(), light->getAttenuationConstant(), light->getAttenuationLinear(), light->getAttenuationQuadric());
lightCopy->setPosition(light->getPosition());
lightCopy->setDirection(light->getDirection());
if (lightCopy->getType() == Ogre::Light::LT_SPOTLIGHT)
lightCopy->setSpotlightRange(light->getSpotlightInnerAngle(), light->getSpotlightOuterAngle(), light->getSpotlightFalloff());
lightCopy->setPowerScale(light->getPowerScale());
lightCopy->setCastShadows(light->getCastShadows());
// create a new container for the cloned light
OgreContainer *lightCopyContainer = new OgreContainer(lightCopy);
lightCopy->setUserAny(Ogre::Any(lightCopyContainer));
if (!light->getUserAny().isEmpty()) {
OgreContainer *lightContainer = Ogre::any_cast<OgreContainer *>(light->getUserAny());
if (lightContainer)
QObject::connect(lightContainer, SIGNAL(sceneNodeUpdated()), lightCopyContainer, SLOT(updateLight()));
}
result = dynamic_cast<Ogre::MovableObject *>(lightCopy);
} else if (typeName == "Camera") {
// clone camera
Ogre::Camera *camera = dynamic_cast<Ogre::Camera *>(movableObject);
Ogre::Camera *cameraCopy = sceneManager->createCamera(name.toStdString());
//.........这里部分代码省略.........
示例11: frameRenderingQueued
bool OgreSmartBody::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
if(mWindow->isClosed())
return false;
//Need to capture/update each device
mKeyboard->capture();
mMouse->capture();
if(mKeyboard->isKeyDown(OIS::KC_ESCAPE))
return false;
// smartbody
if (!m_pScene)
return true;
SmartBody::SBSimulationManager* sim = m_pScene->getSimulationManager();
sim->setTime((Ogre::Root::getSingleton().getTimer()->getMilliseconds() / 1000.0f) - mStartTime);
m_pScene->update();
int numCharacters = m_pScene->getNumCharacters();
if (numCharacters == 0)
return true;
const std::vector<std::string>& characterNames = m_pScene->getCharacterNames();
for (size_t n = 0; n < characterNames.size(); n++)
{
SmartBody::SBCharacter* character = m_pScene->getCharacter(characterNames[n]);
if (!this->getSceneManager()->hasEntity(characterNames[n]))
continue;
Ogre::Entity* entity = this->getSceneManager()->getEntity(characterNames[n]);
Ogre::Skeleton* meshSkel = entity->getSkeleton();
Ogre::Node* node = entity->getParentNode();
SrVec pos = character->getPosition();
SrQuat ori = character->getOrientation();
//std::cout << ori.w << ori.x << " " << ori.y << " " << ori.z << std::endl;
node->setPosition(pos.x, pos.y, pos.z);
node->setOrientation(ori.w, ori.x, ori.y, ori.z);
// Update joints
SmartBody::SBSkeleton* sbSkel = character->getSkeleton();
int numJoints = sbSkel->getNumJoints();
for (int j = 0; j < numJoints; j++)
{
SmartBody::SBJoint* joint = sbSkel->getJoint(j);
try
{
SrQuat orientation = joint->quat()->value();
Ogre::Vector3 posDelta(joint->getPosition().x, joint->getPosition().y, joint->getPosition().z);
Ogre::Quaternion quatDelta(orientation.w, orientation.x, orientation.y, orientation.z);
Ogre::Bone* bone = meshSkel->getBone(joint->getName());
if (!bone)
continue;
bone->setPosition(bone->getInitialPosition() + posDelta);
bone->setOrientation(quatDelta);
}
catch (Ogre::ItemIdentityException& ex)
{
// Should not happen as we filtered using m_mValidBones
}
}
}
return true;
}
示例12: Update
//.........这里部分代码省略.........
i->second.weight_ -= (1.0f / i->second.fade_period_) * frametime;
if (i->second.weight_ <= 0.0f)
{
i->second.weight_ = 0.0f;
i->second.phase_ = PHASE_STOP;
}
}
break;
}
// Set weight & step the animation forward
if (i->second.phase_ != PHASE_STOP)
{
Ogre::Real advance = i->second.speed_factor_ * frametime;
Ogre::Real new_weight = i->second.weight_ * i->second.weight_factor_;
if (new_weight != animstate->getWeight())
animstate->setWeight((Ogre::Real)i->second.weight_ * i->second.weight_factor_);
if (advance != 0.0f)
animstate->addTime((Ogre::Real)(i->second.speed_factor_ * frametime));
if (!animstate->getEnabled())
animstate->setEnabled(true);
}
else
{
// If stopped, disable & remove this animation from list
animstate->setEnabled(false);
erase_list.push_back(i->first);
}
}
for (uint i = 0; i < erase_list.size(); ++i)
{
animations_.erase(erase_list[i]);
}
// High-priority/low-priority blending code
if (entity->hasSkeleton())
{
Ogre::SkeletonInstance* skel = entity->getSkeleton();
if (!skel)
return;
if (highpriority_mask_.size() != skel->getNumBones())
highpriority_mask_.resize(skel->getNumBones());
if (lowpriority_mask_.size() != skel->getNumBones())
lowpriority_mask_.resize(skel->getNumBones());
for (uint i = 0; i < skel->getNumBones(); ++i)
{
highpriority_mask_[i] = 1.0;
lowpriority_mask_[i] = 1.0;
}
// Loop through all high priority animations & update the lowpriority-blendmask based on their active tracks
for (AnimationMap::iterator i = animations_.begin(); i != animations_.end(); ++i)
{
Ogre::AnimationState* animstate = GetAnimationState(entity, i->first);
if (!animstate)
continue;
// Create blend mask if animstate doesn't have it yet
if (!animstate->hasBlendMask())
animstate->createBlendMask(skel->getNumBones());
if ((i->second.high_priority_) && (i->second.weight_ > 0.0))
{
// High-priority animations get the full weight blend mask
animstate->_setBlendMaskData(&highpriority_mask_[0]);
if (!skel->hasAnimation(animstate->getAnimationName()))
continue;
Ogre::Animation* anim = skel->getAnimation(animstate->getAnimationName());
Ogre::Animation::NodeTrackIterator it = anim->getNodeTrackIterator();
while (it.hasMoreElements())
{
Ogre::NodeAnimationTrack* track = it.getNext();
unsigned id = track->getHandle();
// For each active track, reduce corresponding bone weight in lowpriority-blendmask
// by this animation's weight
if (id < lowpriority_mask_.size())
{
lowpriority_mask_[id] -= i->second.weight_;
if (lowpriority_mask_[id] < 0.0) lowpriority_mask_[id] = 0.0;
}
}
}
}
// Now set the calculated blendmask on low-priority animations
for (AnimationMap::iterator i = animations_.begin(); i != animations_.end(); ++i)
{
Ogre::AnimationState* animstate = GetAnimationState(entity, i->first);
if (!animstate)
continue;
if (i->second.high_priority_ == false)
animstate->_setBlendMaskData(&lowpriority_mask_[0]);
}
}
}
示例13: AniName
void
AnimationSelector::Reload(void)
{
resetState();
if (!Ogre::ResourceGroupManager::getSingletonPtr())
return;
if(NULL == GetDataManipulator())
return;
mAnimationList->Freeze();
wxTreeItemId root = mAnimationList->GetRootItem();
mAnimationList->Unselect();
mAnimationList->DeleteChildren(root);
if (mIsMeshAnim)
{
// Get animation list of current mesh
Fairy::ObjectPtr pCurMesh = GetDataManipulator()->m_pMeshObject;
if (!pCurMesh)
{
mAnimationList->Thaw();
return;
}
Fairy::StaticEntityObject* entity = static_cast<Fairy::StaticEntityObject*>((pCurMesh).get());
Ogre::Entity* pCurEntity = entity->getEntity();
if(pCurEntity && pCurEntity->hasSkeleton())
{
//更新动画列表
unsigned short numAnim = pCurEntity->getSkeleton()->getNumAnimations();
for(int i=0;i<numAnim;++i)
{
Ogre::String AniName = pCurEntity->getSkeleton()->getAnimation(i)->getName();
wxTreeItemId item = AddLeaf(root, AniName);
mAnimationList->SetItemData(item, new AnimationItemData(AniName));
}
}
mAnimationList->Thaw();
}
else
{
Fairy::LogicModel* pObjModel = GetDataManipulator()->m_pObjTemplate;
if (!pObjModel)
{
mAnimationList->Thaw();
return;
}
Fairy::LogicModelManager::AnimationSkeletonLinks* pAniLinks = GetDataManipulator()->_getCurAniLinks();
if (!pAniLinks)
{
mAnimationList->Thaw();
return;
}
for ( Fairy::LogicModelManager::AnimationSkeletonLinks::iterator iter = pAniLinks->begin(); iter!= pAniLinks->end(); ++iter)
{
Ogre::String AniName(iter->first);
wxTreeItemId item = AddLeaf(root, AniName);
mAnimationList->SetItemData(item, new AnimationItemData(AniName));
}
mAnimationList->Thaw();
}
}
示例14: update
void GameObjectFlashLight::update(double elapsedSeconds)
{
if (isEnabled()) //there is no point to updating the flashlight when it's not active
{
GameObject::update(elapsedSeconds);
mCurrentColour=calculateCurrentColour(elapsedSeconds);
setColour(mCurrentColour);
GameObjectOnyPtr ony = mGameWorldManager->getGameObjectOny();
Ogre::Vector3 pos;
if (ony.get() && ony->getRenderComponentEntity()->getEntity()->hasSkeleton()
&& ony->getRenderComponentEntity()->getEntity()->getSkeleton()->hasBone(ATTACH_BONE_NAME))
{
Ogre::Entity* ent = ony->getRenderComponentEntity()->getEntity();
Ogre::Node* bone = ent->getSkeleton()->getBone(ATTACH_BONE_NAME);
pos=Utils::getNodeWorldPosition(ent,bone);
}
else
{
pos=ony->getRenderComponentPositional()->getPosition();
}
mRenderComponentPositional->setPosition(pos);
mRenderComponentPositional->setOrientation(
ony->getRenderComponentPositional()->getOrientation()*
Ogre::Quaternion(Ogre::Degree(180),Ogre::Vector3::UNIT_Y)*
Ogre::Quaternion(Ogre::Radian(rollAngle),Ogre::Vector3::UNIT_Z));
rollAngle+=elapsedSeconds*DEFAULT_ROLL_OMEGA;
//constrain the angle into the range [0..2PI)
if (rollAngle>=2*PI)
{
//The while addition is a safety check for situations
//where the angle increases above 4*PI, which
//might happen as a result of a dramatic drop in
//the framerate
while(rollAngle>=2*PI)
{
rollAngle-=2*PI;
}
}
if (mPhysicsComponentVolumeConvex.get() && mPhysicsComponentVolumeConvex->isInUse())
{
//OUCH! BUT FOR THE MOMENT WE LEAVE IT LIKE THIS as there's an error getting the orientation if not done that way
//mPhysicsComponentVolumeConvex->destroy();
//mPhysicsComponentVolumeConvex->create();
mPhysicsComponentVolumeConvex->setPosition(pos);
mPhysicsComponentVolumeConvex->setOrientation(ony->getRenderComponentPositional()->getOrientation()*Ogre::Quaternion(Ogre::Degree(180),Ogre::Vector3::UNIT_Y));
}
if (mPhysicsComponentWeapon.get() && mPhysicsComponentWeapon->isInUse())
{
mPhysicsComponentWeapon->setPosition(pos);
Vector3 nextMovement;
nextMovement=mLastBonePosition-pos+ony->getPhysicsComponentCharacterOny()->getOuternMovement();
nextMovement.normalise();
mPhysicsComponentWeapon->setOuternMovement(nextMovement);
mPhysicsComponentWeapon->setCyclicCharacter(nextMovement==Vector3::ZERO);
//Logger::getInstance()->log("setOuternMovement " + Ogre::StringConverter::toString(pos-mLastBonePosition));
//mPhysicsComponentWeapon->setOrientation(orient);
}
mLastBonePosition=pos;
}
}
示例15: initOgreAR
int initOgreAR(aruco::CameraParameters camParams, unsigned char* buffer, std::string resourcePath)
{
/// INIT OGRE FUNCTIONS
#ifdef _WIN32
root = new Ogre::Root(resourcePath + "plugins_win.cfg", resourcePath + "ogre_win.cfg");
#elif __x86_64__ || __ppc64__
root = new Ogre::Root(resourcePath + "plugins_x64.cfg", resourcePath + "ogre.cfg");
#else
root = new Ogre::Root(resourcePath + "plugins.cfg", resourcePath + "ogre.cfg");
#endif
if (!root->showConfigDialog()) return -1;
Ogre::SceneManager* smgr = root->createSceneManager(Ogre::ST_GENERIC);
/// CREATE WINDOW, CAMERA AND VIEWPORT
Ogre::RenderWindow* window = root->initialise(true);
Ogre::Camera *camera;
Ogre::SceneNode* cameraNode;
camera = smgr->createCamera("camera");
camera->setNearClipDistance(0.01f);
camera->setFarClipDistance(10.0f);
camera->setProjectionType(Ogre::PT_ORTHOGRAPHIC);
camera->setPosition(0, 0, 0);
camera->lookAt(0, 0, 1);
double pMatrix[16];
camParams.OgreGetProjectionMatrix(camParams.CamSize,camParams.CamSize, pMatrix, 0.05,10, false);
Ogre::Matrix4 PM(pMatrix[0], pMatrix[1], pMatrix[2] , pMatrix[3],
pMatrix[4], pMatrix[5], pMatrix[6] , pMatrix[7],
pMatrix[8], pMatrix[9], pMatrix[10], pMatrix[11],
pMatrix[12], pMatrix[13], pMatrix[14], pMatrix[15]);
camera->setCustomProjectionMatrix(true, PM);
camera->setCustomViewMatrix(true, Ogre::Matrix4::IDENTITY);
window->addViewport(camera);
cameraNode = smgr->getRootSceneNode()->createChildSceneNode("cameraNode");
cameraNode->attachObject(camera);
/// CREATE BACKGROUND FROM CAMERA IMAGE
int width = camParams.CamSize.width;
int height = camParams.CamSize.height;
// create background camera image
mPixelBox = Ogre::PixelBox(width, height, 1, Ogre::PF_R8G8B8, buffer);
// Create Texture
mTexture = Ogre::TextureManager::getSingleton().createManual("CameraTexture",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Ogre::TEX_TYPE_2D,width,height,0,Ogre::PF_R8G8B8,Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
//Create Camera Material
Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create("CameraMaterial", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Ogre::Technique *technique = material->createTechnique();
technique->createPass();
material->getTechnique(0)->getPass(0)->setLightingEnabled(false);
material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
material->getTechnique(0)->getPass(0)->createTextureUnitState("CameraTexture");
Ogre::Rectangle2D* rect = new Ogre::Rectangle2D(true);
rect->setCorners(-1.0, 1.0, 1.0, -1.0);
rect->setMaterial("CameraMaterial");
// Render the background before everything else
rect->setRenderQueueGroup(Ogre::RENDER_QUEUE_BACKGROUND);
// Hacky, but we need to set the bounding box to something big, use infinite AAB to always stay visible
Ogre::AxisAlignedBox aabInf;
aabInf.setInfinite();
rect->setBoundingBox(aabInf);
// Attach background to the scene
Ogre::SceneNode* node = smgr->getRootSceneNode()->createChildSceneNode("Background");
node->attachObject(rect);
/// CREATE SIMPLE OGRE SCENE
// add sinbad.mesh
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(resourcePath + "Sinbad.zip", "Zip", "Popular");
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
for(int i=0; i<MAX_MARKERS; i++) {
Ogre::String entityName = "Marker_" + Ogre::StringConverter::toString(i);
Ogre::Entity* ogreEntity = smgr->createEntity(entityName, "Sinbad.mesh");
Ogre::Real offset = ogreEntity->getBoundingBox().getHalfSize().y;
ogreNode[i] = smgr->getRootSceneNode()->createChildSceneNode();
// add entity to a child node to correct position (this way, entity axis is on feet of sinbad)
Ogre::SceneNode *ogreNodeChild = ogreNode[i]->createChildSceneNode();
ogreNodeChild->attachObject(ogreEntity);
// Sinbad is placed along Y axis, we need to rotate to put it along Z axis so it stands up over the marker
// first rotate along X axis, then add offset in Z dir so it is over the marker and not in the middle of it
ogreNodeChild->rotate(Ogre::Vector3(1,0,0), Ogre::Radian(Ogre::Degree(90)));
ogreNodeChild->translate(0,0,offset,Ogre::Node::TS_PARENT);
// mesh is too big, rescale!
const float scale = 0.006675f;
ogreNode[i]->setScale(scale, scale, scale);
// Init animation
ogreEntity->getSkeleton()->setBlendMode(Ogre::ANIMBLEND_CUMULATIVE);
if(i==0)
{
baseAnim[i] = ogreEntity->getAnimationState("HandsClosed");
topAnim[i] = ogreEntity->getAnimationState("HandsRelaxed");
}
else if(i==1)
{
//.........这里部分代码省略.........