[fluxus] how to get position etc after being moved by the physics engine?

Dave Griffiths dave at pawfal.org
Tue Jul 18 02:52:58 PDT 2006


> Dave Griffiths wrote:
>>> Hi all,
>>>
>>> I've got some code that splits an object in two, but the two new
>>> objects
>>> are always created at the origin because I don't know how to get the
>>> position of the original object after it has been moved around by the
>>> physics engine.  Any clues?
>>
>> does:
>>
>> (grab object)
>> (let ((pos (vtransform (vector 0 0 0) (get-transform))))
>> (ungrab)
>> ...
>> )
>>
>> work?
>
> Perfect! :)

phew - hadn't tried it with physical objects :)

>> (you probably want the rotation too)
>
> Not necessary at the moment, but it would be nice to know how to get it

well - it's doable, but I'm not sure how the physics will work with the
rotation, ode doesn't make this very easy, and I keep changing my mind how
to handle it.

the (get-transform) returns the current matrix of the grabbed primitive,
so you can extract the scale, rotation or position from that.

transforming a point collapses the scale and rotation, and gives you the
worldspace position of the primitive.

to also pass on scaling and rotation then you can just do something like:

(grab object)
(let ((transform (get-transform))))
(ungrab)
(grab new-object)
(identity)         ; clear any previous transforms
(concat transform) ; copy object's transform
(ungrab))

extracting the rotation from the scale (if you don't want to pass the
scaling on) is harder and slow, but can be done - better is to avoid
having any scale in the transform by "baking" the scale into the vertex
positions by scaling it first, then doing (apply-transform) and then
setting the rotation and position.

> - I didn't know where to look in the manual to find this stuff  - the
> function list is strangely empty on the website - but vtransform sounds
> like it might be in the maths section.

yup, it's in the maths section, but I just realised (concat) and
(identity) are missing. the function list will return shortly, along with
complete online help, hopefully.

cheers,

dave

cheers,

dave




More information about the Fluxus mailing list