Previous topicNext topic

Object properties/parameters

Suggestions for new features for Magic.
Post Reply
artnik
Posts: 268
Joined: Tue Jan 05, 2016 5:33 pm

Object properties/parameters

Post by artnik »

After doing some work in Director, I'm really digging the ability of that software to reference an object properties, such as .x, .y, .z, etc.

Would there be a way to add variables/modifiers that can self-reference an objects position/scale, etc, or do you think that's best handled through globals?

A use case would be to animate an object's scale or colour based on it's position, so it would automatically vary based on where it was on screen.
Magic
Site Admin
Posts: 3440
Joined: Wed Apr 09, 2014 9:28 pm

Re: Object properties/parameters

Post by Magic »

Yes, globals would probably be the best way. Otherwise Magic doesn't really have the concept of "objects"; how would you access an object's position? How do you even refer to a specific object?
artnik
Posts: 268
Joined: Tue Jan 05, 2016 5:33 pm

Re: Object properties/parameters

Post by artnik »

I was thinking that it would work as a Source/Feature combination.

i.e. If you added a scale transform, the Source would be "SELF" and Feature would be ".x, .y, .z" etc, and then you would add modifiers as usual.
Magic
Site Admin
Posts: 3440
Joined: Wed Apr 09, 2014 9:28 pm

Re: Object properties/parameters

Post by Magic »

I'm not sure I understand. "Self" only works inside the current module. The question is, how do you get the properties of another module? That is, how does the Color module get the Scale? That's where globals come in.
artnik
Posts: 268
Joined: Tue Jan 05, 2016 5:33 pm

Re: Object properties/parameters

Post by artnik »

I think I understand, but when adding a chain of modules, I am assuming the first module added creates a 2D plane object that is passed down that chain, so the "self" is referring to that specific plane. Even when adding a 3D object, is it correct that it's really a 2D render buffer of that object that is referenced in subsequent modules?

But, of course that really assumes that the software is tracking the module inputs and outputs as planes that have positions, or are those planes always fixed in place at full resolution and only have their textures modified by the modules? Always happy to learn more about how things work. :-)
Magic
Site Admin
Posts: 3440
Joined: Wed Apr 09, 2014 9:28 pm

Re: Object properties/parameters

Post by Magic »

If we're just talking about 3D stuff, then we're really talking about matrices and matrix transformations. Very deep topic. Googling quickly, maybe http://www.opengl-tutorial.org/beginner ... o-matrices would be a place to start.

Perhaps the most important thing to understand is this: In Magic, if the only modules you use are Model, DepthTest, Scale, Rotate, and Translate, then you are never dealing with 2D images (except for the final rendered image). All these modules operate directly on the overall geometry of the scene. More specifically, they alter the current matrix, which you can think of as the mathematical context inside which an object is rendered. As the quote says at the top of the linked page, "The engines don’t move the ship at all. The ship stays where it is and the engines move the universe around it." This is particularly relevant because an object doesn't know anything about its position/size/rotation in the world. When dealing with 3D graphics, the world gets manipulated so that when an object gets drawn (or requested to be drawn), it is always drawn at the current position/size/rotation ("state") of the world. Then to draw another object in the same scene, the world gets un-manipulated back to its default state, and then re-manipulated in a different way. It seems backwards at first, but it is extremely fast and efficient when using graphics cards which are specifically optimized to do matrix math (called linear algebra): https://en.wikipedia.org/wiki/Linear_algebra#Matrices.

Here is another similar Q&A I found: "How does the camera work in 3D applications? As far as 3D applications are concerned, there is no camera. More specifically, the camera is always located at the eye space coordinate (0., 0., 0.). To give the appearance of moving the camera, the application must move the scene with the inverse of the camera transformation." The key is: move the scene with the inverse of the camera transformation. So now you might understand that the Magic modules I described above don't actually move objects; they move the scene.

Further, the idea that there are "objects in a scene" is in some sense a human simplification for the purpose of more intuitively understanding how 3D graphics works. But behind the scenes (pun intended?), there are no objects, just a ton of math determining where and how to draw millions of independent triangles.

In Magic, as soon as you start using 2D modules (any image effects, etc.), then you do an intermediate "rendering" of the world into a 2D rectangle which is drawn at the exact dimensions of the current window and textured with a snapshot of the scene. But it still exists in the 3D world. So if you put any Scale/Translate/Rotate modules after it, then you are manipulating that rectangle just as you could manipulate something in the Model module. But those later modules won't affect any of the geometry before the intermediate render.

As a closing thought, anytime any program uses shaders to create 2D effects, it's just a "trick". You're actually seeing a dynamically textured rectangle in the 3D world which happens to be drawn at an (x,y,z) position that perfectly covers the current window size.
artnik
Posts: 268
Joined: Tue Jan 05, 2016 5:33 pm

Re: Object properties/parameters

Post by artnik »

Thank-you for that. That just demystified a lot of misconceptions. Much appreciated.
Magic
Site Admin
Posts: 3440
Joined: Wed Apr 09, 2014 9:28 pm

Re: Object properties/parameters

Post by Magic »

Another way to describe it that I just thought of: In Magic, the modules get rendered the opposite way you might think. Most people assume that (for example) the rendering would start with a Model module; then it might get scaled by a Scale module; then Translated; then maybe a ColorRGB module gets applied. But actually what's happening is this: Start with the world (the Magic module); change the color of the world; translate the world; scale the world; draw a model at the current color and position of the world. Backwards, basically.

In any scene, the modules are a tree rotated 90 degrees to the right. https://en.wikipedia.org/wiki/Tree_(data_structure). Traversing a tree always starts with the root.
Post Reply