GetWorldFromScreenPosition: Difference between revisions
No edit summary |
(fixed typo in description (thaft -> that)) |
||
(8 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Client function}} | {{Client function}} | ||
This function allows you to retrieve the world position corresponding to | This function allows you to retrieve the world position corresponding to a 2D position on the screen, at a certain depth. | ||
If you want to detect what element is at a particular point on the screen, use [[processLineOfSight]] between the camera position and the position returned from this function when passed a high depth value (100 or so, depending how far away you want to detect elements at). | |||
As expected, setting 0 as the distance will cause the point retrived to be within the camera itself. That means that drawing any 3D thing in that point would result in it not being visible. Depending on the camera near clip distance, however, the minimum distance to be able to view it can vary. | |||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
float float float getWorldFromScreenPosition ( float x, float y ) | float, float, float getWorldFromScreenPosition ( float x, float y, float depth ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''x:''' A float value | *'''x:''' A float value indicating the x position on the screen, in pixels. | ||
*'''y:''' A float value | *'''y:''' A float value indicating the y position on the screen, in pixels. | ||
*'''depth:''' A float value indicating the distance from the camera of the point whose coordinates we are retrieving, in units. | |||
===Returns=== | ===Returns=== | ||
Returns three | Returns three ''x'', ''y'', ''z'' [[float]]s indicating the world position if successful, ''false'' otherwise. | ||
==Example== | ==Example== | ||
This example binds the local player's "'''i'''" key to a function that creates an explosion in the middle of the screen. | This example binds the local player's "'''i'''" key to a function that creates an explosion in the middle of the screen. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function explosion ( | function explosion () | ||
local x, y, z = getWorldFromScreenPosition ( | local w, h = guiGetScreenSize () | ||
local x, y, z = getWorldFromScreenPosition ( w/2, h/2, 10 ) | |||
createExplosion ( x, y, z, 11 ) | createExplosion ( x, y, z, 11 ) | ||
end | end | ||
bindKey ( "i", "down | bindKey ( "i", "down", explosion ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{Client_world_functions}} | {{Client_world_functions}} |
Latest revision as of 11:16, 7 July 2018
This function allows you to retrieve the world position corresponding to a 2D position on the screen, at a certain depth.
If you want to detect what element is at a particular point on the screen, use processLineOfSight between the camera position and the position returned from this function when passed a high depth value (100 or so, depending how far away you want to detect elements at).
As expected, setting 0 as the distance will cause the point retrived to be within the camera itself. That means that drawing any 3D thing in that point would result in it not being visible. Depending on the camera near clip distance, however, the minimum distance to be able to view it can vary.
Syntax
float, float, float getWorldFromScreenPosition ( float x, float y, float depth )
Required Arguments
- x: A float value indicating the x position on the screen, in pixels.
- y: A float value indicating the y position on the screen, in pixels.
- depth: A float value indicating the distance from the camera of the point whose coordinates we are retrieving, in units.
Returns
Returns three x, y, z floats indicating the world position if successful, false otherwise.
Example
This example binds the local player's "i" key to a function that creates an explosion in the middle of the screen.
function explosion () local w, h = guiGetScreenSize () local x, y, z = getWorldFromScreenPosition ( w/2, h/2, 10 ) createExplosion ( x, y, z, 11 ) end bindKey ( "i", "down", explosion )
See Also
- createSWATRope
- getBirdsEnabled
- getCoronaReflectionsEnabled
- getGarageBoundingBox
- getGaragePosition
- getGarageSize
- getGroundPosition
- getInteriorFurnitureEnabled
- getNearClipDistance
- getPedsLODDistance
- getRoofPosition
- getScreenFromWorldPosition
- getVehiclesLODDistance
- getWorldFromScreenPosition
- isAmbientSoundEnabled
- isLineOfSightClear
- isWorldSoundEnabled
- processLineOfSight
- resetAmbientSounds
- resetBlurLevel
- resetColorFilter
- resetCoronaReflectionsEnabled
- resetNearClipDistance
- resetPedsLODDistance
- resetVehiclesLODDistance
- resetWorldSounds
- setAmbientSoundEnabled
- setBirdsEnabled
- setColorFilter
- setCoronaReflectionsEnabled
- setInteriorFurnitureEnabled
- setInteriorSoundsEnabled
- setNearClipDistance
- setPedsLODDistance
- setVehiclesLODDistance
- setWorldSoundEnabled
- testLineAgainstWater
- areTrafficLightsLocked
- getAircraftMaxHeight
- getAircraftMaxVelocity
- getCloudsEnabled
- getFarClipDistance
- getFogDistance
- getGameSpeed
- getGravity
- getHeatHaze
- getInteriorSoundsEnabled
- getJetpackMaxHeight
- getMinuteDuration
- getMoonSize
- getOcclusionsEnabled
- getRainLevel
- getSunColor
- getSunSize
- getTime
- getTrafficLightState
- getWeather
- getWindVelocity
- getSkyGradient
- getPlayerBlurLevel
- getZoneName
- isGarageOpen
- removeWorldModel
- resetFarClipDistance
- resetFogDistance
- resetHeatHaze
- resetMoonSize
- resetRainLevel
- resetSkyGradient
- resetSunColor
- resetSunSize
- resetWindVelocity
- restoreAllWorldModels
- restoreWorldModel
- setAircraftMaxHeight
- setAircraftMaxVelocity
- setCloudsEnabled
- setFarClipDistance
- setFogDistance
- setGameSpeed
- setGarageOpen
- setGravity
- setHeatHaze
- setInteriorSoundsEnabled
- setMinuteDuration
- setMoonSize
- setOcclusionsEnabled
- setRainLevel
- setSkyGradient
- setSunColor
- setSunSize
- setTime
- setTrafficLightState
- setTrafficLightsLocked
- setWeather
- setWeatherBlended
- setWindVelocity
- setJetpackMaxHeight
- setPlayerBlurLevel