예제 #1
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;
}
예제 #2
0
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);
    }
}
예제 #3
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;

}
예제 #4
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;
}
예제 #5
0
    void addEdgePlane(const osg::Vec3& corner, const osg::Vec3& edge)
    {
        osg::Vec3 normal( edge.y(), -edge.x(), 0.0f);
        normal.normalize();

        add(osg::Plane(normal, corner));
    }
예제 #6
0
 void setMinMax(const osg::Vec3& pos)
 {
     _maxY = std::max(_maxY, (double) pos.y());
     _minY = std::min(_minY, (double) pos.y());
     _maxX = std::max(_maxX, (double) pos.x());
     _minX = std::min(_minX, (double) pos.x());
 }
예제 #7
0
double MultitouchNavigation::angleBetween3DVectors(osg::Vec3 v1, osg::Vec3 v2)
{
    // http://codered.sat.qc.ca/redmine/projects/spinframework/repository/revisions/b6245189c19a7c6ba4fdb126940321c41c44e228/raw/src/spin/osgUtil.cpp

    // normalize vectors (note: this must be done alone, not within any vector arithmetic. why?!)
    v1.normalize();
    v2.normalize();

    // Get the dot product of the vectors
    double dotProduct = v1 * v2;

    // for acos, the value has to be between -1.0 and 1.0, but due to numerical imprecisions it sometimes comes outside this range
    if (dotProduct > 1.0)
        dotProduct = 1.0;
    if (dotProduct < -1.0)
        dotProduct = -1.0;

    // Get the angle in radians between the 2 vectors (should this be -acos ? ie, negative?)
    double angle = acos(dotProduct);

    // Here we make sure that the angle is not a -1.#IND0000000 number, which means indefinite
    if (std::isnan(angle)) //__isnand(x)
        return 0;

    // Return the angle in radians
    return (angle);
}
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);
}
예제 #9
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;
}
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;
}
예제 #11
0
파일: Uniform.cpp 프로젝트: aalex/osg
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;
}
예제 #12
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;
}
예제 #13
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
}
예제 #14
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() );
}
예제 #15
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;
    }
}
예제 #16
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;
}
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());
}
예제 #18
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
예제 #19
0
파일: Frustum.cpp 프로젝트: cefix/cefix
    double Frustum::getAngleBetween(const osg::Vec3 &a, const osg::Vec3 &b) {

        float dot = a * b;
        float mag = a.length() * b.length();
        
        double angle = acos(dot/mag);
        
		if (osg::isNaN(angle)) 
            return 0;
        else
            return angle;
    }
예제 #20
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);
  }
}
예제 #21
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;
    }
}
예제 #22
0
파일: Hermite.cpp 프로젝트: cefix/cefix
// -------------------------------------------------------------------------
void Hermite::getTangentOnSegment(osg::Vec3& tangent, double distance, unsigned int segment)
{
	float fH1 = ( 6.0f * distance - 6.0f) * distance;
	float fH2 = ( 3.0f * distance - 4.0f) * distance + 1.0f;
	float fH3 = ( 3.0f * distance - 2.0f) * distance;
	float fH4 = (-6.0f * distance + 6.0f) * distance;

	const ControlPoint& begin = (*_segments)[segment].getBegin();
	const ControlPoint& end   = (*_segments)[segment].getEnd();

	tangent = begin.position * fH1 + begin.tangent * fH2 + end.tangent * fH3 + end.position * fH4;
	tangent.normalize();
	
	/*
	tangent[0] = begin->position.x * fH1 +
		begin->tangent.x  * fH2 +
		end->tangent.x    * fH3 +
		end->position.x   * fH4;
	tangent[1] = begin->position.y * fH1 +
		begin->tangent.y  * fH2 +
		end->tangent.y    * fH3 +
		end->position.y   * fH4;
	tangent[2] = begin->position.z * fH1 +
		begin->tangent.z  * fH2 +
		end->tangent.z    * fH3 +
		end->position.z   * fH4;

	Math::normalize(tangent);
	*/
	
}
예제 #23
0
bool
HeightFieldUtils::getNormalAtNormalizedLocation(const osg::HeightField* input,
                                                double nx, double ny,
                                                osg::Vec3& output,
                                                ElevationInterpolation interp)
{
    double xcells = (double)(input->getNumColumns()-1);
    double ycells = (double)(input->getNumRows()-1);

    double w = input->getXInterval() * xcells * 111000.0;
    double h = input->getYInterval() * ycells * 111000.0;

    double ndx = 1.0/xcells;
    double ndy = 1.0/ycells;

    double xmin = osg::clampAbove( nx-ndx, 0.0 );
    double xmax = osg::clampBelow( nx+ndx, 1.0 );
    double ymin = osg::clampAbove( ny-ndy, 0.0 );
    double ymax = osg::clampBelow( ny+ndy, 1.0 );

    osg::Vec3 west (xmin*w, ny*h, getHeightAtNormalizedLocation(input, xmin, ny, interp));
    osg::Vec3 east (xmax*w, ny*h, getHeightAtNormalizedLocation(input, xmax, ny, interp));
    osg::Vec3 south(nx*w, ymin*h, getHeightAtNormalizedLocation(input, nx, ymin, interp));
    osg::Vec3 north(nx*w, ymax*h, getHeightAtNormalizedLocation(input, nx, ymax, interp));

    output = (west-east) ^ (north-south);
    output.normalize();
    return true;
}
예제 #24
0
bool
TileModel::ElevationData::getNormal(const osg::Vec3d&      ndc,
                                    const GeoLocator*      ndcLocator,
                                    osg::Vec3&             output,
                                    ElevationInterpolation interp ) const
{
    if ( !_locator.valid() || !ndcLocator )
    {
        output.set(0,0,1);
        return false;
    }

    double xcells = (double)(_hf->getNumColumns()-1);
    double ycells = (double)(_hf->getNumRows()-1);
    double xres = 1.0/xcells;
    double yres = 1.0/ycells;

    osg::Vec3d hf_ndc;
    GeoLocator::convertLocalCoordBetween( *ndcLocator, ndc, *_locator.get(), hf_ndc );

    float centerHeight = HeightFieldUtils::getHeightAtNormalizedLocation(_hf.get(), hf_ndc.x(), hf_ndc.y(), interp);

    osg::Vec3d west ( hf_ndc.x()-xres, hf_ndc.y(), 0.0 );
    osg::Vec3d east ( hf_ndc.x()+xres, hf_ndc.y(), 0.0 );
    osg::Vec3d south( hf_ndc.x(), hf_ndc.y()-yres, 0.0 );
    osg::Vec3d north( hf_ndc.x(), hf_ndc.y()+yres, 0.0 );

    if (!HeightFieldUtils::getHeightAtNormalizedLocation(_neighbors, west.x(),  west.y(),  west.z(), interp))
        west.z() = centerHeight;
    if (!HeightFieldUtils::getHeightAtNormalizedLocation(_neighbors, east.x(),  east.y(),  east.z(), interp))
        east.z() = centerHeight;
    if (!HeightFieldUtils::getHeightAtNormalizedLocation(_neighbors, south.x(), south.y(), south.z(), interp))
        south.z() = centerHeight;
    if (!HeightFieldUtils::getHeightAtNormalizedLocation(_neighbors, north.x(), north.y(), north.z(), interp))
        north.z() = centerHeight;

    osg::Vec3d westWorld, eastWorld, southWorld, northWorld;
    _locator->unitToModel(west,  westWorld);
    _locator->unitToModel(east,  eastWorld);
    _locator->unitToModel(south, southWorld);
    _locator->unitToModel(north, northWorld);

    output = (eastWorld-westWorld) ^ (northWorld-southWorld);
    output.normalize();

    return true;
}
예제 #25
0
float ConeSector::operator() (const osg::Vec3& eyeLocal) const
{
    float dotproduct = eyeLocal*_axis;
    float length = eyeLocal.length();
    if (dotproduct>_cosAngle*length) return 1.0f; // fully in sector
    if (dotproduct<_cosAngleFade*length) return 0.0f; // out of sector
    return (dotproduct-_cosAngleFade*length)/((_cosAngle-_cosAngleFade)*length);
}
예제 #26
0
void LightSource::init(const osg::Vec3& position, const osg::Vec4& ambient,
                       const osg::Vec4& diffuse, const osg::Vec4& specular)
{
  if (initialized_)
    return;

  light_source_->getLight()->setPosition(osg::Vec4(position.x(), position.y(), position.z(), 1.0f));
  light_source_->getLight()->setAmbient(ambient);
  light_source_->getLight()->setDiffuse(diffuse);
  light_source_->getLight()->setSpecular(specular);

  addChild(light_source_.get());

  initialized_ = true;

  return;
}
예제 #27
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;



		



}
예제 #28
0
void dtAnim::GetCelestialCoordinates(osg::Vec3 target,
                                     const osg::Vec3 &lookForward,                                    
                                     float &azimuth, 
                                     float &elevation)
{  
   target.normalize();

   // Derive the reference frame for the "look" pose
   osg::Vec3 frameRight = lookForward ^ osg::Z_AXIS;
   osg::Vec3 frameUp    = frameRight ^ lookForward;

   osg::Matrix frameMatrix(frameRight.x(),  frameRight.y(),  frameRight.z(),  0.0f,                            
                           lookForward.x(), lookForward.y(), lookForward.z(), 0.0f,
                           frameUp.x(),     frameUp.y(),     frameUp.z(),     0.0f,
                           0.0f,            0.0f,            0.0f,            1.0f);  

   // Transform the target into the proper coordinate frame
   target = frameMatrix * target;

   // Project our target vector onto the xy plane 
   // in order to calculate azimuth
   osg::Vec3f targetRight = target ^ osg::Z_AXIS;
   targetRight.normalize();

   osg::Vec3f targetForward = osg::Z_AXIS ^ targetRight;
   targetForward.normalize();    

   // Use the projected vector to calculate the azimuth
   // between the projection and the character forward
   float lookDotTargetForward   = targetForward * osg::Y_AXIS;
   float targetDotTargetForward = targetForward * target;

   // acos needs it's parameter between -1 and 1
   dtUtil::Clamp(lookDotTargetForward, -1.0f, 1.0f);
   dtUtil::Clamp(targetDotTargetForward, -1.0f, 1.0f);

   // We need to manually determine the sign
   float azimuthSign   = ((target * osg::X_AXIS) > 0.0f) ? -1.0f: 1.0f;    
   float elevationSign = ((target * osg::Z_AXIS) > 0.0f) ? 1.0f: -1.0f;

   // We can use the angle between the projection
   // and the original target to determine elevation
   elevation  = acos(targetDotTargetForward) * elevationSign;
   azimuth    = acos(lookDotTargetForward) * azimuthSign;
}
예제 #29
0
CSulScreenAlignedQuad::CSulScreenAlignedQuad( float fViewW, float fViewH, osg::Texture2D* tex, const osg::Vec3& pos, sigma::uint32 w, sigma::uint32 h )
{
	float x = pos.x();
	float y = pos.y();
	float z = pos.z();

	// create geometry quad
	m_rGeomQuad = new CSulGeomQuad( osg::Vec3( x + w/2.0f, fViewH - (y+h/2.0f) , z ), w, h, CSulGeomQuad::PLANE_XY );
	m_rGeomQuad->setTexture( tex );

	m_geodeQuad = new CSulGeode;
	m_geodeQuad->addDrawable( m_rGeomQuad );

	osg::Matrixd mOrtho = osg::Matrix::ortho2D( 0, fViewW, 0, fViewH );
	setMatrix( mOrtho );

	initConstructor();
}
void SoundUpdateCallback::operator()(osg::Node *node, osg::NodeVisitor *nodeVisitor)
{
    const osg::FrameStamp *frameStamp = nodeVisitor->getFrameStamp();

    if ( !_sound || !_sound->isValid() || (frameStamp == NULL))
    {
        traverse(node, nodeVisitor);
        return;
    }

    const double currTime = frameStamp->getReferenceTime();
    const double diffTime = currTime - _prevTime;

    if (diffTime >= _updateIntervalInSeconds)
    {
        const osg::Vec3 currPosition = osg::computeLocalToWorld(nodeVisitor->getNodePath()).getTrans();
        osg::Vec3 velocity(0, 0, 0);

        // Update the position and compute the velocity only if the position changed
        if (currPosition != _prevPosition)
        {
            _sound->setPosition(currPosition.x(), currPosition.y(), currPosition.z());

            // Automatically compute the velocity, based on movement
            if (_firstRun)
            {
                _firstRun = false;
            }
            else
            {
                velocity = currPosition - _prevPosition;
                velocity /= diffTime;
            }
        }

        _sound->setVelocity(velocity.x(), velocity.y(), velocity.z());
        _prevTime = currTime;
        _prevPosition = currPosition;

        // Compute the direction of the sound source, if it is directional
    }

    traverse(node, nodeVisitor);
}