This exposure to the pv3d engine and 3D programming is also a kind of semi-solution, so Mark Two articles for their own learning pv3d ..
Humans initially use a matrix of nine values to represent the Rotation Position of a three-dimensional object. Its defect is that the data is big, and it cannot automatically generate an excessive angle between two angles.
Since the matrix description angle is too abstract, humans have invented three values of the Euler's angle ). The curl is a very irresponsible guy. The number of rotated circles and the order of rotation are completely different. 3D Animators are the most annoying
One of the worst cases is the universal lock (Gimbal
Lock) 'this guy's problem. After rotating for several times according to different axes, the three axes X, Y, and Z are completely in the same direction. That is to say, the angle is easy to rotate until there is only one
The direction can be rotated, which is a horrible 'universal lock '.
Later, the clever Irish mathematician invented the quaternion, which is the perfect solution to describe three-dimensional space rotation so far.
Just like a matrix, a * B does not satisfy the multiplication exchange rate. That is to say, a * B is not equal to B *. The reason why the four-dimensional element can clearly express three-dimensional rotation is that it is actually a 'four-dimensional 'algorithm. Here, the 'four-dimensional 'is used in mathematics. You don't need to imagine what a four-dimensional world is like = _ =. It's just one more axis and one more parameter.
We mainly introduce several common methods and usage of quaternion in pv3d, without involving too much mathematical knowledge, so don't worry. The quaternion class is located in the org-papervision-core-Math package.
// Four values are required to construct a four-dimensional array (the family name is 4 RMB = _ =). x, y, and z are three-dimensional vectors, indicating any axis ', W is a scalar, indicating the degree of rotation. This is the almost perfect angle rotation.
The reason why the Quaternary element is not 'absolute perfection' is that the transition rate during interpolation is not constant and is difficult to solve. However, this is much smaller than the 'terrorism universal lock.
Public Function quaternion (X: Number = 0, Y: Number = 0, Z: Number = 0, W: Number = 1)
// The following two values are 'convert from the optimum angle to calculate the siloid' and 'convert from the Matrix to calculate the siloid '. This is a very common method. If you know the angle or matrix of an object, you can generate the corresponding element.
In pv3d, The Tranform attribute of any displayobject3d is to transform its matrix, and this matrix will be used to obtain the currently rotated element. (These methods are used when the flab camera is rotated)
Public static function createfromees (ax: Number, ay: Number, AZ: Number, usedegrees: Boolean = false)
Public static function createfrommatrix (Matrix: matrix3d)
// Returns the inverse of the preceding two. They are 'obtain the excellent angle of the known quarant' and 'obtain the matrix of the known quarant'
Public Function toeuler ()
Public Function get matrix ()
// Interpolation is one of the most important functions of the Quaternary element. In the slerp method parameters, QA indicates the start Rotation Position, and QB indicates the end Rotation Position, apha can be regarded as the ratio of A interpolation position. The value is between 0 and 1.
Public static function slerp (QA: quaternion, QB: quaternion, Alpha: Number)
Idea of perfect Rotation
Yes:
We must first know our start position and end position. In many cases, we use a displayobject3d virtual end position. We can use its. Tranform (which is a matrix value) to convert it into a quaternary element.
When we know the two-end element, we only need to increase the Alpha value (from 0 to 1) for each struct to insert any number of the four elements of the transition frame.
Then, the ry of each vertex is reversed to a matrix. After the current object location is multiplied by a matrix, a new position of each vertex is obtained.
The following are the basic operations of the Quaternary element (it is not necessary to know it in general). The Wikipedia can provide a more professional explanation of the 'quaternary element.
Wikipedia-quaternary
(A new window will be opened)
// Evaluate the modulo. The distance from the Quaternary element to the origin is simply the length.
Public Function get modulo ()
// Common Rail
Public static function conjugate (A: quaternion)
// Point Multiplication
Public static function dot (A: quaternion, B: quaternion)
// Name
Public static function multiply (A: quaternion, B: quaternion)
// Calculate the difference
Public static Function Sub (A: quaternion, B: quaternion)
// Sum
Public static function add (A: quaternion, B: quaternion)