예제 #1
0
/*! Depending on translationConstraintType(), constrain \p translation to be along an axis or
  limited to a plane defined in the world coordinate system by
  translationConstraintDirection(). */
void WorldConstraint::constrainTranslation(Vec& translation, Frame* const frame)
{
  Vec proj;
  switch (translationConstraintType())
    {
    case AxisPlaneConstraint::FREE:
      break;
    case AxisPlaneConstraint::PLANE:
      if (frame->referenceFrame())
	{
	  proj = frame->referenceFrame()->transformOf(translationConstraintDirection());
	  translation.projectOnPlane(proj);
	}
      else
	translation.projectOnPlane(translationConstraintDirection());
      break;
    case AxisPlaneConstraint::AXIS:
      if (frame->referenceFrame())
	{
	  proj = frame->referenceFrame()->transformOf(translationConstraintDirection());
	  translation.projectOnAxis(proj);
	}
      else
	translation.projectOnAxis(translationConstraintDirection());
      break;
    case AxisPlaneConstraint::FORBIDDEN:
      translation = Vec(0.0, 0.0, 0.0);
      break;
    }
}
예제 #2
0
/*! Translates the Frame so that its position() lies on the line defined by \p origin and \p
  direction (defined in the world coordinate system).

Simply uses an orthogonal projection. \p direction does not need to be normalized. */
void Frame::projectOnLine(const Vec& origin, const Vec& direction)
{
	// If you are trying to find a bug here, because of memory problems, you waste your time.
	// This is a bug in the gcc 3.3 compiler. Compile the library in debug mode and test.
	// Uncommenting this line also seems to solve the problem. Horrible.
	// cout << "position = " << position() << endl;
	// If you found a problem or are using a different compiler, please let me know.
	const Vec shift = origin - position();
	Vec proj = shift;
	proj.projectOnAxis(direction);
	translate(shift-proj);
}
예제 #3
0
	virtual void constrainRotation(Quaternion& q, Frame * const fr)
	{
		const Vec up = fr->transformOf(Vec(0.0, 0.0, 1.0));
		Vec axis = q.axis();
		float angle = 2.0*acos(q[3]);
		if (fabs(axis*up) > fabs(axis.x))
			axis.projectOnAxis(up);
		else
		{
			angle = (axis.x > 0.0) ? angle : -angle;
			axis.setValue(fabs(axis.x), 0.0, 0.0);
			const float currentAngle = asin(fr->inverseTransformOf(Vec(0.0, 0.0, -1.0)).z);
			if (currentAngle + angle > -0.2)
				angle = -0.2 - currentAngle; // Not too low
			if (currentAngle + angle < -M_PI/2.0)
				angle = -M_PI/2.0 - currentAngle; // Do not pass on the other side
		}
		q = Quaternion(axis, angle);
	}
예제 #4
0
/*! Depending on translationConstraintType(), constrain \p translation to be along an axis or
  limited to a plane defined in the Frame local coordinate system by
  translationConstraintDirection(). */
void LocalConstraint::constrainTranslation(Vec& translation, Frame* const frame)
{
  Vec proj;
  switch (translationConstraintType())
    {
    case AxisPlaneConstraint::FREE:
      break;
    case AxisPlaneConstraint::PLANE:
      proj = frame->rotation().rotate(translationConstraintDirection());
      translation.projectOnPlane(proj);
      break;
    case AxisPlaneConstraint::AXIS:
      proj = frame->rotation().rotate(translationConstraintDirection());
      translation.projectOnAxis(proj);
      break;
    case AxisPlaneConstraint::FORBIDDEN:
      translation = Vec(0.0, 0.0, 0.0);
      break;
    }
}
예제 #5
0
/*! When rotationConstraintType() is AxisPlaneConstraint::AXIS, constrain \p rotation to be a rotation
  around an axis whose direction is defined in the camera() coordinate system by
  rotationConstraintDirection(). */
void CameraConstraint::constrainRotation(Quaternion& rotation, Frame* const frame)
{
  switch (rotationConstraintType())
    {
    case AxisPlaneConstraint::FREE:
      break;
    case AxisPlaneConstraint::PLANE:
      break;
    case AxisPlaneConstraint::AXIS:
      {
	Vec axis = frame->transformOf(camera()->frame()->inverseTransformOf(rotationConstraintDirection()));
	Vec quat = Vec(rotation[0], rotation[1], rotation[2]);
	quat.projectOnAxis(axis);
	rotation = Quaternion(quat, 2.0*acos(rotation[3]));
      }
      break;
    case AxisPlaneConstraint::FORBIDDEN:
      rotation = Quaternion(); // identity
      break;
    }
}
예제 #6
0
/*! When rotationConstraintType() is AxisPlaneConstraint::AXIS, constrain \p rotation to be a rotation
  around an axis whose direction is defined in the Frame local coordinate system by
  rotationConstraintDirection(). */
void LocalConstraint::constrainRotation(Quaternion& rotation, Frame* const)
{
  switch (rotationConstraintType())
    {
    case AxisPlaneConstraint::FREE:
      break;
    case AxisPlaneConstraint::PLANE:
      break;
    case AxisPlaneConstraint::AXIS:
      {
	Vec axis = rotationConstraintDirection();
	Vec quat = Vec(rotation[0], rotation[1], rotation[2]);
	quat.projectOnAxis(axis);
	rotation = Quaternion(quat, 2.0*acos(rotation[3]));
      }
      break;
    case AxisPlaneConstraint::FORBIDDEN:
      rotation = Quaternion(); // identity
      break;
    }
}
void ManipulatedFrameSetConstraint::constrainTranslation(Vec& translation, Frame* const) 
{
   // Filter the translation
   switch (translationConstraintType()) {
      case AXIS:
         translation.projectOnAxis(translationConstraintDirection());
         break;

      case PLANE:
         translation.projectOnPlane(translationConstraintDirection());
         break;

     default:
         break;
   }

   QList<GLObject*>::iterator iter, end;
   for (iter = m_primitives.begin(), end = m_primitives.end(); iter != end; ++iter) {
       (*iter)->m_frame.translate(translation);
   }
}
예제 #8
0
/*! Depending on translationConstraintType(), constrain \p translation to be along an axis or
  limited to a plane defined in the camera() coordinate system by
  translationConstraintDirection(). */
void CameraConstraint::constrainTranslation(Vec& translation, Frame* const frame)
{
  Vec proj;
  switch (translationConstraintType())
    {
    case AxisPlaneConstraint::FREE:
      break;
    case AxisPlaneConstraint::PLANE:
      proj = camera()->frame()->inverseTransformOf(translationConstraintDirection());
      if (frame->referenceFrame())
	proj = frame->referenceFrame()->transformOf(proj);
      translation.projectOnPlane(proj);
      break;
    case AxisPlaneConstraint::AXIS:
      proj = camera()->frame()->inverseTransformOf(translationConstraintDirection());
      if (frame->referenceFrame())
	proj = frame->referenceFrame()->transformOf(proj);
      translation.projectOnAxis(proj);
      break;
    case AxisPlaneConstraint::FORBIDDEN:
      translation = Vec(0.0, 0.0, 0.0);
      break;
    }
}
예제 #9
0
// Contrainte de rotation de la caméra
void MyConstraint::constrainRotation(Quaternion &rotation, Frame *const frame)
{
    Vec axis = rotation.axis();
    double angle = rotation.angle();

    //printf("[%lf %lf] \n", frame->orientation().angle(), rotation.angle());
    //printf("/%lf %lf %lf\\\n", frame->orientation().axis().x, frame->orientation().axis().y, frame->orientation().axis().z) ;
    // printf("<%lf %lf %lf>\n", frame->position().x, frame->position().y, frame->position().z);
    //printf("|%lf %lf %lf|\n", rotation.axis().x, rotation.axis().y, rotation.axis().z);
    //axis.z = 0;

    /*
    if ((frame->orientation().angle() + angle) > 3.14/2.0)
    {
        rotation.setAxisAngle(rotation.axis(), -rotation.angle());
        //frame->rotate(Quaternion(frame->orientation().axis(),0.0));
    }
    */
    /*
    Vec quat = Vec(rotation[0], rotation[1], rotation[3]);
    quat.projectOnAxis(axis);

    if (frame->position().y <= 0.3)
    angle = -angle;

    rotation = Quaternion(quat, angle);
    */

    Vec axisC (0.0,1.0,0.0);

    axis = frame->transformOf(camera()->frame()->inverseTransformOf(axisC));
    Vec quat = Vec(rotation[0], rotation[1], rotation[2]);
    quat.projectOnAxis(axis);
    rotation = Quaternion(quat, 2.0*acos(rotation[3]));
    // printf("|%lf %lf %lf|\n", rotation.axis().x, rotation.axis().y, rotation.axis().z);
}