Learning Of with the ofBook repo, I am adapting a few examples from the animation chapter written by @zach.
Using example #14 sinExample_atan, I wanted to make the rectangle class an extension of OfNode and simply make this node roll around its z local axis to target the mouse position.
My code does’t work properly and I can’t figure out why. This might not be the best way to proceed?
I also thought of using the lookAt() function but I do not wan’t the Z axis to aim at mouse position but the X axis instead.
Thanks for any help.
Until now I didn’t take care about ofNode (shame on me !)
I don’t see an addChildren function in ofNode
Does it means that we must create ofMeshes, then use ofMesh.addParent() to connect them to an ofNode (which would be seen as a NULL object in AfterEffects for example) ?
@tactif - two options, either create an object that extends ofNode (and overrides the custom draw function) or use the transformGL() / restoreTransformGL() functionality.
@tim1 – do you want the object to face the mouse by rotating on it’s Z axis? Right now, you are calculating an angle based on relative mouse changes, but this seems wrong – if the mouse is moving straight to the right, angle is always going to be 0, if it’s moving to the left, 180. it seems better to compute the angle between the object and the mouse, like:
when I do this, the object follows the mouse. (also, note things things like roll are cummulative, if you call roll(1) every frame, the object will spin… in this case, we find the absolute angle change between the object and the mouse and se the absolute orientation).
it might be slower than calculating the orientation directly and in this case it might not simplify much compared to just using the trigonometric functions but for other uses nesting 2 or more nodes to get transformations that you can’t do with one is really useful.