Nice job Jason... 

Gordon Tomlinson
Product Manager 3d Technology & Future Products
Overwatch(r)
An Operating Unit of Textron Systems

-----Original Message-----
From: osg-users-boun...@lists.openscenegraph.org
[mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Jason
Daly
Sent: Monday, February 15, 2010 6:26 PM
To: OpenSceneGraph Users
Subject: Re: [osg-users] Two rotations on an object?

R Fritz wrote:
> 1. Put your sun at the origin of world co-ordinates.
> 2. Put the planet at the origin. Make its axis of rotation the z axis.
> 3. Use a rotate transform to rotate it around its axis. (You've got 
> this part.) 4. Translate the planet along the x axis, to its orbital
radius.
> 5. Use a rotation around the z to position the planet in the x-y
plane. 
> (If the planet's orbit is not in the x-y plane, you will need more
> transformations.)
>
> These techniques are covered in most introductory computer graphics 
> texts--that's where to go to learn about this kind of problem; 
> studying software docs won't get you very far.
>   

I agree that you should try to familiarize yourself with the basics of
computer graphics before asking the list about things like this.

That said, I'll try to explain the relevant parts at a high level...


Graphical 3D objects are composed of polygons, which are specified by
their vertices (points in space).  Each object is typically modeled
relative to the origin of Euclidean space (0, 0, 0).  In order to place
an object somewhere else in space, or rotate it to a different
orientation, you need to transform its vertices.  This is done by
multiplying each vertex by a 4x4 matrix (I won't get into why the matrix
is 4x4, you can look that up :-) ).  Transformation matrices can be set
up to do translation (move vertices to another location relative to the
origin), rotate, scale, and do other kinds of operations.  You can also
combine operations (a translate, followed by a rotate, for example), by
simply multiplying the individual transformation matrices together.

One more thing to realize is that each transformation essentially sets
up a new, local coordinate system relative to the previously established
system.  When you translate an object, say along the X-axis first, then
rotate it, you'll be rotating the translated coordinate system around
the world's origin, so your object will effectively orbit the origin.  
Now, purists will argue that it's really the other way around, and the
rotate is really happening first, followed by a translate along the new,
rotated X-axis.  It's all matter of perspective, though.  Until you
grasp the concepts (which might be a while, believe me), if you think
you have the sequence right, but it's not working, just try reversing
it, and that will usually fix it  :-)

In your case, you have two objects (a sun and a planet).  The sun is
easy to handle, just draw it exactly as its modeled.  The planet needs a
total of three operations, though.  First you need to rotate the planet
around its own axis, then you need to translate it away from the sun
(about 93,000,000 miles should do  :-) ), then you need to rotate it
again to have it orbit the sun around it

Now, in a scene graph like OSG, all transforms are applied as the graph
is traversed from the root of the graph to the leaves, where the
geometry lives.  So, in order to draw the scene like you want, you'll
need to attach the sun to the root of the scene (so it will be drawn at
the origin), then you'll need to create your three transformations and
attach them as children of each other, attaching the planet to the final
transform.  Like this:


              (root)
               /   \
            (sun) (orbit rotation
                     \
                   (translation)
                       \
                    (planet rotation)
                         \
                       (planet)


Now, I did this off the top of my head, so if it doesn't work, just try
reversing the order, like I said above  :-)

--"J"

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or
g
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to