[Plib-devel] Quaternion Development Direction
Brought to you by:
sjbaker
From: Negative0 <neg...@ea...> - 2000-02-25 08:57:53
|
Hello, I submitted a few changes to Steve to fix the Quaternion code. I had emailed the list before asking for help, then I realized that there was several errors in the sg libraries Quaternion routines. Off the top off my head I remember 4 errors (sgNormalizeQuat, sgInvertQuat, sgMultQuat, sgSlerpQuat), but I have far more drastic changes in mind that can't be made until we find out how many people it will impact. I'd like to point out that nobody could possibly be using Quaternions (correctly) at this point, so the impact should be nil. First: The other calls in sg all use float arrays, so making function calls simply uses the variables name. But the quats, being structs, need the address assignment operator. If sgQuat were an array of floats as well it would make all the sg function calls similar in syntax and you would avoid situations like: sgMakeMat4( matrix, &quat ), by using an array of floats it would be sgMakeMat4( matrix, quat ) Second: By making it an array of floats it matches the sgVec3 definition and becomes ambiguous in some of the function overloading. My personal take on the function overloading is what I was taught. Don't overload dissimilar functions. sgMakeQuat( quat, vec ) and sgMakeQuat( quat, axis, angle ) may appear to be similar enough because they both make a quat, but they're not. They do totally different things to get a quat. However gAngleAxisToQuat( quat, angle, axis ) and sgAngleAxisToQuat( quat, angle, x, y, z ) ARE similar enough because its the same operation (in fact the x,y,z form wraps a call to the axis form). As another example, all the functions that convert a quat *could* be forced into a sgConvertQuat(...) naming scheme, but that would constrain the syntax and make adding new functions harder. Here's a list of the proposed functions, parameter order, and naming scheme: #define SGfloat GLfloat #define sgFloat GLfloat typedef sgFloat sgQuat[4] sgQuatToEuler( sgFloat yaw, sgFloat pitch, sgFloat roll, sgQuat quat ) sgEulerToQuat( sgQuat quat, sgFloat yaw, sgFloat pitch, sgFloat roll ) sgQuatToAngleAxis( sgFloat angle, sgVec3 axis, sgQuat quat ) sgAngleAxisToQuat( sgQuat quat, sgFloat angle, sgVec3 axis ) sgQuatToAngleAxis( sgFloat angle, sgFloat x, sgFloat y, sgFloat z, sgQuat quat ) sgAngleAxisToQuat( sgQuat quat, sgFloat angle, sgFloat x, sgFloat y, sgFloat z ) sgQuatToMatrix( sgMat4 matrix, sgQuat quat ) sgMatrixToQuat( sgQuat quat, sgMat4 matrix ) sgMakeIdentQuat ( sgQuat dst ) sgSetQuat ( sgQuat dst, const sgFloat w, const sgFloat x, const sgFloat y, const sgFloat z ) sgSetQuat( sgQuat dst, const sgVec4 src ) sgCopyQuat ( sgQuat dst, const sgQuat src ) sgNormalizeQuat ( sgQuat dst, const sgQuat src ) sgNormalizeQuat ( sgQuat dst ) sgInvertQuat ( sgQuat dst, const sgQuat src ) sgInvertQuat ( sgQuat dst ) sgMultQuat ( sgQuat dst, const sgQuat a, const sgQuat b ) sgPostMultQuat ( sgQuat dst, const sgQuat q ) sgPreMultQuat ( sgQuat dst, const sgQuat q ) sgRotQuat ( sgQuat dst, const sgFloat angle, const sgVec3 axis ) sgRotQuat ( sgQuat dst, const sgFloat angle, const sgFloat x, const sgFloat y, const sgFloat z ) sgSlerpQuat( sgQuat dst, const sgQuat from, const sgQuat to, const sgFloat step ) You'll notice that I have actually killed every sgMakeQuat call which is different than the way sgMat4 and sgVec3 (etc) work. If everyone thinks this is too different, or takes the sg library in the wrong direction, that's fine. I'll make sure Steve has the patches needed to make the sg Quaternions work. But if people like the syntax and change, then let the list know and I can send in all of the changes. -negative0 |