bool HydraxSample1App::keyPressed(const OIS::KeyEvent &arg) { /* if (arg.key == OIS::KC_Q) { mCurrentSkyBox++; if (mCurrentSkyBox == 3) { mCurrentSkyBox = 0; } } mSceneMgr->setSkyBox(true,mSkyBoxes[mCurrentSkyBox],1000,true); mHydrax->setSunPosition(mSunPosition[mCurrentSkyBox]); mHydrax->setSunColor(mSunColor[mCurrentSkyBox]); mSceneMgr->getLight("Light0")->setPosition(mSunPosition[mCurrentSkyBox]); mSceneMgr->getLight("Light0")->setSpecularColour(mSunColor[mCurrentSkyBox].x,mSunColor[mCurrentSkyBox].y,mSunColor[mCurrentSkyBox].z);*/ if (arg.key == OIS::KC_1 || arg.key == OIS::KC_2 || arg.key == OIS::KC_3) { CEGUI::Point point = CEGUI::MouseCursor::getSingleton().getPosition(); Ogre::Ray ray = mCameraMan->getCamera()->getCameraToViewportRay(point.d_x/mWindow->getWidth(),point.d_y/mWindow->getHeight()); mRaySceneQuery->setRay(ray); Ogre::RaySceneQueryResult * mRayQueryResult = &(mRaySceneQuery->execute()); Ogre::RaySceneQueryResult::iterator itr = mRayQueryResult->begin(); while(itr != mRayQueryResult->end()) { if(itr->worldFragment) { Ogre::Entity * ent; Ogre::SceneNode * node; if (arg.key == OIS::KC_1) { ent = mSceneMgr->createEntity(entityNames[0]); ent->setMaterialName(materialNames[0]); node = mSceneMgr->getRootSceneNode()->createChildSceneNode(itr->worldFragment->singleIntersection + Ogre::Vector3(0,200,0)); } else if (arg.key == OIS::KC_2) { ent = mSceneMgr->createEntity(entityNames[1]); ent->setMaterialName(materialNames[1]); node = mSceneMgr->getRootSceneNode()->createChildSceneNode(itr->worldFragment->singleIntersection); } else if (arg.key == OIS::KC_3) { ent = mSceneMgr->createEntity(entityNames[2]); ent->setMaterialName(materialNames[2]); node = mSceneMgr->getRootSceneNode()->createChildSceneNode(itr->worldFragment->singleIntersection); } node->attachObject(ent); break; } itr++; } } return true; }
//----------------------------------------------------------------------- bool OrthoCameraGizmo::select(const Ogre::RaySceneQueryResult& queryResult, const Ogre::ColourValue& pixelColour) { // Check whether one of the objects of which this Gizmo exists is is the RaySceneQueryResult Ogre::RaySceneQueryResult::const_iterator it; Ogre::RaySceneQueryResult::const_iterator itEnd = queryResult.end(); bool exists = false; Ogre::MovableObject* movableObject = 0; for (it = queryResult.begin(); it != itEnd; ++it) { movableObject = (*it).movable; if (movableObject == mOrthoCameraEntityBox || movableObject == mOrthoCameraEntityX || movableObject == mOrthoCameraEntityMinX || movableObject == mOrthoCameraEntityY || movableObject == mOrthoCameraEntityZ || movableObject == mOrthoCameraEntityMinZ) { exists = true; break; } } // If none of the objects was it, forget it if (!exists) { return false; } // Validate the pixelcolour (at the x,y location) mAxis = Gizmo::AXIS_NONE; if (pixelColour.r > 0.6 && pixelColour.g < 0.05 && pixelColour.b < 0.05 && movableObject == mOrthoCameraEntityX) { mAxis = Gizmo::AXIS_X; } else if (pixelColour.r > 0.6 && pixelColour.g < 0.05 && pixelColour.b < 0.05 && movableObject == mOrthoCameraEntityMinX) { mAxis = Gizmo::AXIS_MIN_X; } else if (pixelColour.r < 0.05 && pixelColour.g > 0.6 && pixelColour.b < 0.05 && !m45DegreesOrtho) { mAxis = Gizmo::AXIS_Y; } else if (pixelColour.r < 0.05 && pixelColour.g < 0.05 && pixelColour.b > 0.6 && movableObject == mOrthoCameraEntityZ) { mAxis = Gizmo::AXIS_Z; } else if (pixelColour.r < 0.05 && pixelColour.g < 0.05 && pixelColour.b > 0.6 && movableObject == mOrthoCameraEntityMinZ) { mAxis = Gizmo::AXIS_MIN_Z; } return true; }
//------------------------------------------------------------------------------------- ///controls collision in given direction (true-front false-back) bool Player::collision(bool goAhead){ Ogre::Ray ray = Ogre::Ray(sceneNode->getPosition(), getDirection(sceneNode->getOrientation(),goAhead)); Ogre::RaySceneQuery* mRaySceneQuery = manager->createRayQuery(ray); Ogre::RaySceneQueryResult result = mRaySceneQuery->execute(); for(Ogre::RaySceneQueryResult::iterator it = result.begin(); it != result.end() ; ++it){ if((it->distance < farFarAway)&& (it->distance > 0)){ return true; } } return false; }
bool Player::Update(InputManager* input, PhysicsManager* physics, EWSManager* ews, const OgreTransform& transform) { if(input->isCFGKeyPressed(InputManager::ENVWARNSYS)) { placeEWS(ews,physics,transform); } cGunData* gun = nullptr; if(_equippables[_curEquippable].equip->getIsWeapon()) { gun = static_cast<cGunData*>(_equippables[_curEquippable].equip); } if(gun != nullptr) { bool movkey = false; movkey = (input->isCFGKeyPressed(InputManager::FORWARD) || input->isCFGKeyPressed(InputManager::BACKWARD)|| input->isCFGKeyPressed(InputManager::RIGHT) || input->isCFGKeyPressed(InputManager::LEFT)); if(input->isMBPressed(OIS::MB_Left)) { //shoot gun //std::cout << "MB_Left pressed..." << std::endl; gun->fire(); //check for collisions with enemies if first time through if(gun->shouldDamage()) { Ogre::SceneManager* scene = _equipNode->getCreator(); Ogre::Vector3 dir = transform.direction; Ogre::Ray ray(transform.position,dir); Ogre::RaySceneQuery* rayQuery = scene->createRayQuery(ray); rayQuery->setSortByDistance(true); Ogre::RaySceneQueryResult results = rayQuery->execute(); auto shot = [this,gun] (Ogre::RaySceneQueryResultEntry& entry) { if(entry.movable != nullptr) { std::string name = entry.movable->getName().substr(3,std::string::npos); LevelData::BaseEntity* ent = LuaManager::getSingleton().getEntity(name); if(ent != nullptr && (ent->getType() == LevelData::NPC || ent->getType() == LevelData::ENEMY)) { _damageInterface->registerShotAtEnemy(gun->getGunshotData(),name); } } }; std::for_each(results.begin(),results.end(),shot); scene->destroyQuery(rayQuery); } } else { gun->setFiring(false); } if(input->isCFGKeyPressed(InputManager::RELOAD)) { gun->reload(); } if(movkey) { gun->setMoving(true); } else { if(gun->isMoving()) { gun->setMoving(false); } } } if(_damageInterface != nullptr) { //this clears out the added-up damage in the interface. _health -= static_cast<int>(_damageInterface->getTotalDamagePlayer()); } return true; }