Author Topic: Maxscript - Corona sun and targeted lights - get the yaw and pitch  (Read 3747 times)

2019-09-07, 12:50:19

3dwannab

  • Active Users
  • **
  • Posts: 362
    • View Profile
Hi anyone out there that can help with a mathematical / maxscript question.
I need to translate Corona sun and target lights pos and rotations to get me the yaw and pitch.

How can I do this? "It times like these - Dave Grohl" I wish I paid more attention in Maths class!!

Is this even close?
Code: [Select]
(
 /*  x,y,z,roll,pitch,yaw */
 sun = selection[1]
 roll = sun.rotInParent[1]
 pitch = sun.rotInParent[2]
 yaw = sun.rotInParent[3]
 )


There's multiple different ways people are viewing this. This is just one page I found:
https://www.quora.com/How-do-you-represent-Roll-Pitch-Yaw-in-terms-of-X-Y-Z-axes-in-space


Cheers!
« Last Edit: 2019-09-07, 15:32:03 by 3dwannab »

2019-09-12, 23:03:42
Reply #1

makco

  • Active Users
  • **
  • Posts: 24
    • View Profile
I would use a sun without a target (as suns position is irrelevant in corona), and just worry about the 3 axis rotation.
Try the below:
Code: [Select]
sun =Coronasun()
sun.name = "scriptedSun2"
sun.position = [0,0,300]
sun.targeted =false
fn easyRotation obj x y z =
(
try(obj.rotation.x_rotation = 90-x)catch() -- Invert the height as 90 should be up and 0 should be down for the sun
try(obj.rotation.y_rotation = y)catch()
try(obj.rotation.z_rotation = z)catch()
)

easyRotation Sun 0 0 0

2019-09-12, 23:08:12
Reply #2

3dwannab

  • Active Users
  • **
  • Posts: 362
    • View Profile
That's not what I was after. I managed to sort it out.

Code: [Select]
/*
convertDirectionToYawPitchAsPoint2Value function

Translates any items point3 direction and returns it as
yaw and pitch in degrees as a point2 value.

Usage: convertDirectionToYawPitchAsPoint2Value <selection>[1]
Returns: [<expr>, <expr>]
*/

fn convertDirectionToYawPitchAsPoint2Value theItem =
(
  direction = theItem.dir
  yaw = atan2(direction.x) (direction.y)
  pitch = asin(-direction.z)
  return [yaw, pitch]
  )
-- print ((convertDirectionToYawPitchAsPoint2Value $)[1] as string + " yaw")
-- print ((convertDirectionToYawPitchAsPoint2Value $)[2] as string + " pitch")

2019-09-12, 23:12:10
Reply #3

makco

  • Active Users
  • **
  • Posts: 24
    • View Profile