void LevelLoader::loadOtherDataFromXml(XmlNode* otherDataNode) { XmlNode* dynamicObjNode = otherDataNode->GetFirstChildByNodeName(DYNAMIC_OBJECT_TAG); while (dynamicObjNode != nullptr) { int objXmlId = dynamicObjNode->GetAttributeValueI(ID_ATTRIBUTE); std::string prefab = dynamicObjNode->GetAttributeValueS(PREFAB_ATTRIBUTE); int xGridPosition = dynamicObjNode->GetAttributeValueI(X_ATTRIBUTE); float yPosition = dynamicObjNode->GetAttributeValueF(Y_ATTRIBUTE); int zGridPosition = dynamicObjNode->GetAttributeValueI(Z_ATTRIBUTE); float rotation = dynamicObjNode->GetAttributeValueF(ROTATION_ATTRIBUTE) inRadians; GameObject* dynamicObj = PrefabLoader::InstantiateGameObjectFromPrefab(FRAMEWORK->GetFileSystemUtils()->GetDevicePrefabsResourcesPath() + prefab + PREFAB_EXTENSION, ENGINE->GetSceneGraph3D()); idsFromXml[objXmlId] = dynamicObj->GetId(); // Position and orient the object dynamicObj->GetTransform()->SetPosition(xGridPosition, yPosition, -zGridPosition); dynamicObj->GetTransform()->SetOrientation(rotation, YAXIS); // Check for overloaded components XmlNode* compNode = dynamicObjNode->GetFirstChildByNodeName(COMPONENT_TAG); while (compNode != nullptr) { PrefabLoader::LoadComponentFromComponentNodeInPrefab(dynamicObj, compNode); compNode = compNode->GetNextSiblingByNodeName(COMPONENT_TAG); } GridZone* zone = dynamicObj->GetComponent<GridZone>(); if (zone != nullptr) { SINGLETONS->GetGridManager()->placeZoneOnGrid(dynamicObj->GetId());//GetGrid()->AddGridZone(dynamicObj->GetId()); } dynamicObjNode = dynamicObjNode->GetNextSiblingByNodeName(DYNAMIC_OBJECT_TAG); } // TODO [Implement] Other things such as triggerables }
DebugMenuTouchHandlers::DebugMenuTouchHandlers() : UiTouchHandlers() { this->cameraSpeed = 2.0f; GameObject* debugCam = new GameObject(ENGINE->GetSceneGraph3D()); ENGINE->GetSceneGraph3D()->GetRootGameObject()->AddChild(debugCam->GetId()); Camera* camComponent = debugCam->AddComponent<Camera>(); camComponent->SetFOV(30.0f inRadians); GameObject* shadyCam = (GameObject*)ENGINE->GetSceneGraph3D()->GetMainCamera()->GetObject(); debugCam->GetTransform()->SetPosition(shadyCam->GetTransform()->GetPosition()); debugCam->GetTransform()->SetOrientation(shadyCam->GetTransform()->GetOrientation()); this->shadyCamId = shadyCam->GetId(); ENGINE->GetSceneGraph3D()->SetMainCameraId(debugCam->GetId()); }
void initUiGameObjects() { { GameObject* camera = new GameObject(ENGINE->GetSceneGraphUi()); ENGINE->GetSceneGraphUi()->GetRootGameObject()->AddChild(camera->GetId()); Camera* cameraComponent = camera->AddComponent<Camera>(); cameraComponent->SetCameraType(CAMERA_TYPE_ORTHO); camera->GetTransform()->SetPosition(0.0f, 0.0f, 400.0f); camera->GetTransform()->Rotate(10.0f inRadians, YAXIS); // camera->GetTransform()->SetOrientation(-45.0f inRadians, camera->GetTransform()->GetUp()); // camera->GetTransform()->Rotate(45.0f inRadians, camera->GetTransform()->GetLeft()); camera->GetTransform()->LookAt(0.0f, 0.0f, 0.0f); ENGINE->GetSceneGraphUi()->SetMainCameraId(camera->GetId()); } { std::string pathToTestUiScene = FRAMEWORK->GetFileSystemUtils()->GetDeviceUiScenesResourcesPath() + "mainMenu.uiscene"; UiSceneLoader::LoadUiSceneFromUiSceneFile(pathToTestUiScene.c_str(), new MainMenuTouchHandlers()); } }
GameObject* GameObjectManager::GetGameObject(const Ogre::String& id){ GameObject* go = NULL; std::list<GameObject*>::iterator it; for (it = m_game_objects.begin(); it != m_game_objects.end(); it++){ go = *it; if (go->GetId() == id){ return go; } } return NULL; }
void LevelLoader::createCamera() { GameObject* shadyCamObj = PrefabLoader::InstantiateGameObjectFromPrefab(FRAMEWORK->GetFileSystemUtils()->GetDevicePrefabsResourcesPath() + "ShadyCamera" + PREFAB_EXTENSION, ENGINE->GetSceneGraph3D()); Camera* cam = shadyCamObj->GetComponent<Camera>(); VERIFY(cam != nullptr, "Game camera object has Camera component"); ENGINE->GetSceneGraph3D()->SetMainCameraId(shadyCamObj->GetId()); SINGLETONS->GetGridManager()->SetShadyCamera((ShadyCamera*)cam); AudioListener* listener = shadyCamObj->GetComponent<AudioListener>(); ASSERT(listener != nullptr, "Game camera object has AudioListener component"); if (listener != nullptr) { listener->SetAsActiveListener(); } }
void LevelLoader::loadUnitDataFromXml(XmlNode* unitBaseNode) { // Start with player units XmlNode* unitNode = unitBaseNode->GetFirstChildByNodeName(""); while (unitNode != nullptr) { int unitXmlId = unitNode->GetAttributeValueI(ID_ATTRIBUTE); std::string unitPrefab = unitNode->GetAttributeValueS(PREFAB_ATTRIBUTE); GameObject* unitObj = PrefabLoader::InstantiateGameObjectFromPrefab(FRAMEWORK->GetFileSystemUtils()->GetDevicePrefabsResourcesPath() + unitPrefab + PREFAB_EXTENSION, ENGINE->GetSceneGraph3D()); idsFromXml[unitXmlId] = unitObj->GetId(); // Units require a GridNavigator component GridNavigator* gNav = unitObj->GetComponent<GridNavigator>(); ASSERT(gNav != nullptr, "Unit with id %d has GridNavigator component", unitObj->GetId()); // Read the initial position of the unit int gX = unitNode->GetAttributeValueI(X_ATTRIBUTE); int gZ = unitNode->GetAttributeValueI(Z_ATTRIBUTE); float rotation = unitNode->GetAttributeValueF(ROTATION_ATTRIBUTE) inRadians; // Add the unit to the grid SINGLETONS->GetGridManager()->placeUnitOnGrid(unitObj->GetId(), gX, gZ); // Orient the unit. unitObj->GetTransform()->SetOrientation(rotation, YAXIS); // Check unit type if (unitNode->GetName() == ENEMY_UNIT_TAG) { EnemyUnit* enemyUnit = unitObj->GetComponent<EnemyUnit>(); ASSERT(enemyUnit != nullptr, "Enemy unit with id %d has EnemyUnit component", unitObj->GetId()); enemyUnit->Activate(); AiPerception* aiPerception = unitObj->GetComponent<AiPerception>(); ASSERT(aiPerception != nullptr, "Enemy unit with id %d has AiPerception component", unitObj->GetId()); aiPerception->Activate(); AiRoutine* aiRoutine = unitObj->GetComponent<AiRoutine>(); ASSERT(aiRoutine != nullptr, "Enemy unit with id %d has AiRoutine component", unitObj->GetId()); // Load the AI routine. XmlNode* aiCommandNode = unitNode->GetFirstChildByNodeName(AI_COMMAND_TAG); std::vector<std::string> commands; while (aiCommandNode != nullptr) { std::string command = aiCommandNode->GetValue(); commands.push_back(command); aiCommandNode = aiCommandNode->GetNextSiblingByNodeName(AI_COMMAND_TAG); } aiRoutine->SetBehavior(commands); } GridZone* zone = unitObj->GetComponent<GridZone>(); if (zone != nullptr) { SINGLETONS->GetGridManager()->placeZoneOnGrid(unitObj->GetId());//GetGrid()->AddGridZone(dynamicObj->GetId()); } unitNode = unitNode->GetNextSiblingByNodeName(""); } }
void LevelLoader::loadStaticDataFromXml(XmlNode* staticNode) { XmlNode* staticObjNode = staticNode->GetFirstChildByNodeName(STATIC_OBJECT_TAG); while (staticObjNode != nullptr) { int objXmlId = staticObjNode->GetAttributeValueI(ID_ATTRIBUTE); std::string prefab = staticObjNode->GetAttributeValueS(PREFAB_ATTRIBUTE); int westBound = staticObjNode->GetAttributeValueI(X_ATTRIBUTE); float yPosition = staticObjNode->GetAttributeValueF(Y_ATTRIBUTE); int southBound = staticObjNode->GetAttributeValueI(Z_ATTRIBUTE); int objWidth = staticObjNode->GetAttributeValueI(WIDTH_ATTRIBUTE); int objHeight = staticObjNode->GetAttributeValueI(HEIGHT_ATTRIBUTE); float rotation = staticObjNode->GetAttributeValueF(ROTATION_ATTRIBUTE) inRadians; GameObject* staticObj = PrefabLoader::InstantiateGameObjectFromPrefab(FRAMEWORK->GetFileSystemUtils()->GetDevicePrefabsResourcesPath() + prefab + PREFAB_EXTENSION, ENGINE->GetSceneGraph3D()); idsFromXml[objXmlId] = staticObj->GetId(); // Add the object to the grid SINGLETONS->GetGridManager()->placeStaticObjectOnGrid(staticObj->GetId(), westBound, southBound, objWidth, objHeight); staticObj->GetTransform()->Translate(yPosition, YAXIS); staticObj->GetTransform()->SetOrientation(rotation, YAXIS); staticObjNode = staticObjNode->GetNextSiblingByNodeName(STATIC_OBJECT_TAG); } }
void LevelLoader::loadEndConditionsFromXml(XmlNode* linkBaseNode) { XmlNode* winConditionNode = linkBaseNode->GetFirstChildByNodeName(WIN_CONDITION_TAG); //ASSERT(winConditionNode != nullptr, "Level has a win condition"); while (winConditionNode != nullptr) { int switchXmlId = winConditionNode->GetAttributeValueI(ID_ATTRIBUTE); ObjectIdType switchId = idsFromXml[switchXmlId]; SINGLETONS->GetLevelManager()->AddWinCondition(switchId); winConditionNode = winConditionNode->GetNextSiblingByNodeName(WIN_CONDITION_TAG); } XmlNode* loseConditionNode = linkBaseNode->GetFirstChildByNodeName(LOSE_CONDITION_TAG); while (loseConditionNode != nullptr) { int switchXmlId = loseConditionNode->GetAttributeValueI(ID_ATTRIBUTE); ObjectIdType switchId = idsFromXml[switchXmlId]; SINGLETONS->GetLevelManager()->AddLoseCondition(switchId); loseConditionNode = loseConditionNode->GetNextSiblingByNodeName(LOSE_CONDITION_TAG); } // Generate the default lose condition GameObject* defaultLose = PrefabLoader::InstantiateGameObjectFromPrefab(FRAMEWORK->GetFileSystemUtils()->GetDevicePrefabsResourcesPath() + DEFAULT_LOSE_CONDITION + PREFAB_EXTENSION, ENGINE->GetSceneGraph3D()); SINGLETONS->GetLevelManager()->AddLoseCondition(defaultLose->GetId()); }
int TestFuntion() { // Instantiate a ComponentMapper so that its singleton get stored: /* ComponentMapper* componentMapper = */ new ComponentMapper(); { #if 0 /* GameObject* gameObject = */ PrefabLoader::InstantiateGameObjectFromPrefab( FRAMEWORK->GetFileSystemUtils()->GetDevicePrefabsResourcesPath() + "monkey.prefab", ENGINE->GetSceneGraph3D()); #endif } FRAMEWORK->GetLogger()->dbglog("\nIn TestFunction()"); #if 0 GameObject* wavybox = ENGINE->GetSceneGraph()->GetGameObjectById(109); if (wavybox != nullptr) { Transform* transform = wavybox->GetTransform(); transform->Scale(4.0f); } #endif { #if 0 SINGLETONS->GetLevelManager()->LoadLevelFromFile(FRAMEWORK->GetFileSystemUtils()->GetDeviceBaseResourcesPath() + "levels/SD_TestScene.lvl"); GameObject* testZone = new GameObject(ENGINE->GetSceneGraph3D()); ENGINE->GetSceneGraph3D()->GetRootGameObject()->AddChild(testZone->GetId()); GridZone* zone = testZone->AddComponent<GridZone>(); zone->SetZoneBounds(3, 0, 5, 5); #endif } { #if 0 GameObject* camera = new GameObject(ENGINE->GetSceneGraph3D()); ENGINE->GetSceneGraph3D()->GetRootGameObject()->AddChild(camera->GetId()); ShadyCamera* cameraComponent = camera->AddComponent<ShadyCamera>(); cameraComponent->SetCameraType(CAMERA_TYPE_PERSPECTIVE); ENGINE->GetSceneGraph3D()->SetMainCameraId(camera->GetId()); cameraComponent->SetGridManager(SINGLETONS->GetGridManager()); //cameraComponent->PanTo(0.0f, 0.0f); cameraComponent->MoveToRoom(0.0f, 0.0f); //cameraComponent->ZoomToOverview(); GameObject* walker = new GameObject(ENGINE->GetSceneGraph3D()); ENGINE->GetSceneGraph3D()->GetRootGameObject()->AddChild(walker->GetId()); #endif } { #if 0 GameObject* testGameScript = new GameObject(ENGINE->GetSceneGraph3D()); ENGINE->GetSceneGraph3D()->GetRootGameObject()->AddChild(testGameScript->GetId()); MeshRenderer* meshRenderer = testGameScript->AddComponent<MeshRenderer>(); meshRenderer->InitMesh(FRAMEWORK->GetFileSystemUtils()->GetDeviceModelResourcesFolderName() + "Suzanne.model"); testGameScript->AddComponent<SampleGameScript>(); GridNavigator* gNav = testGameScript->AddComponent<GridNavigator>(); gNav->SetGridPosition(0, 2); testGameScript->AddComponent<PlayerUnit>(); #endif } { #if 0 GameObject* testGameScript = new GameObject(ENGINE->GetSceneGraph3D()); ENGINE->GetSceneGraph3D()->GetRootGameObject()->AddChild(testGameScript->GetId()); MeshRenderer* meshRenderer = testGameScript->AddComponent<MeshRenderer>(); meshRenderer->InitMesh(FRAMEWORK->GetFileSystemUtils()->GetDeviceModelResourcesFolderName() + "Suzanne.model"); testGameScript->AddComponent<SampleGameScript>(); GridNavigator* gNav = testGameScript->AddComponent<GridNavigator>(); gNav->SetGridPosition(10, 4); testGameScript->AddComponent<PlayerUnit>(); #endif } { #if 0 GameObject* testGameScript = new GameObject(ENGINE->GetSceneGraph3D()); ENGINE->GetSceneGraph3D()->GetRootGameObject()->AddChild(testGameScript->GetId()); MeshRenderer* meshRenderer = testGameScript->AddComponent<MeshRenderer>(); meshRenderer->InitMesh(FRAMEWORK->GetFileSystemUtils()->GetDeviceModelResourcesFolderName() + "Suzanne.model"); testGameScript->AddComponent<SampleGameScript>(); GridNavigator* gNav = testGameScript->AddComponent<GridNavigator>(); gNav->SetGridPosition(8, 2); testGameScript->AddComponent<BaseUnit>(); #endif } { #if 1 /*GameObject* gameObject = */PrefabLoader::InstantiateGameObjectFromPrefab( FRAMEWORK->GetFileSystemUtils()->GetDevicePrefabsResourcesPath() + "test.prefab", ENGINE->GetSceneGraph3D()); #endif } { #if 1 /*GameObject* gameObject = */PrefabLoader::InstantiateGameObjectFromPrefab( FRAMEWORK->GetFileSystemUtils()->GetDevicePrefabsResourcesPath() + "fire_0.prefab", ENGINE->GetSceneGraph3D()); #endif } { #if 1 /*GameObject* gameObject = */PrefabLoader::InstantiateGameObjectFromPrefab( FRAMEWORK->GetFileSystemUtils()->GetDevicePrefabsResourcesPath() + "fire_1.prefab", ENGINE->GetSceneGraph3D()); #endif } { #if 1 /*GameObject* gameObject = */PrefabLoader::InstantiateGameObjectFromPrefab( FRAMEWORK->GetFileSystemUtils()->GetDevicePrefabsResourcesPath() + "fire_2.prefab", ENGINE->GetSceneGraph3D()); #endif } { #if 1 /*GameObject* gameObject = */PrefabLoader::InstantiateGameObjectFromPrefab( FRAMEWORK->GetFileSystemUtils()->GetDevicePrefabsResourcesPath() + "fire_3.prefab", ENGINE->GetSceneGraph3D()); #endif } { #if 0 GameObject* gameObject = PrefabLoader::InstantiateGameObjectFromPrefab( FRAMEWORK->GetFileSystemUtils()->GetDevicePrefabsResourcesPath() + "test.prefab", ENGINE->GetSceneGraph3D()); FRAMEWORK->GetLogger()->dbglog("\nDoes gameObject have unit tag %i", gameObject->HasTag("Unit")); FRAMEWORK->GetLogger()->dbglog("\nDoes gameObject have batman tag %i", gameObject->HasTag("Batman")); FRAMEWORK->GetLogger()->dbglog("\nDoes gameObject have arispace tag %i", gameObject->HasTag("Airspace")); FRAMEWORK->GetLogger()->dbglog("\nadding the unit tag"); gameObject->AddTag("Unit"); FRAMEWORK->GetLogger()->dbglog("\nDoes gameObject have unit tag %i", gameObject->HasTag("Unit")); FRAMEWORK->GetLogger()->dbglog("\nadding the airspace, batman and mispelled tag tag"); gameObject->AddTag("Airspace"); gameObject->AddTag("Batman"); gameObject->AddTag("sdfdgsdgad"); FRAMEWORK->GetLogger()->dbglog("\nDoes gameObject have unit tag %i", gameObject->HasTag("Unit")); FRAMEWORK->GetLogger()->dbglog("\nDoes gameObject have batman tag %i", gameObject->HasTag("Batman")); FRAMEWORK->GetLogger()->dbglog("\nDoes gameObject have arispace tag %i", gameObject->HasTag("Airspace")); FRAMEWORK->GetLogger()->dbglog("\removing the airspace and unit tag tag"); gameObject->RemoveTag("Airspace"); gameObject->RemoveTag("Unit"); FRAMEWORK->GetLogger()->dbglog("\nDoes gameObject have unit tag %i", gameObject->HasTag("Unit")); FRAMEWORK->GetLogger()->dbglog("\nDoes gameObject have batman tag %i", gameObject->HasTag("Batman")); FRAMEWORK->GetLogger()->dbglog("\nDoes gameObject have arispace tag %i", gameObject->HasTag("Airspace")); FRAMEWORK->GetLogger()->dbglog("\removing the airspace and unit tag again!"); FRAMEWORK->GetLogger()->dbglog("\nDoes gameObject have unit tag %i", gameObject->HasTag("Unit")); FRAMEWORK->GetLogger()->dbglog("\nDoes gameObject have batman tag %i", gameObject->HasTag("Batman")); FRAMEWORK->GetLogger()->dbglog("\nDoes gameObject have arispace tag %i", gameObject->HasTag("Airspace")); gameObject->RemoveTag("Airspace"); #endif } initUiGameObjects(); return 4; }
void LevelLoader::adjustLighting() { /* * Read in settings: */ float BRIGHTNESS_MULTIPLIER = 1.0f; SettingLevel_t brightness_level = FRAMEWORK->GetSettings()->GetSetting(SETTING_TYPE_brightness); switch (brightness_level) { case SETTING_LEVEL_off : BRIGHTNESS_MULTIPLIER = 0.0f; break; case SETTING_LEVEL_low : BRIGHTNESS_MULTIPLIER = 0.3f; break; case SETTING_LEVEL_medium: BRIGHTNESS_MULTIPLIER = 0.6f; break; case SETTING_LEVEL_high : BRIGHTNESS_MULTIPLIER = 1.0f; break; default : BRIGHTNESS_MULTIPLIER = 0.6f; break; } { // Add main directional light: GameObject* dlight = new GameObject(ENGINE->GetSceneGraph3D()); ENGINE->GetSceneGraph3D()->GetRootGameObject()->AddChild(dlight->GetId()); DirectionalLight* dlightComponent = dlight->AddComponent<DirectionalLight>(); dlight->GetTransform()->SetPosition(0.0f, 0.0f, 0.0f); dlight->GetTransform()->Rotate(40.0f inRadians, XAXIS); dlight->GetTransform()->Rotate(90.0f inRadians, YAXIS); // dlightComponent->SetAmbientColor(0.2f, 0.2f, 0.2f, 1.0f); dlightComponent->SetDiffuseColorInts(255, 194, 194, 255); dlightComponent->SetIntensity(0.85f * BRIGHTNESS_MULTIPLIER); dlightComponent->SetLightType(MAIN_LIGHT_STRING); } { // Add additional light: GameObject* dlight = new GameObject(ENGINE->GetSceneGraph3D()); ENGINE->GetSceneGraph3D()->GetRootGameObject()->AddChild(dlight->GetId()); DirectionalLight* dlightComponent = dlight->AddComponent<DirectionalLight>(); dlight->GetTransform()->SetPosition(0.0f, 0.0f, 0.0f); dlight->GetTransform()->Rotate(30.0f inRadians, 1.0f, 0.0f, 0.0f); dlight->GetTransform()->Rotate(-45.0f inRadians, 0.0f, 1.0f, 0.0f); // dlightComponent->SetAmbientColor(0.0f, 0.0f, 0.0f, 1.0f); dlightComponent->SetDiffuseColorInts(108, 126, 201, 255); dlightComponent->SetIntensity(0.45f * BRIGHTNESS_MULTIPLIER); dlightComponent->SetLightType(ADDITIONAL_LIGHT_STRING); } { // Add additional light: GameObject* dlight = new GameObject(ENGINE->GetSceneGraph3D()); ENGINE->GetSceneGraph3D()->GetRootGameObject()->AddChild(dlight->GetId()); DirectionalLight* dlightComponent = dlight->AddComponent<DirectionalLight>(); dlight->GetTransform()->SetPosition(0.0f, 0.0f, 0.0f); dlight->GetTransform()->Rotate(30.0f inRadians, 1.0f, 0.0f, 0.0f); dlight->GetTransform()->Rotate(45.0f inRadians, 0.0f, 1.0f, 0.0f); // dlightComponent->SetAmbientColor(0.0f, 0.0f, 0.0f, 1.0f); dlightComponent->SetDiffuseColorInts(255, 187, 69, 255); dlightComponent->SetIntensity(0.75 * BRIGHTNESS_MULTIPLIER); dlightComponent->SetLightType(ADDITIONAL_LIGHT_STRING); } { // Add additional light: GameObject* dlight = new GameObject(ENGINE->GetSceneGraph3D()); ENGINE->GetSceneGraph3D()->GetRootGameObject()->AddChild(dlight->GetId()); DirectionalLight* dlightComponent = dlight->AddComponent<DirectionalLight>(); dlight->GetTransform()->SetPosition(0.0f, 0.0f, 0.0f); dlight->GetTransform()->Rotate(30.0f inRadians, 1.0f, 0.0f, 0.0f); dlight->GetTransform()->Rotate(-135.0f inRadians, 0.0f, 1.0f, 0.0f); // dlightComponent->SetAmbientColor(0.0f, 0.0f, 0.0f, 1.0f); dlightComponent->SetDiffuseColorInts(121, 175, 204, 255); dlightComponent->SetIntensity(0.65 * BRIGHTNESS_MULTIPLIER); dlightComponent->SetLightType(ADDITIONAL_LIGHT_STRING); } // Set up depth camera properties for real time shadows: ENGINE->GetShadowMap()->SetOrthoBounds(-30.0f, 30.0f, -30.0f, 30.0f, 0.0f, 60.0f); }
GameObject* PickObject(const Vec2f& mouseScreen) { // Get object carried by player - don't pick Ve1Object* carried = 0; Player* player = GetLocalPlayer(); if (player) { carried = player->GetCarrying(); } Vec3f mouseWorldNear; Vec3f mouseWorldFar; Unproject(mouseScreen, 0, &mouseWorldNear); Unproject(mouseScreen, 1, &mouseWorldFar); LineSeg lineSeg(mouseWorldNear, mouseWorldFar); GameObject* selectedObj = 0; GameObjects* objs = TheGame::Instance()->GetGameObjects(); float bestDist = 9e20f; for (GameObjects::iterator it = objs->begin(); it != objs->end(); ++it) { GameObject* pgo = it->second; Assert(pgo); Ve1Object* v = dynamic_cast<Ve1Object*>(pgo); Assert(v); if (!v->IsPickable()) { #ifdef PICK_DEBUG std::cout << " Obj " << pgo->GetId() << " is not pickable.\n"; #endif continue; } if (v == carried) { // Can't select it then! std::cout << "Skipping carried object " << *v << "\n"; continue; } const AABB& aabb = pgo->GetAABB(); if (Clip(lineSeg, aabb, 0)) { #ifdef PICK_DEBUG std::cout << " Obj " << pgo->GetId() << " IS PICKED!\n"; #endif // Line seg intersects this box // Choose object whose centre (position) is closest to line seg..? // float dist = LineSeg(mouseWorldNear, mouseWorldFar).SqDist(pgo->GetPos()); float dist = (mouseWorldNear - pgo->GetPos()).SqLen(); // pick closest // Treat skybox as least attractive option, followed by terrain if (dynamic_cast<Skybox*>(v)) { #ifdef PICK_DEBUG std::cout << " Obj " << pgo->GetId() << " skybox so treated as far away\n"; #endif dist = 9e19f; } else if (dynamic_cast<Terrain*>(v)) { #ifdef PICK_DEBUG std::cout << " Obj " << pgo->GetId() << " terrain so treated as far away\n"; #endif dist = 9e18f; } #ifdef PICK_DEBUG std::cout << " Obj " << pgo->GetId() << " sqDist: " << dist << "\n"; #endif if (dist < bestDist) { #ifdef PICK_DEBUG std::cout << " Obj " << pgo->GetId() << " AND IS CLOSEST!\n"; #endif bestDist = dist; selectedObj = pgo; } } else { #ifdef PICK_DEBUG std::cout << " Obj " << pgo->GetId() << " is not picked.\n"; #endif } } return selectedObj; }