void LineAnalysis::analysis(osg::Vec3d pos) { if (m_firstPoint == osg::Vec3d()) { return; } if (m_pLine == NULL) { osgEarth::Features::Feature* pFeature = new osgEarth::Features::Feature( new osgEarth::Features::LineString, m_pMap3D->getSRS(), m_lineStyle); m_pLine = new osgEarth::Annotation::FeatureNode(m_pMap3D->getMapNode(), pFeature); m_pPlaceNode = new osgEarth::Annotation::PlaceNode( m_pMap3D->getMapNode(), osgEarth::GeoPoint::GeoPoint(), "", m_textStyle); m_pLayerGroup->addChild(m_pLine); m_pLayerGroup->addChild(m_pPlaceNode); } osgEarth::Symbology::Geometry* pGeom = m_pLine->getFeature()->getGeometry(); pGeom->clear(); m_pLine->setStyle(m_lineStyle); pGeom->push_back(m_firstPoint); pGeom->push_back(pos); m_pLine->init(); // 碰撞检测 QString str; osgUtil::IntersectVisitor iv; osg::ref_ptr<osg::LineSegment> line = new osg::LineSegment( getWorldCoord(osg::Vec3d(m_firstPoint.x(), m_firstPoint.y(), m_firstPoint.z() + 2)), getWorldCoord(osg::Vec3d(pos.x(), pos.y(), pos.z() + 2))); iv.addLineSegment(line); m_pMap3D->getMapNode()->getTerrain()->accept(iv); if (iv.hits()) { str = QStringLiteral("两点不可见"); } else { str = QStringLiteral("两点可见"); } m_pPlaceNode->setText(str.toStdWString()); m_pPlaceNode->setPosition( osgEarth::GeoPoint::GeoPoint(m_pMap3D->getSRS(), pos.x(), pos.y())); }
/** * Returns a location from the Area grid coords. * @param x The x grid coord. * @param y The y grid coord. * @return a Location */ Location Area::getLocationFromGridCoord(const int x, const int y) { float fx, fz; getWorldCoord(x, y, fx, fz); Location location; location.setArea(this); location.setXYZ(fx, 0.0, fz); return location; }
/** * Sets if a tile is solid or not. * @param x The X grid coordinate. * @param y The Y grid coordinate. * @param solid If true the tile is solid. * @see isSolid() */ void Area::setSolid(const int x, const int y, const bool solid) { if(x >= getWidth() || y >= getHeight() || x < 0 || y < 0) { return; } // Already solid... /*if(isSolid(x, y) && solid) { return; }*/ if(!solid) { //RigidBody* blocker = *(walkblockers_+(y*width_)+x); RigidBody* blocker = walkblockers_[x][y]; if(blocker) { //blocker->removeRigidBody_(); //blocker->removeBody(getPhysics()); #warning ['TODO']: This should delete the old blocker... delete(blocker); } //*(walkblockers_+(y*width_)+x) = NULL; walkblockers_[x][y] = NULL; } if(solid) { float fx,fz; getWorldCoord(x, y, fx, fz); RigidBody* blocker = new RigidBody("BLOCKER", NULL); blocker->setTempory(true); blocker->setShape(new btBoxShape(btVector3(0.5f, 0.5f, 0.5f))); blocker->setMass(0.0f); blocker->setXYZ(fx, 0.5f, fz); //*(walkblockers_+(y*width_)+x) = blocker; walkblockers_[x][y] = blocker; addObject(blocker); } }
void GameScene::createScene(void) { //#pragma region tempboard // Ogre::Entity *tempBoard = mSceneMgr->createEntity("bomb_tempboard","cube.mesh"); // tempBoard->setMaterialName("Examples/Rockwall"); // Ogre::SceneNode *tempBoardNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("boomb_tempboard"); // //tempBoardNode->setScale(7.0,7.0,7.0); // tempBoardNode->setPosition(0,0,0); // Ogre::Quaternion q1 = tempBoardNode->getOrientation(); // Ogre::Quaternion q2(Ogre::Degree(90),Ogre::Vector3::UNIT_Y); // tempBoardNode->setOrientation(q1*q2); // tempBoardNode->attachObject(tempBoard); //#pragma endregion //for(int x=0;x<15;++x) //{ // for(int y=0;y<13;++y) // { // if(map.getMapAtPos(x,y)==MAP_DESTROYABLE) // { // Ogre::Entity *destroyableBlock = mSceneMgr->createEntity("cube.mesh"); // //destroyableBlock->setMaterialName("Examples/Rockwall"); // destroyableBlock->setCastShadows(true); // mapNode[x][y] = mSceneMgr->getRootSceneNode()->createChildSceneNode(); // mapNode[x][y]->setPosition(0,0,0); // mapNode[x][y]->setPosition(getWorldCoord(Ogre::Vector2(x,y))); // mapNode[x][y]->attachObject(destroyableBlock); // } // else if(map.getMapAtPos(x,y) == MAP_INDESTROYABLE) // { // Ogre::Entity *indestroyableBlock = mSceneMgr->createEntity("cube.mesh"); // //indestroyableBlock->setMaterialName("boomb_testInDestroyable"); // indestroyableBlock->setCastShadows(true); // mapNode[x][y] = mSceneMgr->getRootSceneNode()->createChildSceneNode(); // mapNode[x][y]->setPosition(0,0,0); // mapNode[x][y]->setPosition(getWorldCoord(Ogre::Vector2(x,y))); // mapNode[x][y]->attachObject(indestroyableBlock); // } // } //} gameMap = new GameMap(mSceneMgr); //test player Ogre::Entity *playerEntity = mSceneMgr->createEntity("player","robot.mesh"); playerEntity->setCastShadows(false); Ogre::SceneNode* PlayerNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("playerNode"); //Ogre::Vector2 testvector=Ogre::Vector2(20,5); PlayerNode->setPosition(getWorldCoord( gameMap->getPlayerInitPos(),0)); PlayerNode->setScale(4.0,2.0,4.0); PlayerNode->attachObject(playerEntity); player=new Player(playerEntity,PlayerNode,mSceneMgr,mCamera,mKeyboard); //add 3 enemy //1 EnemyAI* tempEnemy; Ogre::Vector2 vectorPosition; bool isVisible; Ogre::Entity *npc; npc = mSceneMgr->createEntity("Bomberman1Sphere12.mesh"); npc->setCastShadows(false); NPCPlayerNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); NPCPlayerNode->setScale(120,120,120); NPCPlayerNode->yaw(Ogre::Degree(180)); isVisible=gameMap->getEnemyInitPos(vectorPosition); if(isVisible) { NPCPlayerNode->setPosition(getWorldCoord(vectorPosition,80)); NPCPlayerNode->attachObject(npc); tempEnemy=new EnemyAI(npc,NPCPlayerNode,mSceneMgr,mCamera,mKeyboard); } else { vectorPosition.x=1; vectorPosition.y=1; NPCPlayerNode->setPosition(getWorldCoord(vectorPosition,80)); NPCPlayerNode->attachObject(npc); tempEnemy=new EnemyAI(npc,NPCPlayerNode,mSceneMgr,mCamera,mKeyboard); tempEnemy->setDead(); } //push enemyList.push_back(tempEnemy); //2 npc = mSceneMgr->createEntity("bomberman2Sphere09.mesh"); npc->setCastShadows(false); NPCPlayerNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); NPCPlayerNode->setScale(120,120,120); NPCPlayerNode->yaw(Ogre::Degree(180)); isVisible=gameMap->getEnemyInitPos(vectorPosition); if(isVisible) { NPCPlayerNode->setPosition(getWorldCoord(vectorPosition,80)); NPCPlayerNode->attachObject(npc); tempEnemy=new EnemyAI(npc,NPCPlayerNode,mSceneMgr,mCamera,mKeyboard); } else { vectorPosition.x=1; vectorPosition.y=1; NPCPlayerNode->setPosition(getWorldCoord(vectorPosition,80)); NPCPlayerNode->attachObject(npc); tempEnemy=new EnemyAI(npc,NPCPlayerNode,mSceneMgr,mCamera,mKeyboard); tempEnemy->setDead(); } //push enemyList.push_back(tempEnemy); //npc = mSceneMgr->createEntity("ninja.mesh"); //npc->setCastShadows(false); //NPCPlayerNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); //NPCPlayerNode->setScale(1.5,1.0,1.5); //vectorPosition=Ogre::Vector2(15,15); //NPCPlayerNode->setPosition(getWorldCoord(vectorPosition)); ////NPCPlayerNode->yaw( Ogre::Degree( -90 ) ); //NPCPlayerNode->attachObject(npc); //tempEnemy=new EnemyAI(npc,NPCPlayerNode,mSceneMgr,mCamera,mKeyboard); //enemyList.push_back(tempEnemy); //3 npc = mSceneMgr->createEntity("Bomberman1Sphere12.mesh"); npc->setCastShadows(false); NPCPlayerNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); NPCPlayerNode->setScale(120,120,120); NPCPlayerNode->yaw(Ogre::Degree(180)); isVisible=gameMap->getEnemyInitPos(vectorPosition); if(isVisible) { NPCPlayerNode->setPosition(getWorldCoord(vectorPosition,80)); NPCPlayerNode->attachObject(npc); tempEnemy=new EnemyAI(npc,NPCPlayerNode,mSceneMgr,mCamera,mKeyboard); } else { vectorPosition.x=1; vectorPosition.y=1; NPCPlayerNode->setPosition(getWorldCoord(vectorPosition,80)); NPCPlayerNode->attachObject(npc); tempEnemy=new EnemyAI(npc,NPCPlayerNode,mSceneMgr,mCamera,mKeyboard); tempEnemy->setDead(); } //push enemyList.push_back(tempEnemy); /* npc = mSceneMgr->createEntity("ninja.mesh"); npc->setCastShadows(false); NPCPlayerNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); NPCPlayerNode->setScale(1.5,1.0,1.5); vectorPosition=Ogre::Vector2(5,13); NPCPlayerNode->setPosition(getWorldCoord(vectorPosition)); NPCPlayerNode->attachObject(npc); tempEnemy=new EnemyAI(npc,NPCPlayerNode,mSceneMgr,mCamera,mKeyboard); enemyList.push_back(tempEnemy);*/ //ÉèÖÃbonus //gameMap->setMapTypeAtGridPos(3,15,GRID_ADD_SPEED); //gameMap->setMapTypeAtGridPos(12,3,GRID_ADD_SPEED); //gameMap->setMapTypeAtGridPos(20,10,GRID_ADD_HEALTH); //gameMap->setMapTypeAtGridPos(7,15,GRID_ADD_HEALTH); //gameMap->setMapTypeAtGridPos(22,3,GRID_ADD_SPEED); //gameMap->setMapTypeAtGridPos(20,10,GRID_ADD_BOMB); //gameMap->setMapTypeAtGridPos(3,7,GRID_ADD_HEALTH); //gameMap->setMapTypeAtGridPos(4,3,GRID_ADD_BOMB_POWER); //gameMap->setMapTypeAtGridPos(1,2,GRID_ADD_BOMB); //set life display npc = mSceneMgr->createEntity("PlayerHeadRobot2.mesh"); npc->setCastShadows(false); NPCPlayerNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); NPCPlayerNode->setScale(120,120,120); NPCPlayerNode->pitch(Ogre::Degree(60)); vectorPosition.x=13; vectorPosition.y=19; NPCPlayerNode->setPosition(getWorldCoord(vectorPosition,100)); NPCPlayerNode->attachObject(npc); playerLifeList.push_back(NPCPlayerNode); npc = mSceneMgr->createEntity("PlayerHeadRobot2.mesh"); npc->setCastShadows(false); NPCPlayerNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); NPCPlayerNode->setScale(120,120,120); NPCPlayerNode->pitch(Ogre::Degree(60)); vectorPosition.x=12; vectorPosition.y=19; NPCPlayerNode->setPosition(getWorldCoord(vectorPosition,100)); NPCPlayerNode->attachObject(npc); playerLifeList.push_back(NPCPlayerNode); npc = mSceneMgr->createEntity("PlayerHeadRobot2.mesh"); npc->setCastShadows(false); NPCPlayerNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); NPCPlayerNode->setScale(120,120,120); NPCPlayerNode->pitch(Ogre::Degree(60)); vectorPosition.x=11; vectorPosition.y=19; NPCPlayerNode->setPosition(getWorldCoord(vectorPosition,100)); NPCPlayerNode->attachObject(npc); playerLifeList.push_back(NPCPlayerNode); // Set ambient light mSceneMgr->setAmbientLight(Ogre::ColourValue(0.4, 0.4, 0.4)); mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE); // Create a light Ogre::Light* l = mSceneMgr->createLight("pointlight"); l->setType(Ogre::Light::LT_POINT); l->setPosition(Ogre::Vector3(0, 700, 0)); l->setDiffuseColour(1.0, 1.0, 1.0); l->setSpecularColour(0.5, 0.5, 0.5); //terrain Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 0); Ogre::MeshManager::getSingleton().createPlane("ground", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 3000, 3000, 20, 20, true, 1,12.5, 12.5, Ogre::Vector3::UNIT_Z); Ogre::Entity* entGround = mSceneMgr->createEntity("GroundEntity", "ground"); Ogre::SceneNode* planeNode= mSceneMgr->getRootSceneNode()->createChildSceneNode(); planeNode->attachObject(entGround); planeNode->setPosition(60,0,60); entGround->setMaterialName("Examples/GrassFloor"); entGround->setCastShadows(false); //sky mSceneMgr->setSkyBox(true, "Examples/SceneSkyBox1", 5000, false); }