Re: [osg-users] Improper rotation
Hi, Seems like i can't advice anything really usefull on 3ds max and modelling stuff, because i'm have never done any modelling, i'm just programmer. Though it can be that model is fine in modelling tool, and export settings apply optimizations that cause things go wrong. If you use 3ds max and osgExp then there are option called Flatten Static Transforms under optimizations section, you want that turned off (unchecked). Cheers, Sergey -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=35675#35675 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Improper rotation
Hi Sergey, really thanks for your help. hybr wrote: Hi, Basically what you need to do is translate rod to (0,0,0), apply rotation that u need, and translate back to original position. If your math is right and you still haven't expected results i'd say that your model has static transforms removed and translated to vertices coords, so center of your rod in local coords is not gonna be (0,0,0), and hence you will get wrong results with rotations, since your math assume that center of your rod in local coords is (0,0,0) to do proper rotation. You can try use like model bbox or bounding sphere center in local model coords and transform model to that coords instead of (0,0,0) before rotation or re-export your model without flatten static transforms optimization. I checked more times my math operations on matrix and seem to be right. I also checked the center of table, and center of each rod and you got reason: the model has static transforms removed and translated to vertices coords. I downloaded this model from Google Sketchup, it was done in Sketchup and then converted in .3ds. Now the issue is this: i don't have much experience in 3dsmax, so i tryed to set manually a pivot for each rod but this doesn't help. can you tell me how to fix my model as you suggested? Alternatively, can you post here a link to a useful hot-to ? I'm really in crisis, I have already lost a lot of time to fix these issues -_-' Thanks a lot, Axel -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=35653#35653 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Improper rotation
Hi Tom, thanks a lot for your answer! Tom Pearce wrote: In the step where you're calculating m, it looks like you're applying the rotation to the original matrix, which includes a translation already. Yes, this is (perhap) what i want. I try to be less ambiguous: my scene is a small room with a table at the center. The table, how you can see in pics has 8 rods, The table is translated by (0, 0, -309) to be placed on the floor My goal is to rotate a rdd using the mouse wheel: when i pick scroll up on a rod it should rotate the related rod by +angle (the variable rotation in code) on Y axis (-rotation if i scroll down). This is why (in my reasoning) i use the original matrix for rotate: i should not know how much rotated is the rod. The rod only need to be rotated on its Y axis, it should not be translated Tom Pearce wrote: I'm not sure why you say that the rotation and translation is formally right - the final translation should be equal to the original translation if you're rotating about a local axis, but it isn't. I said formally right because reading the output it seems that the rod is positioned right, but i'm not sure of this, since visually the rod is bad positioned after the rotation. Sincerely, more time I spend on this issue, more I feel confused :-)) However, to understand better how rods have to work (for rotating) , look some seconds of the following video: http://www.youtube.com/watch?v=p06NT8M5cKU PS: excuse my archaic English! -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=35602#35602 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Improper rotation
Hi, Basically what you need to do is translate rod to (0,0,0), apply rotation that u need, and translate back to original position. If your math is right and you still haven't expected results i'd say that your model has static transforms removed and translated to vertices coords, so center of your rod in local coords is not gonna be (0,0,0), and hence you will get wrong results with rotations, since your math assume that center of your rod in local coords is (0,0,0) to do proper rotation. You can try use like model bbox or bounding sphere center in local model coords and transform model to that coords instead of (0,0,0) before rotation or re-export your model without flatten static transforms optimization. Cheers, Sergey -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=35618#35618 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Improper rotation
I understood part of the issue, and thus I corrected (part of) the error. Now seems that the rotation and the translation is formally right, but visually translation is wrong. I enclosed 3 pics of the scene, before rotating, after 1st rotation and after 2nd rotation. I correct the source as follows: Code: printVector(Original amtRod trans: , amtRod-getWorldMatrices()[0].getTrans()); printVector(Original amtRod rotate: , amtRod-getWorldMatrices()[0].getRotate()); printVector(\t amtRod center: , amtRod-getBound().center()); osg::Vec3 offset = amtRod-getWorldMatrices()[0].getTrans(); printVector(\t amtRod offset = , offset); osg::Matrix get = osg::Matrix::translate(- offset); osg::Matrix m = amtRod-getMatrix() * osg::Matrix::rotate(rotation, osg::Vec3(0,1,0)); osg::Matrix put = osg::Matrix::translate( offset); amtRod-setMatrix( get * m * put ); printVector(\t get.getTrans = , get.getTrans()); printVector(\t m.getRotate = , m.getRotate()); printVector(\t m.getTrans = , m.getTrans()); printVector(Current amtRod trans: , amtRod-getWorldMatrices()[0].getTrans()); printVector(Current amtRod rotate: , amtRod-getWorldMatrices()[0].getRotate()); Now the output is: Original amtRod trans: (0, 0, -309) Original amtRod rotate: (0, 0, 0) amtRod center: (6.55547, 150.952, -142.15) amtRod offset = (0, 0, -309) get.getTrans = (-0, -0, 309) m.getRotate = (0, -0.130526, 0) m.getTrans = (79.9751, 0, -298.471) Current amtRod trans: (0, 0, -309) Current amtRod rotate: (0, -0.130526, 0) Original amtRod trans: (0, 0, -309) Original amtRod rotate: (0, -0.130526, 0) amtRod center: (-36.8519, 150.952, -146.139) amtRod offset = (0, 0, -309) get.getTrans = (-0, -0, 309) m.getRotate = (0, -0.258819, 0) m.getTrans = (79.9751, 0, -298.471) Current amtRod trans: (-74.5249, 0, -339.869) Current amtRod rotate: (0, -0.258819, 0) Are there suggestions? -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=35587#35587 Attachments: http://forum.openscenegraph.org//files/after_2nd_rotation_175.png http://forum.openscenegraph.org//files/after_1st_rotation_272.png http://forum.openscenegraph.org//files/before_rotating_202.png ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Improper rotation
Hi Axel, In the step where you're calculating m, it looks like you're applying the rotation to the original matrix, which includes a translation already. Code: osg::Matrix m = amtRod-getMatrix() * osg::Matrix::rotate(rotation, osg::Vec3(0,1,0)); It sounds like what you want to do is rotate then translate - so you can create a rotation matrix, post-multiply it by a translation matrix (the translation of the original), and set the product as your overall matrix. Something like: Code: osg::Matrix rotation = osg::Matrix::rotate(rotation_amount, rotation_axis); osg::Matrix translation = osg::Matrix::translate(original_translation); amtRod-setMatrix(rotation*translation); I'm not sure why you say that the rotation and translation is formally right - the final translation should be equal to the original translation if you're rotating about a local axis, but it isn't. Cheers, Tom -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=35591#35591 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org