Citro3D: How to apply quaternions to your object?

Discussion in '3DS - Homebrew Development and Emulators' started by delete12345, Aug 10, 2016.

  1. delete12345
    OP

    delete12345 GBAtemp Fan

    Member
    387
    160
    Feb 27, 2010
    United States
    Taipei, Taiwan
    Citro3D now supports quaternions.

    When you create a new quaternion, what do you do with it, so you can apply rotations to your object?

    And do you have to do it inside the PICA vertex shader?
     
  2. SimplyFedorable

    SimplyFedorable Evangelion Geek

    Member
    566
    227
    Apr 7, 2016
    United States
    melee hell
    Compelty off topic, but it is Citra, not Citro
     
  3. Voxel

    Voxel Clumsy Coder

    Member
    GBAtemp Patron
    Voxel is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    5,181
    5,841
    Jun 27, 2015
    United Kingdom
    England, UK
    PF2M and Joel16 like this.
  4. SimplyFedorable

    SimplyFedorable Evangelion Geek

    Member
    566
    227
    Apr 7, 2016
    United States
    melee hell
    oh, my bad. Sorry!
     
  5. catlover007

    catlover007 GBAtemp Regular

    Member
    158
    178
    Oct 23, 2015
    Germany
    well you have multiple options.
    The easier one would be to convert your quaternion to a matrix and multiply your modelView matrix with it, which you pass into the vertex shader.
    Another option(the more difficult but better option) would be to pass the quaternion to your vertex shader and use magic quaternion math(which you have to copy and translate to Pica assembler by yourself from the source code of c3d, see here: https://github.com/fincs/citro3d/blob/master/source/maths/quat_crossfvec3.c) to apply the rotation to your vertices(watch out for the order, first rotate then translate).
     
    marc00077 likes this.
  6. delete12345
    OP

    delete12345 GBAtemp Fan

    Member
    387
    160
    Feb 27, 2010
    United States
    Taipei, Taiwan
    Thanks for your help.

    What should the C3D_FVec argument be? I remembered vaguely that it's for forward, up, and right, but I would like for confirmation.
     
  7. catlover007

    catlover007 GBAtemp Regular

    Member
    158
    178
    Oct 23, 2015
    Germany
    The q is the quaternion which represents the rotation and v is the vector that should be rotated(around point zero)
     
  8. delete12345
    OP

    delete12345 GBAtemp Fan

    Member
    387
    160
    Feb 27, 2010
    United States
    Taipei, Taiwan
    Ah, then I may be mistakenly referring to FVec3_CrossQuat(v, q) instead? Thanks for the info.
     
  9. catlover007

    catlover007 GBAtemp Regular

    Member
    158
    178
    Oct 23, 2015
    Germany
    what are you going to do? I'm a little bit confused the first way or the second?
     
  10. delete12345
    OP

    delete12345 GBAtemp Fan

    Member
    387
    160
    Feb 27, 2010
    United States
    Taipei, Taiwan
    Using quaternions to move around in the world. Not relying on matrix transformations as much as possible. This is to force myself to learn about quaternions and trying to embed the big picture of using it into my brain, so I can get past the hurdles for thinking about it conceptually.
     
  11. catlover007

    catlover007 GBAtemp Regular

    Member
    158
    178
    Oct 23, 2015
    Germany
    ah, ok. I never really understood how they work internally.

    Good luck
     
  12. pigman46

    pigman46 Newbie

    Newcomer
    9
    10
    Jun 23, 2009
    United States
    Don't try to understand how they work internally. It's a 4-dimensional abstraction where three of the dimensions are imaginary. You only need to understand what their operations accomplish.

    — Posts automatically merged - Please don't double post! —

    Quaternions are orientations; they do not include position. You can use quats to "move" rotationally. You need to translate using the result from cross multiplying with a vector if you want to use them for moving position.

    Yes. Quat+Vec3 (orientation plus position) uses less memory than a 4x4 matrix. Additionally, quat operations are cheaper than their equivalent matrix operations. Plus you have the whole reason they were invented: the quotient of two rotations. This allows you to slerp between two orientations. You can't do this (generically) at all with matrix math.
     
  13. kprovost7314

    kprovost7314 GBAtemp's Official Bara Master

    Member
    1,688
    883
    Dec 24, 2014
    United States
    In that bara manga ( ͡° ͜ʖ ͡°)
    How do you even use Citro3D? And why do we need shader files?
     
  14. koz

    koz Advanced Member

    Newcomer
    82
    23
    Jul 7, 2015
    I liked this math series about quaternions by Professor Norman Wildberger at UNSW (Australia).

    https://www.youtube.com/user/njwildberger/search?query=quaternions

    Start here:
     
  15. delete12345
    OP

    delete12345 GBAtemp Fan

    Member
    387
    160
    Feb 27, 2010
    United States
    Taipei, Taiwan
    You will have to look up the example codes provided with a devkitPro installation. Citro3D is like OpenGL ES 2.0, hence the shader files. (Analogy only)