Ejemplo n.º 1
0
void dPluginCamera::SetMatrix (dFloat yaw, dFloat roll, dFloat distance)
{
//	dMatrix yawMatrix_ (dYawMatrix(yaw));
//	dMatrix rollMatrix_ (dRollMatrix(roll));
//	m_matrix = rollMatrix_ * yawMatrix_;
//	m_matrix.m_posit = dVector (-10.0f, 5.0f, 10.0f, 1.0f);

	m_cameraRoll = dClamp(roll, -85.0f * 3.141692f / 180.0f, 85.0f * 3.141692f / 180.0f);
	m_cameraYaw = dMod (yaw, 2.0f * 3.141592f);
	m_distance = (distance < 0.5f) ? 0.5f : distance;

	dMatrix yawMatrix (dYawMatrix(m_cameraYaw));
	dMatrix rollMatrix (dRollMatrix(m_cameraRoll));
	m_matrix = rollMatrix * yawMatrix;
	m_matrix.m_posit = m_matrix.RotateVector(dVector (-distance, 0.0f, 0.0f, 1.0f)) + m_pointOfInterest;
	m_matrix.m_posit.m_w = 1.0f;
}
void Object::rotateInAxisZ(GLfloat rollAngle) 
{
    mat4 rollMatrix(1.0f);
    vec3 origin_aux = origin;
    
    translate(-origin_aux);

    rollMatrix = rotate(rollMatrix, rollAngle, axisZ);

    axisX = vec3(rollMatrix * vec4(axisX, 1.0f));
    axisY = vec3(rollMatrix * vec4(axisY, 1.0f));
    axisZ = vec3(rollMatrix * vec4(axisZ, 1.0f));

    transformations = rollMatrix * transformations;

    translate(origin_aux);
}
Ejemplo n.º 3
0
  //-------------------------------------------------------
  /// Returns the rotation matrix of the bone.
  ///
  /// Each bone defines its own coordinate system.
  /// The position of the coordinates depend on the
  /// coordinates of the bone (head, tail) and a 'roll' value.
  /// BoneRotation returns a rotation matrix which describes
  /// the rotation of the bone-coordinate-system relativ to
  /// its parent bone.
  /// See Avatara.doc for more information and illustrations.
  ///
  /// \param head The head vector.
  /// \param tail The tail vector.
  /// \param roll The roll in radiant.
  /// \return Rotation matrix.
  //-------------------------------------------------------
  Matrix BoneRotation(Vector head, Vector tail, float roll)
  {
    Vector boneVector(tail - head);
    boneVector.Normalize();

    // Axis of rotation
    Vector axis = CrossProduct(UnitVectorY, boneVector);
    Matrix rotation(IdentityMatrix);

    // check if axis exists (crossproduct might be 0!)
    if(axis.Length() > EPSILON)
    {
      // Rotation axis exists
      // calculate rotation
      axis.Normalize();
      float theta = acos(DotProduct(UnitVectorY, boneVector));
      rotation.SetRotation(axis, theta);
    }
    else
    {
      // Rotation axis does not exist.
      // boneVector either points in the same direction as y-unit-vector
      // or in the opposite direction.

      if(DotProduct(UnitVectorY, boneVector) < 0)
      {
        // boneVector points in opposite direction:
        rotation.M(0, 0) = -1.0;
        rotation.M(1, 1) = -1.0;
      }
    }

    // Roll matrix
    Matrix rollMatrix(IdentityMatrix);
    rollMatrix.SetRotation(boneVector, roll);

    return rollMatrix * rotation;
  }