x
Yes
No
Do you want to visit DriveHQ English website?
首页
产品服务
价格
免费试用
下载客户端
关于我们
云文件服务
|
云备份服务
|
FTP服务
|
企业邮箱服务
|
网站托管
|
客户端软件
云文件服务
云备份服务
FTP服务
企业级邮箱服务
网站托管
客户端软件
SkinnedVisObj.cpp - Hosted on DriveHQ Cloud IT Platform
返回上层目录
上传
下载
共享
发布
新建文件夹
新建文件
复制
剪切
删除
粘贴
评论
升级服务
路径: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\GameFactory\SkinnedVisObj.cpp
旋转
特效
属性
历史版本
#include "SkinnedVisObj.h" #include "BoneVisObj.h" //MyHashTable
SkinnedVisObj::animationPool = MyHashTable
(); SkinnedVisObj::SkinnedVisObj(const String& resourceName) :CompoundVisObj(),LoadedVisObj(resourceName),mSceneNode(NULL),mMainEntity(NULL), mCurAnimation(NULL),mManualControl(false){ mSceneNode = dynamic_cast
(mNode); myassert(mSceneNode!=NULL); //mName = mNode->getName();//unique name buildPartFromBone(mSceneNode); #ifdef _GF_RECORD_BONES //record mFile = fopen(("soldier_"+mNode->getName()+".txt").c_str(),"w"); mFrameNumber = 0; #endif // _GF_RECORD_BONES } void SkinnedVisObj::SetManualControl(bool manualControl){ mManualControl = manualControl; for(list
::iterator iter = visObjOrderPool.GetPool().begin();iter != visObjOrderPool.GetPool().end();iter++){ dynamic_cast
(*iter)->SetManualControl(mManualControl); } ////if (mCurAnimation) mCurAnimation->SetManualControl(manualControl); //for (MyIterator
iter = mAnimationPool.Begin();!mAnimationPool.IsEnd(iter);iter.Next()){ // SkinnedVisObj::Animation* anim = iter.GetCurrent(); // anim->SetManualControl(manualControl,visObjOrderPool); //} } String SkinnedVisObj::getTransformedName(const String& originalName)const{ String ret = String(originalName); while (true){ int pos = ret.find_first_of(' '); if (pos==string::npos) break; ret.replace(pos,1,"_"); }; return ret; } void SkinnedVisObj::buildPartFromBone(SceneNode* node){ for (SceneNode::ObjectIterator iterEntity = node->getAttachedObjectIterator();iterEntity.hasMoreElements();){ Entity* entity = dynamic_cast
(iterEntity.getNext()); myassert(entity!=NULL); mEntityPool.Put(entity); if (mMainEntity==NULL) mMainEntity = entity; Skeleton::BoneIterator rootBoneIter = entity->getSkeleton()->getRootBoneIterator(); if (rootBoneIter.hasMoreElements()){ buildPartFromBone(node,rootBoneIter.getNext()); } //for (Skeleton::BoneIterator iterBone = entity->getSkeleton()->getBoneIterator();iterBone.hasMoreElements();){ // Bone* bone = iterBone.getNext(); // String key = getTransformedName(bone->getName()); // if (!visObjPool.Exist(key)) { // BoneVisObj* visObj = new BoneVisObj(node,bone); // visObjPool.Put(key,visObj); // }else{ // //int aaa = 0;//there are two bones having the same name, 'neck' // } // //SkeletonInstance* skeIns = entity->getSkeleton(); // //for (int i=0;i
getNumAnimations();i++){ // // skeIns->getAnimation(i)->destroyNodeTrack(bone->getHandle()); // //} //} } for (SceneNode::ChildNodeIterator iterNode = node->getChildIterator();iterNode.hasMoreElements();){ SceneNode* nextNode = dynamic_cast
(iterNode.getNext()); myassert(nextNode!=NULL); buildPartFromBone(nextNode); } } void SkinnedVisObj::buildPartFromBone(Node* parentNode, Node* bone){ String key = getTransformedName(bone->getName()); if (!visObjPool.Exist(key)) { BoneVisObj* visObj = new BoneVisObj(parentNode,bone); visObjPool.Put(key,visObj); visObjOrderPool.Put(visObj);//father first, children later }else{ //bone existed! that mean it has been controlled by another entity before, just attach to it BoneVisObj* visObj = new BoneVisObj(parentNode,bone,dynamic_cast
(visObjPool.Get(key)));//attach it with the previous bone visObjPool.Put(key+parentNode->getName(),visObj);//with this key, it cannot be assigned to any physical object visObjOrderPool.Put(visObj);//it needs to update itself } for (Node::ChildNodeIterator iter = bone->getChildIterator();iter.hasMoreElements();){ Node* childBone = iter.getNext(); buildPartFromBone(parentNode,childBone); } } SkinnedVisObj::~SkinnedVisObj(){ #ifdef _GF_RECORD_BONES fprintf(mFile,"-1\n"); fprintf(mFile,"end of file.\n"); fclose(mFile); #endif // _GF_RECORD_BONES mSceneNode = NULL; SAFE_DELETE(mCurAnimation); mEntityPool.Clear(); } SkinnedVisObj::Animation::Animation(MyListNonRemovable
& entityPool, const String& name){ //mEntityPool = &entityPool; //mName = name; for (list
::iterator iter = entityPool.GetPool().begin();iter!=entityPool.GetPool().end();iter++){ Entity* entity = *iter; AnimationState* state = entity->getAnimationState(name); state->setLoop(true); mStatePool.Put(state); } } SkinnedVisObj::Animation::~Animation(){ for (list
::iterator iter = mStatePool.GetPool().begin();iter!=mStatePool.GetPool().end();iter++){ AnimationState* state = *iter; //SAFE_DELETE(state);//cannot delete this state, it will be deleted later } mStatePool.Clear(); } void SkinnedVisObj::Animation::SetEnabled(bool enabled){ for (list
::iterator iter = mStatePool.GetPool().begin();iter!=mStatePool.GetPool().end();iter++){ AnimationState* state = *iter; state->setEnabled(enabled); } } //void SkinnedVisObj::Animation::SetManualControl(bool enabled,MyListNonRemovable
& visObjOrderPool){ // if (enabled){ // //mAnimation->destroyAllTracks(); // for (list
::iterator iter = mEntityPool->GetPool().begin();iter!=mEntityPool->GetPool().end();iter++){ // Entity* entity = *iter; // for (list
::iterator iterVisObj = visObjOrderPool.GetPool().begin(); // iterVisObj!=visObjOrderPool.GetPool().end();iterVisObj++){ // BoneVisObj* bone = dynamic_cast
(*iterVisObj); // //entity->getSkeleton()->getAnimation(mName)->destroyNodeTrack(bone->_GetBone()->getHandle()); // } // } // } //} SkinnedVisObj::Animation* SkinnedVisObj::GetAnimation(const String& name){ //return reinterpret_cast
(mMainEntity->getAnimationState(name)); if (mAnimationPool.Exist(/*mName+*/name)){ return mAnimationPool.Get(/*mName+*/name); }else{ SkinnedVisObj::Animation* newAnim = new SkinnedVisObj::Animation(mEntityPool,name); mAnimationPool.Put(/*mName+*/name,newAnim); return newAnim; } } void SkinnedVisObj::Animation::AddTime(Real time){ for (list
::iterator iter = mStatePool.GetPool().begin();iter!=mStatePool.GetPool().end();iter++){ AnimationState* state = *iter; state->addTime(time); } } void SkinnedVisObj::SetAnimation(SkinnedVisObj::Animation* animation){ if (!mManualControl){ if (mCurAnimation) mCurAnimation->SetEnabled(false); mCurAnimation = animation; mCurAnimation->SetEnabled(true); } } void SkinnedVisObj::SetNoAnimation(){ if (mCurAnimation) mCurAnimation->SetEnabled(false); mCurAnimation = NULL; } void SkinnedVisObj::FrameMove(Real elapsedTime){ CompoundVisObj::FrameMove(elapsedTime); if (mCurAnimation!=NULL) mCurAnimation->AddTime(elapsedTime); #ifdef _GF_RECORD_BONES //record here fprintf(mFile,"%d\n",mFrameNumber); Vec3 pos = this->GetPosition(); fprintf(mFile,"%f %f %f\n",pos.x,pos.y,pos.z); GFQuat q = this->GetOrientation(); fprintf(mFile,"%f %f %f %f\n",q.x,q.y,q.z,q.w); mFrameNumber++; for (list
::iterator iter = visObjOrderPool.GetPool().begin(); iter != visObjOrderPool.GetPool().end();iter++){ BoneVisObj* bone = dynamic_cast
(*iter); fprintf(mFile,"%s\n",bone->GetName().c_str()); Vec3 pos = bone->GetPosition(); fprintf(mFile,"%f %f %f\n",pos.x,pos.y,pos.z); GFQuat q = bone->GetOrientation(); fprintf(mFile,"%f %f %f %f\n",q.x,q.y,q.z,q.w); fprintf(mFile,"\n"); } #endif // _GF_RECORD_BONES }
SkinnedVisObj.cpp
网页地址
文件地址
上一页
52/55
下一页
下载
( 7 KB )
Comments
Total ratings:
0
Average rating:
无评论
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.