tracking position of opengl object when anchor is set

petcode's icon

hello jitter pros,

having a question how to track the position of opengl object when anchor is set.
with the getposition message, i only get the staic center of the object.

here is a simple patch, which demonstrate the issue.

looking forward for any help !

pc

Max Patch
Copy patch and select New From Clipboard in Max.
Rob Ramirez's icon

you are going to have to use anim.node for this.
you can query the worldpos attribute to get the world-space position of a 3d object.

also, never use a [metro 1] to drive your renderer, instead use [qmetro]

Max Patch
Copy patch and select New From Clipboard in Max.
petcode's icon

thanks rob for the explanation and the patch !

but there seems to be a little offset between the word- and object coordinates.

Max Patch
Copy patch and select New From Clipboard in Max.

here is a demo patch:

Rob Ramirez's icon

it's a little tricky, but you simply need to send a bang to the jit.anim.node after setting the rotate. this causes it to update immediately, rather than waiting for the the render context to update it. so when you get the world-position, it's already updated based on the new rotation of the anim.node.

Max Patch
Copy patch and select New From Clipboard in Max.

alternatively, you could use jit.anim.drive to drive the animation.

Max Patch
Copy patch and select New From Clipboard in Max.
petcode's icon

hey rob,

thanks so much for your help !

one more thing, which is not clear to me is:
if i rotate the whole scene, the two circles does not align anymore in 3d space.

putted a jit.gl.handle to the render.

Max Patch
Copy patch and select New From Clipboard in Max.

here is the code:

Rob Ramirez's icon

did i mention this stuff gets tricky?

so this actually makes sense if you thing about it. the gl.handle is affecting the gl.render node, which is the root node of all the nodes and objects in the context.
to make your patch work, then you must use the worldtolocal message of jit.anim.node, which takes a world-position (from the spinning object), and creates the local position value based on the objects current world-position that will bring the object to that world-position.

Max Patch
Copy patch and select New From Clipboard in Max.

a simpler alternative is to never adjust the gl.render transforms. this is my advice for any kind of patch that has to do work with transforms. instead, create a new jit.anim.node and attach the handle to that, and then parent that to all the other anim.nodes you want the handle to control.

Max Patch
Copy patch and select New From Clipboard in Max.
petcode's icon

hey rob,

i just want to thank for your help.
now i got everythin working.

perhaps it woud be nice, if all open gl objects could tell us their "real" position by sending something like a "getWorldPos" message.

then, we could save many objects ;-)

have a nice day,
pc