bool GameLayer::init() { CCLayer::init(); CCSize size = CCDirector::sharedDirector()->getWinSize(); screenW = size.width; screenH = size.height; createBox2DWorld(); generateBackground(); setTerrain(Terrain::terrainWithWorld(world)); addChild(getTerrain()); setHero(Hero::heroWithWorld(world)); getTerrain()->addChild(getHero()); setTouchEnabled(true); tapDown = false; scheduleUpdate(); return true; }
GameLayer::~GameLayer() { delete world; world = NULL; getBackground()->release(); getTerrain()->release(); setBackground(NULL); setTerrain(NULL); }
void SceneTerrain::loadFrom(const std::shared_ptr<XmlChunk> &chunk, const XmlParser &xmlParser) { this->name = chunk->getAttributeValue(NAME_ATTR); setTerrain(TerrainReaderWriter().loadFrom(chunk, xmlParser)); auto collisionTerrainShape = std::make_shared<urchin::CollisionHeightfieldShape>(terrain->getMesh()->getVertices(), terrain->getMesh()->getXSize(), terrain->getMesh()->getZSize()); RigidBody *terrainRigidBody = new RigidBody(this->name, Transform<float>(terrain->getPosition()), collisionTerrainShape); setupInteractiveBody(terrainRigidBody); }
void LandOverlay::build( const TilePos& pos ) { City &city = Scenario::instance().getCity(); Tilemap &tilemap = city.getTilemap(); _master_tile = &tilemap.at( pos ); for (int dj = 0; dj<_size; ++dj) { for (int di = 0; di<_size; ++di) { Tile &tile = tilemap.at( pos + TilePos( di, dj ) ); tile.set_master_tile(_master_tile); tile.set_picture(_picture); TerrainTile &terrain = tile.get_terrain(); terrain.setOverlay(this); setTerrain(terrain); } } }
bool GameLayer::init() { CCLayer::init(); CCSize size = CCDirector::sharedDirector()->getWinSize(); screenW = size.width; screenH = size.height; createBox2DWorld(); //setBackground(CCSprite::spriteWithFile("background.png")); //setBackground(generateBackground()); //getBackground()->setPosition(ccp(screenW/2, screenH/2)); //getBackground()->setScaleX(screenW/getBackground()->getTextureRect().size.width); //getBackground()->setScaleY(screenH/getBackground()->getTextureRect().size.height); //CCLog("sw = %f, sh = %f, bw = %f, bh = %f", screenW, screenH, getBackground()->getTextureRect().size.width, getBackground()->getTextureRect().size.height); //ccTexParams tp = {GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT}; //getBackground()->getTexture()->setTexParameters(&tp); //addChild(getBackground()); generateBackground(); setTerrain(Terrain::terrainWithWorld(world)); addChild(getTerrain()); setHero(Hero::heroWithWorld(world)); getTerrain()->addChild(getHero()); setIsTouchEnabled(true); tapDown = false; scheduleUpdate(); return true; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { QGLFormat glFormat; glFormat.setVersion(3, 3); glFormat.setProfile(QGLFormat::CoreProfile); glFormat.setSampleBuffers(true); viewer = new ModelViewer(glFormat, this); connect(viewer, SIGNAL(openGLInitialized()), this, SLOT(setTerrain())); //-------------------------------------------------------------------------------- QGroupBox *gbStaticOptions = new QGroupBox("Static", this); gbStaticOptions->setFlat(true); sbPCount = new QSpinBox(this); sbPCount->setRange(4, 100000); sbPCount->setSingleStep(50); sbPCount->setValue(10000); sbPSSize = new QSpinBox(this); sbPSSize->setRange(50, 1000); sbPSSize->setSingleStep(50); sbPSSize->setValue(400); sbTCSize = new QSpinBox(this); sbTCSize->setRange(1, 400); sbTCSize->setSingleStep(1); sbTCSize->setValue(2); QGridLayout *statLayout = new QGridLayout(); statLayout->setContentsMargins(0, 0, 0, 0); statLayout->setSpacing(5); statLayout->setColumnStretch(0, 0); statLayout->setColumnStretch(1, 1); statLayout->addWidget(new QLabel("Max particles:", this), 1, 0); statLayout->addWidget(sbPCount, 1, 1); statLayout->addWidget(new QLabel("Cube size:", this), 2, 0); statLayout->addWidget(sbPSSize, 2, 1); statLayout->addWidget(new QLabel("Terrain grid size:", this), 3, 0); statLayout->addWidget(sbTCSize, 3, 1); gbStaticOptions->setLayout(statLayout); //-------------------------------------------------------------------------------- QGroupBox *gbDynamicOptions = new QGroupBox("Dynamic", this); gbDynamicOptions->setFlat(true); QComboBox *cbBType = new QComboBox(this); cbBType->addItem("perspective"); cbBType->addItem("fixed size"); cbBType->setCurrentIndex(0); connect(cbBType, SIGNAL(currentIndexChanged(int)), viewer, SLOT(setBillboardType(int))); sbTDist = new QDoubleSpinBox(this); sbTDist->setRange(0, 100); sbTDist->setSingleStep(1); sbTDist->setValue(50); connect(sbTDist, SIGNAL(valueChanged(double)), viewer, SLOT(setDistanceThreshold(double))); QCheckBox *cbShowTerrain = new QCheckBox("Show skybox", this); cbShowTerrain->setChecked(true); connect(cbShowTerrain, SIGNAL(toggled(bool)), viewer, SLOT(setShowTerrain(bool))); QCheckBox *cbShowWireframe = new QCheckBox("Wireframe", this); cbShowWireframe->setChecked(false); connect(cbShowWireframe, SIGNAL(toggled(bool)), viewer, SLOT(setWireframeMode(bool))); QPushButton *pbGenerate = new QPushButton("Generate", this); connect(pbGenerate, SIGNAL(clicked()), this, SLOT(generateParticles())); QGridLayout *dynLayout = new QGridLayout(); dynLayout->setContentsMargins(0, 0, 0, 0); dynLayout->setSpacing(5); dynLayout->setColumnStretch(0, 0); dynLayout->setColumnStretch(1, 1); dynLayout->addWidget(new QLabel("Billboard type:", this), 0, 0); dynLayout->addWidget(cbBType, 0, 1); dynLayout->addWidget(new QLabel("Thres distance:", this), 1, 0); dynLayout->addWidget(sbTDist, 1, 1); dynLayout->addWidget(cbShowTerrain, 2, 0, 1, 2); dynLayout->addWidget(cbShowWireframe, 3, 0, 1, 2); dynLayout->addWidget(pbGenerate, 4, 0, 1, 2); gbDynamicOptions->setLayout(dynLayout); //-------------------------------------------------------------------------------- QGroupBox *gbTerrainOptions = new QGroupBox("Terrain", this); gbTerrainOptions->setFlat(true); cbTerrainTexture = new QComboBox(this); cbTerrainTexture->addItem("texture 1"); connect(cbTerrainTexture, SIGNAL(currentIndexChanged(int)), this, SLOT(setTerrainTexture(int))); QComboBox *cbTerrainMode = new QComboBox(this); cbTerrainMode->addItem("texture"); cbTerrainMode->addItem("normal"); cbTerrainMode->addItem("facet norm."); cbTerrainMode->addItem("vertex norm."); connect(cbTerrainMode, SIGNAL(currentIndexChanged(int)), viewer, SLOT(setTerrainTexMode(int))); QDoubleSpinBox *sbContrast = new QDoubleSpinBox(this); sbContrast->setRange(0.1, 10.0); sbContrast->setSingleStep(0.1); sbContrast->setValue(1.0); connect(sbContrast, SIGNAL(valueChanged(double)), viewer, SLOT(setTerrainContrast(double))); sbTPers = new QSpinBox(this); sbTPers->setRange(1, 500); // sbTPers->setSingleStep(10); sbTPers->setValue(10); sbTFreq = new QSpinBox(this); sbTFreq->setRange(1, 500); // sbTFreq->setSingleStep(10); sbTFreq->setValue(10); sbTAmp = new QDoubleSpinBox(this); sbTAmp->setRange(0.1, 100.0); sbTAmp->setValue(30.0); sbTOct = new QSpinBox(this); sbTOct->setRange(1, 10); sbTOct->setValue(3); QPushButton *pbUpdateTerrain = new QPushButton("Update terrain", this); connect(pbUpdateTerrain, SIGNAL(clicked()), this, SLOT(generateTerrain())); QGridLayout *terLayout = new QGridLayout(); terLayout->setContentsMargins(0, 0, 0, 0); terLayout->setSpacing(5); terLayout->addWidget(new QLabel("Texture:", this), 0, 0); terLayout->addWidget(cbTerrainTexture, 0, 1); terLayout->addWidget(new QLabel("Mode:", this), 1, 0); terLayout->addWidget(cbTerrainMode, 1, 1); terLayout->addWidget(new QLabel("Contrast:", this), 2, 0); terLayout->addWidget(sbContrast, 2, 1); terLayout->addWidget(new QLabel("Persistence:", this), 3, 0); terLayout->addWidget(sbTPers, 3, 1); terLayout->addWidget(new QLabel("Frequency:", this), 4, 0); terLayout->addWidget(sbTFreq, 4, 1); terLayout->addWidget(new QLabel("Amplitude:", this), 5, 0); terLayout->addWidget(sbTAmp, 5, 1); terLayout->addWidget(new QLabel("Octaves:", this), 6, 0); terLayout->addWidget(sbTOct, 6, 1); terLayout->addWidget(pbUpdateTerrain, 7, 0, 1, 2); gbTerrainOptions->setLayout(terLayout); //-------------------------------------------------------------------------------- QGroupBox *gbCameraOptions = new QGroupBox("Camera", this); gbCameraOptions->setFlat(true); cbCameraMode = new QCheckBox("Single camera", this); cbCameraMode->setChecked(true); connect(cbCameraMode, SIGNAL(toggled(bool)), this, SLOT(setCameraMode(bool))); cbCurrentCamera = new QComboBox(this); cbCurrentCamera->addItem("particles"); cbCurrentCamera->addItem("free"); cbCurrentCamera->setEnabled(false); connect(cbCurrentCamera, SIGNAL(currentIndexChanged(int)), viewer, SLOT(setCurrentCamera(int))); QGridLayout *camLayout = new QGridLayout(); camLayout->setContentsMargins(0, 0, 0, 0); camLayout->setSpacing(5); camLayout->addWidget(cbCameraMode, 0, 0, 1, 2); camLayout->addWidget(new QLabel("Camera:", this), 1, 0); camLayout->addWidget(cbCurrentCamera, 1, 1); gbCameraOptions->setLayout(camLayout); //-------------------------------------------------------------------------------- QGroupBox *gbOptions = new QGroupBox("Options", this); QGridLayout *optLayout = new QGridLayout(); optLayout->setSpacing(5); optLayout->setContentsMargins(5, 5, 5, 5); optLayout->setColumnStretch(0, 0); optLayout->setColumnStretch(1, 1); optLayout->addWidget(gbStaticOptions, 0, 0, 1, 2); optLayout->addWidget(gbDynamicOptions, 1, 0, 1, 2); optLayout->addWidget(gbTerrainOptions, 3, 0, 1, 2); optLayout->addWidget(gbCameraOptions, 4, 0, 1, 2); optLayout->setRowStretch(2, 1); gbOptions->setLayout(optLayout); QWidget *w = new QWidget(this); QHBoxLayout *layout = new QHBoxLayout(); layout->setContentsMargins(5, 5, 5, 5); layout->setSpacing(5); layout->addWidget(viewer, 1); layout->addWidget(gbOptions, 0); w->setLayout(layout); this->setCentralWidget(w); this->setWindowTitle("CG Task 4"); }
void TShadow::render( FnTerrain& fyTerrain ) { setTerrain( fyTerrain.Object() ); Render(); }
//------------------------------------------------------------------------------ // transmit() -- send radar emissions //------------------------------------------------------------------------------ void RealBeamRadar::transmit(const LCreal dt) { BaseClass::transmit(dt); // Test parameters double latitude = 0; double longitude = 0; beamWidth = 7.0; // const Simulation::Player* own = getOwnship(); if (own != nullptr) { // Get our ownship parameters altitude = static_cast<LCreal>(own->getAltitude()); latitude = own->getLatitude(); longitude = own->getLongitude(); // Locate the terrain elevation database if (terrain == nullptr) { const Simulation::Simulation* sim = own->getSimulation(); if (sim != nullptr) { setTerrain( sim->getTerrain() ); } } } // Transmitting, scanning const Simulation::Antenna* ant = getAntenna(); if (isTransmitting() && ant != nullptr && image != nullptr && terrain != nullptr && terrain->isDataLoaded()) { // Compute max range (NM) LCreal maxRngNM = getRange(); // Compute ground range LCreal groundRange[IMG_HEIGHT]; computeGroundRanges(groundRange, IMG_HEIGHT, maxRngNM); // Compute slant range LCreal slantRange2[IMG_HEIGHT]; computeSlantRanges2(slantRange2, IMG_HEIGHT, groundRange, altitude); // Compute the loss from range LCreal rangeLoss[IMG_HEIGHT]; computeRangeLoss(rangeLoss, IMG_HEIGHT, slantRange2); // Compute the earth's curvature effect LCreal curvature[IMG_HEIGHT]; computeEarthCurvature(curvature, IMG_HEIGHT, maxRngNM, static_cast<LCreal>(Basic::Nav::ERAD60)); LCreal hue = 120.0; // see Hsv LCreal saturation = 0.0; // see Hsv const Basic::Hsva* grayTable[19]; grayTable[0] = new Basic::Hsva( hue, saturation, 0.0f, 1.0f ); grayTable[1] = new Basic::Hsva( hue, saturation, 0.0872f, 1.0f ); grayTable[2] = new Basic::Hsva( hue, saturation, 0.1736f, 1.0f ); grayTable[3] = new Basic::Hsva( hue, saturation, 0.2588f, 1.0f ); grayTable[4] = new Basic::Hsva( hue, saturation, 0.3420f, 1.0f ); grayTable[5] = new Basic::Hsva( hue, saturation, 0.4226f, 1.0f ); grayTable[6] = new Basic::Hsva( hue, saturation, 0.5000f, 1.0f ); grayTable[7] = new Basic::Hsva( hue, saturation, 0.5736f, 1.0f ); grayTable[8] = new Basic::Hsva( hue, saturation, 0.6428f, 1.0f ); grayTable[9] = new Basic::Hsva( hue, saturation, 0.7071f, 1.0f ); grayTable[10] = new Basic::Hsva( hue, saturation, 0.7660f, 1.0f ); grayTable[11] = new Basic::Hsva( hue, saturation, 0.8192f, 1.0f ); grayTable[12] = new Basic::Hsva( hue, saturation, 0.8660f, 1.0f ); grayTable[13] = new Basic::Hsva( hue, saturation, 0.9063f, 1.0f ); grayTable[14] = new Basic::Hsva( hue, saturation, 0.9397f, 1.0f ); grayTable[15] = new Basic::Hsva( hue, saturation, 0.9659f, 1.0f ); grayTable[16] = new Basic::Hsva( hue, saturation, 0.9848f, 1.0f ); grayTable[17] = new Basic::Hsva( hue, saturation, 0.9962f, 1.0f ); grayTable[18] = new Basic::Hsva( hue, saturation, 1.0f, 1.0f ); // Get antenna look angles antAzAngle = static_cast<LCreal>(ant->getAzimuthD()); antElAngle = static_cast<LCreal>(ant->getElevationD()); // Which ray are we on? LCreal halfRay = static_cast<LCreal>(IMG_WIDTH/2.0f); int ray = static_cast<int>(((antAzAngle/45.0f) * halfRay) + halfRay); if (ray < 0) ray = 0; if (ray > (IMG_WIDTH-1)) ray = (IMG_WIDTH-1); if (fpass) { ray0 = ray; fpass = false; } // --- // For all rays from ray0 to our current ray // --- int icol = ray0; while (icol != ray) { for (int irow = 0; irow < IMG_HEIGHT; irow++) { elevations[irow] = 0; aacData[irow] = 1.0; validFlgs[irow] = false; maskFlgs[irow] = false; } // Direction int xx = icol - (IMG_WIDTH/2); LCreal direction = 45.0 * static_cast<LCreal>(xx) / static_cast<LCreal>(IMG_WIDTH/2); // get a strip of elevations from south to north unsigned int num = terrain->getElevations(elevations, validFlgs, IMG_HEIGHT, latitude, longitude, direction, groundRange[IMG_HEIGHT-1], interpolate); // Apply earth curvature effects to terrain elevations for (int irow = 0; irow < IMG_HEIGHT; irow++) { elevations[irow] -= curvature[irow]; } // Generate Masks Basic::Terrain::vbwShadowChecker(maskFlgs, elevations, validFlgs, IMG_HEIGHT, groundRange[IMG_HEIGHT-1], altitude, antElAngle, beamWidth); // Compute AAC data Basic::Terrain::aac(aacData, elevations, maskFlgs, IMG_HEIGHT, groundRange[IMG_HEIGHT-1], altitude); // Draw a line along the Y points (moving from south to north along the latitude lines) for (int irow = 0; irow < IMG_HEIGHT; irow++) { LCreal sn = aacData[irow]; // convert to a color (or gray) value osg::Vec3 color(0,0,0); if (validFlgs[irow] && !maskFlgs[irow]) { Basic::Terrain::getElevationColor(sn, 0.0, 1.0, grayTable, 19, color); } // store this color int idx = irow*imgWidth*PIXEL_SIZE + icol*PIXEL_SIZE; image[idx+0] = static_cast<unsigned char>( 255.0 * color[0] ); image[idx+1] = static_cast<unsigned char>( 255.0 * color[1] ); image[idx+2] = static_cast<unsigned char>( 255.0 * color[2] ); } if (icol < ray) icol++; else if (icol > ray) icol--; } ray0 = ray; } }
//------------------------------------------------------------------------------ // deleteData() -- delete member data //------------------------------------------------------------------------------ void RealBeamRadar::deleteData() { setTerrain( nullptr ); freeImageMemory(); }
BattleTile::~BattleTile() { setTerrain(0); setUnit(0); }