/***************************************************************
* Function: setCenterPos()
***************************************************************/
void CAVEGroupReferencePlane::setCenterPos(const osg::Vec3 &center)
{
    /* snap 'center' vector with respect to mUnitGridSize */
    Vec3 centerRounded;
    float snapUnitX, snapUnitY, snapUnitZ;
    snapUnitX = snapUnitY = snapUnitZ = mUnitGridSize;
    if (center.x() < 0) snapUnitX = -mUnitGridSize;
    if (center.y() < 0) snapUnitY = -mUnitGridSize;
    if (center.z() < 0) snapUnitZ = -mUnitGridSize;
    int xSeg = (int)(abs((int)((center.x() + 0.5 * snapUnitX) / mUnitGridSize)));
    int ySeg = (int)(abs((int)((center.y() + 0.5 * snapUnitY) / mUnitGridSize)));
    int zSeg = (int)(abs((int)((center.z() + 0.5 * snapUnitZ) / mUnitGridSize)));
    centerRounded.x() = xSeg * snapUnitX;
    centerRounded.y() = ySeg * snapUnitY;
    centerRounded.z() = zSeg * snapUnitZ;

    /* set highlights of either XZ plane or YZ plane */
    Vec3 offset = centerRounded - mCenter;
    float offx = offset.x() * offset.x();
    float offy = offset.y() * offset.y();
    if (offx > offy) mYZPlaneGeode->setAlpha(1.0f);
    else mYZPlaneGeode->setAlpha(0.4f);
    if (offx < offy) mXZPlaneGeode->setAlpha(1.0f);
    else mXZPlaneGeode->setAlpha(0.4f);

    mCenter = centerRounded;
    Matrixf transMat;
    transMat.makeTranslate(mCenter);
    mMatrixTrans->setMatrix(transMat);
}
Exemplo n.º 2
0
void daeWriter::writeUpdateTransformElements(const osg::Vec3 &pos, const osg::Quat &q,    const osg::Vec3 &s)
{
    // Make a scale place element
    domScale *scale = daeSafeCast< domScale >( currentNode->add( COLLADA_ELEMENT_SCALE ) );
    scale->setSid("scale");
    scale->getValue().append3( s.x(), s.y(), s.z() );

    // Make a three rotate place elements for the euler angles
    // TODO decompose quaternion into three euler angles
    osg::Quat::value_type angle;
    osg::Vec3 axis;
    q.getRotate( angle, axis );

    domRotate *rot = daeSafeCast< domRotate >( currentNode->add( COLLADA_ELEMENT_ROTATE ) );
    rot->setSid("rotateZ");
    rot->getValue().append4( 0, 0, 1, osg::RadiansToDegrees(angle) );

    rot = daeSafeCast< domRotate >( currentNode->add( COLLADA_ELEMENT_ROTATE ) );
    rot->setSid("rotateY");
    rot->getValue().append4( 0, 1, 0, osg::RadiansToDegrees(angle) );

    rot = daeSafeCast< domRotate >( currentNode->add( COLLADA_ELEMENT_ROTATE ) );
    rot->setSid("rotateX");
    rot->getValue().append4( 1, 0, 0, osg::RadiansToDegrees(angle) );

    // Make a translate place element
    domTranslate *trans = daeSafeCast< domTranslate >( currentNode->add( COLLADA_ELEMENT_TRANSLATE ) );
    trans->setSid("translate");
    trans->getValue().append3( pos.x(), pos.y(), pos.z() );
}
Exemplo n.º 3
0
void osgParticle::Particle::render(osg::RenderInfo& renderInfo, const osg::Vec3& xpos, const osg::Vec3& xrot) const
{
#if defined(OSG_GL_MATRICES_AVAILABLE)
    if (_drawable.valid())
    {
        bool requiresRotation = (xrot.x()!=0.0f || xrot.y()!=0.0f || xrot.z()!=0.0f);
        glColor4f(_current_color.x(),
                  _current_color.y(),
                  _current_color.z(),
                  _current_color.w() * _current_alpha);
        glPushMatrix();
        glTranslatef(xpos.x(), xpos.y(), xpos.z());
        if (requiresRotation)
        {
            osg::Quat rotation(xrot.x(), osg::X_AXIS, xrot.y(), osg::Y_AXIS, xrot.z(), osg::Z_AXIS);
#if defined(OSG_GLES1_AVAILABLE)
            glMultMatrixf(osg::Matrixf(rotation).ptr());
#else
            glMultMatrixd(osg::Matrixd(rotation).ptr());
#endif
        }
        _drawable->draw(renderInfo);
        glPopMatrix();
    }
#else
    OSG_NOTICE<<"Warning: Particle::render(..) not supported for user-defined shape."<<std::endl;
#endif
}
/***************************************************************
* Function: setInitPosition()
***************************************************************/
void CAVEGeodeSnapSolidshape::setInitPosition(const osg::Vec3 &initPos, bool snap)
{
    if (snap)
    {
        /* round intersected position to integer multiples of 'mSnappingUnitDist' */
        Vec3 initPosRounded;
        float snapUnitX, snapUnitY, snapUnitZ;
        snapUnitX = snapUnitY = snapUnitZ = mSnappingUnitDist;
        if (initPos.x() < 0) 
            snapUnitX = -mSnappingUnitDist;
        if (initPos.y() < 0) 
            snapUnitY = -mSnappingUnitDist;
        if (initPos.z() < 0) 
            snapUnitZ = -mSnappingUnitDist;

        int xSeg = (int)(abs((int)((initPos.x() + 0.5 * snapUnitX) / mSnappingUnitDist)));
        int ySeg = (int)(abs((int)((initPos.y() + 0.5 * snapUnitY) / mSnappingUnitDist)));
        int zSeg = (int)(abs((int)((initPos.z() + 0.5 * snapUnitZ) / mSnappingUnitDist)));

        initPosRounded.x() = xSeg * snapUnitX;
        initPosRounded.y() = ySeg * snapUnitY;
        initPosRounded.z() = zSeg * snapUnitZ;

        mInitPosition = initPosRounded;
    }
    else
    {
        mInitPosition = initPos;
    }
}
Exemplo n.º 5
0
osg::MatrixTransform* createOffOriginOSGBox( osg::Vec3 size )
{
    const osg::Vec3 dim( size * 2 );

    osg::Geode * geode = new osg::Geode;
    osg::Geometry * geom = new osg::Geometry;
    osg::Vec3Array * v = new osg::Vec3Array;

    v->resize( 8 );
    ( *v )[ 0 ] = osg::Vec3( 0, 0, 0 );
    ( *v )[ 1 ] = osg::Vec3( 0, dim.y(), 0 );
    ( *v )[ 2 ] = osg::Vec3( dim.x(), dim.y(), 0 );
    ( *v )[ 3 ] = osg::Vec3( dim.x(), 0, 0 );
    ( *v )[ 4 ] = osg::Vec3( 0, 0, dim.z() );
    ( *v )[ 5 ] = osg::Vec3( dim.x(), 0, dim.z() );
    ( *v )[ 6 ] = osg::Vec3( dim.x(), dim.y(), dim.z() );
    ( *v )[ 7 ] = osg::Vec3( 0, dim.y(), dim.z() );
    geom->setVertexArray( v );

    osg::Vec3Array * n = new osg::Vec3Array;
    n->resize( 6 );
    ( *n )[ 0 ] = osg::Vec3( 0, 0, -1 );
    ( *n )[ 1 ] = osg::Vec3( 0, 0, 1 );
    ( *n )[ 2 ] = osg::Vec3( -1, 0, 0 );
    ( *n )[ 3 ] = osg::Vec3( 1, 0, 0 );
    ( *n )[ 4 ] = osg::Vec3( 0, -1, 0 );
    ( *n )[ 5 ] = osg::Vec3( 0, 1, 0 );
    geom->setNormalArray( n );
    geom->setNormalBinding( osg::Geometry::BIND_PER_PRIMITIVE );

    osg::Vec4Array * c = new osg::Vec4Array;
    c->resize( 8 );
    ( *c )[ 0 ] = osg::Vec4( 1, 1, 1, 1 );
    ( *c )[ 1 ] = osg::Vec4( .6, 0, 0, 1 );
    ( *c )[ 2 ] = osg::Vec4( .6, 0, 0, 1 );
    ( *c )[ 3 ] = osg::Vec4( .6, 0, 0, 1 );
    ( *c )[ 4 ] = osg::Vec4( .6, 0, 0, 1 );
    ( *c )[ 5 ] = osg::Vec4( .6, 0, 0, 1 );
    ( *c )[ 6 ] = osg::Vec4( .6, 0, 0, 1 );
    ( *c )[ 7 ] = osg::Vec4( .6, 0, 0, 1 );
    geom->setColorArray( c );
    geom->setColorBinding( osg::Geometry::BIND_PER_VERTEX );

    GLushort indices[] =
    {
        0, 1, 2, 3,
        4, 5, 6, 7,
        0, 4, 7, 1,
        3, 2, 6, 5,
        0, 3, 5, 4,
        1, 7, 6, 2
    };
    geom->addPrimitiveSet( new osg::DrawElementsUShort( GL_QUADS, 24, indices ) );
    geode->addDrawable( geom );

    osg::MatrixTransform * mt = new osg::MatrixTransform();
    mt->addChild( geode );
    return( mt );
}
void PanoDrawableLOD::setZoom(osg::Vec3 dir, float k)
{
    for(std::map<int,sph_model*>::iterator it = _pdi->modelMap.begin(); it!= _pdi->modelMap.end(); it++)
    {
	it->second->set_zoom(dir.x(),dir.y(),dir.z(),k);
    }

    for(std::map<int,sph_model*>::iterator it = _pdi->transitionModelMap.begin(); it!= _pdi->transitionModelMap.end(); it++)
    {
	it->second->set_zoom(dir.x(),dir.y(),dir.z(),k);
    }
}
Exemplo n.º 7
0
void AudioHandler::loadSound(int soundID, osg::Vec3 &dir, osg::Vec3 &pos)
{
    if (!_isConnected)
        return;

    uint8_t packet[256];
    int32_t size;

    float yaw, pitch, roll;

/*    yaw = acos(dir.x());
    if (dir.y() < 0) 
        yaw = M_PI * 2 - yaw;
    yaw += M_PI * 0.5;
    if (yaw > M_PI * 2) 
        yaw -= M_PI * 2;*/

    float val;
    if(dir.x() >= 0)
    {
        if(dir.y() >= 0)
        {
            val = acos( dir.x() );
        }
        else
        {
            val = 2*M_PI - acos( dir.x() );
        }
    }
    else
    {
        if(dir.y() >= 0)
        {
            val = M_PI - acos( -dir.x() );
        }
        else
        {
            val = M_PI + acos( -dir.x() );
        }
    }
    yaw = val;

    pitch = M_PI * 0.5 - atan(dir.z());
    roll = 0.0f;

    size = oscpack(packet, "/sc.elevators/pose", "iffffff", soundID, 
        pos.x() / 1000, pos.y() / 1000, pos.z() / 1000, yaw, pitch, roll);

    if (send(_sock, (char *) packet, size, 0))
    {
        //std::cerr << "AudioHandler  Viewer's info: " << viewPos.x() << " " << viewPos.y() << " " << viewPos.z() << std::endl;	
    }
}
Exemplo n.º 8
0
TouchSensor::TouchSensor(dSpaceID odeSpace, dBodyID sensorBody, float mass,
		osg::Vec3 pos, float x, float y, float z, std::string label) :
		collideSpace_(odeSpace), label_(label) {
	// create own space to avoid physical collisions with other objects
	sensorSpace_ = dHashSpaceCreate(0);
	// create Sensor geom in this different space
	dMass massOde;
	dMassSetBoxTotal(&massOde, mass, x, y, z);
	dBodySetMass(sensorBody, &massOde);
	sensorGeometry_ = dCreateBox(sensorSpace_, x, y, z);
	dBodySetPosition(sensorBody, pos.x(), pos.y(), pos.z());
	dGeomSetPosition(sensorGeometry_, pos.x(), pos.y(), pos.z());
	dGeomSetBody(sensorGeometry_, sensorBody);
}
Exemplo n.º 9
0
osg::Vec3  CVehicle::calIntersectionPoint(const osg::Vec3& pa1,const osg::Vec3& pa2,const osg::Vec3& pb1,const osg::Vec3& pb2)
{
	osg::Vec3 intersectionPoint,pa12,pb12;
	double t;
	pa12 = pa2 - pa1;
	pb12 = pb2 - pb1;

	double temp =  (pa12.y() * pb12.x()) - (pb12.y() * pa12.x());
	if(temp < 0.001)
		return pa2;
	else
		t =( (pb1.y() - pa1.y()) * pb12.x() + (pa1.x() - pb1.x()) * pb12.y() ) / temp;

	double x,y,z;
	x = pa1.x() + pa12.x() * t;
	y = pa1.y() + pa12.y() * t;
	z = pa1.z() + pa12.z() * t;
	intersectionPoint.set(x,y,z);

	return intersectionPoint;



		



}
Exemplo n.º 10
0
osg::Vec3 ConfigManager::getVec3(std::string attributeX, std::string attributeY,
        std::string attributeZ, std::string path, osg::Vec3 def, bool * found)
{
    bool hasEntry = false;
    bool isFound;

    osg::Vec3 result;
    result.x() = getFloat(attributeX,path,def.x(),&isFound);
    if(isFound)
    {
        hasEntry = true;
    }
    result.y() = getFloat(attributeY,path,def.y(),&isFound);
    if(isFound)
    {
        hasEntry = true;
    }
    result.z() = getFloat(attributeZ,path,def.z(),&isFound);
    if(isFound)
    {
        hasEntry = true;
    }

    if(found)
    {
        *found = hasEntry;
    }
    return result;
}
Exemplo n.º 11
0
osg::Vec2 calcCoordReprojTrans(const osg::Vec3 &vert,const osg::Matrix &trans,const osg::Matrix &viewProj,const osg::Vec2 &size,const osg::Vec4 &ratio){
    osg::Vec4 v(vert.x(),vert.y(),vert.z(),1.0);
    v=v*trans;
    v=v*viewProj;
    v.x() /= v.w();
    v.y() /= v.w();
    v.z() /= v.w();
    v.w() /= v.w();
    //std::cout << "Pre shift " << v << std::endl;
    v.x() /= size.x();;
    v.y() /= size.y();


    v.x() -= (ratio.x()/size.x());
    v.y() -= (ratio.y()/size.y());
    //std::cout << "Post shift " << v << std::endl;


    //  std::cout << "PP shift " << v << std::endl;


    osg::Vec2 tc(v.x(),v.y());
    tc.x() *= ratio.z();
    tc.y() *=ratio.w();
    //tc.x()*=ratio.x();
    //tc.y()*=ratio.y();
    tc.x()/=(ratio.z());
    tc.y()/=(ratio.w());


    return tc;

}
Exemplo n.º 12
0
bool HeightFieldLayer::getValue(unsigned int i, unsigned int j, osg::Vec3& value) const
{
    value.x() = _heightField->getHeight(i,j);
    value.y() = _defaultValue.y();
    value.z() = _defaultValue.z();
    return true;
}
Exemplo n.º 13
0
void addRandomClouds(osg::Group* model, std::vector<Ref<CloudModel> >& clouds, osg::Vec3 dimensions, int count) {
	std::vector<Ref<CloudModel> >::size_type cloudIndex = 0;
	for(int i=0;i<count;++i, ++cloudIndex) {
		// Wrap around when there is no more clouds.
		if(cloudIndex >= clouds.size())
			cloudIndex = 0;

		float x = GenerateRandomNumber(0 - dimensions.x(), dimensions.x());
		float y = GenerateRandomNumber(0 - dimensions.y(), dimensions.y());
		float z = GenerateRandomNumber(0 - dimensions.z(), dimensions.z());

		osg::ref_ptr<osg::MatrixTransform> transformation = new osg::MatrixTransform();
		transformation->setMatrix(osg::Matrix::translate(x, y, z));
		transformation->addChild(clouds.at(cloudIndex)->getNode());
		model->addChild(transformation.get());
	}
}
osg::Quat makeQuat(const osg::Vec3& radians, ERotationOrder fbxRotOrder)
{
    fbxDouble3 degrees(
        osg::RadiansToDegrees(radians.x()),
        osg::RadiansToDegrees(radians.y()),
        osg::RadiansToDegrees(radians.z()));
    return makeQuat(degrees, fbxRotOrder);
}
Exemplo n.º 15
0
void VELOModel::addTrack(osg::Vec3& v1, osg::Vec3& v2){
	float d = sqrt(pow(v2.x()-v1.x(), 2) + pow(v2.y()-v1.y(), 2) + pow(v2.z()-v1.z(), 2));
	
	osg::ref_ptr<osg::MatrixTransform> t2 = new osg::MatrixTransform;
	t2->setMatrix( osg::Matrix::scale(1.0f, 1.0f, d) );
	t2->addChild( _trackGeode.get() );
	
	osg::ref_ptr<osg::MatrixTransform> t3 = new osg::MatrixTransform;
	t3->setMatrix( osg::Matrix::rotate(osg::Vec3f(0.0f, 0.0f, 1.0f), v2 - v1) );
	t3->addChild( t2.get() );

	osg::ref_ptr<osg::MatrixTransform> t1 = new osg::MatrixTransform;
	t1->setMatrix( osg::Matrix::translate(osg::Vec3f(((v2.x() - v1.x()) / 2.0f) + v1.x(), ((v2.y() - v1.y()) / 2.0f) + v1.y(), ((v2.z() - v1.z()) / 2.0f) + v1.z())) );
	t1->addChild( t3.get() );

	tracks->addChild( t1.get() );
}
Exemplo n.º 16
0
osg::Vec3 Particle_Viewer::fixPosition(osg::Vec3 position)
{
    osg::Vec3 fixPosition;
    fixPosition.x()=position.x();
    fixPosition.y()=position.z();
    fixPosition.z()=position.y();
    return fixPosition;
}
Exemplo n.º 17
0
bool Uniform::getElement( unsigned int index, osg::Vec3& v3 ) const
{
    if( index>=getNumElements() || !isCompatibleType(FLOAT_VEC3) ) return false;
    unsigned int j = index * getTypeNumComponents(getType());
    v3.x() = (*_floatArray)[j];
    v3.y() = (*_floatArray)[j+1];
    v3.z() = (*_floatArray)[j+2];
    return true;
}
float HfT_osg_Plugin01_ParametricSurface::abstand(osg::Vec3 startPickPos, int i)
{
    float x = (*mp_Points_Geom)[i].x() - startPickPos.x();
    float y = (*mp_Points_Geom)[i].y() - startPickPos.y();
    float z = (*mp_Points_Geom)[i].z() - startPickPos.z();

    float abst = (float)sqrt(x * x + y * y + z * z);
    return abst;
}
Exemplo n.º 19
0
TexturedCuboid::TexturedCuboid(const osg::Vec3 &from, const osg::Vec3 &size) :
    Cuboid(from, size)
{
    _textureDrawable = new osg::Geometry();

    osg::Vec3Array *pyramidVertices = new osg::Vec3Array();
    {
        pyramidVertices->push_back( from + osg::Vec3(0, 0, size.z()));
        pyramidVertices->push_back( from + osg::Vec3(size.x(), 0, size.z()));
        pyramidVertices->push_back( from + osg::Vec3(size.x(), size.y(), size.z()));
        pyramidVertices->push_back( from + osg::Vec3(0, size.y(), size.z()));
    }

    _textureDrawable->setVertexArray( pyramidVertices );

    osg::DrawElementsUInt *face = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
    face->push_back(0);
    face->push_back(1);
    face->push_back(2);
    face->push_back(3);
    
    _textureDrawable->addPrimitiveSet(face);
        
    osg::Vec2Array* texcoords = new osg::Vec2Array(4);
    {
        (*texcoords)[0].set(size.x(), 0.0f);
        (*texcoords)[1].set(0.0f, 0.0f);
        (*texcoords)[3].set(size.x(), size.y() / 3.0f);
        (*texcoords)[2].set(0.0f,  size.y() / 3.0f); 

        _textureDrawable->setTexCoordArray(0, texcoords);
    }
             
    _texture = new osg::Texture2D;
    _texture->setDataVariance(osg::Object::DYNAMIC); 
    _texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT); 
    _texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);

    osg::StateSet* stateSet = _textureDrawable->getOrCreateStateSet();
    stateSet->setTextureAttributeAndModes(0, _texture, osg::StateAttribute::ON);
    
    _textureDrawable->setStateSet(stateSet);
    addDrawable(_textureDrawable);
}
Exemplo n.º 20
0
//
// Set the lighting material attributes for this osgmaterial
//
void HogBoxMaterial::SetMaterial(osg::Vec3 ambi, osg::Vec3 diffuse, osg::Vec3 spec, double exp)
{
	//store the material values
	_ambientColour = ambi;
	osg::Vec4 ambi4 = osg::Vec4(ambi.x(), ambi.y(), ambi.z(), _alpha);
	_diffuseColor = diffuse;
	osg::Vec4 diffuse4 = osg::Vec4(diffuse.x(), diffuse.y(), diffuse.z(), _alpha);
	_specularColour = spec;
	osg::Vec4 spec4 = osg::Vec4(spec.x(), spec.y(), spec.z(), _alpha);
	_shininess = exp;

	//set the ambient colour
	_material->setAmbient(_lightFace, ambi4);
	//set the diffuse colour
	_material->setDiffuse(_lightFace, diffuse4);
	//set the specular colour
	_material->setSpecular(_lightFace, spec4);
	//set the shininess
	_material->setShininess(_lightFace, _shininess);

	_material->setColorMode(osg::Material::OFF);

	//apply the material to the stateset
#ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
	_stateset->setAttributeAndModes(_material.get(), osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
	//normalise
	_stateset->setMode( GL_NORMALIZE, osg::StateAttribute::ON);
#endif
	
	this->SetTwoSidedLightingEnabled(_backFaceLit);


	
	//set hogbox material uniforms
	_ambientColourUni->set(_ambientColour);
	_diffuseColourUni->set(_diffuseColor);
	_specularColourUni->set(_specularColour);
	_specularExpUni->set((float)_shininess);
	
	_alphaUni->set((float)_alpha);
	
	_twoSidedUni->set((int)_backFaceLit);

}
Exemplo n.º 21
0
void DataOutputStream::writeVec3(const osg::Vec3& v){

//	std::cout << "write " << _ostream->tellp() << std::endl;

    writeFloat(v.x());
    writeFloat(v.y());
    writeFloat(v.z());

    if (_verboseOutput) std::cout<<"read/writeVec3() ["<<v<<"]"<<std::endl;
}
Exemplo n.º 22
0
inline osg::Vec3 ReaderWriterOBJ::transformNormal(const osg::Vec3& vec, const bool rotate) const
{
    if(rotate==true)
    {
        return osg::Vec3(vec.x(),-vec.z(),vec.y());
    }
    else
    {
        return vec;
    }
}
Exemplo n.º 23
0
bool ContourLayer::getValue(unsigned int i, unsigned int j, osg::Vec3& value) const
{
    if (!_tf) return false;

    const osg::Vec4& v = _tf->getPixelValue(i);
    value.x() = v.x();
    value.y() = v.y();
    value.z() = v.z();

    return true;
}
Exemplo n.º 24
0
void VELOModel::addHit(osg::Vec3& coords){

	osg::ref_ptr<osg::MatrixTransform> t1 = new osg::MatrixTransform;
	t1->setMatrix( osg::Matrix::translate(
		coords.x() - HIT_RADIUS,
		coords.y(),
		coords.z()) );
	t1->addChild( _hitGeode.get() );

	hits->addChild( t1.get() );
}
Exemplo n.º 25
0
void ComputeBoundingBoxByRotation(osg::BoundingBox & InOut,osg::Vec3 BBCenter,float BBSize,osg::Matrixd Rotation)
{
	osg::BoundingBox bb;
	bb.set(BBCenter.x()-BBSize,BBCenter.y()-BBSize,BBCenter.z()-BBSize,BBCenter.x()+BBSize,BBCenter.y()+BBSize,BBCenter.z()+BBSize);
    osg::BoundingBox Tbb;
	for(unsigned int i=0;i<8;i++)
    {
        Tbb.expandBy(Rotation.preMult(bb.corner(i)));
    }
	InOut.set(Tbb.xMin(),Tbb.yMin(),Tbb.zMin(),Tbb.xMax(),Tbb.yMax(),Tbb.zMax());
}
Exemplo n.º 26
0
	virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object* pObject, osg::NodeVisitor* pNodeVisitor )
	{
		osgViewer::Viewer* pViewer = dynamic_cast<osgViewer::Viewer*>(&aa);
        if ( !pViewer )
		{
			return false;
		}

		if ( ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN )
		{
			if ( ea.getKey()==osgGA::GUIEventAdapter::KEY_Up )
			{
				pos.z() += 1.0f;
				updateTransform();
			}

			if ( ea.getKey()==osgGA::GUIEventAdapter::KEY_Down )
			{
				pos.z() -= 1.0f;
				updateTransform();
			}

			if ( ea.getKey()==osgGA::GUIEventAdapter::KEY_Left )
			{
				pos.x() -= 1.0f;
				updateTransform();
			}

			if ( ea.getKey()==osgGA::GUIEventAdapter::KEY_Right )
			{
				pos.x() += 1.0f;
				updateTransform();
			}

			g_pSI->reset();
			g_pSI->setPosition( pos );
			testCol();
		}

		return false;
	}
Exemplo n.º 27
0
void PanoManipulator::JumpTo(osg::Vec3 NewSpatialPos)
{
PartialVertexDEM JumpLoc;
JumpLoc.Lat = NewSpatialPos.y();
JumpLoc.Lon = NewSpatialPos.x();
JumpLoc.Elev = NewSpatialPos.z();
MasterScene.DegToCart(JumpLoc);

_eye[0] = JumpLoc.XYZ[0];
_eye[1] = JumpLoc.XYZ[1];
_eye[2] = JumpLoc.XYZ[2];
} // PanoManipulator::JumpTo
Exemplo n.º 28
0
void VertexCollectionVisitor::addVertex(osg::Vec3 vertex)
{
  if (_geocentric)
  {
    double lat, lon, height;
    _ellipsoidModel->convertXYZToLatLongHeight(vertex.x(), vertex.y(), vertex.z(), lat, lon, height);
    _vertices->push_back(osg::Vec3d(osg::RadiansToDegrees(lon), osg::RadiansToDegrees(lat), height));
  }
  else
  {
    _vertices->push_back(vertex);
  }
}
Exemplo n.º 29
0
void CameraFlight::navigate(osg::Matrix destMat, osg::Vec3 destVec)
{
    osg::Matrix objMat = SceneManager::instance()->getObjectTransform()->getMatrix();

    switch(_flightMode)
    {
	case INSTANT:{
	    cout<<"USING INSTANT"<<endl;
	    SceneManager::instance()->setObjectMatrix(destMat);
	    break;
	}
	case SATELLITE:
	    cout<<"USING SATELLITE"<<endl;

	    t = 0.0;
	    total = 0.0;
	
    	    objMat.decompose(trans2, rot2, scale2, so2);
	    a = (maxHeight - trans2[1])/25.0;

	    map->getProfile()->getSRS()->getEllipsoid()->convertLatLongHeightToXYZ(
					destVec.x(),destVec.y(),destVec.z(),toVec.x(),toVec.y(),toVec.z());

	    fromVec = origPlanetPoint;

	    fromVec.normalize();
	    toVec.normalize();

	    origAngle = acos((fromVec * toVec)/((fromVec.length() * toVec.length())));	
	    origAngle = RadiansToDegrees(origAngle);

	    angle = origAngle;

    	    if(origAngle <= 10) {
		maxHeight = 6.5e+9;
	    }

	    else {
		maxHeight = 2.0e+10;
	    }

	    flagRot = true;
	    break;
	case AIRPLANE:
	    cout<<"USING AIRPLANE"<<endl;
	    break;
	default:
	    cout<<"PICK THE ALGORYTHM!!!!"<<endl;
	    break;
    }
}
Exemplo n.º 30
0
BoxObstacle::BoxObstacle(dWorldID odeWorld, dSpaceID odeSpace,
		const osg::Vec3& pos, const osg::Vec3& size, float density,
		const osg::Vec3& rotationAxis, float rotationAngle) :
		size_(size) {


	if (density >= RobogenUtils::OSG_EPSILON_2){
		// if not fixed, create body
		box_ = dBodyCreate(odeWorld);
		dMass massOde;
		dMassSetBox(&massOde, density, size.x(), size.y(), size.z());
		dBodySetMass(box_, &massOde);
	} else{
		// otherwise make body 0
		box_ = 0;

	}
	boxGeom_ = dCreateBox(odeSpace, size.x(), size.y(), size.z());
	dGeomSetBody(boxGeom_, box_);
	dGeomSetPosition(boxGeom_, pos.x(), pos.y(), pos.z());
	// for some reason body/geom position do not get tied together as they
	// should, so we set the body position as well, and use it when getting
	// the position on non-stationary bodies
	if (box_ != 0)
		dBodySetPosition(box_, pos.x(), pos.y(), pos.z());

	if (rotationAngle >= RobogenUtils::OSG_EPSILON_2){
		osg::Quat rotation;
		rotation.makeRotate(rotationAngle,rotationAxis);
		dQuaternion quatOde;
		quatOde[0] = rotation.w();
		quatOde[1] = rotation.x();
		quatOde[2] = rotation.y();
		quatOde[3] = rotation.z();
		dGeomSetQuaternion(boxGeom_, quatOde);

	}
}