Example #1
0
void AsMatrix3D::appendRotation(float degrees, const AsVector3D_ref& axis, const AsVector3D_ref& pivotPoint)
{
	bool hasPivot = ((pivotPoint != AS_NULL) && (((pivotPoint->x != 0.0f) || (pivotPoint->y != 0.0f)) || (pivotPoint->z != 0.0f)));
	if(hasPivot)
	{
		appendTranslation(-pivotPoint->x, -pivotPoint->y, -pivotPoint->z);
	}
	float radians = AsMathHelper::toRadians(degrees);
	float cosA = AsMath::cos(radians);
	float sinA = AsMath::sin(radians);
	float ax = axis->x;
	float ay = axis->y;
	float az = axis->z;
	if((((ax == 0.0f) && (ay == 0.0f)) && (az == 1.0f)))
	{
		appendValues(cosA, -sinA, 0, 0, sinA, cosA, 0, 0, 0, 0, 1, 0);
	}
	else
	{
		if((((ax == 0.0f) && (ay == 1.0f)) && (az == 0.0f)))
		{
			appendValues(cosA, 0, sinA, 0, 0, 1, 0, 0, -sinA, 0, cosA, 0);
		}
		else
		{
			if((((ax == 1.0f) && (ay == 0.0f)) && (az == 0.0f)))
			{
				appendValues(1, 0, 0, 0, 0, cosA, -sinA, 0, 0, sinA, cosA, 0);
			}
			else
			{
				throw AS_NEW(AsNotImplementedError,());
			}
		}
	}
	if(hasPivot)
	{
		appendTranslation(pivotPoint->x, pivotPoint->y, pivotPoint->z);
	}
}
////////////////////////////////////////////////////////////////////////
//
// Description:
//    Stretch the dragger according to the motion along the plane
//    projector
//
// Use: private
//
void
SoTranslate2Dragger::drag()
//
////////////////////////////////////////////////////////////////////////
{
    // Set up the projector space and view.
    // Working space is space at end of motion matrix.
	planeProj->setViewVolume( getViewVolume() );    
	planeProj->setWorkingSpace( getLocalToWorldMatrix() );

    // Get newHitPt and startHitPt in workspace.
	SbVec3f newHitPt = planeProj->project( getNormalizedLocaterPosition()); 
	SbVec3f startHitPt = getLocalStartingPoint();

    // Convert newHitPt to world space and save this as our new worldRestartPt
	getLocalToWorldMatrix().multVecMatrix( newHitPt, worldRestartPt );

    // Figure out the translation relative to start position.
        SbVec3f motion = newHitPt - startHitPt;

    // Maybe we need to constrain the motion...
    if ( !shftDown )
	translateDir = -1;
    else {
	// The shift key is pressed. This means 1-D translation.
	if ( translateDir == -1 ) {
	    // The 1-D direction is not defined. Calculate it based on which
	    // direction got the maximum locater motion.
            if ( isAdequateConstraintMotion() ) {
		if ( fabs( motion[0]) > fabs( motion[1]))
		    translateDir = 0;
		else 
		    translateDir = 1;

		// Set the axis feedback switch to the given direction.
		setSwitchValue( axisFeedbackSwitch.getValue(), translateDir );
	    }
	    else {
		// Not ready to pick a direction yet. Don't move.
		return;
	    }
	}
	// get the projection of 'motion' onto the preferred axis.
	SbVec3f constrainedMotion(0,0,0);
	constrainedMotion[translateDir] = motion[translateDir];
	motion = constrainedMotion;
    }

    // Append this to the startMotionMatrix, which we saved at the beginning
    // of the drag, to find the current motion matrix.
	setMotionMatrix( appendTranslation( getStartMotionMatrix(), motion ) );
}
void TranslateRadialDragger::
drag()
{
  // Things can change between renderings. To be safe, update
  // the projector with the current values.
  lineProj->setViewVolume(getViewVolume());
  lineProj->setWorkingSpace(getLocalToWorldMatrix());

  // Find the new intersection on the projector.
  SbVec3f newHitPt
    = lineProj->project(getNormalizedLocaterPosition());

  // Get initial point expressed in our current local space.
  SbVec3f startHitPt = getLocalStartingPoint();

  // Motion in local space is difference between old and
  // new positions.
  SbVec3f motion = newHitPt - startHitPt;

  // Append this to the startMotionMatrix, which was saved
  // automatically at the beginning of the drag, to find
  // the current motion matrix.
  setMotionMatrix( appendTranslation(getStartMotionMatrix(), motion));
}
Example #4
0
			inline
			Ptr
			appendTranslation(Vector3Ptr value)
			{
				return appendTranslation(value->x(), value->y(), value->z());
			}