x
Yes
No
Do you want to visit DriveHQ English website?
首页
产品服务
价格
免费试用
下载客户端
关于我们
云文件服务
|
云备份服务
|
FTP服务
|
企业邮箱服务
|
网站托管
|
客户端软件
云文件服务
云备份服务
FTP服务
企业级邮箱服务
网站托管
客户端软件
Soldier.cpp - Hosted on DriveHQ Cloud IT Platform
返回上层目录
上传
下载
共享
发布
新建文件夹
新建文件
复制
剪切
删除
粘贴
评论
升级服务
路径: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\Soldier.cpp
旋转
特效
属性
历史版本
#include "Soldier.h" #include "GameFactoryDemo.h" #include "Line3D.h" using namespace GameFactory; int Soldier::numSoldier = 0; SceneNode* Soldier::referenceNode = NULL; float Soldier::FireRange = 60; float Soldier::FireHeight = 8; int Soldier::EvaluateRange = 6; int Soldier::WayPointQueueLength = 10; Soldier* Soldier::selectedSoldier = NULL; void Soldier::SelectSoldier(NxShape* shape){ if (shape->getActor().readBodyFlag(NX_BF_KINEMATIC)){ if (selectedSoldier!=NULL){ selectedSoldier->mBody->setMaterialName("marine-body"); } selectedSoldier = (Soldier*)shape->getActor().userData; if (selectedSoldier!=NULL) selectedSoldier->mBody->setMaterialName("Examples/Rockwall"); } } bool Soldier::IsCovered(Vector3 from, Vector3 to){ return ((from-to).length()>Soldier::FireRange) || SkeletalApplication::GetSingleton()->RayCast(from + Vector3(0,0,Soldier::FireHeight), to + Vector3(0,0,Soldier::FireHeight),NULL,NULL); } Soldier::Soldier(SceneManager *pSceneMgr, RenderWindow* renderWindow, NxScene* gScene) { curBodyAnimation = NULL; curHeadAnimation = NULL; if (referenceNode==NULL){ referenceNode = pSceneMgr->getRootSceneNode()->createChildSceneNode(); OgreMax::OgreMaxScene* myScene = new OgreMax::OgreMaxScene(); myScene->Load("marine.scene",renderWindow,OgreMax::OgreMaxScene::NO_OPTIONS,pSceneMgr,referenceNode); //referenceNode->setScale(0.5f,0.5f,0.5f); referenceNode->setVisible(false); // Report whether hardware skinning is enabled or not Technique* t = ((Entity*)((SceneNode*)referenceNode->getChild("Marine-body"))->getAttachedObject(0))->getSubEntity(0)->getMaterial()->getBestTechnique(); Pass* p = t->getPass(0); if (p->hasVertexProgram() && p->getVertexProgram()->isSkeletalAnimationIncluded()) SkeletalApplication::GetSingleton()->mDebugText = "Hardware skinning is enabled"; else SkeletalApplication::GetSingleton()->mDebugText = "Software skinning is enabled"; } mNameSuffix = StringConverter::toString(numSoldier); //mNode = pSceneMgr->getRootSceneNode()->createChildSceneNode(); mNode = CloneSceneNode(referenceNode,(SceneNode*)referenceNode->getParent(),mNameSuffix); //mNode->showBoundingBox(true); //add bounding box to PhysX mNode->_updateBounds(); mNode->_update(true,false); mNode->_updateBounds(); //const AxisAlignedBox* pBoundingBox = &(mNode->_getWorldAABB()); AxisAlignedBox pBoundingBox = AxisAlignedBox(Vector3(-0.5,-0.5,-0.5),Vector3(0.5,0.5,0.5)); NxBodyDesc bodyDesc; bodyDesc.angularDamping = 0.5f; NxVec3 initialVelocityNX = NxVec3(0,0,0); NxBoxShapeDesc boxDesc; Vector3 vv = (pBoundingBox.getMaximum()-pBoundingBox.getMinimum())/2; boxDesc.dimensions = Vector3ToNxVec3(vv*Vector3(0.5f,0.5f,1.8f)); vv+= pBoundingBox.getMinimum(); NxActorDesc actorDesc; actorDesc.shapes.pushBack(&boxDesc); actorDesc.body = &bodyDesc; actorDesc.density = 10.0f; actorDesc.globalPose.t = Vector3ToNxVec3(vv); //gScene->createActor(actorDesc)->userData = (void*)size_t(size); actor = gScene->createActor(actorDesc); actor->raiseBodyFlag(NX_BF_KINEMATIC); actor->userData = (void*)this; //printf("Total: %d actors\n", gScene->getNbActors()); mBody = (Entity*)((SceneNode*)mNode->getChild("Marine-body"+mNameSuffix))->getAttachedObject(0); mHead = (Entity*)((SceneNode*)mNode->getChild("head"+mNameSuffix))->getAttachedObject(0); mWeapon = pSceneMgr->getEntity("gun-01"+mNameSuffix); setAnimation("idle_stand"); moving = false; rotating = false; numSoldier++; } Soldier::~Soldier(void) { } void Soldier::setAnimation(String name){ if (curBodyAnimation) curBodyAnimation->setEnabled(false); curBodyAnimation = mBody->getAnimationState(name); curBodyAnimation->setEnabled(true); curBodyAnimation->setLoop(true); if (curHeadAnimation) curHeadAnimation->setEnabled(false); curHeadAnimation = mHead->getAnimationState(name); curHeadAnimation->setEnabled(true); curHeadAnimation->setLoop(true); } bool Soldier::IsAt(Vector3 pos){ return (mNode->getPosition()-pos).length()<0.2f; } void Soldier::ReachTo(Vector3 pos){ if (!IsAt(pos)){ if (!moving) setAnimation("run_forward"); moving = true; movingTarget = pos; }else { if (moving) setAnimation("idle_stand"); moving = false; } } void Soldier::RotateTo(Vector3 pos, Real elapsedTime){ rotatingTarget = pos; pos.z=0.0f; Vector3 movingVector=(pos-mNode->getPosition()).normalisedCopy();//the displacement vector //Rotate(Vector3::UNIT_Y,Radian::Radian(Degree(45))); //movingVector.y = -movingVector.y; Real angle; if (movingVector.x==0){ if (movingVector.y>0) angle = 3.14159/2; else angle = -3.14159/2; }else{ angle = atanf(movingVector.y/movingVector.x); if (movingVector.x<0) angle+=3.14159; } angle+=3*3.14159/2;//to make this angle identical to character angle if (angle>3.14159*2) angle-=3.14159*2;//make sure it is not greater than 360 degrees Real curAngle; curAngle = mNode->getOrientation().getRoll().valueRadians(); if (curAngle<0) curAngle+=3.14159*2; Real distPlus,distMinus,dist; if (angle>curAngle){ distPlus = abs(angle-curAngle); distMinus = abs(3.14159*2-angle+curAngle); if (distPlus
3.14159/180*2){ Rotate(Quaternion(Radian(curAngle+dist*elapsedTime*4.0f),Vector3::UNIT_Z)); rotating = true; } else rotating = false; } void Soldier::ShotAt(Vector3 pos, Real elapsedTime){ setAnimation("shot_bullet");//shot_rocket RotateTo(pos,elapsedTime); Vector3 hitPos, hitNorm,from; from = mNode->getPosition()+Vector3(0,0,7); if (SkeletalApplication::GetSingleton()->RayCast(from,pos,&hitPos,&hitNorm,false,true)){ SkeletalApplication::GetSingleton()->smoke->AddSmoke(hitPos,hitNorm); } } void Soldier::MoveTo(Vector3 pos, Real elapsedTime){ setAnimation("run_forward"); pos.z=0.0f; Vector3 movingVector=(pos-mNode->getPosition()).normalisedCopy();//the displacement vector Translate(mNode->getPosition()+movingVector*1.0f*elapsedTime); //Rotate(Vector3::UNIT_Y,Radian::Radian(Degree(45))); //movingVector.y = -movingVector.y; Real angle; if (movingVector.x==0){ if (movingVector.y>0) angle = 3.14159/2; else angle = -3.14159/2; }else{ angle = atanf(movingVector.y/movingVector.x); if (movingVector.x<0) angle+=3.14159; } angle+=3*3.14159/2;//to make this angle identical to character angle if (angle>3.14159*2) angle-=3.14159*2;//make sure it is not greater than 360 degrees Real curAngle; curAngle = mNode->getOrientation().getRoll().valueRadians(); if (curAngle<0) curAngle+=3.14159*2; Real distPlus,distMinus,dist; if (angle>curAngle){ distPlus = abs(angle-curAngle); distMinus = abs(3.14159*2-angle+curAngle); if (distPlus
3.14159/180*2) Rotate(Quaternion(Radian(curAngle+dist*elapsedTime*4.0f),Vector3::UNIT_Z)); } void Soldier::FrameMove(Real time){ curBodyAnimation->addTime(time); curHeadAnimation->addTime(time); if (moving){ MoveTo(movingTarget,time); ReachTo(movingTarget); } if (rotating){ RotateTo(rotatingTarget,time); } }
Soldier.cpp
网页地址
文件地址
上一页
42/45
下一页
下载
( 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.