Torch::Torch( World * world ) : AWorldObject( world ) { mFlareSize = 5.0f; mColorCycle = 0.0f; mFlareRotation = 0.0f; mFlarePosition = QVector3D(0,1.6,0); setBoundingSphere( mFlareSize + mFlarePosition.length() ); if( !sQuadVertexBuffer.isCreated() ) { sQuadVertexBuffer = QGLBuffer( QGLBuffer::VertexBuffer ); sQuadVertexBuffer.create(); sQuadVertexBuffer.bind(); sQuadVertexBuffer.setUsagePattern( QGLBuffer::StaticDraw ); sQuadVertexBuffer.allocate( sQuadVertices, sizeof(sQuadVertices) ); sQuadVertexBuffer.release(); } mMaterial = new Material( scene()->glWidget(), "Flare" ); world->addLightSource( this ); mModel = new StaticModel( scene()->glWidget(), "SpearTorch" ); }
PowerUp::PowerUp( Landscape * landscape, QString type, const QPoint & mapPosition, int mapRadius ) : AWorldObject( landscape->world() ), mLandscape( landscape ), mPosition( mapPosition ), mRadius( mapRadius ), mRotationAngle( 0.0f ), mRandom(false) { setBoundingSphere( 1.0f ); if( type == "health" ) { mPowerType = HEALTH; mMaterial = new Material( landscape->scene()->glWidget(), "PowerUp_Health" ); } else if( type == "armor" ) { mPowerType = ARMOR; mMaterial = new Material( landscape->scene()->glWidget(), "PowerUp_Armor" ); } else if( type == "weapon_laser" ) { mPowerType = WEAPON_LASER; mMaterial = new Material( landscape->scene()->glWidget(), "PowerUp_Weapon_Laser" ); } respawn(); }
World::World() { int nrows = 15,ncols = 15; // Define blocks size.height for(int i = 0; i < nrows; ++i) { _rowHeights.push_back(80 + 100*double(std::rand())/RAND_MAX); } // Define blocks size.width for(int i = 0; i < ncols; ++i) { _colWidths.push_back(80 + 100*double(std::rand())/RAND_MAX); } Geo::RectSplitter splitter(Vector(20,20)); _blockMatrix.reserve(nrows); double y = 0; for(int i = 0; i < nrows; ++i) { _blockMatrix.push_back(WorldRow()); WorldRow &row = _blockMatrix.back(); row.reserve(ncols); double x = 0; for(int j = 0; j < ncols; ++j) { Geo::Rectangle blockRect = Geo::Rectangle(Point(x,y),Vector(_colWidths[j],_rowHeights[i])).inset(6); row.push_back(Block(blockRect, splitter, _texturePool)); x += _colWidths[j]; } y += _rowHeights[i]; } setBoundingSphere(BoundingSphere::createWithAABox(Point(),Point() + size())); }
Flower::Flower( Landscape * landscape, const QString & filename, const QPoint & mapPosition, int mapRadius, int number, int priority ) : AVegetation( landscape->world(), priority ), mLandscape( landscape ) { QPointF position = mLandscape->terrain()->fromMap( mapPosition ); QSizeF radi = mLandscape->terrain()->fromMap( QSize( mapRadius, mapRadius ) ); mModel = new StaticModel( world()->scene()->glWidget(), filename ); setPosition( QVector3D( position.x(), 0, position.y() ) ); setBoundingSphere( qMax( radi.width(),radi.height() ) ); for( int i=0; i<number; i++ ) { QVector3D treePos; int tries = 0; do { QVector2D random = RandomNumber::inUnitCircle(); treePos.setX( position.x() + random.x() * radi.width() ); treePos.setZ( position.y() + random.y() * radi.height() ); treePos.setY( mLandscape->terrain()->getHeight( QPointF( treePos.x(),treePos.z()) ) - 1.0f ); tries++; if( tries > 1000 ) { qWarning() << QObject::tr("Giving up placing trees - no suitable position found"); return; } } while( treePos.y() < mLandscape->waterHeight() ); QMatrix4x4 pos; pos.translate( treePos ); pos.scale( RandomNumber::minMax( 0.3f, 0.4f ) ); pos.rotate( RandomNumber::minMax( -10.0f, 10.0f ), 1.0f, 0.0f, 0.0f ); pos.rotate( RandomNumber::minMax( 0.0f, 360.0f ), 0.0f, 1.0f, 0.0f ); pos.rotate( RandomNumber::minMax( -10.0f, 10.0f ), 1.0f, 0.0f, 0.0f ); mInstances.append( pos ); mPositions.append( treePos ); } }
RenderableDebugPlane::RenderableDebugPlane(const ghoul::Dictionary& dictionary) : Renderable(dictionary) , _texture("texture", "Texture", -1, -1, 255) , _billboard("billboard", "Billboard", false) , _size("size", "Size", glm::vec2(1,1), glm::vec2(0.f), glm::vec2(1.f, 25.f)) , _origin(Origin::Center) , _shader(nullptr) , _quad(0) , _vertexPositionBuffer(0) { glm::vec2 size; dictionary.getValue("Size", size); _size = size; if (dictionary.hasKey("Name")){ dictionary.getValue("Name", _nodeName); } if (dictionary.hasKey("Texture")) { int t; dictionary.getValue("Texture", t); _texture = t; } std::string origin; if (dictionary.getValue("Origin", origin)) { if (origin == "LowerLeft") { _origin = Origin::LowerLeft; } else if (origin == "LowerRight") { _origin = Origin::LowerRight; } else if (origin == "UpperLeft") { _origin = Origin::UpperLeft; } else if (origin == "UpperRight") { _origin = Origin::UpperRight; } else if (origin == "Center") { _origin = Origin::Center; } } // Attempt to get the billboard value bool billboard = false; if (dictionary.getValue("Billboard", billboard)) { _billboard = billboard; } int texture; if (dictionary.getValue("Texture", texture)) _texture = texture; addProperty(_texture); addProperty(_billboard); addProperty(_size); _size.onChange([this](){ _planeIsDirty = true; }); setBoundingSphere(_size.value()); }