Forums > Jitter

tracking position of opengl object when anchor is set

March 3, 2014 | 5:31 am

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

<pre><code>

– Pasted Max Patch, click to expand. –

</code></pre>


March 3, 2014 | 9:20 am

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]

– Pasted Max Patch, click to expand. –

March 4, 2014 | 6:00 am

thanks rob for the explanation and the patch !

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

here is a demo patch:

<code>

– Pasted Max Patch, click to expand. –

</code>


March 4, 2014 | 10:52 am

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.

– Pasted Max Patch, click to expand. –

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

– Pasted Max Patch, click to expand. –

March 4, 2014 | 11:06 am

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.

here is the code:

<code>

– Pasted Max Patch, click to expand. –

</code>


March 4, 2014 | 4:05 pm

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.

– Pasted Max Patch, click to expand. –

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.

– Pasted Max Patch, click to expand. –

March 13, 2014 | 6:39 am

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


Viewing 7 posts - 1 through 7 (of 7 total)