GetUnProjectedPoint
From MaratisWiki
(Difference between revisions)
Dahnielson (Talk | contribs) |
Dahnielson (Talk | contribs) m |
||
(2 intermediate revisions by one user not shown) | |||
Line 1: | Line 1: | ||
− | Returns the un-projected point of a screen-space point | + | {{lua-function|getUnProjectedPoint|object, vector}} |
+ | |||
+ | Returns the un-projected point of a screen-space point. | ||
+ | |||
+ | {{lua-function-param|object|object to operate on}} | ||
+ | {{lua-function-param|vector|vector}} | ||
point = getUnProjectedPoint(Camera, vec3(x, y, z)) | point = getUnProjectedPoint(Camera, vec3(x, y, z)) | ||
Line 5: | Line 10: | ||
It can be used for example to pick a 3d object using the mouse position : | It can be used for example to pick a 3d object using the mouse position : | ||
− | + | function onSceneUpdate() | |
− | + | ||
− | + | mx = getAxis("MOUSE_X") | |
− | + | my = getAxis("MOUSE_Y") | |
− | + | ||
− | + | V1 = getUnProjectedPoint(Camera, vec3(mx, my, 0)) | |
− | + | V2 = getUnProjectedPoint(Camera, vec3(mx, my, 1)) | |
− | + | ||
− | + | point, object = rayHit(V1, V2) -- note that rayHit only detects objects with physics enabled | |
− | + | ||
− | + | if point then | |
− | + | rotate(object, {0, 0, -1}, 1) -- rotate the selected object | |
− | + | end | |
− | + | ||
− | end | + | end |
[[Category:Lua scripting]] | [[Category:Lua scripting]] | ||
+ | [[Category:Lua function]] | ||
+ | [[Category:Camera]] |
Latest revision as of 00:13, 9 February 2014
getUnProjectedPoint(object, vector)
Returns the un-projected point of a screen-space point.
-
object
: object to operate on -
vector
: vector
point = getUnProjectedPoint(Camera, vec3(x, y, z))
It can be used for example to pick a 3d object using the mouse position :
function onSceneUpdate() mx = getAxis("MOUSE_X") my = getAxis("MOUSE_Y") V1 = getUnProjectedPoint(Camera, vec3(mx, my, 0)) V2 = getUnProjectedPoint(Camera, vec3(mx, my, 1)) point, object = rayHit(V1, V2) -- note that rayHit only detects objects with physics enabled if point then rotate(object, {0, 0, -1}, 1) -- rotate the selected object end end