void initialise() { srand(time(NULL)); glEnable(GL_DEPTH_TEST); glEnable(GL_VERTEX_ARRAY); glClearColor(0.3f, 0.6f, 0.9f, 1.0f); //========Set Camera===================================== fpsCam = new first_person_camera(); fpsCam->setProjection(glm::pi<float>() / 4.0f, screenWidth/screenHeight, 0.1f, 10000.0f); fpsCam->setPositon(glm::vec3(1.73964, 4.51647, -23.0497)); fpsCam->rotate(0.0f, 0.0f); currentCam = fpsCam; //============================================================= //Setup frustrum planes planes = new frustrumPlanes(); planes->setPlanes(currentCam); viewFrus = new viewingFrustrum(); frustum = new frus(); //==========Set up shaders================================ if (!eff.addShader("lit_textured.vert", GL_VERTEX_SHADER)) exit(EXIT_FAILURE); if (!eff.addShader("lighting.frag", GL_FRAGMENT_SHADER)) exit(EXIT_FAILURE); if (!eff.addShader("point_light.frag", GL_FRAGMENT_SHADER)) exit(EXIT_FAILURE); if (!eff.addShader("spot_light.frag", GL_FRAGMENT_SHADER)) exit(EXIT_FAILURE); if (!eff.addShader("Fog.frag", GL_FRAGMENT_SHADER)) exit(EXIT_FAILURE); if (!eff.addShader("lit_textured.frag", GL_FRAGMENT_SHADER)) exit(EXIT_FAILURE); if (!eff.create()) exit(EXIT_FAILURE); //========================================================== //==========Load in scene file============================= scene1 = loadScene("TableAndChairs.json"); scene = scene1; //========================================================= //=========Create terrain=================================== geometry* geom = createTerrain(scene1->textures["heightmap"]); scene1->geometry["terrain"] = geom; render_object* obj = new render_object(); obj->geometry = geom; obj->material = scene1->material["mat_001"]; obj->transform.scale = (glm::vec3(1.0, 8.0, 1.0)); obj->transform.position = (glm::vec3(0.0, -3.0, 0.0)); scene1->objects["terrain"] = obj; //========================================================== }
Room::Room(int i, int j, RoomType type, RoomSpecial special) :ro_roomNumber(type) , ro_roomSpecial(special) { m_x = i * 1280; m_y = j * 720; //could probably do this above but eh createTerrain(type); //topwall createWall(m_x + 0, m_y + 0, 570, 93, TOP, false, false); if (!ro_doorNorth){ createWall(m_x + 570, m_y + 0, 130, 93, TOP, true, false); } else{ createWall(m_x + 570, m_y + 0, 130, 93, TOP, true, true); } createWall(m_x + 710, m_y + 0, 570, 93, TOP, false, false); //rightwall createWall(m_x + 1129, m_y + 0, 151, 331, RIGHT, false, false); if (!ro_doorEast){ createWall(m_x + 1129, m_y + 301, 151, 117, RIGHT, true, false); } else{ createWall(m_x + 1129, m_y + 301, 151, 117, RIGHT, true, true); } createWall(m_x + 1129, m_y + 418, 151, 302, RIGHT, false, false); //bottomwall createWall(m_x + 0, m_y + 625, 570, 160, BOTTOM, false, false); if (!ro_doorSouth){ createWall(m_x + 570, m_y + 625, 130, 160, BOTTOM, true, false); } else{ createWall(m_x + 570, m_y + 625, 130, 160, BOTTOM, true, true); } createWall(m_x + 710, m_y + 625, 570, 160, BOTTOM, false, false); //leftwall createWall(m_x + 0, m_y + 0, 151, 331, LEFT, false, false); if (!ro_doorWest){ createWall(m_x + 0, m_y + 301, 151, 117, LEFT, true, false); } else{ createWall(m_x + 0, m_y + 301, 151, 117, LEFT, true, true); } createWall(m_x + 0, m_y + 418, 151, 302, LEFT, false, false); }
/*F*********************************************************** * DEFAULT CONSTRUCTOR * * NOTES : has performance issues on larger maps *F*/ Ground::Ground() { dim = 25; platform = new Platform(rand() % dim, rand () % dim); for(int i = -(dim/2); i < (dim/2); ++i) { std::vector <float> row (dim); elev.push_back(row); } createTerrain(); for(int i = -(dim/2); i < (dim/2); ++i) { std::vector <Tile> row; for(int j = -(dim/2); j < (dim/2); ++j) { Tile t(i + x, elev[i + (dim/2)][j + (dim/2)] - 14 + y, j + z); row.push_back(t); } floor.push_back(row); } }
void AppDemarrage::remplirScene() { // Lumière ambiante : mSceneMgr->setAmbientLight(Ogre::ColourValue(0.6, 0.6, 0.6)); //ajout d'un brouillard mSceneMgr->setFog(Ogre::FOG_LINEAR, Ogre::ColourValue(0.5f, 0.8f, 0.8f), 0.5, 100, 200); // Ajout d'un "soleil" mLight = mSceneMgr->createLight("light1"); mLight->setType(Ogre::Light::LT_DIRECTIONAL); mLight->setDirection(10.0, -20.0, -5); mLight->setDiffuseColour(0.4, 0.4, 0.4); mLight->setCastShadows(true); // Ajout des modèles 3D Ogre::Entity *bonhomme = mSceneMgr->createEntity("2eBonhomme", "Sinbad.mesh"); Ogre::SceneNode *nodeBon = mSceneMgr->getRootSceneNode()->createChildSceneNode(); nodeBon->attachObject(bonhomme); nodeBon->setPosition(Ogre::Vector3(100, 5, 100)); // Lumière diffuse : /*Ogre::Light* light = mSceneMgr->createLight("lightPoint"); light->setPosition(15, 30, 15); light->setDiffuseColour(1.0, 1.0, 1.0); light->setCastShadows(true);*/ //Ajout d'un plan pour le sol Ogre::Plane plan(Ogre::Vector3::UNIT_Y, 0); Ogre::MeshManager::getSingleton().createPlane("sol", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plan, 500, 500, 1, 1, true, 1, 1, 1, Ogre::Vector3::UNIT_Z); Ogre::Entity *entSol= mSceneMgr->createEntity("EntiteSol", "sol"); mNodeSol = mSceneMgr->getRootSceneNode()->createChildSceneNode(); mNodeSol->attachObject(entSol); entSol->setMaterialName("grassFloor"); entSol->setCastShadows(false); createTerrain(); }
Map* loadMapFromFile(char * filePath) { FILE* input; int number; int lines; int rows; Map* map; input = fopen(filePath,"rt"); if(fscanf(input,"%d",&lines) == EOF || fscanf(input,"%d",&rows) == EOF) { printf("error in fileRead\n"); exit(01); } else if (lines <= 0 || rows <= 0) { printf("error in fileRead\n"); exit(02); } map = createMap(lines,rows); while(fscanf(input,"%d",&number) != EOF) { int i=0; int j=0; if(j>=rows) { j=0; i++; } map->matrix[i][j] = createTerrain(i,j,number); j++; } return map; }
void initialise() { srand(time(NULL)); glEnable(GL_DEPTH_TEST); glEnable(GL_VERTEX_ARRAY); //glClearColor(0.0f, 1.0f, 1.0f, 1.0f); // Set the accumulation buffer clearing colour to black at 0,0f alpha //glClearAccum(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_POINT_SMOOTH); // Smooth the points so that they're circular and not square glPointSize(fw->particleSize); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //IntroCamera introCam = new target_camera(); introCam->setProjection(glm::degrees(glm::quarter_pi<float>()), screenWidth/screenHeight, 0.1f, 10000.0f); introCam->setTarget(glm::vec3(0.0f, 0.0f, 0.0f)); introCam->setPositon(glm::vec3(-0.0, 0.0, -3.0)); //Fireworkcam===================================== fireworkCam = new first_person_camera(); fireworkCam->setProjection(glm::pi<float>() / 4.0f, screenWidth/screenHeight, 0.1f, 10000.0f); fireworkCam->setPositon(glm::vec3(1.73964, 4.51647, -23.0497)); fireworkCam->rotate(0.0f, 0.0f); //============================================================= //Fireworkcam1=================================================== fireworkCam1 = new first_person_camera(); fireworkCam1->setProjection(glm::pi<float>() / 4.0f, screenWidth/screenHeight, 0.1f, 10000.0f); fireworkCam1->setPositon(glm::vec3(1.73964, 4.51647, -500.0497)); fireworkCam1->rotate(0.0f, 0.0f); //================================================================== //Scene2 camera============================================================== scene2Cam = new first_person_camera(); scene2Cam->setProjection(glm::pi<float>() / 4.0f, screenWidth/screenHeight, 0.1f, 10000.0f); scene2Cam->setPositon(glm::vec3(-4.23435, 1.73269, -8.24032)); scene2Cam->rotate(0.65f, 0.0f); //=============================================================================== //Scene2Cam1=========================================================== //Scene2 camera============================================================== scene2Cam1 = new first_person_camera(); scene2Cam1->setProjection(glm::pi<float>() / 4.0f, screenWidth/screenHeight, 0.1f, 10000.0f); scene2Cam1->setPositon(glm::vec3(4.23435, 1.73269, 15.24032)); scene2Cam1->rotate(-2.8f, 0.0f); //=============================================================================== if (!eff.addShader("lit_textured.vert", GL_VERTEX_SHADER)) exit(EXIT_FAILURE); if (!eff.addShader("lighting.frag", GL_FRAGMENT_SHADER)) exit(EXIT_FAILURE); if (!eff.addShader("point_light.frag", GL_FRAGMENT_SHADER)) exit(EXIT_FAILURE); if (!eff.addShader("spot_light.frag", GL_FRAGMENT_SHADER)) exit(EXIT_FAILURE); //if (!eff.addShader("Fog.frag", GL_FRAGMENT_SHADER)) //exit(EXIT_FAILURE); if (!eff.addShader("lit_textured.frag", GL_FRAGMENT_SHADER)) exit(EXIT_FAILURE); if (!eff.create()) exit(EXIT_FAILURE); /*eff.setUniform("fogParams.iEquation", FogParameters::iFogEquation); eff.setUniform("fogParams.vFogColor", FogParameters::vFogColor); if (FogParameters::iFogEquation == 0) { eff.setUniform("fogParams.fStart", FogParameters::fStart); eff.setUniform("fogParams.fEnd", FogParameters::fEnd); } else eff.setUniform("fogParams.fDensity", FogParameters::fDensity);*/ effect* post_eff = new effect(); if(!post_eff->addShader("post_process.vert", GL_VERTEX_SHADER)) exit(EXIT_FAILURE); if(!post_eff->addShader("Sepia.frag", GL_FRAGMENT_SHADER)) exit(EXIT_FAILURE); if (!post_eff->create()) exit(EXIT_FAILURE); effect* post_eff1 = new effect(); if(!post_eff1->addShader("post_process.vert", GL_VERTEX_SHADER)) exit(EXIT_FAILURE); if(!post_eff1->addShader("Greyscale.frag", GL_FRAGMENT_SHADER)) exit(EXIT_FAILURE); if (!post_eff1->create()) exit(EXIT_FAILURE); effect* post_eff2 = new effect(); if(!post_eff2->addShader("post_process.vert", GL_VERTEX_SHADER)) exit(EXIT_FAILURE); if(!post_eff2->addShader("Negative.frag", GL_FRAGMENT_SHADER)) exit(EXIT_FAILURE); if (!post_eff2->create()) exit(EXIT_FAILURE); effect* post_eff3 = new effect(); if(!post_eff3->addShader("post_process.vert", GL_VERTEX_SHADER)) exit(EXIT_FAILURE); if(!post_eff3->addShader("NightPostProc.frag", GL_FRAGMENT_SHADER)) exit(EXIT_FAILURE); if (!post_eff3->create()) exit(EXIT_FAILURE); effect* post_eff4 = new effect(); if(!post_eff4->addShader("post_process.vert", GL_VERTEX_SHADER)) exit(EXIT_FAILURE); if(!post_eff4->addShader("NoPostProc.frag", GL_FRAGMENT_SHADER)) exit(EXIT_FAILURE); if (!post_eff4->create()) exit(EXIT_FAILURE); lastKeyPress = '2'; selectedPostProc = 'O'; lastCam = '9'; scene1 = loadScene("TableAndChairs.json"); //scene2 = loadScene("scene.json"); scene2 = loadScene("ParkBench.json"); scene3 = loadScene("Insturctions.json"); geometry* geom = createTerrain(scene1->textures["heightmap"]); scene1->geometry["terrain"] = geom; render_object* obj = new render_object(); obj->geometry = geom; obj->material = scene1->material["mat_001"]; obj->transform.scale = (glm::vec3(1.0, 8.0, 1.0)); obj->transform.position = (glm::vec3(0.0, -3.0, 0.0)); scene1->objects["terrain"] = obj; post_proc1 = new post_process(post_eff); post_proc1->create(screenWidth, screenHeight); post_proc2 = new post_process(post_eff1); post_proc2->create(screenWidth, screenHeight); post_proc3 = new post_process(post_eff2); post_proc3->create(screenWidth, screenHeight); post_proc4 = new post_process(post_eff3); post_proc4->create(screenWidth, screenHeight); post_proc5 = new post_process(post_eff4); post_proc5->create(screenWidth, screenHeight); //post_proc = post_proc1; std::vector<std::string> cubemap_texs; cubemap_texs.push_back("xpos.png"); cubemap_texs.push_back("xneg.png"); cubemap_texs.push_back("ypos.png"); cubemap_texs.push_back("yneg.png"); cubemap_texs.push_back("zpos.png"); cubemap_texs.push_back("zneg.png"); std::vector<std::string> cubemap_texs1; cubemap_texs1.push_back("posx.jpg"); cubemap_texs1.push_back("negx.jpg"); cubemap_texs1.push_back("posy.jpg"); cubemap_texs1.push_back("negy.jpg"); cubemap_texs1.push_back("posz.jpg"); cubemap_texs1.push_back("negz.jpg"); cubemap* cm = new cubemap(cubemap_texs); cm->create(); cubemap* cm1 = new cubemap(cubemap_texs1); cm1->create(); sb1 = new skybox(cm); sb1->create(); sb2 = new skybox(cm1); sb2->create(); }
Qgs3DMapScene::Qgs3DMapScene( const Qgs3DMapSettings &map, Qt3DExtras::QForwardRenderer *defaultFrameGraph, Qt3DRender::QRenderSettings *renderSettings, Qt3DRender::QCamera *camera, const QRect &viewportRect, Qt3DCore::QNode *parent ) : Qt3DCore::QEntity( parent ) , mMap( map ) , mForwardRenderer( defaultFrameGraph ) { connect( &map, &Qgs3DMapSettings::backgroundColorChanged, this, &Qgs3DMapScene::onBackgroundColorChanged ); onBackgroundColorChanged(); // TODO: strange - setting OnDemand render policy still keeps QGIS busy (Qt 5.9.0) // actually it is more busy than with the default "Always" policy although there are no changes in the scene. //renderSettings->setRenderPolicy( Qt3DRender::QRenderSettings::OnDemand ); #if QT_VERSION >= 0x050900 // we want precise picking of terrain (also bounding volume picking does not seem to work - not sure why) renderSettings->pickingSettings()->setPickMethod( Qt3DRender::QPickingSettings::TrianglePicking ); #endif // Camera float aspectRatio = ( float )viewportRect.width() / viewportRect.height(); camera->lens()->setPerspectiveProjection( 45.0f, aspectRatio, 10.f, 10000.0f ); mFrameAction = new Qt3DLogic::QFrameAction(); connect( mFrameAction, &Qt3DLogic::QFrameAction::triggered, this, &Qgs3DMapScene::onFrameTriggered ); addComponent( mFrameAction ); // takes ownership // Camera controlling mCameraController = new QgsCameraController( this ); // attaches to the scene mCameraController->setViewport( viewportRect ); mCameraController->setCamera( camera ); mCameraController->resetView( 1000 ); // create terrain entity createTerrain(); connect( &map, &Qgs3DMapSettings::terrainGeneratorChanged, this, &Qgs3DMapScene::createTerrain ); connect( &map, &Qgs3DMapSettings::terrainVerticalScaleChanged, this, &Qgs3DMapScene::createTerrain ); connect( &map, &Qgs3DMapSettings::mapTileResolutionChanged, this, &Qgs3DMapScene::createTerrain ); connect( &map, &Qgs3DMapSettings::maxTerrainScreenErrorChanged, this, &Qgs3DMapScene::createTerrain ); connect( &map, &Qgs3DMapSettings::maxTerrainGroundErrorChanged, this, &Qgs3DMapScene::createTerrain ); // create entities of renderers Q_FOREACH ( const QgsAbstract3DRenderer *renderer, map.renderers() ) { Qt3DCore::QEntity *newEntity = renderer->createEntity( map ); newEntity->setParent( this ); } // listen to changes of layers in order to add/remove 3D renderer entities connect( &map, &Qgs3DMapSettings::layersChanged, this, &Qgs3DMapScene::onLayersChanged ); Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity; Qt3DCore::QTransform *lightTransform = new Qt3DCore::QTransform; lightTransform->setTranslation( QVector3D( 0, 1000, 0 ) ); // defaults: white, intensity 0.5 // attenuation: constant 1.0, linear 0.0, quadratic 0.0 Qt3DRender::QPointLight *light = new Qt3DRender::QPointLight; light->setConstantAttenuation( 0 ); //light->setColor(Qt::white); //light->setIntensity(0.5); lightEntity->addComponent( light ); lightEntity->addComponent( lightTransform ); lightEntity->setParent( this ); #if 0 ChunkedEntity *testChunkEntity = new ChunkedEntity( AABB( -500, 0, -500, 500, 100, 500 ), 2.f, 3.f, 7, new TestChunkLoaderFactory ); testChunkEntity->setEnabled( false ); testChunkEntity->setParent( this ); chunkEntities << testChunkEntity; #endif connect( mCameraController, &QgsCameraController::cameraChanged, this, &Qgs3DMapScene::onCameraChanged ); connect( mCameraController, &QgsCameraController::viewportChanged, this, &Qgs3DMapScene::onCameraChanged ); #if 0 // experiments with loading of existing 3D models. // scene loader only gets loaded only when added to a scene... // it loads everything: geometries, materials, transforms, lights, cameras (if any) Qt3DCore::QEntity *loaderEntity = new Qt3DCore::QEntity; Qt3DRender::QSceneLoader *loader = new Qt3DRender::QSceneLoader; loader->setSource( QUrl( "file:///home/martin/Downloads/LowPolyModels/tree.dae" ) ); loaderEntity->addComponent( loader ); loaderEntity->setParent( this ); // mesh loads just geometry as one geometry... // so if there are different materials (e.g. colors) used in the model, this information is lost Qt3DCore::QEntity *meshEntity = new Qt3DCore::QEntity; Qt3DRender::QMesh *mesh = new Qt3DRender::QMesh; mesh->setSource( QUrl( "file:///home/martin/Downloads/LowPolyModels/tree.obj" ) ); meshEntity->addComponent( mesh ); Qt3DExtras::QPhongMaterial *material = new Qt3DExtras::QPhongMaterial; material->setAmbient( Qt::red ); meshEntity->addComponent( material ); Qt3DCore::QTransform *meshTransform = new Qt3DCore::QTransform; meshTransform->setScale( 1 ); meshEntity->addComponent( meshTransform ); meshEntity->setParent( this ); #endif if ( map.hasSkyboxEnabled() ) { Qt3DExtras::QSkyboxEntity *skybox = new Qt3DExtras::QSkyboxEntity; skybox->setBaseName( map.skyboxFileBase() ); skybox->setExtension( map.skyboxFileExtension() ); skybox->setParent( this ); // docs say frustum culling must be disabled for skybox. // it _somehow_ works even when frustum culling is enabled with some camera positions, // but then when zoomed in more it would disappear - so let's keep frustum culling disabled defaultFrameGraph->setFrustumCullingEnabled( false ); } // force initial update of chunked entities onCameraChanged(); }
bool MapView::init() { if (!Layer::init()) { return false; } m_mapW = MAP->mapW(); m_mapH = MAP->mapH(); m_gridW = MAP->gridW(); m_gridH = MAP->gridH(); m_displayW = MAP->displayW(); m_displayH = MAP->displayH(); createBg(); createGrid(); createTerrain(); // 注册点击事件; auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesBegan = [=](const std::vector<Touch*> &touches, Event *event) { CCASSERT(!m_draggingTouch, ""); m_draggingTouch = touches[0]; }; listener->onTouchesMoved = [=](const std::vector<Touch*> &touches, Event *event) { CCASSERT(m_draggingTouch, ""); for (const auto &touch : touches) { if (m_draggingTouch == touch) { auto lastPoint = (touch->getPreviousLocation()); auto point = (touch->getLocation()); m_draggingMoveDistance2 += (point - lastPoint).lengthSquared(); if (m_draggingMoveDistance2 > DRAG_MIN_DISTANCE2) { GameLogic::getInstance()->handleDragMap(point - lastPoint); } } } }; listener->onTouchesEnded = [=](const std::vector<Touch*> &touches, Event *event) { CCASSERT(m_draggingTouch, ""); for (const auto &touch : touches) { auto lastPoint = (touch->getPreviousLocation()); auto point = (touch->getLocation()); m_draggingMoveDistance2 += (point - lastPoint).lengthSquared(); if (m_draggingMoveDistance2 < DRAG_MIN_DISTANCE2) { GameLogic::getInstance()->handleTouch(point); } if ( m_draggingTouch == touch ) { m_draggingTouch = nullptr; m_draggingMoveDistance2 = 0.0f; } } }; this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this); return true; }