SGSTerrain::SGSTerrain(std::string& terrain_file, Size size) : __width(size.width), __height(size.height) { __terrain_info = new TERRAIN_TYPE[__width * __height]; loadTerrain(terrain_file); }
int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutInitWindowPosition(100, 100); glutInitWindowSize(800, 400); glutCreateWindow("MotorCross"); _terrain = loadTerrain("heightmap.bmp", 20); //Initialize(); initRendering(); motorcycle= new Motor(motor_x,motor_y); glutReshapeFunc(windowResize); glutDisplayFunc(renderScene); // glutIdleFunc(update); glutIgnoreKeyRepeat(1); glutMouseFunc(mouseButton); glutMotionFunc(mouseMove); glutKeyboardFunc(processNormalKeys); glutSpecialFunc(pressSpecialKey); glutSpecialUpFunc(releaseSpecialKey); glEnable(GL_DEPTH_TEST); glutTimerFunc(50, update, 0); glutMainLoop(); return 0; }
int main(int argc, char** argv) { loadTerrain(); glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_RGBA | GLUT_DOUBLE | GLUT_MULTISAMPLE); glutInitWindowSize(s_width, s_height); glutInitWindowPosition(0, 0); glutCreateWindow("Terrain"); glewInit(); initVertexBufferObject(); initTexture(); initShader(); glClearColor(1.0, 1.0, 1.0, 1.0); glEnable(GL_DEPTH_TEST); glEnable(GL_MULTISAMPLE); glutDisplayFunc(on_display); glutReshapeFunc(on_reshape); glutKeyboardFunc(on_keyboard); glutTimerFunc(1, on_timer, 1); glutMainLoop(); return 0; }
// Init /////////////////////////////////////////////////// void init(void) { _terrain = loadTerrain("heightmap1.bmp", 20); glClearColor(1.0, 1.0, 1.0, 1.0); initLight(); image1 = loadTexture("reflection__.bmp"); image2 = loadTexture("brick_bump.bmp"); image3 = loadTexture("sand_dn.bmp"); }
GameLogic::GameLogic(void) { mTerrain = NULL; loadTerrain(257, 257, 10.0f, 10.0f, "Art\\heightmap17_257.raw", 3.0f, 0.0f); float terrainWidth = mTerrain->getWidth(); float terrainDepth = mTerrain->getDepth(); mSceneManager = new QuadTree(AABB(D3DXVECTOR3(-terrainWidth/2, 0, -terrainDepth/2), D3DXVECTOR3(terrainWidth/2, 0, terrainDepth/2))); loadAllBoxes(); }
void Game::initWorld() { // gen models for terrainBlock and core Model::createModel(terrain_block_model_id); Model::createModel(core_model_id); // init terrain World::world = new World(loadTerrain()); // init test entity Core* test_entity = new Core(); World::world->addEntity(test_entity); // init test group Group* test_group = new Group(); test_group->addEntity(test_entity); World::world->addGroup(test_group); }
void ChunkManager::initialize(const std::string& saveFolder) { double amplitude = 64; double persistence = 0.01; double frequency = 0.05; double octaves = 1 ; srand(time(NULL)); double randomseed = rand() % 1990; if(jsonChunkExist(saveFolder + "A_terrain.json")) randomseed = loadTerrain(saveFolder); m_PerlinNoise = PerlinNoise(persistence, frequency, amplitude, octaves, randomseed); m_pathJson = saveFolder; saveTerrain(randomseed); }
bool WSWorld::init() { m_worldPopulation = 0; if( !loadTerrain( WSApp::instance()->getSetting("/config/WorldCfg")) ) return false; TiXmlDocument doc; CLog::instance()->log(CLog::msgFlagResources, CLog::msgLvlInfo,__FUNCTION__, _("Loading mobs info...")); doc.LoadFile("../data/zones/teeran/mobs.xml"); if (doc.Error()) { CLog::instance()->log(CLog::msgFlagResources, CLog::msgLvlError,__FUNCTION__, _("XML parser returned an error: %s\n"), doc.ErrorDesc()); return false; } TiXmlElement* mobsxml = doc.FirstChildElement("mobs"); CWorldCharMob::setDefaults(mobsxml); TiXmlNode* childNode; for ( childNode = mobsxml->FirstChild(); childNode != 0; childNode = childNode->NextSibling() ) if (childNode->Type() == TiXmlNode::ELEMENT) if (!strcmp(childNode->Value(), "mob")) // { insertEntity(WSEntityPtr(new CWorldCharMob(getNewEntityID(), childNode->ToElement()))); // CharMobPtr mob(new CWorldCharMob(childNode->ToElement())); // insertCharMob(mob); // } else if (!strcmp(childNode->Value(), "flock")) // { insertEntity(WSEntityPtr(new CMobFlock(getNewEntityID(), childNode->ToElement()))); // MobFlockPtr flock(new CMobFlock(childNode->ToElement())); // m_flocks.push_back(flock); // } CLog::instance()->log(CLog::msgFlagResources, CLog::msgLvlInfo,__FUNCTION__, _("WSWorld.init: Done.")); return true; };
Level::Level(string folder_p, string game_name) { folder = folder_p; terrain_info_file = "terrain"; direct_light_name = ""; spawn_yaw = 0.0f; spawn_dead_height = -3000.0f; spawn_camera_view = LIBGENS_LEVEL_CAMERA_VIEW_FORWARD; spawn_position = Vector3(0.0f, 0.0f, 0.0f); spawn_mode = "Stand"; spawn_speed = 0.0f; spawn_time = 0.0f; game_mode = LIBGENS_LEVEL_GAME_GENERATIONS; if (game_name == LIBGENS_LEVEL_GAME_STRING_UNLEASHED) { game_mode = LIBGENS_LEVEL_GAME_UNLEASHED; } loadStage(); loadSceneEffect(); loadSets(); loadTerrain(); }
void TutorialApplication::loadMap(l2p::StringRef name) { l2p::Package *package = l2p::Package::GetPackage(name); if (!package) return; std::vector<std::shared_ptr<l2p::UModel>> models; package->GetObjects("Model", models); // Find the largest model. The others aren't right or something like that... std::shared_ptr<l2p::UModel> m = nullptr; for (auto i = models.begin(), e = models.end(); i != e; ++i) { if (!m) { m = *i; continue; } if ((*i)->nodes.size() > m->nodes.size()) m = *i; } // Get region from path. { name.substr(0, 2).getAsInteger(10, m->regionX); name.substr(3, 2).getAsInteger(10, m->regionY); mLoadedRegions.push_back(std::make_pair(m->regionX, m->regionY)); } if (m->points.size() != 0) loadBSP(m); std::vector<std::shared_ptr<l2p::ABlockingVolume>> blocking_volumes; package->GetObjects("BlockingVolume", blocking_volumes); for (auto i = blocking_volumes.begin(), e = blocking_volumes.end(); i != e; ++i) { std::shared_ptr<l2p::UModel> m = (*i)->brush; if (m) { Ogre::SceneNode *n = loadBSP(m, false); if (n) { assignActorPropsToNode(*i, n); n->showBoundingBox(true); dynamic_cast<Ogre::Entity*>( n->getAttachedObject(0))->setMaterialName("Volume/Display"); } } } std::vector<std::shared_ptr<l2p::ATerrainInfo>> terrains; package->GetObjects("TerrainInfo", terrains); for (auto i = terrains.begin(), e = terrains.end(); i != e; ++i) { loadTerrain(*i); } std::vector<std::shared_ptr<l2p::AStaticMeshActor>> smeshes; package->GetObjects("StaticMeshActor", smeshes); package->GetObjects("MovableStaticMeshActor", smeshes); for (auto i = smeshes.begin(), e = smeshes.end(); i != e; ++i) { if ( (*i)->bHidden || (*i)->bDeleteMe || !(*i)->bCollideActors || !(*i)->bBlockActors || !(*i)->bBlockPlayers ) continue; loadStaticMeshActor(*i); } }
int runApp( options::variables_map const& opts ) { // Create renderer dp::sg::renderer::rix::gl::SceneRendererSharedPtr renderer = dp::sg::renderer::rix::gl::SceneRenderer::create ( opts["renderengine"].as<std::string>().c_str() , getShaderManager( opts["shadermanager"].as<std::string>() ) ); renderer->setCullingEnabled( false ); dp::math::Vec3f offset( 0.0f, 0.0f, 0.0f ); std::vector<float> resolution = opts["resolution"].as<std::vector<float> >(); if ( !opts["offset"].empty() ) { std::vector<float> ov = opts["resolution"].as<std::vector<float> >(); if ( ov.size() == 3 ) { offset[0] = ov[0]; offset[1] = ov[1]; offset[2] = ov[2]; } else { std::cerr << "resolution argument count is wrong, skipping." << std::endl; } } dp::sg::ui::ViewStateSharedPtr viewStateHandle = loadTerrain( opts["heightmap"].as<std::string>(), opts["texturemap"].as<std::string>(), dp::math::Vec3f(resolution[0], resolution[1], resolution[2]), offset ); dp::sg::ui::setupDefaultViewState( viewStateHandle ); viewStateHandle->setAutoClipPlanes(true); if ( !opts["headlight"].empty() ) { if ( viewStateHandle && viewStateHandle->getScene() && !dp::sg::algorithm::containsLight( viewStateHandle->getScene() ) && viewStateHandle->getCamera() && ( viewStateHandle->getCamera()->getNumberOfHeadLights() == 0 ) ) { // Use the defaults! Note that LightSource ambientColor is black. viewStateHandle->getCamera()->addHeadLight( dp::sg::core::createStandardPointLight() ); } } // Setup default OpenGL format descriptor // We need to create a default format first to be able to check if a stereo pixelformat is available later. // (An unfortunate RenderContextFormat.isAvailable() interface due to Linux.) dp::gl::RenderContextFormat format; // create a widget which shows the scene //dp::sg::ui::glut::SceneRendererWidget w( format ); TerrainRenderer w; // TODO format is not yet supported #if 0 if (stereo) { format.setStereo( stereo ); if ( !w.setFormat( format ) ) // This automatically checks if the format is available. { std::cout << "Warning: No stereo pixelformat available." << std::endl; } } #endif viewStateHandle->setAutoClipPlanes( opts["autoclipplanes"].as<bool>() ); //w.setNumberOfFrames( frames ); w.setViewState( viewStateHandle ); w.setSceneRenderer( renderer ); if ( !opts["continuous"].empty() ) { w.setContinuousUpdate( true ); w.setShowFrameRate( true ); } if( opts["frames"].as<int>() != -1 ) { w.setNumberOfFrames( opts["frames"].as<int>() ); } w.setDuration( opts["duration"].as<double>() ); w.setWindowSize( 640, 480 ); //w.show(); // Keep only once reference to the renderer in the widget. This is necessary since the OpenGL resources // used by the renderer must be deleted before the window gets destroyed. renderer.reset(); glutMainLoop(); return w.getExitCode(); }
void ZombieGame::init() { keyboard_ = DevicePtr(new InputKeyboard(SDLK_UP, SDLK_DOWN, SDLK_LEFT, SDLK_RIGHT, SDLK_SPACE, SDLK_r, SDLK_LSHIFT, SDLK_e)); clipsize_ = 0; bulletsInWeapon_ = 0; health_ = 0; scale_ = 1.f; lastSpawnTime_ = engine_.getTime(); spawnPeriod_ = 0.5f; addKeyListener([&](gui::Component& component, const SDL_Event& keyEvent) { keyboard_->eventUpdate(keyEvent); }); if (zombieEntry_.getDeepChildEntry("music switch").getBool()) { music_ = zombieEntry_.getDeepChildEntry("music track").getMusic(); music_.setVolume(zombieEntry_.getDeepChildEntry("music volume").getFloat()); music_.play(-1); } tree_ = zombieEntry_.getDeepChildEntry("tree image").getSprite(); wall_ = zombieEntry_.getDeepChildEntry("buildings wallImage").getSprite(); nbrUnits_ = 0; unitMaxLimit_ = zombieEntry_.getDeepChildEntry("settings unitLimit").getInt(); innerSpawnRadius_ = zombieEntry_.getDeepChildEntry("settings innerSpawnRadius").getFloat(); outerSpawnRadius_ = zombieEntry_.getDeepChildEntry("settings outerSpawnRadius").getFloat(); terrain_.loadRoadSprites(zombieEntry_.getDeepChildEntry("roads")); loadTerrain(); explosionProperties_ = zombie::loadExplosion(zombieEntry_.getDeepChildEntry("explosion")); humanInjured_ = zombieEntry_.getDeepChildEntry("human injuredAnimation").getAnimation(); humanDie_ = zombieEntry_.getDeepChildEntry("human dieAnimation").getAnimation(); Unit2D human(loadUnit(this, "human", zombieEntry_, false)); human.setDieSound(zombieEntry_.getDeepChildEntry("human dieSound").getSound()); human.setHitSound(zombieEntry_.getDeepChildEntry("human hitSound").getSound()); zombieInjured_ = zombieEntry_.getDeepChildEntry("zombie injuredAnimation").getAnimation(); zombieDie_ = zombieEntry_.getDeepChildEntry("zombie dieAnimation").getAnimation(); Unit2D zombie(loadUnit(this, "zombie", zombieEntry_, true)); zombie.setDieSound(zombieEntry_.getDeepChildEntry("zombie dieSound").getSound()); zombie.setHitSound(zombieEntry_.getDeepChildEntry("zombie hitSound").getSound()); // Add human to engine. { State state(Position(85,120), ORIGO, 0); //Position p = generatePosition(spawningPoints_); //State state(Position(200,200), ORIGO, 0); Unit* unit = units_.pushBack(human); engine_.add(unit); unit->setState(state); unit->setActive(true); unit->setAwake(true); players_.push_back(std::unique_ptr<HumanPlayer>(new HumanPlayer(keyboard_, unit))); viewPosition_ = state.position_; refViewPosition_ = viewPosition_; ++nbrUnits_; } // Add zombies to engine. calculateValidSpawningPoints(units_[0]); unsigned int unitLevel = zombieEntry_.getDeepChildEntry("settings unitLevel").getInt(); for (unsigned int i = 1; i <= unitLevel && i < units_.getMaxSize(); ++i) { Position p = generatePosition(vaildSpawningPoints_); float angle = calculateAnglePointToPoint(p, units_[0].getPosition()); State state(p, ORIGO, angle); Unit* unit = units_.pushBack(zombie); engine_.add(unit); unit->setState(state); unit->setActive(true); unit->setAwake(true); players_.push_back(std::unique_ptr<ZombieBehavior>(new ZombieBehavior(unit))); } // Add cars to engine. Car2D car(zombie::loadCar(zombieEntry_.getDeepChildEntry("car"))); for (unsigned int i = 0; i < 8 && i < units_.getMaxSize(); ++i) { State state(Position(85,130), ORIGO, 0); Car* c = cars_.pushBack(car); engine_.add(c); c->setState(state); c->setActive(true); c->setAwake(true); } // Add missile to engine. Missile2D missile(loadMissile2D(this, zombieEntry_.getDeepChildEntry("equipment missile"))); for (unsigned int i = 0; i < 10 && i < units_.getMaxSize(); ++i) { engine_.add(missiles_.emplaceBack(missile)); } setBackgroundColor(0, 0.1f, 0); zombiesKilled_ = 0; drawBuildings_.createVBO(buildings_, wall_.getTexture()); }