Ejemplo n.º 1
0
// redraw the window
void display( void )
{
    // create the matrix
    OSG::Matrix m;
    OSG::Real32 t = glutGet(GLUT_ELAPSED_TIME);
    
    // set the transforms' matrices
    m.setTransform(OSG::Vec3f(0,
                              0, 
                              OSG::osgSin(t / 1000.f) * 1.5),
                   OSG::Quaternion(OSG::Vec3f (1, 0, 0), 
                                   t / 500.f));

    cyltrans->setMatrix(m);
    
    m.setTransform(OSG::Vec3f(OSG::osgSin(t / 2000.f), 
                              0, 
                              0),
                   OSG::Quaternion(OSG::Vec3f (0, 0, 1), 
                                   t / 2000.f));

    tortrans->setMatrix(m);
    
    mgr->redraw();
}
Ejemplo n.º 2
0
// create the motion matrix for a light source at time t
void makeMatrix(OSG::Real32 t, OSG::Matrix &result)
{
    OSG::Matrix m;
    
    result.setTransform(OSG::Quaternion(OSG::Vec3f(0,0,1), -OSG::Pi / 2));    
    
    m.setTransform(OSG::Vec3f(1, 0, 0));
    result.multLeft(m);
    
    m.setTransform(OSG::Quaternion(OSG::Vec3f(0,1,0), t / 1000.f));    
    result.multLeft(m);

    m.setTransform(OSG::Vec3f(2, 0, 0));
    result.multLeft(m);
    
    m.setTransform(OSG::Quaternion(OSG::Vec3f(0,0,1), t / 3000.f));
    result.multLeft(m); 
}
Ejemplo n.º 3
0
void Transform::setTranslation(OSG::Real32 x, OSG::Real32 y, OSG::Real32 z) 
{
    OSG::Matrix m;
    
    m.setTransform(OSG::Vec3f(x,y,z));
    
    // OSG::beginEditCP(_transform);
    _transform->setMatrix(m);
    // OSG::endEditCP(_transform);
}
// redraw the window
void display( void )
{
    // create the matrix
    OSG::Matrix m;
    OSG::Real32 t = glutGet(GLUT_ELAPSED_TIME );
    
    m.setTransform(OSG::Quaternion(OSG::Vec3f(0,1,0), t / 1000.f));
    
    // set the transform's matrix
    trans->setMatrix(m);

    OSG::commitChanges();
   
    mgr->redraw();
}
Ejemplo n.º 5
0
//
// redraw the window
//
void display(void)
{
    // light spot direction and light position must be provided in eye space
    update_light_state(ubo_light_state, lights);

    // create the matrix
    OSG::Matrix m;
    OSG::Real32 t = glutGet(GLUT_ELAPSED_TIME );
    
    // set the transforms' matrices
    m.setTransform(OSG::Vec3f(0, 0, OSG::osgSin(t / 1000.f) * 1.5),
                   OSG::Quaternion( OSG::Vec3f (1, 0, 0), t / 500.f));

    cyltrans->setMatrix(m);
    
    m.setTransform(OSG::Vec3f(OSG::osgSin(t / 1000.f), 0, 0),
                   OSG::Quaternion( OSG::Vec3f (0, 0, 1), t / 1000.f));

    tortrans->setMatrix(m);

    OSG::commitChanges();
    
    mgr->redraw();
}
Ejemplo n.º 6
0
//
// In  case the clip plane data change this function is called
//
void updateClipPlanes(const VecClipPlaneData& vec)
{
    int sz  = vec.size();

    for(int i = 0; i < iNumClipPlanes; ++i)
    {
        OSG::ClipPlaneChunk *clipPlaneChunk =
            vecClipPlaneDetails[i]._clipPlaneChunk;

        clipPlaneChunk->setEnable(false);

        if(i < sz)
        {
            const ClipPlaneData& data = vec[i];

            //
            // Update the clip plane chunk
            //
            clipPlaneChunk->setEquation(data._equation);
            clipPlaneChunk->setEnable  (data._enabled );

            //
            // and the plane transform core
            //
            OSG::Matrix rotMat;
            OSG::Vec4f v1(0.f, 0.f, -1.f, 0.f);
            OSG::Quaternion q(OSG::Vec3f(v1), OSG::Vec3f(data._equation));
            rotMat.setTransform(q);

            OSG::Matrix mat;
            OSG::Vec3f v2(0.0f, 0.0f, data._equation[3]);
            mat.setTranslate(v2);

            mat.multLeft(rotMat);

            vecClipPlaneDetails[i]._planeTrafoCore->setMatrix(mat);
        }
    }
}
Ejemplo n.º 7
0
// redraw the window
void display( void )
{
    // create the matrix
    OSG::Matrix m;
    OSG::Real32 t = glutGet(GLUT_ELAPSED_TIME );
    
    // set the transforms' matrices
    for(OSG::UInt16 i=0; i < ncopies; ++i)
    {
        m.setTransform(OSG::Vec3f(
                           OSG::osgSin(t / 1000.f + i * 4 * ncopies / OSG::Pi), 
                           OSG::osgCos(t / 1000.f + i * 6 * ncopies / OSG::Pi), 
                           OSG::osgSin(t / 1000.f + i * 7 * ncopies / OSG::Pi)),
                       OSG::Quaternion(OSG::Vec3f (1,1,0), 
                                       t / 1000.f + i * 4 * ncopies / OSG::Pi));
    
        trans[i]->setMatrix(m);
    }

    OSG::commitChanges();
    
    mgr->redraw();
}
Ejemplo n.º 8
0
// redraw the window
void display( void )
{
    // update the geometry
    OSG::Matrix m;

    OSG::Real32 t = glutGet(GLUT_ELAPSED_TIME );

    m.setTransform(OSG::Vec3f(OSG::osgSin(t / 1000.f),
                              OSG::osgCos(t / 1000.f),
                              OSG::osgSin(t / 1000.f)),

                   OSG::Quaternion( OSG::Vec3f(0,1,0), t / 1000.f));

    trans->setMatrix(m);

    // update the image

    grabImage(image);

    // redraw the screen

    mgr->redraw();
}
Ejemplo n.º 9
0
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();
}
Ejemplo n.º 10
0
void Grid::initGeometry(const OSG::Real32 width, const OSG::Real32 height,
                        const OSG::Real32 granularity,
                        const Grid::Corner corner,
                        const OSG::Vec3f& cornerPos,
                        const OSG::Quaternion& rot,
                        const OSG::Color3f& color)
{
   OSG::SimpleMaterialPtr plane_mat = OSG::SimpleMaterial::create();

#if OSG_MAJOR_VERSION < 2
   OSG::CPEditor pme(plane_mat,
                     OSG::SimpleMaterial::AmbientFieldMask         |
                        OSG::SimpleMaterial::DiffuseFieldMask      |
                        OSG::SimpleMaterial::LitFieldMask          |
                        OSG::SimpleMaterial::TransparencyFieldMask);
#endif
   plane_mat->setLit(false);
   plane_mat->setAmbient(color);
   plane_mat->setDiffuse(color);
   plane_mat->setTransparency(0.90f);

   OSG::SimpleMaterialPtr line_mat =
#if OSG_MAJOR_VERSION < 2
      OSG::SimpleMaterialPtr::dcast(OSG::deepClone(plane_mat));
#else
      OSG::cast_dynamic<OSG::SimpleMaterialPtr>(OSG::deepClone(plane_mat));
#endif

#if OSG_MAJOR_VERSION < 2
   OSG::CPEditor lme(line_mat, OSG::SimpleMaterial::TransparencyFieldMask);
#endif
   line_mat->setTransparency(0.0f);

   mPlaneNode = OSG::makePlaneGeo(width, height, 1, 1);
#if OSG_MAJOR_VERSION < 2
   OSG::CPEditor pne(mPlaneNode.core(), OSG::Geometry::MaterialFieldMask);
#endif
   mPlaneNode->setMaterial(plane_mat);

   const float half_width(width / 2.0f);
   const float half_height(height / 2.0f);

   std::cout << "Corner = " << cornerPos << std::endl;
   OSG::Vec3f center_pt;

   switch ( corner )
   {
      case LOWER_LEFT:
         center_pt[0] = cornerPos[0] + half_width;
         center_pt[1] = cornerPos[1] + half_height;
         center_pt[2] = cornerPos[2];
         break;
      case LOWER_RIGHT:
         center_pt[0] = cornerPos[0] - half_width;
         center_pt[1] = cornerPos[1] + half_height;
         center_pt[2] = cornerPos[2];
         break;
      case UPPER_RIGHT:
         center_pt[0] = cornerPos[0] - half_width;
         center_pt[1] = cornerPos[1] - half_height;
         center_pt[2] = cornerPos[2];
         break;
      case UPPER_LEFT:
         center_pt[0] = cornerPos[0] + half_width;
         center_pt[1] = cornerPos[1] - half_height;
         center_pt[2] = cornerPos[2];
         break;
   }

   std::cout << "Center = " << center_pt << std::endl;

   mRoot = OSG::Transform::create();

   OSG::Matrix xform;
   xform.setTransform(center_pt, rot, OSG::Vec3f(1.0f, 1.0f, 1.0f),
                      OSG::Quaternion(), cornerPos - center_pt);

   move(xform);

   OSG::GeoPTypesPtr type = OSG::GeoPTypesUI8::create();
#if OSG_MAJOR_VERSION < 2
   OSG::CPEditor te(type, OSG::GeoPTypesUI8::GeoPropDataFieldMask);
#endif
   type->addValue(GL_LINES);

   unsigned int vertex_count(0);

   OSG::GeoPositions3fPtr pos = OSG::GeoPositions3f::create();
#if OSG_MAJOR_VERSION < 2
   OSG::CPEditor pe(pos, OSG::GeoPositions3f::GeoPropDataFieldMask);
#endif
   for ( float i = -half_width; i <= half_width; i += granularity )
   {
      pos->addValue(OSG::Pnt3f(i, -half_height, 0.0f));
      pos->addValue(OSG::Pnt3f(i, half_height, 0.0f));
      vertex_count += 2;
   }
   for ( float i = -half_height; i <= half_height; i += granularity )
   {
      pos->addValue(OSG::Pnt3f(-half_width, i, 0.0f));
      pos->addValue(OSG::Pnt3f(half_width, i, 0.0f));
      vertex_count += 2;
   }

//   std::cout << "vertex_count = " << vertex_count << std::endl;

   OSG::GeoPLengthsPtr length = OSG::GeoPLengthsUI32::create();
#if OSG_MAJOR_VERSION < 2
   OSG::CPEditor le(length, OSG::GeoPLengthsUI32::GeoPropDataFieldMask);
#endif
   length->addValue(vertex_count);

   OSG::GeoNormals3fPtr norms = OSG::GeoNormals3f::create();
#if OSG_MAJOR_VERSION < 2
   OSG::CPEditor ne(norms, OSG::GeoNormals3f::GeoPropDataFieldMask);
#endif
   for ( unsigned int i = 0; i < vertex_count; ++i )
   {
      norms->addValue(OSG::Vec3f(0.0f, 0.0f, 1.0f));
   }

   mGridNode = OSG::Geometry::create();

#if OSG_MAJOR_VERSION < 2
   OSG::CPEditor gnce(mGridNode.core(),
                      OSG::Geometry::TypesFieldMask        |
                         OSG::Geometry::LengthsFieldMask   |
                         OSG::Geometry::PositionsFieldMask |
                         OSG::Geometry::NormalsFieldMask   |
                         OSG::Geometry::MaterialFieldMask);
#endif
   mGridNode->setTypes(type);
   mGridNode->setLengths(length);
   mGridNode->setPositions(pos);
   mGridNode->setNormals(norms);
   mGridNode->setMaterial(line_mat);

#if OSG_MAJOR_VERSION < 2
   OSG::CPEditor re(mRoot.node(), OSG::Node::ChildrenFieldMask);
#endif
   mRoot.node()->addChild(mGridNode);
   mRoot.node()->addChild(mPlaneNode);

   setSelected(false);
}