Subversion Repositories gelsvn

Rev

Rev 306 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 306 Rev 501
Line 32... Line 32...
32
		/// Get a 3x3 rotation matrix from a quaternion
32
		/// Get a 3x3 rotation matrix from a quaternion
33
    Mat3x3f get_Mat3x3f() const
33
    Mat3x3f get_Mat3x3f() const
34
    {
34
    {
35
      float s = 2/norm();
35
      float s = 2/norm();
36
      // note that the all q_*q_ are used twice (optimize)
36
      // note that the all q_*q_ are used twice (optimize)
37
      return Mat3x3f(Vec3f(1.0 - s*(qv[1]*qv[1] + qv[2]*qv[2]),
37
      return Mat3x3f(Vec3f(1.0f - s*(qv[1]*qv[1] + qv[2]*qv[2]),
38
			         s*(qv[0]*qv[1] - qw*qv[2]),
38
			         s*(qv[0]*qv[1] - qw*qv[2]),
39
			         s*(qv[0]*qv[2] + qw*qv[1])),
39
			         s*(qv[0]*qv[2] + qw*qv[1])),
40
		     Vec3f(      s*(qv[0]*qv[1] + qw*qv[2]),
40
		     Vec3f(      s*(qv[0]*qv[1] + qw*qv[2]),
41
  			   1.0 - s*(qv[0]*qv[0] + qv[2]*qv[2]),
41
  			   1.0f - s*(qv[0]*qv[0] + qv[2]*qv[2]),
42
			         s*(qv[1]*qv[2] - qw*qv[0])),
42
			         s*(qv[1]*qv[2] - qw*qv[0])),
43
		     Vec3f(      s*(qv[0]*qv[2] - qw*qv[1]),
43
		     Vec3f(      s*(qv[0]*qv[2] - qw*qv[1]),
44
			         s*(qv[1]*qv[2] + qw*qv[0]),
44
			         s*(qv[1]*qv[2] + qw*qv[0]),
45
			   1.0 - s*(qv[0]*qv[0] + qv[1]*qv[1])));
45
			   1.0f - s*(qv[0]*qv[0] + qv[1]*qv[1])));
46
    }
46
    }
47
 
47
 
48
    /// Get a 4x4 rotation matrix from a quaternion
48
    /// Get a 4x4 rotation matrix from a quaternion
49
    Mat4x4f get_Mat4x4f() const
49
    Mat4x4f get_Mat4x4f() const
50
    {
50
    {
51
      float s = 2/norm();
51
      float s = 2.0f/norm();
52
      // note that the all q_*q_ are used twice (optimize?)
52
      // note that the all q_*q_ are used twice (optimize?)
53
      return Mat4x4f(Vec4f(1.0 - s*(qv[1]*qv[1] + qv[2]*qv[2]),
53
      return Mat4x4f(Vec4f(1.0f - s*(qv[1]*qv[1] + qv[2]*qv[2]),
54
			         s*(qv[0]*qv[1] - qw*qv[2]),
54
			         s*(qv[0]*qv[1] - qw*qv[2]),
55
			         s*(qv[0]*qv[2] + qw*qv[1]),
55
			         s*(qv[0]*qv[2] + qw*qv[1]),
56
		           0.0),
56
		           0.0f),
57
		     Vec4f(      s*(qv[0]*qv[1] + qw*qv[2]),
57
		     Vec4f(      s*(qv[0]*qv[1] + qw*qv[2]),
58
			   1.0 - s*(qv[0]*qv[0] + qv[2]*qv[2]),
58
			   1.0f - s*(qv[0]*qv[0] + qv[2]*qv[2]),
59
			         s*(qv[1]*qv[2] - qw*qv[0]),
59
			         s*(qv[1]*qv[2] - qw*qv[0]),
60
			   0.0),
60
			   0.0f),
61
		     Vec4f(      s*(qv[0]*qv[2] - qw*qv[1]),
61
		     Vec4f(      s*(qv[0]*qv[2] - qw*qv[1]),
62
			         s*(qv[1]*qv[2] + qw*qv[0]),
62
			         s*(qv[1]*qv[2] + qw*qv[0]),
63
			   1.0 - s*(qv[0]*qv[0] + qv[1]*qv[1]),
63
			   1.0f - s*(qv[0]*qv[0] + qv[1]*qv[1]),
64
			   0.0),
64
			   0.0f),
65
		     Vec4f(0.0, 0.0, 0.0, 1.0));
65
		     Vec4f(0.0f, 0.0f, 0.0f, 1.0f));
66
    }
66
    }
67
		
67
		
68
	/// Create an identity quaternion
68
	/// Create an identity quaternion
69
  inline Quatf identity_Quatf()
69
  inline Quatf identity_Quatf()
70
  {
70
  {
71
    return Quatf(Vec3f(0.0));
71
    return Quatf(Vec3f(0.0f));
72
  }
72
  }
73
 
73
 
74
	};
74
	};
75
 
75
 
76
}
76
}