x
Yes
No
Do you want to visit DriveHQ English website?
首页
产品服务
价格
免费试用
下载客户端
关于我们
云文件服务
|
云备份服务
|
FTP服务
|
企业邮箱服务
|
网站托管
|
客户端软件
云文件服务
云备份服务
FTP服务
企业级邮箱服务
网站托管
客户端软件
EntitySelector.cpp - Hosted on DriveHQ Cloud IT Platform
返回上层目录
上传
下载
共享
发布
新建文件夹
新建文件
复制
剪切
删除
粘贴
评论
升级服务
路径: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\GameFactory\C2Template\EntitySelector.cpp
旋转
特效
属性
历史版本
#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
网页地址
文件地址
上一页
9/19
下一页
下载
( 4 KB )
Comments
Total ratings:
0
Average rating:
无评论
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.