示例#1
0
bool
TileModel::ElevationData::getNormal(const osg::Vec3d& ndc,
                                    const GeoLocator* ndcLocator,
                                    osg::Vec3&        output ) const
{
    if ( !_locator.valid() || !ndcLocator )
    {
        output.set(0,0,1);
        return false;
    }

    osg::Vec3d hf_ndc;
    GeoLocator::convertLocalCoordBetween( *ndcLocator, ndc, *_locator.get(), hf_ndc );
    return HeightFieldUtils::getNormalAtNormalizedLocation( _hf.get(), hf_ndc.x(), hf_ndc.y(), output );
}
示例#2
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;
}
示例#3
0
void Yiq::getYIQ(osg::Vec3& hhh) const
{
    hhh.set(yiq[Y],yiq[I],yiq[Q]);
}
示例#4
0
// ================================================
// convertRotMtxToEuler
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
void convertRotMtxToEuler( const osg::Matrix &m, osg::Vec3 &euler ) 
{
	osg::Vec3 yaxis( 0., 1., 0. ), zaxis( 0., 0., 1. );
	float heading, pitch, roll;
	
	osg::Vec3 headingv, pitchv, hpnormalv, v;

	pitchv = m.preMult( yaxis );
	headingv = pitchv;
	// zero-out the z component
	headingv[2] = 0.;
	// normalize
	headingv.normalize();
	
	/////////////////////////////////////////////////////////////////
	// HEADING
	/////////////////////////////////////////////////////////////////
	
	// the dot product of the two vectors will get us the cosine of the 
	// angle between them
	float cosH = headingv * yaxis; // dot product
	ARCCOS_SANITY( cosH )
	heading = acos(cosH);
	
	// the cross product of the two vectors will get us the vector normal 
	// to them
	v = headingv ^ yaxis; // cross product
	if( v[2] > 0. )
	{
		heading *= -1.;
	}
	
	
	/////////////////////////////////////////////////////////////////
	// PITCH
	/////////////////////////////////////////////////////////////////
	
	float cosP = pitchv * headingv; // dot product
	ARCCOS_SANITY( cosP )
	pitch = acos(cosP);

	if( pitchv[2] < 0. )
	{
		pitch *= -1.;
	}


	/////////////////////////////////////////////////////////////////
	// ROLL
	/////////////////////////////////////////////////////////////////
	
	hpnormalv = pitchv ^ headingv;
	hpnormalv.normalize();
	// If pitch is negative, hpnormalv will point in the "wrong" direction.
	// In this situation, we'll negate hpnormalv.  If we didn't do this, 
	// we'd get roll values that change sign as pitch changes from positive to 
	// negative or vice versa (yuck).
	if( pitch < 0. )
		hpnormalv *= -1.;
		
	osg::Vec3 zm;
	zm = m.preMult( zaxis );

/*
cout << "vv color " << "zm" << " 0.5 0.5 1.0\n";
cout << "vv set zm " << zm  << endl;
cout << "vv color pitchv 1 0 1\n";
cout << "vv set pitchv " << pitchv  << endl;
cout << "vv color headingv 1 .5 1\n";
cout << "vv set headingv " << headingv  << endl;
cout << "vv color " << "hpnormalv" << " 1. 1. 1.\n";
cout << "vv set hpnormalv " << hpnormalv << endl;
*/
	
	float cosR = zm * hpnormalv;
	ARCCOS_SANITY( cosR )
	roll = acos(cosR);
	// if the normal is roughly coincident with pitchv, then we need 
	// to negate the sign of the roll angle
	osg::Vec3 rollplanenormalv = zm ^ hpnormalv;
	rollplanenormalv.normalize();
//cout << "vv color " << "rollplanenormalv" << " .3 .3 .3\n";
//cout << "vv set rollplanenormalv " << rollplanenormalv << endl;
	if( pitchv * rollplanenormalv > 0. )
	{
		roll *= -1.;
	}
	
	euler.set( roll, pitch, heading );
//cout << "r p h " << euler << endl;
}
示例#5
0
void CameraFlight::menuCallback(cvr::MenuItem * item)
{
    if (item == _instant)
    {
	if(activeMode != item)
	{
	    activeMode->setValue(false);
	    std::cerr<<"Instant Transition has selected"<<std::endl;
	}

	activeMode = _instant;
	_instant->setValue(true);
	_flightMode = INSTANT;
    }

    else if (item == _satellite)
    {
	if(activeMode != item)
	{
	    activeMode->setValue(false);
	    std::cerr<<"Satellite Transition has selected"<<std::endl;
	}

	activeMode = _satellite;
	_satellite->setValue(true);
	_flightMode = SATELLITE;
    }

    else if (item == _reset)
    {
	if(activeMode != item)
	{
	    activeMode->setValue(false);
	    std::cerr<<"Reset Back to original"<<std::endl;
	}

	activeMode = _reset;
	_reset->setValue(true);
	
	SceneManager::instance()->setObjectMatrix(_origMatrix);
	SceneManager::instance()->setObjectScale(_origScale);
    }

    else if (item == _dest1)
    {
	if(destMode != item && destMode != NULL)
	{
	    destMode->setValue(false);
	    _dest1->setValue(true);
	}

	if(destMode != item) {
	    destMode = _dest1;
	    _destMat.set(_destMat1);
	    _destVec.set(0.573827, -2.04617, 0.0);
	    navigate(_destMat, _destVec);
	}
	else {
	    destMode = _dest1;
	}
	
    }

    else if (item == _dest2)
    {
	if(destMode != item && destMode != NULL)
	{
	    destMode->setValue(false);
	}

	destMode = _dest2;
	_dest2->setValue(true);
	_destMat.set(_destMat2);
	_destVec.set(0.622566, 2.43884, 0.0);
	navigate(_destMat, _destVec);
    }

    else if (item == _dest3)
    {
	if(destMode != item && destMode != NULL)
	{
	    destMode->setValue(false);
	}

	destMode = _dest3;
	_dest3->setValue(true);
	_destMat.set(_destMat3);
	_destVec.set(-1.51126, 1.54642, 0.0);
	navigate(_destMat, _destVec);
    }

    else if (item == _dest4)
    {
	if(destMode != item && destMode != NULL)
	{
	    destMode->setValue(false);
	}

	destMode = _dest4;
	_dest4->setValue(true);
	_destMat.set(_destMat4);
	_destVec.set(-0.590719, 2.63979, 0.0);
	navigate(_destMat, _destVec);
    }

    else if (item == _dest5)
    {
	if(destMode != item && destMode != NULL)
	{
	    destMode->setValue(false);
	}

	destMode = _dest5;
	_dest5->setValue(true);
	_destMat.set(_destMat5);
	_destVec.set(0.67315, 0.389608, 0.0);
	navigate(_destMat, _destVec);
    }
 
    else if (item == _dest6)
    {
	if(destMode != item && destMode != NULL)
	{
	    destMode->setValue(false);
	}

	destMode = _dest6;
	_dest6->setValue(true);
	_destMat.set(_destMat6);
	_destVec.set(0.590992, -2.05847, 0.0);
	navigate(_destMat, _destVec);
    }
}
示例#6
0
void Cmy::getCMY(osg::Vec3& hhh) const
{
    hhh.set(cmy[CYAN],cmy[MAGENTA],cmy[YELLOW]);
}
示例#7
0
void Cie::getCIE(osg::Vec3& hhh) const
{
    hhh.set(cie[LUMINANCE],cie[X],cie[Y]);
}
示例#8
0
void Hsv::getHSV(osg::Vec3& hhh) const
{
    hhh.set(hsv[HUE],hsv[SATURATION],hsv[VALUE]);
}