Re: [osg-users] Two rotations on an object?
Ernie Smethurst wrote: Code: PositionAttitudeTransform *rotate_planetFive = new PositionAttitudeTransform; rotate_planetFive->addChild( geode_planetFive ); rotate_planetFive->setUpdateCallback( new AnimationPathCallback(osg::Vec3(0,0,0), osg::Z_AXIS, inDegrees(45.0f)) ); //ROTATE AROUND THE SUN Vec3 central_point = primitive_planetFive->getCenter(); //GET THE CURRENT LOCATION OF THE CIRCLE WHILST IS ROTATES rotate_planetFive->setUpdateCallback( new AnimationPathCallback(osg::Vec3(central_point), osg::Z_AXIS, inDegrees(45.0f)) ); But that doesnt work, it only applies the second setUpdateCallback() when i need both to run. Sorry if it seems I am posting excessively, I just get a little bit obsessive when I cant get the coding correct, Apologies. Of course it does. You replace your first update callback on one transform with a second. As I said before, you need three transforms here. A rotate, followed by a translate, followed by another rotate. Since you're using PAT's, one of them can handle two transforms (one rotate and one translate, which is what you have now), but you'll need a second transform to do the other rotation. As I said in my previous message, in a scene graph like OSG, you combine rotations by using the graph's hierarchy. What you should have is your planet's geometry as a child of a PAT doing a rotation, which itself is a child of another PAT doing the other rotation and the translation. The final PAT should be attached to the root of the scene. --"J" ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Two rotations on an object?
Thank you all for your replies, Much appreciated. I understand about how 3D graphics works in regards to coordinate systems and such and i understand how I want the scene to act and work, its just getting the code to actually make this happen. Going about applying the two transforms to my sphere is where i am stuck because i dont have a firm grasp with the OSG language. For example, below rotates a sphere that is originally placed as 10,0,0 around 0,0,0 (imagine that is where a sun is placed), whilst it is doing that i also need it to rotate on its own central axis. As it will be spinning on its own XYZ which will change as it rotates i choose its current XYZ postion as the point on which to rotate using the getCenter() method, still cant get it working though. Code: PositionAttitudeTransform *rotate_planetFive = new PositionAttitudeTransform; rotate_planetFive->addChild( geode_planetFive ); rotate_planetFive->setUpdateCallback( new AnimationPathCallback(osg::Vec3(0,0,0), osg::Z_AXIS, inDegrees(45.0f)) ); //ROTATE AROUND THE SUN Vec3 central_point = primitive_planetFive->getCenter(); //GET THE CURRENT LOCATION OF THE CIRCLE WHILST IS ROTATES PositionAttitudeTransform *rotate_planetFiver = new PositionAttitudeTransform; rotate_planetFiver->addChild( geode_planetFive ); rotate_planetFiver->setUpdateCallback( new AnimationPathCallback(osg::Vec3(central_point), osg::Z_AXIS, inDegrees(45.0f)) ); //USING THE SPHERE CURRENT LOCATION, ROTATE AROUND IT. Doing this and, as expected, two spheres are shown, one that stays at its original location and just spins and another that "orbits" around 0,0,0. Now I need to combine both of the transforms onto a single sphere, but i just cant figure out the code for that. I tried this: Code: PositionAttitudeTransform *rotate_planetFive = new PositionAttitudeTransform; rotate_planetFive->addChild( geode_planetFive ); rotate_planetFive->setUpdateCallback( new AnimationPathCallback(osg::Vec3(0,0,0), osg::Z_AXIS, inDegrees(45.0f)) ); //ROTATE AROUND THE SUN Vec3 central_point = primitive_planetFive->getCenter(); //GET THE CURRENT LOCATION OF THE CIRCLE WHILST IS ROTATES rotate_planetFive->setUpdateCallback( new AnimationPathCallback(osg::Vec3(central_point), osg::Z_AXIS, inDegrees(45.0f)) ); But that doesnt work, it only applies the second setUpdateCallback() when i need both to run. Sorry if it seems I am posting excessively, I just get a little bit obsessive when I cant get the coding correct, Apologies. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=24203#24203 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Two rotations on an object?
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
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.org
Re: [osg-users] Two rotations on an object?
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. Randolph On 2010-02-14 19:22:50 -0800, Ernie Smethurst said: I am trying to create a scene of a planetary system, using textures, lighting and primitives and am currently stuck with a problem that I cant quite work out, How to apply to rotations to a sphere. As it is a planet that I am trying to model it will rotate around its own axis and also rotate around a central sun. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Two rotations on an object?
Thanks for pointing me toward the PositonAttidudeTransform class. Below is what im trying: Code: MatrixTransform *rotate_planetFive = new MatrixTransform; rotate_planetFive->addChild( geode_planetFive ); rotate_planetFive->setUpdateCallback( new AnimationPathCallback(osg::Vec3(2.0f, 0.0f, 0.0f), osg::Z_AXIS, inDegrees(-300.0f)) ); PositionAttitudeTransform *trans_planetFive = new PositionAttitudeTransform; rotate_planetFive->addChild( geode_planetFive ); rotate_planetFive->setUpdateCallback( new AnimationPathCallback(osg::Vec3(0.0f, 0.0f, 0.0f), osg::Z_AXIS, inDegrees(25.0f)) ); The MatrixTransform makes the object spin on its own axis and then the PositionAttitudeTransform makes the object orbit around a central point. When i run each part separately, they work fine but now i need them to do both at the same time, ands the problem. I add them to my scene like this: Code: simpleGroup->addChild(trans_planetFive); simpleGroup->addChild(rotate_planetFive); But they cannot work together at the same time. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=24196#24196 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Two rotations on an object?
Hi, ups... ;) I have corrected it. Thank you! Cheers, Torben -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=24185#24185 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Two rotations on an object?
Ernie Smethurst wrote: a chain of PAT Notes I'm not really sure what PAT notes are, I've checked the OSG quick start guide and cant see anything regarding PAT Notes. Thanks for any input. PAT = PositionAttitudeTransform Also I think he meant "nodes", not "notes" :-) --"J" ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Two rotations on an object?
> a chain of PAT Notes I'm not really sure what PAT notes are, I've checked the OSG quick start guide and cant see anything regarding PAT Notes. Thanks for any input. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=24182#24182 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Two rotations on an object?
Hi, you could to it as a chain of PAT Notes 1. rotate to the desired angle of the planet around sun 2. translate the planet to add you desired radius 3. Rotate the plane to rotate it around it own axis. Cheers, Torben -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=24152#24152 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Two rotations on an object?
So i am learning to use OSG and am currently learning the basics and am currently creating little scenes to help me understand how it all works and such. I am trying to create a scene of a planetary system, using textures, lighting and primitives and am currently stuck with a problem that I cant quite work out, How to apply to rotations to a sphere. As it is a planet that I am trying to model it will rotate around its own axis and also rotate around a central sun. Below is what i use to get the planet to rotate around its own axis: Code: MatrixTransform *moon_Rotate = new MatrixTransform; moon_Rotate->addChild( geode_moon); moon_Rotate->setUpdateCallback( new AnimationPathCallback(osg::Vec3(0, 0, 0), osg::Z_AXIS, inDegrees(25.0f)) ); This works successfully, but how would I then add a second rotation to make it rotate around another sphere that I have created? Thanks for any input. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=24150#24150 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org