Results 1 to 6 of 6

Thread: Matrix rotation with offset

  1. #1
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Matrix rotation with offset

    So I have 2 objects I want to rotate. from 1 I only know the D3DMatrix and position. Now I want the other mesh to "Stick" to it on my update function with an offset. So when object 1 is 40 units away on the X axis and I rotate object 2 90 degrees, object 1 should be 40 units on the y axis. (know what I mean?)
    NecroSOFT - End of line -

  2. #2

    Matrix rotation with offset

    It seems to be the typical planet orbit problem

    Lets say, the sun is the middle of your universe... so it's at 0,0,0

    rotating the sun would be

    clear worldmatrix
    rotate worldmatrix // turn sun
    draw sun

    to let the earth turn around the sun it would be

    clear the worldmatrix
    translate worldmatrix // move earth to its distance from the sun
    rotate worldmatrix // rotate the world around the sun
    draw earth

    letting the earth turn on it's own axis would be
    clear the worldmatrix
    rotate worldmatrix // rotate earth around its axis
    translate worldmatrix // move world in position
    draw earth

    letting the earth turn around the sun, while its turning around its own axis would be
    clear the worldmatrix
    rotate worldmatrix // rotate world around its axis
    translate worldmatrix // move it to distance
    rotate worldmatrix // turn it around sun
    draw earth


    Now, if the sun is not at 0,0,0 but at 40,0,0

    then according to the last step it would be
    clear the worldmatrix
    rotate worldmatrix // rotate world around its axis
    translate worldmatrix // move it to distance
    rotate worldmatrix // turn it around sun
    translate worldmatrix(40,0,0) // move it to the sun
    draw earth

    It's all just a matter of the order in which you manipulate the worldmatrix.

    Hope I understood your question right
    <a href="http://www.greatgamesexperiment.com/game/Valgard/?utm_source=gge&amp;utm_medium=badge_game"><img border="0" alt="GGE" title="GGE" src="http://static.greatgamesexperiment.com/badge/game/valgard/gge400x56.png"></a>

  3. #3

    Matrix rotation with offset

    Hey, nice explanation! Think you got the nail on the head there
    My site: DelphiTuts.com (coming soon)...

    Download Font Studio 4.21 here.

  4. #4
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Matrix rotation with offset

    This would work great as a tutorial on 3D graphics with illustrations.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  5. #5
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Matrix rotation with offset

    great explanation... but I wanna know how to calculate those things...

    I already can position and rotate stuff... but I need to position the "earth" with an offset to the "sun" (and + rotation from the sun, like they are welded together)
    NecroSOFT - End of line -

  6. #6

    Matrix rotation with offset

    Hmmm.... I think I don't understand you

    The "earth" rotates around the sun... but with the rotation of the sun? Is this correct? Like a, lets say mountain on the earth?

    It's all the same... No matter if things are "welded together or not.."

    You know the position and rotation of "sun"... You need to know this, because you want your earth to move there and rotate exactly the same...

    So what you need to do is:

    ClearWorldMatrix;
    Rotate matrix with SUNs rotation
    Translate Matrix to suns position.
    draw sun
    ClearWorldMatrix;
    Translate Matrix to the distance earth has from sun
    Rotate matrix with SUNs rotation
    Translate Matrix to suns position.
    draw earth
    <a href="http://www.greatgamesexperiment.com/game/Valgard/?utm_source=gge&amp;utm_medium=badge_game"><img border="0" alt="GGE" title="GGE" src="http://static.greatgamesexperiment.com/badge/game/valgard/gge400x56.png"></a>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •