Author Topic: safely interpolate rotations  (Read 6192 times)

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
safely interpolate rotations
« on: January 04, 2010, 11:45:39 pm »
hi,

Ardor uses quaternions for rotations. in demo, it calculates a rotation from a vector to a vector and interpolates rotation with identity rotation. AFAIK with quaternions this is perfectly legal and make sense.

i tried to emulate this in jPCT by interpolating two matrices. sometimes results become very strange. i guess this happens when two rotations (matrices) are too different. afterall interpolating matrices for rotations does not makes sense mathematically.

so is there a safe way in jPCT to interpolate a rotation ?

r a f t

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: safely interpolate rotations
« Reply #1 on: January 04, 2010, 11:54:26 pm »
No, there isn't. You are right that the matrix interpolation fails, if the input matrices are too different. Imagine one matrix that rotates a vertex to 0,0,1 and another that rotates it to 0,0,-1. It's impossible to interpolate between these matrices by using a linear interpolation of the matrices' values and create proper inbetween states that way. jPCT ensures that the interpolated matrix is a valid rotation matrix, but it doesn't make any assurances if it really fits the purpose.
You have to use your own quaternion implementation for this. Cyberkilla's old Skeletal-API from the download page should have one IIRC. Maybe that helps.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: safely interpolate rotations
« Reply #2 on: January 04, 2010, 11:59:55 pm »
I've had a quick look at his API. It has a Quaternion class and a method in the Matrix class to create a Matrix from a quaternion. Looks promising IMHO...except that it doesn't say anything about row-/column-majority... ;)

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: safely interpolate rotations
« Reply #3 on: January 05, 2010, 12:03:19 am »
ok, i'll have a look at that.

you sometimes say that, one can do anything with matrices that can be done with quaternions. seems as it's not the case actually ;)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: safely interpolate rotations
« Reply #4 on: January 05, 2010, 10:23:49 am »
No, that's still true. Both concepts are mathematically equivalent. When both concepts were invented, they struggled for which is best....and matrices won. But that doesn't mean that everything is as easy in one concept as it is in the other. Or in other words: I've no idea how to do this interpolation with matrices, but it is possible somehow.
Anyway, go with quats for this. It should be much easier. And i assume that CK's Matrix class is column-major, because he used jPCT's set- and getDump()-method to convert between the two IIRC...and that method actually does an implicit conversion.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: safely interpolate rotations
« Reply #5 on: January 05, 2010, 05:34:59 pm »
ok, i will make a quaternion which can interoperate with jPCT matrices. and maybe you can add it or your own to jPCT core for such purposes.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: safely interpolate rotations
« Reply #6 on: January 07, 2010, 11:36:00 pm »
i really think a simple quaternion is needed in jPCT core. what do you think ?

Bones has a Quaternion which is a stripped and modified version of Ardor's. modified to fit jPCT matrices. i'm not sure it's bug free but i've extensively tested (with random values) converting to/from jPCT matrices

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: safely interpolate rotations
« Reply #7 on: January 07, 2010, 11:43:14 pm »
If i'm allowed to take that part and add it, i will happily do so.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: safely interpolate rotations
« Reply #8 on: January 07, 2010, 11:51:00 pm »
it sounds ok with the "Do whatever with it" license ;)

Offline MrCoder

  • byte
  • *
  • Posts: 2
  • Destroy, Erase, Improve
    • View Profile
    • Ardor3D
Re: safely interpolate rotations
« Reply #9 on: January 13, 2010, 11:18:39 pm »
    1. The origin of this software must not be misrepresented; you must not
    claim that you wrote the original software. If you use this software
    in a product, an acknowledgment in the product documentation would be
    appreciated but is not required.

    2. Altered source versions must be plainly marked as such, and must not be
    misrepresented as being the original software.


    3. This notice may not be removed or altered from any source
    distribution.

http://ardorlabs.trac.cvsdude.com/Ardor3Dv1/browser/trunk/LICENSE

feel free to add some ardor3d notes/mentionings on the jpct site ;)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: safely interpolate rotations
« Reply #10 on: January 13, 2010, 11:46:16 pm »
Is it ok to add these to a closed source distribution like jPCT then? I can't find any information in the license that deals with that. It speaks of "source versions" and "source distributions", but jPCT isn't. On the other hand, it allows one to distribute modified, even commercial, versions without mentioning the product (Ardor3D).

So according to the license, i'm allowed to modify the sources and distribute a product based on that freely and i don't have to mention Ardor3D (albeit appreciated, of course)...but do i have to distribute the sources!? The license doesn't seem to cover this.

Don't get this wrong. It's not my intention to claim that i did this class or something like that, if i should decide to add it...i just want to get this right.

Offline MrCoder

  • byte
  • *
  • Posts: 2
  • Destroy, Erase, Improve
    • View Profile
    • Ardor3D
Re: safely interpolate rotations
« Reply #11 on: January 14, 2010, 03:19:45 pm »
With the current license I think it's fine for you to add modified sources to your stuff (i guess it says you should add notes in your source that it is, but since it's closed source who can check :) )

Just wanted to clarify that it's not really a "Do whatever with it", even if it's close ;)