Esempio n. 1
0
void initFloor(void)
{
    OSG::GeometryUnrecPtr  floor  = OSG::makePlaneGeo(2000.f, 2000.f, 10, 10);
    OSG::NodeUnrecPtr      floorN = OSG::makeNodeFor(floor);
    OSG::TransformUnrecPtr xform  = OSG::Transform::create();
    OSG::NodeUnrecPtr      xformN = OSG::makeNodeFor(xform);

    OSG::ImageUnrecPtr           img = OSG::ImageFileHandler::the()->read("sand1Tile.png");
    OSG::TextureObjChunkUnrecPtr tex = OSG::TextureObjChunk::create();
    tex->setImage(img);

    OSG::ChunkMaterial *chunkMat = dynamic_cast<OSG::ChunkMaterial *>(floor->getMaterial());
    if(chunkMat != NULL)
    {
        chunkMat->addChunk(tex);
    }

    OSG::Quaternion quat;
    quat.setValueAsAxisDeg(OSG::Vec3f(1.f, 0.f, 0.f), -90.f);

    xform->editMatrix().setRotate(quat);

    xformN->addChild(floorN);
    g->rootN->addChild(xformN);
}
Esempio n. 2
0
//do Animation-Calculations here
void Animate()
{
    static OSG::Real64 t0 = OSG::getSystemTime();

    OSG::Real64 t = OSG::getSystemTime() - t0;

    OSG::Real32 rotb = t * 10.0;
    if(rotb > 360.0)
        rotb -= 360.0;

    OSG::Real32 rotc1 = t * 20.0;
    if(rotc1 > 360.0)
        rotc1 -= 360.0;

    OSG::Real32 rotc2 = t * 40.0;
    if(rotc2 > 360.0)
        rotc2 -= 360.0;

    OSG::Quaternion q;
    q.setValueAsAxisDeg(0,0,1, rotb);
    globals->box_trans->editMatrix().setRotate(q);

    q.setValueAsAxisDeg(0,0,1, rotc1);
    globals->cylinder1_trans->editMatrix().setRotate(q);

    q.setValueAsAxisDeg(0,0,1, rotc2);
    globals->cylinder2_trans->editMatrix().setRotate(q);

    globals->mgr->redraw();
}
OSG::NodeTransitPtr createScene(OSG::Window *win)
{
   OSG::NodeRecPtr rootN = OSG::makeNodeFor(OSG::Group::create());

   // Create ground:
   OSG::NodeUnrecPtr groundN = OSG::makePlane(25,25,1,1);
   OSG::Matrix m;
   OSG::Quaternion q;
   q.setValueAsAxisDeg(OSG::Vec3f(1,0,0), -90);
   m.setRotate(q);

   OSG::TransformUnrecPtr groundTransC = OSG::Transform::create();
   groundTransC->setMatrix(m);

   OSG::NodeUnrecPtr groundTransN = OSG::makeNodeFor(groundTransC);
   groundTransN->addChild(groundN);
   rootN->addChild(groundTransN);

   // Set ground material:
   OSG::SimpleMaterialUnrecPtr mat = OSG::SimpleMaterial::create();
   mat->setDiffuse(OSG::Color3f(0.8,0.8,0.8));
   dynamic_cast<OSG::Geometry*>(groundN->getCore())->setMaterial(mat);

//   // Create figure:
//   OSG::NodeUnrecPtr figure1N =
//         OSG::SceneFileHandler::the()->read("../Models/Figure.obj");

//   G.figure1TransC = OSG::Transform::create();
//   OSG::NodeUnrecPtr trans1N = OSG::makeNodeFor(G.figure1TransC);
//   trans1N->addChild(figure1N);
//   rootN->addChild(trans1N);

   OSG::NodeUnrecPtr figureModelA =
         OSG::SceneFileHandler::the()->read("../assets/Figure.obj");

   BoardGame::Figure* figureA = new BoardGame::Figure();
   figureA->setModel(figureModelA);
   rootN->addChild(figureA->getRoot());

   OSG::NodeUnrecPtr figureModelB =
         OSG::SceneFileHandler::the()->read("../assets/Figure.obj");

   BoardGame::Figure* figureB = new BoardGame::Figure();
   figureB->setModel(figureModelB);
   rootN->addChild(figureB->getRoot());

   G.selectedNode = figureModelA;

   return(OSG::NodeTransitPtr(rootN));
}
void Animate()
{
    //Show FPS
    //showFpsCounter();

    if(bAnim == true)
    {
        static OSG::Real64   t0 = OSG::getSystemTime();
        
        OSG::Real64          t = OSG::getSystemTime() - t0;
        
        OSG::Real32          rot0 = t * 0.25;
        if(rot0 > 360.0)
            rot0 -= 360.0;
        
        OSG::Real32          rota = t * 0.5;
        if(rota > 360.0)
            rota -= 360.0;
        
        OSG::Real32          rotb = t * 1.0;
        if(rotb > 360.0)
            rotb -= 360.0;
        
        OSG::Real32          rotc = t * 1.5;
        if(rotc > 360.0)
            rotc -= 360.0;
        
        OSG::Real32          rotd = t * 2.0;
        if(rotd > 360.0)
            rotd -= 360.0;
        
        //    _light2_trans->editMatrix().setTranslate(-100.0*sin(rota),-100.0*cos(rota), 250.0);
        
        //animate Trees
        OSG::Quaternion      q;
        
        q.setValueAsAxisRad(1, 1, 1, 0.5 * sin(rota));
        _tree1_trans->editMatrix().setRotate(q);
        _tree1_trans->editMatrix().setScale(OSG::Vec3f(12.0, 12.0, 10.0));
        
        q.setIdentity();
        
        q.setValueAsAxisRad(1, 1, 1, 0.5 * sin(rotc));
        _tree2_trans->editMatrix().setRotate(q);
        _tree2_trans->editMatrix().setScale(OSG::Vec3f(12.0, 12.0, 10.0));
        
        q.setIdentity();
        
        q.setValueAsAxisRad(1, 1, 1, 0.5 * sin(rotb));
        _tree3_trans->editMatrix().setRotate(q);
        _tree3_trans->editMatrix().setScale(OSG::Vec3f(12.0, 12.0, 10.0));
        
        q.setIdentity();
        
        q.setValueAsAxisRad(1, 1, 1, 0.5 * sin(rotb));
        _tree4_trans->editMatrix().setRotate(q);
        _tree4_trans->editMatrix().setScale(OSG::Vec3f(12.0, 12.0, 10.0));
        
        q.setIdentity();
        
        q.setValueAsAxisRad(1, 1, 1, 0.5 * sin(rotc));
        _tree5_trans->editMatrix().setRotate(q);
        _tree5_trans->editMatrix().setScale(OSG::Vec3f(12.0, 12.0, 10.0));
        
        q.setIdentity();
        
        q.setValueAsAxisRad(1, 1, 1, 0.5 * sin(rotb));
        _tree6_trans->editMatrix().setRotate(q);
        _tree6_trans->editMatrix().setScale(OSG::Vec3f(12.0, 12.0, 10.0));
        
        q.setIdentity();
        
        q.setValueAsAxisRad(1, 1, 1, 0.5 * sin(rotd));
        _tree7_trans->editMatrix().setRotate(q);
        _tree7_trans->editMatrix().setScale(OSG::Vec3f(12.0, 12.0, 10.0));
        
        q.setIdentity();
        
        q.setValueAsAxisRad(1, 1, 1, 0.5 * sin(rotb));
        _tree8_trans->editMatrix().setRotate(q);
        _tree8_trans->editMatrix().setScale(OSG::Vec3f(12.0, 12.0, 10.0));
        
        q.setIdentity();
        
        q.setValueAsAxisRad(1, 1, 1, 0.5 * sin(rotc));
        _tree9_trans->editMatrix().setRotate(q);
        _tree9_trans->editMatrix().setScale(OSG::Vec3f(12.0, 12.0, 10.0));
        
        q.setIdentity();
        
        {
            OSG::Matrix  m;
            m.setIdentity();
            OSG::Vec3f   scale(0.15f,0.15f,0.15f);
            OSG::Vec3f   trans(-40.0 * sin(rotb),-40.0 * cos(rotb),
                          50.0 + 25.0 * sin(rotd));
            q.setValueAsAxisRad(0, 0, 1, -rotb);
            m.setTransform(trans, q, scale);
            _obj1_trans->setMatrix(m);
        }
        
        
        // {
        //     _light2_trans->editMatrix().setTranslate(-40.0 * sin(rotb), -40.0 *
        //                                              cos(rotb),
        //                                              50.0 + 25.0 * sin(rotd));
        // }
        
        //animate Dinos
        
        {
            OSG::Matrix  m;
            m.setIdentity();
            OSG::Vec3f   scale(5.0,5.0,5.0);
            OSG::Real32  ztrans1 = sin(2.0 * rotd);
            if(ztrans1 < 0)
                ztrans1 *= -1.0;
            OSG::Vec3f   trans(-96.0 * cos(rot0),-96.0 * sin(rot0),
                          10.0 + 8.0 * ztrans1);
            m.setScale(OSG::Vec3f(5.0, 5.0, 5.0));
            q.setValueAsAxisRad(0, 0, 1, rot0 - 170);
            m.setTransform(trans, q, scale);
            _dino1_trans->setMatrix(m);
        }
        
        {
            OSG::Matrix  m;
            m.setIdentity();
            OSG::Vec3f   scale(3.0,3.0,3.0);
            OSG::Real32  ztrans1 = sin(2.5 * rotd);
            if(ztrans1 < 0)
                ztrans1 *= -1.0;
            OSG::Vec3f   trans(-96.0 * cos((rot0 - 0.5)),-96.0 * sin((rot0 - 0.5)),
                          6.0 + 8.0 * ztrans1);
            m.setScale(OSG::Vec3f(5.0, 5.0, 5.0));
            q.setValueAsAxisRad(0, 0, 1, rot0 - 169.9);
            m.setTransform(trans, q, scale);
            _dino2_trans->setMatrix(m);
        }
        
        {
            OSG::Matrix  m;
            m.setIdentity();
            OSG::Vec3f   scale(3.0,3.0,3.0);
            OSG::Real32  ztrans1 = sin(3.0 * rotd);
            if(ztrans1 < 0)
                ztrans1 *= -1.0;
            OSG::Vec3f   trans(-96.0 * cos((rot0 - 0.8)),-96.0 * sin((rot0 - 0.8)),
                          6.0 + 8.0 * ztrans1);
            m.setScale(OSG::Vec3f(5.0, 5.0, 5.0));
            q.setValueAsAxisRad(0, 0, 1, rot0 - 170.1);
            m.setTransform(trans, q, scale);
            _dino3_trans->setMatrix(m);
        }
        
        {
            OSG::Matrix  m;
            m.setIdentity();
            OSG::Vec3f   scale(3.0,3.0,3.0);
            OSG::Real32  ztrans1 = sin(2.75 * rotd);
            if(ztrans1 < 0)
                ztrans1 *= -1.0;
            OSG::Vec3f   trans(-96.0 * cos((rot0 - 1.2)),-96.0 * sin((rot0 - 1.2)),
                          6.0 + 8.0 * ztrans1);
            m.setScale(OSG::Vec3f(5.0, 5.0, 5.0));
            q.setValueAsAxisRad(0, 0, 1, rot0 - 170.1);
            m.setTransform(trans, q, scale);
            _dino4_trans->setMatrix(m);
        }
    }

    _navigator.idle(_mousebuttons, _lastx, _lasty);
    mgr->redraw();
}
Esempio n. 5
0
GridPtr Grid::init(jccl::ConfigElementPtr cfgElt)
{
   vprASSERT(cfgElt->getID() == std::string("grid"));

   const unsigned int req_cfg_version(1);

   // Check for correct version of plugin configuration.
   if ( cfgElt->getVersion() < req_cfg_version )
   {
      std::ostringstream msg;
      msg << "Failed to configure grid '" << cfgElt->getName()
          << "'. Required config element version is " << req_cfg_version
          << ", but this element is version " << cfgElt->getVersion();
      throw PluginException(msg.str(), VRKIT_LOCATION);
   }

   mName = cfgElt->getName();

   const std::string size_prop("size");
   const std::string granularity_prop("granularity");
   const std::string color_prop("color");
   const std::string corner_prop("corner");
   const std::string corner_pos_prop("corner_position");
   const std::string orient_prop("orientation");

   const OSG::Real32 width  = cfgElt->getProperty<OSG::Real32>(size_prop, 0);
   const OSG::Real32 height = cfgElt->getProperty<OSG::Real32>(size_prop, 1);

   if ( width <= 0.0f || height <= 0.0f )
   {
      std::ostringstream msg_stream;
      msg_stream << "Invalid grid dimensions " << width << "x" << height;
      throw PluginException(msg_stream.str(), VRKIT_LOCATION);
   }

   const float granularity = cfgElt->getProperty<float>(granularity_prop);

   if ( granularity <= 0.0f )
   {
      std::ostringstream msg_stream;
      msg_stream << "Invalid grid cell granularity " << granularity;
      throw PluginException(msg_stream.str(), VRKIT_LOCATION);
   }

   OSG::Real32 red   = cfgElt->getProperty<OSG::Real32>(color_prop, 0);
   OSG::Real32 green = cfgElt->getProperty<OSG::Real32>(color_prop, 1);
   OSG::Real32 blue  = cfgElt->getProperty<OSG::Real32>(color_prop, 2);

   if ( red < 0.0f || red > 1.0f )
   {
      std::cerr << "WARNING: Invalid red color value " << red
                << " in config element '" << cfgElt->getName() << "'"
                << std::endl;
      red = 0.0f;
   }

   if ( green < 0.0f || green > 1.0f )
   {
      std::cerr << "WARNING: Invalid green color value " << green
                << " in config element '" << cfgElt->getName() << "'"
                << std::endl;
      green = 0.0f;
   }

   if ( blue < 0.0f || blue > 1.0f )
   {
      std::cerr << "WARNING: Invalid blue color value " << blue
                << " in config element '" << cfgElt->getName() << "'"
                << std::endl;
      blue = 0.0f;
   }

   unsigned int corner_val = cfgElt->getProperty<unsigned int>(corner_prop);
   Corner corner;

   if ( 0 <= corner_val && corner_val <= 3 )
   {
      corner = static_cast<Corner>(corner_val);
   }
   else
   {
      std::ostringstream msg_stream;
      msg_stream << "Invalid corner value " << corner_val
                 << "; must be one of 0, 1, 2, or 3";
      throw PluginException(msg_stream.str(), VRKIT_LOCATION);
   }

   const OSG::Vec3f corner_pos(
      cfgElt->getProperty<float>(corner_pos_prop, 0),
      cfgElt->getProperty<float>(corner_pos_prop, 1),
      cfgElt->getProperty<float>(corner_pos_prop, 2)
   );
   OSG::Quaternion rot;
   rot.setValue(
      gmtl::Math::deg2Rad(cfgElt->getProperty<float>(orient_prop, 0)),
      gmtl::Math::deg2Rad(cfgElt->getProperty<float>(orient_prop, 1)),
      gmtl::Math::deg2Rad(cfgElt->getProperty<float>(orient_prop, 2))
   );

   initGeometry(width, height, granularity, corner, corner_pos, rot,
                OSG::Color3f(red, green, blue));

   return shared_from_this();
}