Jitter/OpenGL: post-scaling a rotated child object or node

Thyme-Traveler's icon

Hello,

In Jitter, trying to scale a jit.gl.node containing a child jit.gl.node object that has been rotated. The goal is to scale the parent/group along the global xyz axes — squishing or distorting the child group — and not just have the child(ren) inherit the scaling along their rotated xyz axes.

For example, scale a [jit.gl.node] containing an xyz-rotated [jit.gl.node] containing, say, a [jit.gl.gridshape] or [jit.gl.sketch], or multiples.

No matter what I do, scaling the outer jit.gl.node scales along the children's own xyz axes and doesn't distort or skew the whole group as desired.

I have tried attaching jit.anim.nodes but can't find any combination of inherit parameters or animmode that does what I want to do.

Searched the forums, but maybe did not search for the right phrase. What is the key to post-scaling rotated object groups?

TFL's icon

Interested in a solution for this too. I guess it's a matter of calculating our own transform matrix and applying it with the concat message for jit.anim.node, but not sure of that.

A workaround would be to apply the transform directly in the geometry like in this example but I really hope we can do that at a higher level.

Maybe Rob could help us here?

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

Rob Ramirez's icon

Interesting. Yes it doesn't look like there's a way to apply scaling in that way using the anim.node system. The only thing I can think of is to apply your rotations on the geometry itself using matrixoutput 2 into a jit.gl.mesh.

I can fire a feature request for this functionality (first anim.node feature request we've gotten in probably about a decade)

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

TFL's icon

Thanks Rob for the insight. +1 for this feature request!

Is there a missing part in your example? Like a jit.gen for calculating the rotation? Because as is the behavior seems to be the same: the object gets scaled alongside its local axis.

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

Rob Ramirez's icon

the example just shows how to scale 2 objects along the same axes using an anim.node hierarchy if one of the objects has a rotation applied. The rotation can only be applied on the matrixoutput enabled gridshape for this technique to work.

Thyme-Traveler's icon

Interesting. Thank you, gents. I was trying to figure out how the matrix-to-mesh flow worked. Seems like matrixoutput can work with mesh shape primitives like [jit.gl.gridshape], but not on a group of objects through a [jit.gl.node], which is what I'm trying to do here. Also, am I correct that all of my multi-colored objects and axes would lose their coloring and texture/pbr if re-digested into a gl.mesh?

Rob's proposed feature would be very helpful. I thought it would be a simple matter to take a group of objects (grouped as a virtual "cube" for cartesian purposes), rotated together as a cube along an arbitrary axis, and then skewed/smashed/stretched along the global xyz axes into a rhombohedron (or occasionally a rectangular prism or another cube if coincidentally aligned with the global xyz axes).

Background: I built a 3D panning/rotation engine with a built-in visualizer. The internal 3D calculations all work pretty well: one panning can be arbitrarily rotated at a given theta along an arbitrary xyz axis (jit.quat sometimes gets a little wonky around the extremes of the Z axis). Meanwhile, cartesian scaling of the entire domain may be performed pre- or post-rotation, and the entire output domain can be moved to revolve around a different cartesian origin. This all works and outputs correctly, but in the visualizer portion, I can't get jitter to display the output 3D domain when rotated and then post-scaled.

Pre-scaling works fine: the output domain (grouped together by a gl.node) is stretched or smashed along its x, y and z axis as needed (gl.node), then rotated xyz or quat (gl.node), and then positioned based on the modified origin (gl.node). Post-scaling is where I'm stuck: the output is rotated (gl.node), and later origin-positioned (gl.node), but in between, the step to scale post-rotation behaves as though it is scaling pre-rotation.

input and output domains (shown here as upper-only polar), with quaternion rotation, cartesian scaling, and origin offset applied to output domain (stuck with post-rotation scaling functioning as pre-rotation scaling, instead of distorting the rotated domain as desired)

Thyme-Traveler's icon

PS Seems like [jit.gl.sketch] has no matrixoutput option? It can draw to a jit.matrix associated with a jit.gl.render, a jit.gl.node, or a jit.window/pwindow (and therefore presumably a jit.world), but there seems to be no option to output pure matrix to a mesh. My project's domain groups use jit.gl.sketch extensively to draw the cages and axes (using jit.gl.gridshape only for the "floor", tilt plane, chaser and origin spheres). Without Rob's proposed enhancement, is gl.mesh post-rotation scaling even possible with gl.sketch?

PPS Separately, had an issue with double-rotating [jit.gl.skybox]. [jit.gl.handle] is attached to the [jit.world], and rotates the world somewhat reliably (only accepts drags within a small area, and the objects tend to "explode" and fly off at an angle when zooming in close—may be a built-in feature but could not find an option to disable). In order to have the skybox rotate along with the world, I have to attach both objects to the gl.handle.

Unfortunately, my source image was not properly aligned, and so I had included "pre"-rotation in the skybox's geometry. As soon as the skybox is attached to the handle object, its pre-rotation is, understandably, overridden. I tried to insert a jit.gl.node between the handle and the skybox for double-rotation, but then the skybox does not rotate at all. My workaround was to modify the skybox source image, which involved equirectangular rotation in an image editor — took about 51 attempts to get "close enough" to my ideal pre-rotation, left it at that.

TFL's icon

Oh, I got Rob's example wrong. Here it is with the correct way to change the rotation without changing the direction of the global scaling:

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

Without Rob's proposed enhancement, is gl.mesh post-rotation scaling even possible with gl.sketch?

I think you could perform the transformation directly in jit.gl.sketch as it give you access to many gl commands, including some to rotate and scale in whichever order you want: using glrotate, glscale, and you might also need glpushmatrix + glpopmatrix. You can find documentation for these gl functions in the gl doc. Be careful, official function names (like glRotate) are not necessarily the same in use in jit.gl.sketch (glrotate). You can find the available commands in the "commands" tab of the jit.gl.sketch help file.