Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Code Snippets

Convert object direction (rotation) to yaw and pitch

Paste down any little snippets or request a new one.

Convert object direction (rotation) to yaw and pitch

Postby neilb » 01 May 2011, 02:08

Shiva's got some functions to specify rotations as yaw, pitch and roll, but there's nothing I could find to get an object's rotation as yaw and pitch.

The following will convert the vector returned by object.getDirection() to yaw and pitch.

Code: Select all
    local dx, dy, dz = object.getDirection(application.getCurrentUserActiveCamera, object.kGlobalSpace)
    local yaw = -math.atan2(dx, -dz)
    local pitch = math.atan2(dy, math.sqrt((dx * dx) + (dz * dz)))
neilb
Platinum Boarder
Platinum Boarder
 
Posts: 463
Location: Adelaide, South Australia

Re: Convert object direction (rotation) to yaw and pitch

Postby kalango » 01 May 2011, 16:13

Nice snippet!
User avatar
kalango
Gold Boarder
Gold Boarder
 
Posts: 196
Location: Nova Scotia - Canada


Return to Code Snippets