units of the Vector2 X&Y
Moderators: Víctor Paredes, Belgarath, slowtiger
units of the Vector2 X&Y
Hello, All!
I have some questions:
Which units used in the x,y cooordinates of the Vector2 class? Which ratio between screen dimensions and that units? If screen center is the "zero point", how can be found cooordinates of the screen edges?
I have some questions:
Which units used in the x,y cooordinates of the Vector2 class? Which ratio between screen dimensions and that units? If screen center is the "zero point", how can be found cooordinates of the screen edges?
Re: units of the Vector2 X&Y
Hello bogush_r,
This won't necessarily relate to the size and position of objects (or layers), because:
Note: you can also change the camera dimensions in the project settings, which will change where an object is placed in regard to the edge of the camera view (if, for example, you change from NTSC to NTSC 16:9 with an existing object). Changing a layer origin will also change an object's (Moho units) position without changing its position on the screen.
Note: the screen edges (in Moho units) might be different for different layers if the layers are not all at the same depth and the layer origins are not all in the same place.
Having said all that, there are some scripting functions that are related to screen units. Have a look at the scripting documentation for:
Regards, Myles.
Moho units! Any resemblance to real world units is purely illusory.bogush_r wrote:Which units used in the x,y cooordinates of the Vector2 class?
There cannot be a fixed ratio between screen dimensions and Moho units, because:bogush_r wrote:Which ratio between screen dimensions and that units?
- you can zoom the workspace (mouse scroll wheel, shift-right-drag)
- you can resize the main Moho window
- you can change your screen resolution
- you can view the same file on different computers and/or monitors
Not an answer but a comment:bogush_r wrote:If screen center is the "zero point", how can be found cooordinates of the screen edges?
This won't necessarily relate to the size and position of objects (or layers), because:
- you can move the camera backwards and forwards
- you can zoom the camera
- you can pan/tilt and track the camera
- you can scale, translate, and rotate a layer
- you can change the depth of a layer
Note: you can also change the camera dimensions in the project settings, which will change where an object is placed in regard to the edge of the camera view (if, for example, you change from NTSC to NTSC 16:9 with an existing object). Changing a layer origin will also change an object's (Moho units) position without changing its position on the screen.
Note: the screen edges (in Moho units) might be different for different layers if the layers are not all at the same depth and the layer origins are not all in the same place.
Having said all that, there are some scripting functions that are related to screen units. Have a look at the scripting documentation for:
- the Point2Vec() function of the MOHO.MohoView class
- the LM.Point class
- the LM.Rect class
Regards, Myles.
"Quote me as saying I was mis-quoted."
-- Groucho Marx
-- Groucho Marx
I don't remember it exactly, as I've been busy with some other stuff. However, the basic Vector2 measurement, in an unscaled or otherwise messed with layer, relates to the vertical (Y) dimesion of the project size. If you place a point at 0, 0, you are dead center. 0,1 puts you right on the top edge of the project. This holds with whatever ridiculous project dimensions you might feel like whipping up, and will stay consistent, based on the Y size of the project no matter how much you change it.
To find where the X sides of the project are, you need to either pull out the project size e.g.
(I'm pretty sure that's the syntax) or you can use the AspectRatio() function to get a ratio directly, I'm not sure off the top of my head but I believe the Y is the 1 in a, say 1:1.66 ratio, and the function would return the 1.66 part for the X.
The numbers seem to hold for the X/Y parts of the Vector3 class as well.
If you need to find when a point is at the edge of the screen, I guess you could put together a matrix with all the various layer and camera transforms, compare it to a rest state matrix, and figure out where you are. Or something like that. That can add up to a bunch of 3D muck that I still have some trouble wrapping my head around, but it's far from impossible. I just can't picture it right now, too tired.
Also, Myles, in a quick 2 second test, changing the Layer Origin doesn't do anything directly to the position, either on screen or by the numbers. I used to have some wierd things happen on-screen when I had changed origins, but that seems to have been cured.
To find where the X sides of the project are, you need to either pull out the project size e.g.
Code: Select all
local w = moho.document:Width()
local h = moho.document:Height()
The numbers seem to hold for the X/Y parts of the Vector3 class as well.
If you need to find when a point is at the edge of the screen, I guess you could put together a matrix with all the various layer and camera transforms, compare it to a rest state matrix, and figure out where you are. Or something like that. That can add up to a bunch of 3D muck that I still have some trouble wrapping my head around, but it's far from impossible. I just can't picture it right now, too tired.
Also, Myles, in a quick 2 second test, changing the Layer Origin doesn't do anything directly to the position, either on screen or by the numbers. I used to have some wierd things happen on-screen when I had changed origins, but that seems to have been cured.
Ah, much more useful information! Thanks Brian!
I must have been doing something particularly silly yesterday, like reading the origin position instead of the point position, because I had another look at moving the layer origin today and you're absolutely right.
Regards, Myles.
I must have been doing something particularly silly yesterday, like reading the origin position instead of the point position, because I had another look at moving the layer origin today and you're absolutely right.
Regards, Myles.
"Quote me as saying I was mis-quoted."
-- Groucho Marx
-- Groucho Marx
- Lost Marble
- Site Admin
- Posts: 2355
- Joined: Tue Aug 03, 2004 6:02 pm
- Location: Scotts Valley, California, USA
- Contact:
Similarly, the point 1,0 puts you at the center of the right-side edge of the project if the project is square-shaped. If the project is non-square (as most are), then one unit in X is still the same as one unit in Y, it's just that where you end up depends on the aspect ratio of the project.7feet wrote:I don't remember it exactly, as I've been busy with some other stuff. However, the basic Vector2 measurement, in an unscaled or otherwise messed with layer, relates to the vertical (Y) dimesion of the project size. If you place a point at 0, 0, you are dead center. 0,1 puts you right on the top edge of the project. This holds with whatever ridiculous project dimensions you might feel like whipping up, and will stay consistent, based on the Y size of the project no matter how much you change it.
Also, I should mention that all this only applies to the default camera and layer positioning. If you move a layer around in 3D, or point the camera in a different position, that will change where an X,Y point maps to in screen space.
Moho data format
I'm working on a program that needs to know the location of the corners of a layer in image space coordinates after Moho applies all of its transformations.
After a lot of experimenting, I assume that Moho treats everything in 3D and uses 4x4 tranformation matrices to apply layers to their final shape and position. What is the composition order of the tranformation matrices? Moho supports rotation about axes (Rl), translation (T), scale (S), and shear (Sh) applied to a layer, and translation (Tc) and rotation (Rc) to the camera:
(I assume the rotation composition order is R = RxRyRz)
Mcamera = Rc Tc
Mlayer = Sh S Rl Tl
therefore
Mfinal = Mcamera Mlayer = Rc Tc Sh S Rl Tl
My thought is that I can construct the component matrices: Rc, Tc, Sh, S, Rl, and Tl using the keyframe parameters. Then if I know the order they are applied I can multiply them into a composite transformation matrix. Finally given any point in the layer's original space I can compute its location in final image space (or vice versa after inverting the matrix). That's a lot of work so I'm hoping someone has a simple answer before I take a plunge.
Maybe there's a LUA command for this already but I couldn't find it.
Thanks for the insight!
After a lot of experimenting, I assume that Moho treats everything in 3D and uses 4x4 tranformation matrices to apply layers to their final shape and position. What is the composition order of the tranformation matrices? Moho supports rotation about axes (Rl), translation (T), scale (S), and shear (Sh) applied to a layer, and translation (Tc) and rotation (Rc) to the camera:
(I assume the rotation composition order is R = RxRyRz)
Mcamera = Rc Tc
Mlayer = Sh S Rl Tl
therefore
Mfinal = Mcamera Mlayer = Rc Tc Sh S Rl Tl
My thought is that I can construct the component matrices: Rc, Tc, Sh, S, Rl, and Tl using the keyframe parameters. Then if I know the order they are applied I can multiply them into a composite transformation matrix. Finally given any point in the layer's original space I can compute its location in final image space (or vice versa after inverting the matrix). That's a lot of work so I'm hoping someone has a simple answer before I take a plunge.
Maybe there's a LUA command for this already but I couldn't find it.
Thanks for the insight!
It's
look in the MOHO>Classes>MohoLayer section of the Scripting Reference. This returns a complete (and you're right, it's 4x4) transformation matrix for the layer, including the effects of all it's parent layers. You also have GetLayerTransform() for just that layer, or GetParentTransform for just the parent layers transform. The latter I am not sure if it is only the specific transformation of the parent layer, or the parent layers full transform, I haven't used that one.
Not sure about the order for the camera. You might dig around in the Track Camera script, maybe give you a clue in the interim.
Code: Select all
GetFullTransform(<frame number - moho.frame>, <matrix to put the transform>, <the Moho document - e.g. moho.document>)
Not sure about the order for the camera. You might dig around in the Track Camera script, maybe give you a clue in the interim.
Thanks for the pointer!
Thanks -
That helps a lot. It takes a while to learn an entire API and sometimes its tricky to find just the right function - you saved me a bundle of time.
That helps a lot. It takes a while to learn an entire API and sometimes its tricky to find just the right function - you saved me a bundle of time.
How to get the final camera matrix transform?
GetFullTransform works very nicely. However it does not include the camera. GetOutsideViewMatrix only returns the orbit transform. If the camera is in the default render state as with a ResetView then it only returns an identity matrix. Is there an easy way to get the camera matrix as it will be rendered at each frame? I've done tons of searching and it appears not.
I've been painstakingly trying to reconstruct the camera transform from the animation parameters. After many days of trial and error I still haven't got it right. The hardest part is the zoom which I'm trying to map to Perspective. I know the matrix order is critical and the second issue is how to get the perspective projection correct? (A related question is how to print the matrix to the LUA console?)
The answer I'm hoping for is what function will return the camera transformation given a frame number OR how do I construct that matrix given the camera inputs: fCameraTrack, fCameraRoll, fCameraPanTilt, and fCameraZoom?
Here's my current attempt.
LM did a fantastic job making so much available through the scripting interface. Maybe what I need is there too!
Thanks!
I've been painstakingly trying to reconstruct the camera transform from the animation parameters. After many days of trial and error I still haven't got it right. The hardest part is the zoom which I'm trying to map to Perspective. I know the matrix order is critical and the second issue is how to get the perspective projection correct? (A related question is how to print the matrix to the LUA console?)
The answer I'm hoping for is what function will return the camera transformation given a frame number OR how do I construct that matrix given the camera inputs: fCameraTrack, fCameraRoll, fCameraPanTilt, and fCameraZoom?
Here's my current attempt.
Code: Select all
local startFrame = 1
local endFrame = 1 -- moho.document:EndFrame()
local layerMatrix = LM.Matrix:new_local()
local cameraMatrix = LM.Matrix:new_local()
local point = LM.Vector2:new_local()
local currentPanTilt = LM.Vector2:new_local()
local near = 0.1 -- What near and far planes does Moho use?
local far = 100.0
aspect = 600 / 400 -- Assume a 600x400 image just for easy testing
for currentFrame = startFrame, endFrame do
print("Getting tranformation for frame " .. currentFrame)
-- Get the interpolated values for the current frame
currentPosition = moho.document.fCameraTrack:GetValue(currentFrame)
currentRoll = moho.document.fCameraRoll:GetValue(currentFrame)
currentPanTilt:Set(moho.document.fCameraPanTilt:GetValue(currentFrame))
-- Moho appears to scale a zoom of 1.0 to a FOV of 60 deg
currentZoom = math.rad(60 / moho.document.fCameraZoom:GetValue(currentFrame))
-- Construct the camera transformation matrix
cameraMatrix:Identity()
cameraMatrix:Perspective(currentZoom, near, far, aspect)
cameraMatrix:Translate(currentPosition.x, currentPosition.y, currentPosition.z)
cameraMatrix:Rotate(LM.X_AXIS, currentPanTilt.x)
cameraMatrix:Rotate(LM.Y_AXIS, currentPanTilt.y)
--cameraMatrix:Rotate(LM.Z_AXIS, currentRoll)
cameraMatrix:Invert();
-- Get the transformation matrix for the layer
moho.layer:GetFullTransform(currentFrame, layerMatrix, moho.document)
-- Compose the camera and layer matrices
cameraMatrix:Multiply(layerMatrix)
-- Try transforming various test points (I change this as needed)
point:Set(0, 0)
cameraMatrix:Transform(point)
print(point.x .. " " .. point.y)
end
Thanks!
Hmmm...
I worked out the matrix composition order. Now I can reconstruct the camera transform. Then I started adding in the layer transformation again and realized that GetFullTransform may actually be the final matrix. I think I was expecting something else. It's a little unintuitive at first that the coordinates are wrt a proportion of the document height.
LM, can you confirm that GetFullTransform returns the result of the entire matrix stack, including layer transforms, bones, and camera?
As an aside, the camera roll seems to be applied differently than the other parameters. To construct the camera matrix all of the parameters need to be negated except the roll.
thanks again
I worked out the matrix composition order. Now I can reconstruct the camera transform. Then I started adding in the layer transformation again and realized that GetFullTransform may actually be the final matrix. I think I was expecting something else. It's a little unintuitive at first that the coordinates are wrt a proportion of the document height.
LM, can you confirm that GetFullTransform returns the result of the entire matrix stack, including layer transforms, bones, and camera?
As an aside, the camera roll seems to be applied differently than the other parameters. To construct the camera matrix all of the parameters need to be negated except the roll.
thanks again
- Lost Marble
- Site Admin
- Posts: 2355
- Joined: Tue Aug 03, 2004 6:02 pm
- Location: Scotts Valley, California, USA
- Contact:
Yes, GetFullTransform does include the camera - it is the full and complete transformation matrix for that layer.
A little twist to the above: if you include the document object as the last argument to GetFullTransform, then the camera effect is included since the camera is really part of the document, not the layer. If you leave out the document object (passing in nil instead), then the camera is excluded from the matrix you get back.
A little twist to the above: if you include the document object as the last argument to GetFullTransform, then the camera effect is included since the camera is really part of the document, not the layer. If you leave out the document object (passing in nil instead), then the camera is excluded from the matrix you get back.