Malkalypse
06-21-2007, 10:32 PM
Okay, I know this has been done before, but I need to get it set up in a way that I can understand so that I am able to use it in my current project.
What I need to get working is a script that will force an object to face directly toward the viewport. I have gotten most of the way there; right now the object does in fact face the viewport, but sometimes will spin sideways or upside-down.
In order to try and make sense of why this might be happening, I have set up a text object that displays the transform information of the viewport. I am still a bit sketchy on reading matrix values, so maybe someone else here can help me.
The relevant code in its current state is as follows:
text size:100 isSelected: on
marker = $
if ((isValidNode $viewportTarget) == false)
then
(
point isSelected:on
viewportTarget = $
$.name = "viewportTarget"
)
marker.rotation.controller = LookAt_Constraint ()
marker.rotation.controller.appendTarget $viewportTarget 50
marker.rotation.controller.target_axis = 2
marker.rotation.controller.upnode_axis = 2
fn viewportSet =
(
viewTM = inverse( getViewTM() )
if gw.IsPerspView()
then $viewportTarget.transform = viewTM
viewTM_1 = viewTM.row1 as string
viewTM_2 = viewTM.row2 as string
viewTM_3 = viewTM.row3 as string
viewTM_4 = viewTM.row4 as string
viewTM_T = viewTM.translation as string
marker.text = "row1: " + viewTM_1 + "\r" \
+ "row2: " + viewTM_2 + "\r" \
+ "row3: " + viewTM_3 + "\r" \
+ "row4: " + viewTM_4 + "\r" \
+ "\r" \
+ "translation: " + viewTM_T
)
registerRedrawViewsCallback viewportSet
select marker
What I need to get working is a script that will force an object to face directly toward the viewport. I have gotten most of the way there; right now the object does in fact face the viewport, but sometimes will spin sideways or upside-down.
In order to try and make sense of why this might be happening, I have set up a text object that displays the transform information of the viewport. I am still a bit sketchy on reading matrix values, so maybe someone else here can help me.
The relevant code in its current state is as follows:
text size:100 isSelected: on
marker = $
if ((isValidNode $viewportTarget) == false)
then
(
point isSelected:on
viewportTarget = $
$.name = "viewportTarget"
)
marker.rotation.controller = LookAt_Constraint ()
marker.rotation.controller.appendTarget $viewportTarget 50
marker.rotation.controller.target_axis = 2
marker.rotation.controller.upnode_axis = 2
fn viewportSet =
(
viewTM = inverse( getViewTM() )
if gw.IsPerspView()
then $viewportTarget.transform = viewTM
viewTM_1 = viewTM.row1 as string
viewTM_2 = viewTM.row2 as string
viewTM_3 = viewTM.row3 as string
viewTM_4 = viewTM.row4 as string
viewTM_T = viewTM.translation as string
marker.text = "row1: " + viewTM_1 + "\r" \
+ "row2: " + viewTM_2 + "\r" \
+ "row3: " + viewTM_3 + "\r" \
+ "row4: " + viewTM_4 + "\r" \
+ "\r" \
+ "translation: " + viewTM_T
)
registerRedrawViewsCallback viewportSet
select marker
