/[hegemonie]/hegemonie/Common/Quaternion.m
ViewVC logotype

Diff of /hegemonie/Common/Quaternion.m

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by dam, Fri Jul 25 21:01:56 2003 UTC revision 1.4 by dam, Fri Aug 22 08:04:09 2003 UTC
# Line 39  Line 39 
39    
40  @implementation Quaternion  @implementation Quaternion
41    
42    + (id) quaternionWithValuesX: (float)x
43                               Y: (float)y
44                               Z: (float)z
45                               W: (float)w
46    {
47      return AUTORELEASE([[self alloc] initWithValuesX: x Y: y Z: z W: w]);
48    }
49    
50    + (id) quaternionWithRotation: (Matrix)rotation
51    {
52      return AUTORELEASE([[self alloc] initWithRotation: rotation]);
53    }
54    
55  /*  /**
56   * This method builds an instance of Quaternion,   * Initializes the quaternion
57   * with all the attributes initialised with the parameters   * with all the attributes initialised with the parameters.
58   */   */
59  - (id) initWithValuesX: (float)x  - (id) initWithValuesX: (float)x
60                       Y: (float)y                       Y: (float)y
# Line 61  Line 73 
73    return self;    return self;
74  }  }
75    
76  /* This method builds an instance of Quaternion,  /**
77   * by converting the matrix in parameter   * Initializes the quaternion using the rotation matrix.
78   * This matrix must be a 4x4 matrix, otherwise the function will crash.   * This matrix must be a 4x4 matrix.
79   */   */
80  - (id) initWithRotation: (Matrix)rotation  - (id) initWithRotation: (Matrix)rotation
81  {  {
# Line 125  Line 137 
137    return self;    return self;
138  }  }
139    
140  /*  /**
141   * This method returns the rotation matrix 4x4 corresponding to the quaternion.   * Converts the quaternion to a 4x4 rotation matrix.
  * So it converts a quaternion to a matrix 4x4.  
142   */   */
143  - (void) convertToRotation: (Matrix)rotation  - (void) convertToRotation: (Matrix)rotation
144  {  {
# Line 167  Line 178 
178  }  }
179    
180    
181  /*  - (float) x
182   * Says if the quaternion in parameter is egal to the current quaternionn, i.e.  {
183   * the values x, y, z and z are egal.    return _x;
184    }
185    
186    - (float) y
187    {
188      return _y;
189    }
190    
191    - (float) z
192    {
193      return _z;
194    }
195    
196    - (float) w
197    {
198      return _w;
199    }
200    
201    /**
202     * Compares the quaternions.
203     * Quaternions are equals, if their x y z w parameters are equal.
204   */   */
205  - (BOOL) isEqual: (Quaternion *)quat  - (BOOL) isEqual: (Quaternion *)quat
206  {  {
# Line 178  Line 209 
209    return _x == quat->_x && _y == quat->_y && _z == quat->_z && _w == quat->_w;    return _x == quat->_x && _y == quat->_y && _z == quat->_z && _w == quat->_w;
210  }  }
211    
212    /**
213     * Negates the quaternion.
214     */
215  - (void) negate  - (void) negate
216  {  {
217    _x = -_x;    _x = -_x;
# Line 186  Line 220 
220    _w = -_w;    _w = -_w;
221  }  }
222    
223  /* Performs a spherical linear interpolation of the two quaternions in  /**
224     * Performs a spherical linear interpolation of the two quaternions in
225   * parameter, and the current quaternion becomes the quaternion interpolated.   * parameter, and the current quaternion becomes the quaternion interpolated.
226   * q1 is the starting quaternion, q2 the final quaternion.   * q1 is the starting quaternion, q2 the final quaternion.
227   * t represents the time for the interpolation; it must be valued   * t represents the time for the interpolation; it must be valued
# Line 198  Line 233 
233  {  {
234    NSParameterAssert (q1);    NSParameterAssert (q1);
235    NSParameterAssert (q2);    NSParameterAssert (q2);
236    NSParameterAssert (t >= 0);    NSParameterAssert (t >= 0.0f);
237    NSParameterAssert (t <= 1);    NSParameterAssert (t <= 1.0f);
   
238    
239    if ([q1 isEqual: q2])    if ([q1 isEqual: q2])
240      {      {

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26