void SpaceNavigatorPluginForm::WalkNavigatorForward( float step, Pnt3f& oldFrom, Pnt3f& oldAt, Vec3f& oldUp )
{
	Vec3f lv = oldFrom - oldAt;
	lv.normalize();

	Vec3f upn = oldUp;
	upn.normalize();

	Vec3f mv = lv - upn.dot(lv)*upn;
	mv.normalize();

	//side vector symbolizes shoulders
	Vec3f sv = mv;
	sv.crossThis(upn);
	sv.normalize();

	oldFrom = oldFrom + step*mv;
	if (!_isOrbitMode)
		oldAt = oldAt + step*mv;
	
	// The following does not work!!
	//osgWidget->getNavigator().setFrom(rFrom);
	//osgWidget->getNavigator().setAt(rAt);

}
void SpaceNavigatorPluginForm::WalkNavigatorRight( float step, Pnt3f& oldFrom, Pnt3f& oldAt, Vec3f& oldUp )
{
	Vec3f lv = oldFrom - oldAt;
	lv.normalize();

	Vec3f upn = oldUp;
	upn.normalize();

	Vec3f mv = lv - upn.dot(lv)*upn;
	mv.normalize();

	Vec3f sv = mv;
	sv.crossThis(upn);
	sv.normalize();

	oldFrom = oldFrom + step*sv;
	if (!_isOrbitMode)
		oldAt = oldAt + step*sv;

}
Пример #3
0
void Trackball::updateRotation(Real32 rLastX,    Real32 rLastY, 
                               Real32 rCurrentX, Real32 rCurrentY)
{
    Quaternion qCurrVal;

    Vec3f  gAxis; /* Axis of rotation */
    Real32 rPhi = 0.f;  /* how much to rotate about axis */
    Vec3f  gP1;
    Vec3f  gP2;
    Vec3f  gDiff;
    Real32 rTmp;

    if( (osgAbs(rLastX - rCurrentX) > TypeTraits<Real32>::getDefaultEps()) ||
        (osgAbs(rLastY - rCurrentY) > TypeTraits<Real32>::getDefaultEps())   )
    {
        /*
         * First, figure out z-coordinates for projection of P1 and P2 to
         * deformed sphere
         */
        
        gP1.setValues(  rLastX,
                        rLastY,
                         projectToSphere(_rTrackballSize, rLastX, rLastY));

        gP2.setValues(  rCurrentX,
                        rCurrentY,
                        projectToSphere(_rTrackballSize, rCurrentX, rCurrentY));
        
        /*
         *  Now, we want the cross product of P1 and P2
         */

        gAxis = gP2;
        gAxis.crossThis(gP1);

        /*
         *  Figure out how much to rotate around that axis.
         */

        gDiff = gP2;
        gDiff -= gP1;

        rTmp = gDiff.length() / (2.0f * _rTrackballSize);


        /*
         * Avoid problems with out-of-control values...
         */
        
        if(rTmp > 1.0) 
            rTmp = 1.0;

        if(rTmp < -1.0) 
            rTmp = -1.0;

        if(_gMode == OSGObject)
            rPhi = Real32(-2.0) * osgASin(rTmp);
        else
            rPhi = Real32( 2.0) * osgASin(rTmp);

    }

    rPhi *= _rRotScale;

    if(_bSum == false)
    {
        _qVal.setValueAsAxisRad(gAxis, rPhi);
    }
    else
    {
        qCurrVal.setValueAsAxisRad(gAxis, rPhi);
        _qVal *= qCurrVal;
//        _qVal.multLeft(qCurrVal);
    }
}