x
Yes
No
Do you want to visit DriveHQ English website?
Inicio
Características
Precios
Prueba gratuita
Software cliente
Acerca de nosotros
Servidor de archivos
|
Solución de copias de seguridad
|
Servidor FTP
|
Servidor de correo electrónico
|
Alojamiento web
|
Software cliente
Servidor de archivos
Solución de copia de seguridad
Servidor FTP
Servidor de correo electrónico
Alojamiento web
Software cliente
Soldier.cpp - Hosted on DriveHQ Cloud IT Platform
Arriba
Subir
Descargar
Compartir
Publicar
Nueva carpeta
Nuevo archivo
Copiar
Cortar
Eliminar
Pegar
Clasificación
Actualizar
Ruta de la carpeta: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\Soldier.cpp
Girar
Efecto
Propiedad
Historial
#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
Dirección de la página
Dirección del archivo
Anterior
42/45
Siguiente
Descargar
( 7 KB )
Comments
Total ratings:
0
Average rating:
No clasificado
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.