That did the trick, so simple (this confirms that my math is totally rusted now, I've got to study again).
Thanks a lot, Marcus.

Cheers.

Juan.

On 1/8/06, Marcus Lindblom <[EMAIL PROTECTED]> wrote:
Juan José Aja Fernández wrote:

> Hi Everyone.
> I'm currently translating an application using ODE and glut to ODE
> with OpenSG.
>
> Everything works fine except the rotations and scaling of my objects,
> I have a function handleTransform wich gets 2 arrays and sets them in
> their proper locations in the model view matrix.
> So basicaly I want to translate this glut/ODE code to OpenSG/ODE:
>
>   glPushMatrix();
>   handleTransform(wheelrot, wheelpos);
>   glScalef(1, 1, 0.2);
>   glutSolidSphere(radius, 10, 10);
>   glPopMatrix();
>
> The above snippet of code draws one of the wheels of my simulated car.
>
> So I changed handleTransform to work with the OpenSG
> rotation-scale-translation matrix:
>
> Matrix handleTransform(const dReal *rot, const dReal *pos)
> {
>   Matrix m = Matrix(rot[0], rot[1], rot[2], pos[0],
>                     rot[4], rot[5], rot[6], pos[1],
>                     rot[8], rot[9], rot[10], pos[2],
>                     0, 0, 0, 1);
>   return m;
> }
>
> This way I can draw my objects in a similar way to this:
>
> beginEditCP...
> {
> m = handleTransform(wheelrot, wheelpos);
> m.setScale (1, 1, 0.2)
> tChasis->setMatrix(m);
> }
> endEditCP......
>
> Which I believe is correct, because the rotations work correctly, but
> the painted objects won't behave adequately (the movement is all
> weird). I guess that my problem is scaling, so I wanted to know how
> can I preserve the initial scaling throughout the execution so the
> shape of my wheels is preserved as in with glut.

You need to apply the scaling after (to the right of) the ODE-transform.
I'm not sure exactly how osg::Matrix::setScale is implemented, and
whether it preserves previous rotations or not. It's quite likely that
is simply sets the matrix to a pure scaling matirix. (It's easy to check
though. Just look in the source. Good thing to do if something does not
do what you expect it to. Did you check what m looks like after the
setScale()-call?)

Given that I'm correct with the above, you have two options. Either
rearrange your scene graph and have two transforms above your geometry
(i.e. root -> ODE-transform -> scaling -> wheel geometry), or, apply the
scaling to the matrix yourself:

m = handleTransform(wheelrot, wheelpos);
Mtx scale;
scale.setScale(1, 1, 0.2)
m *= scale; // (or m.mult(scale); perhaps)
tChasis->setMatrix(m);

That should do the trick. (Of course, you need not recompute 'scale'
every time, if you're picky, but I don't think it will matter the least.)

Best Regards
/Marcus



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&opclick
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to