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
EntitySelector.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\GameFactory\C2Template\EntitySelector.cpp
Girar
Efecto
Propiedad
Historial
#include "..\ScriptEditor.h"//include first #include "EntitySelector.h" #include "..\InputManager.h" #include "..\GameScene.h" #include "Soldier.h" #include "Tank.h" EntitySelector* EntitySelector::theSingleton = NULL; EntitySelector::EntitySelector(){ theSingleton = this; } EntitySelector::~EntitySelector(){ mCurSelectedObjs.Clear(); theSingleton = NULL; } void EntitySelector::deselectAll(){ for (list
::iterator iter = mCurSelectedObjs.GetPool().begin(); iter!=mCurSelectedObjs.GetPool().end();iter++){ SelectableObject* selObj = static_cast
(*iter); selObj->_SetSelected(false); } mCurSelectedObjs.Clear(); } void EntitySelector::RemoveSelectableObject(SelectableObject* obj){ mCurSelectedObjs.Remove(*obj); } void EntitySelector::FrameMove(Real elapsedTime, RMouse* mouse, RKeyboard* keyboard){ static bool mouseLeftIsDown = false; static bool mouseRightIsDown = false; if (mouse->IsButtonDown(OIS::MouseButtonID::MB_Left)){ if (!mouseLeftIsDown){ //this is a click Vec3 from, direction; GameScene::GetSingleton()->_GetRayCameraToViewport(Vec3(mouse->GetX(),mouse->GetY(),0.0f),from,direction); PhysicalEventHandler* object = GameScene::GetSingleton()->RayCastClosest(from,direction); SelectableObject* selectedObject = dynamic_cast
(object); if (selectedObject!=NULL){ if (!keyboard->IsKeyDown(OIS::KeyCode::KC_LCONTROL)) deselectAll(); selectedObject->_SetSelected(!selectedObject->IsSelected());//toggle if (selectedObject->IsSelected()){ mCurSelectedObjs.Put(*selectedObject); }else{ RemoveSelectableObject(selectedObject); } }else{//deselect all if (!keyboard->IsKeyDown(OIS::KeyCode::KC_LCONTROL)) deselectAll(); } } mouseLeftIsDown = true; }else{ mouseLeftIsDown = false; } if (mouse->IsButtonDown(OIS::MouseButtonID::MB_Right)){ if (!mouseRightIsDown){//a click Vec3 from, direction; GameScene::GetSingleton()->_GetRayCameraToViewport(Vec3(mouse->GetX(),mouse->GetY(),0.0f),from,direction); Vec3 hitPos; PhysicalEventHandler* object = GameScene::GetSingleton()->RayCastClosest(from,direction,&hitPos); if (object!=NULL){//hit //dynamic_cast
(mCurrentSelectedObject)->MoveTo(hitPos); for (list
::iterator iter = mCurSelectedObjs.GetPool().begin(); iter!=mCurSelectedObjs.GetPool().end();iter++){ SelectableObject* selObj = static_cast
(*iter); Soldier* soldier = dynamic_cast
(selObj); if (soldier!=NULL){ soldier->MoveTo(hitPos); }else { dynamic_cast
(selObj)->MoveTo(hitPos); } } } } mouseRightIsDown = true; }else{ mouseRightIsDown = false; } static bool spaceDown = false; if (keyboard->IsKeyDown(OIS::KeyCode::KC_SPACE)){ if (!spaceDown){ for (list
::iterator iter = mCurSelectedObjs.GetPool().begin(); iter!=mCurSelectedObjs.GetPool().end();){ bool advance = false; SelectableObject* selObj = static_cast
(*iter); Soldier* soldier = dynamic_cast
(selObj); if (soldier!=NULL) { iter++; advance = true; soldier->Die(); }else{ Tank* tank = dynamic_cast
(selObj); if (tank!=NULL){ //tank->Stop(); iter++; advance = true; SAFE_DELETE(tank); } } if (!advance) iter++; } deselectAll(); spaceDown = true; } }else{ spaceDown = false; } static bool _1Down = false; if (keyboard->IsKeyDown(OIS::KeyCode::KC_1)){ if (!_1Down){ Vec3 from, direction; GameScene::GetSingleton()->_GetRayCameraToViewport(Vec3(mouse->GetX(),mouse->GetY(),0.0f),from,direction); Vec3 hitPos; PhysicalEventHandler* object = GameScene::GetSingleton()->RayCastClosest(from,direction,&hitPos); if (object!=NULL){//hit Soldier* soldier = new Soldier(); soldier->SetPosition(hitPos+Vec3(0,0,1)); } _1Down = true; } }else{ _1Down = false; } static bool _2Down = false; if (keyboard->IsKeyDown(OIS::KeyCode::KC_2)){ if (!_2Down){ Vec3 from, direction; GameScene::GetSingleton()->_GetRayCameraToViewport(Vec3(mouse->GetX(),mouse->GetY(),0.0f),from,direction); Vec3 hitPos; PhysicalEventHandler* object = GameScene::GetSingleton()->RayCastClosest(from,direction,&hitPos); if (object!=NULL){//hit Tank* tank = new Tank(); tank->SetPosition(hitPos+Vec3(0,0,1)); } _2Down = true; } }else{ _2Down = false; } static bool _CDown = false; if (keyboard->IsKeyDown(OIS::KeyCode::KC_C)){ if (!_CDown){ scriptEditor->Compile(); _CDown = true; } }else{ _CDown = false; } }
EntitySelector.cpp
Dirección de la página
Dirección del archivo
Anterior
9/19
Siguiente
Descargar
( 4 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.