Show
Ignore:
Timestamp:
05/20/04 12:15:48 (11 years ago)
Author:
robert
Message:

Added Vec2d, Vec3d and Vec4d classes, and remapped Vec2, Vec3 and Vec4 to
Vec2f, Vec3f an Vec4f respectively, with typedef's to the from Vec* to Vec*f.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgsimulation/osgsimulation.cpp

    r2995 r3008  
    33#include <osg/Group> 
    44#include <osg/Geode> 
     5#include <osg/ShapeDrawable> 
     6#include <osg/Texture2D> 
     7#include <osg/PositionAttitudeTransform> 
     8 
     9#include <osgDB/ReadFile> 
    510 
    611#include <osgParticle/ExplosionEffect> 
     
    813#include <osgParticle/FireEffect> 
    914#include <osgParticle/ParticleSystemUpdater> 
     15 
     16// for the grid data.. 
     17#include "../osghangglide/terrain_coords.h" 
     18 
     19osg::Vec3 computeTerrainIntersection(osg::Node* subgraph,float x,float y) 
     20{ 
     21    osgUtil::IntersectVisitor iv; 
     22    osg::ref_ptr<osg::LineSegment> segDown = new osg::LineSegment; 
     23 
     24    const osg::BoundingSphere& bs = subgraph->getBound(); 
     25    float zMax = bs.center().z()+bs.radius(); 
     26    float zMin = bs.center().z()-bs.radius(); 
     27     
     28    segDown->set(osg::Vec3(x,y,zMin),osg::Vec3(x,y,zMax)); 
     29    iv.addLineSegment(segDown.get()); 
     30 
     31    subgraph->accept(iv); 
     32 
     33    if (iv.hits()) 
     34    { 
     35        osgUtil::IntersectVisitor::HitList& hitList = iv.getHitList(segDown.get()); 
     36        if (!hitList.empty()) 
     37        { 
     38            osg::Vec3 ip = hitList.front().getWorldIntersectPoint(); 
     39            return  ip; 
     40        } 
     41    } 
     42 
     43    return osg::Vec3(x,y,0.0f); 
     44} 
    1045 
    1146 
     
    1752{ 
    1853 
     54    osg::Geode* terrainGeode = new osg::Geode; 
     55    { 
     56        osg::StateSet* stateset = new osg::StateSet(); 
     57        osg::Image* image = osgDB::readImageFile("Images/lz.rgb"); 
     58        if (image) 
     59        { 
     60            osg::Texture2D* texture = new osg::Texture2D; 
     61            texture->setImage(image); 
     62            stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); 
     63        } 
     64 
     65        terrainGeode->setStateSet( stateset ); 
     66 
     67        float size = 1000; // 10km; 
     68        float scale = size/39.0f; // 10km; 
     69        float z_scale = scale*3.0f; 
     70 
     71        osg::HeightField* grid = new osg::HeightField; 
     72        grid->allocateGrid(38,39); 
     73        grid->setXInterval(scale); 
     74        grid->setYInterval(scale); 
     75 
     76        for(unsigned int r=0;r<39;++r) 
     77        { 
     78            for(unsigned int c=0;c<38;++c) 
     79            { 
     80                grid->setHeight(c,r,z_scale*vertex[r+c*39][2]); 
     81            } 
     82        } 
     83        terrainGeode->addDrawable(new osg::ShapeDrawable(grid)); 
     84         
     85        root->addChild(terrainGeode); 
     86    }     
     87 
     88 
     89     
     90    osg::PositionAttitudeTransform* positionEffects = new osg::PositionAttitudeTransform; 
     91    positionEffects->setPosition(computeTerrainIntersection(terrainGeode,100.0f,100.0f)); 
     92    root->addChild(positionEffects); 
     93 
    1994    osgParticle::ExplosionEffect* explosion = new osgParticle::ExplosionEffect; 
    2095    osgParticle::SmokeEffect* smoke = new osgParticle::SmokeEffect; 
    2196    osgParticle::FireEffect* fire = new osgParticle::FireEffect; 
    2297 
    23     root->addChild(explosion); 
    24     root->addChild(smoke); 
    25     root->addChild(fire); 
     98    osg::Geode* geode = new osg::Geode; 
     99    geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f,0.0f,0.0f),10.0f))); 
     100    positionEffects->addChild(geode); 
     101 
     102    positionEffects->addChild(explosion); 
     103    positionEffects->addChild(smoke); 
     104    positionEffects->addChild(fire); 
    26105 
    27106    osgParticle::ParticleSystemUpdater *psu = new osgParticle::ParticleSystemUpdater;