PDA

View Full Version : moving in coordsys local in script controller


fferro2
08-01-2007, 09:54 PM
Hi,
I would like to move an object some units in X,Y directions, all inside a script controller.
The object has a list controller applied to its Transform/Position track.
The first one in the list is a Position XYZ which let me move the object manually.
The second is a script controller and here is the problem:
How can I translate this to a proper local movement: [move Xi units, move Yi units, 0] as a result of the script?
Xi and Yi are variables declared inside the controller.
I'm working with MAX 8.
Thank you

magicm
08-01-2007, 11:05 PM
The only way I can think of is this:

A = the object with the position script controller

1. create a point helper/dummy (B) and align it to the pivot of A

2. assign an orientation constraint to A's rotation controller
and assign B as its target

3. edit the position script controller of A :

- add another variable (for example "TM") and use Assign Track
to bind it to the Transform track of B

- change the script expression to "[ Xi, Yi, 0 ] * TM"
Hope this helps,
Martijn

PEN
08-02-2007, 11:33 AM
How about just linking the object to an object that is orientated in the way that you want to move the object. If you can do this it will solve many issues.

Duncs
08-02-2007, 11:33 AM
Hi guys,

In Maxscript you can use the term 'in coordsys' to specify in which coordinate system to apply transformations. Examples:

in coordsys local $.pos += [10,0,0] -- moves selected object 10 units along its local X axis

in coordsys parent $.pos += [10,0,0] -- along selected object's parent's local X axis

hope this helps

Duncs

fferro2
08-02-2007, 02:45 PM
Thanks PEN and Duncs,

The object cannot be linked (I need it this way).
It's a camera.target and I need to move it in a plane normal to the camera.
I'm thinking about "in coordsys of camera ..."

fferro2
08-02-2007, 03:06 PM
That's what works in a script:

in coordsys camera ( move obj [Xdistance,Ydistance,0])

Now, I want to do it inside a script controller assigned to obj.transform.position

eek
08-02-2007, 03:23 PM
ok so if you want to move it in the transform space of the camera, i.e relative to the camera you can create a tempory space for it to exist in.

($target.transform * inverse $tempObj.transform)

TempObj being a point at the position of the camera, you need to use a point as your get cyclic looping issues unless you make a weak reference to the camera or store it as a variable in an instanced struct. This will give you a matrix transformation looking something like this eg.

Matrix3([1,0,0] [0,1,0] [0,0,1] [12.2, 15.103,302.0])

No in the script controller, if you want this to work on just the position of the target. You give its bezier position controller a script_controller(), with 1 variable called 'camera' assigned as a node to the camera. ( you can call it anything you like):

Tm = Matrix3([1,0,0] [0,1,0] [0,0,1] [12.2, 15.103,302.0])

(Tm * camera.transform).pos

or

[(Tm * camera.transform).pos.x, (Tm * camera.transform).pos.y, 0]

or you could pass a script controller on just the axis' you need.



Local coordynates are the transform space an object is relative to a target - if it has no parent/controller etc then it has either no local space or its local/world space are identical.

mustan9
08-02-2007, 03:29 PM
Thanks eek, I was just going to post something like that. But your post was much better.

:thumbsup:

eek
08-02-2007, 03:47 PM
Thanks eek, I was just going to post something like that. But your post was much better.

:thumbsup:

Cheers thanks, just giving pointer on what transforms are. Really everything is just relativity to something else if you understand this rigging and most 3d based math gets easier. A quick note

in coordysis local/world/target is basically the same as (obj.transform * inverse target.transform). Coordynate system is the transform space your obj is existing and working in. With max you have local, world, view, screen gimbal and pick. Most objects have an internal *root* local space and a world space even if they have no parent.

eg. Our coordynate system is the Earth, the Earth's is the Sun, and the Sun's the Milkyway. Now when an asteroid comes from one ecliptical cycle of one planet and falls into another planets ecliptical cycle it basically is changing its transform space through gravity, or an external force. Gravity/magnetic force then holds it in its new transform space. (bit off topic but its a simple understanding)

fferro2
08-02-2007, 05:24 PM
Thanks eek, mustan9,

I thought there was a way to use "in coordsys" to a result inside a script controller.
As you say, the only way is to use the inverse of the matrix of the desired object space.

CGTalk Moderation
08-02-2007, 05:24 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.