CGTalk > Software Specific Forums > Autodesk 3ds max > 3dsMax SDK and MaxScript
To minimize the ads you see on this page create a CGTalk account and log in HERE
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 01-07-2009, 04:00 AM   #1
steev
Frequenter
 
steev's Avatar
animator
 
Join Date: Oct 2002
Posts: 105
Send a message via Yahoo to steev
matrix transformation & the align tool...

i'm having an issue emulating the behavior of the align tool in script. here's the problem (i've attached a 2009 max file to illustrate)...

i have two objects ($Rotator_01 & $Rotator_02) rotated at arbitrary angles. i have another object ($Pointer) parented to $Rotator1 and aligned with it. i want to realign this child object to the rotation of $Rotator_02. this part is simple (& probably could be simpler than how i have it below)...

Code:
aTm = $Pointer.transform aTm.row1 = $Rotator_02.transform.row1 aTm.row2 = $Rotator_02.transform.row2 aTm.row3 = $Rotator_02.transform.row3 $Pointer.transform = atm


the next step is the sticky part ...
i want to then be able to script the same result as using the align tool to align $Pointer 's orientation to $Rotator_01 on the Z axis only (z checkbox checked). while this doesn't really look like it's being rotated on the z-axis, it does produce the result i need. using the tool is perfect, but for the life of me, i can't figure out how i would do this in script. i'm hoping there's some matrix manipulation voodoo that can do it.
Attached Files
File Type: zip MatrixAlignmentProblem.zip (15.7 KB, 13 views)
__________________
w w w . b e a u t i f u l r o b o t . c o m

Last edited by steev : 01-07-2009 at 01:36 PM.
 
Old 01-07-2009, 02:33 PM   #2
PEN
R&D/Technical Director
 
PEN's Avatar
portfolio
Paul Neale
PEN Productions
Canada
 
Join Date: Jun 2002
Posts: 7,415
I didn't test it much so let me know if this works for you.

Code:
origAngles=$sphere01.transform.rotation as eulerAngles targetAngles=$box01.transform.rotation as eulerAngles in coordsys (transMatrix $sphere01.transform.pos) $sphere01.rotation=eulerAngles origAngles.x origAngles.y targetAngles.z
__________________
Paul Neale
http://paulneale.com
 
Old 01-07-2009, 05:22 PM   #3
steev
Frequenter
 
steev's Avatar
animator
 
Join Date: Oct 2002
Posts: 105
Send a message via Yahoo to steev
thanks paul, but unfortunately that doesn't get the result i'm looking for. i've attached an updated max file to illustrate the desired final alignment. it appears to me that after $Pointer is aligned to $Rotator_02's orientation, i want to $Pointer to adopt $Rotator_01's Y rotation but in relation to $Rotator_02's local coordsys - does that make sense?

i hope the max file can illustrate it better than i can describe it.

thanks!

steev
Attached Files
File Type: zip matrixAlignmentProblem.zip (24.5 KB, 9 views)
__________________
w w w . b e a u t i f u l r o b o t . c o m
 
Old 01-07-2009, 11:53 PM   #4
Gravey
3D Dude
Joel Hewitt
Sydney, Australia
 
Join Date: Dec 2005
Posts: 879
based off the max file in your second post I dont really know what you're trying to do, but based off your first post where you're trying to emulate the align tool in a single axis I have a solution:
Code:
( fn getVectorsAngle v1 v2 = ( acos (dot (normalize v1) (normalize v2)) ) fn getNormalVector v1 v2 = ( normalize (cross v1 v2) ) fn rotateMatrix tm q = ( x = tm.row1 * q y = tm.row2 * q z = tm.row3 * q matrix3 x y z tm.pos ) a = $Pointer b = $Rotator_02 za = a.transform.row3 zb = b.transform.row3 ang = getVectorsAngle za zb norm = getNormalVector za zb q = quat -ang norm -- not sure why the angle has to be negative, but it works... a.transform = rotateMatrix a.transform q )
By looking at the result of the align tool, I determined that for a single axis alignment the entire matrix is being rotated, rather than 'aligned'. The rotation axis is found by the normal to the plane defined by the 2 Z axis vectors (cross product). The rotation angle is found by simply finding the angle between the 2 z axis vectors.

Now I spent a fair while trying to figure out a way to rotate the matrix by using the inbuilt functions like preRotate etc but I couldn't find a solution that worked so I ended up just creating my own function that rotates each axis 'by hand' by multiplying them individually by the quaternion. I used THIS POST in the Geometric calculations thread, for reference.

I have attached an updated max file with some comments (as text objects) and other objects in there for visual aid. Run the above code and it should align as the align tool does. Hopefully its what you're after


EDIT: Ok it seems i was wrong. I tried it on the x and y axis and it didnt work. I double checked the result of the z axis and it was close but not exactly what the align tool does.
Sorry...
Attached Files
File Type: zip matrixAlignmentProblem_solved.zip (69.3 KB, 10 views)

Last edited by Gravey : 01-08-2009 at 01:00 AM.
 
Old 01-09-2009, 04:13 AM   #5
steev
Frequenter
 
steev's Avatar
animator
 
Join Date: Oct 2002
Posts: 105
Send a message via Yahoo to steev
thanks a bunch gravey - looking at the file you posted you definitely put some thought & time into the response & i really appreciate it.

but, unfortunately it still doesn't get the expected result (adopting $Rotator_02's orientation & then re-aligning to Rotator_01's local z orientation only - la using the align tool by hand). i did ham up the expectation in my second post, so the best description i still the first one.

i need to move on, but i would still love to see if this challenge could be solved. i'll hammer away at it in my spare (?) time, but if anyone has an epiphany please post it!

thx again.
__________________
w w w . b e a u t i f u l r o b o t . c o m
 
Old 01-10-2009, 03:13 PM   #6
MatanH
Character TD
 
MatanH's Avatar
portfolio
Matan Halberstadt
Head of Rigging dpt.
snowball studios
Tel-Aviv, Israel
 
Join Date: Oct 2002
Posts: 378
What about using a simple lookat controller instead of a script controller

1. create a point helper and align it and parent it to $Rotator_01.
2. move it on it's local Z axis above $Rotator_01.
3. make $Pointer's rotation controller a lookat constraint.
4. use it's Z axis to look at the point helper.
5. using axis align make $Rotator_02 the upnode and use the same axis to align them.

Hope this helps you..
 
Old 01-10-2009, 03:13 PM   #7
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 12:36 PM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.