DxDrawLine3D: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
FileEX (talk | contribs)
m Legacy version
 
(21 intermediate revisions by 14 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Client function}}  
{{Client function}}  
Draws a line between two points in the 3D world.
This function draws a 3D line between two points in the 3D world - rendered for '''one''' frame.  This should be used in conjunction with [[onClientRender]] in order to display continuously.


==Syntax==
{{Legacy|legacy/DxDrawLine3D}}
 
{{Updated feature/item|1.5.9|1.5.9|22465|
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool dxDrawLine3D ( float startX, float startY, float startZ, float endX, float endY, float endZ, int color, int width )
bool dxDrawLine3D ( float startX, float startY, float startZ, float endX, float endY, float endZ [, int color = 0xFFFFFFFF, float width = 1.0, string stage = "postfx" ] )
</syntaxhighlight>
</syntaxhighlight>


===Required Arguments===  
===Required Arguments===  
'''startX:''' The start X position of the 3D line
* '''startX:''' The start X position of the 3D line, representing a coordinate in the GTA world.
'''startY:''' The start Y position of the 3D line
* '''startY:''' The start Y position of the 3D line, representing a coordinate in the GTA world.
'''startZ:''' The start Z position of the 3D line
* '''startZ:''' The start Z position of the 3D line, representing a coordinate in the GTA world.
'''endX:''' The end X position of the 3D line
* '''endX:''' The end X position of the 3D line, representing a coordinate in the GTA world.
'''endY:''' The end Y position of the 3D line
* '''endY:''' The end Y position of the 3D line, representing a coordinate in the GTA world.
'''endZ:''' The end Z position of the 3D line
* '''endZ:''' The end Z position of the 3D line, representing a coordinate in the GTA world.
'''color:''' An integer of the hex color, produced using [[tocolor]].
 
'''width:''' The width/thickness of the line
==Optional Arguments==
{{OptionalArg}}
* '''color:''' An integer of the hex color, produced using [[tocolor]] or 0xAARRGGBB.
* '''width:''' The width/thickness of the line
* '''stage:''' A string representing a stage at which the actual drawcall should happen:
** prefx - Lines are rendered before the color correction. This stage makes lines look natural to SA but colors could be distorted.
** postfx - Lines are rendered after the color correction. This stage conveys a color from the function to a screen without distortions.
** postgui - Lines are rendered after GUI. The line should be drawn on top of or behind any ingame GUI (rendered by CEGUI).


===Returns===
===Returns===
Returns a ''true'' if the operation was successful, ''false'' otherwise.
Returns a ''true'' if the operation was successful, ''false'' otherwise.
}}


==Example==  
==Example==  
This is a small example of creating 3D Line / "Rope" between vehicle and player.
This is a small example of creating 3D Line / "Rope" between vehicle and player.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
testVehicle = createVehicle ( 411, 0, 0, 5 ) -- Create our test vehicle.
function makeLineAppear()
 
testVehicle = createVehicle ( 411, 0, 0, 5 ) -- Create our test vehicle.
addEventHandler("onClientRender", root, createLine)        -- onClientRender keeps the 3D Line visible.
end
function createLine ( )
function createLine ( )
x1, y1, z1 = getElementPosition ( testVehicle )                      -- Get test vehicles position.
x1, y1, z1 = getElementPosition ( testVehicle )                      -- Get test vehicles position.
x2, y2, z2 = getElementPosition ( getLocalPlayer ())                  -- Get local players position.
x2, y2, z2 = getElementPosition ( localPlayer )                  -- Get local players position.
dxDrawLine3D ( x1, y1, z1, x2, y2, z2, tocolor ( 0, 255, 0, 230 ), 2) -- Create 3D Line between test vehicle and local player.
dxDrawLine3D ( x1, y1, z1, x2, y2, z2, tocolor ( 0, 255, 0, 230 ), 2) -- Create 3D Line between test vehicle and local player.
addEventHandler("onClientRender",getRootElement(), createLine)                -- onClientRender keeps the 3D Line visible.
end
end
addCommandHandler("test", createLine)
addCommandHandler("line", makeLineAppear)
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Drawing_functions}}
{{Drawing_functions}}
[[hu:dxDrawLine3D]]

Latest revision as of 12:51, 27 May 2024

This function draws a 3D line between two points in the 3D world - rendered for one frame. This should be used in conjunction with onClientRender in order to display continuously.


This page describes the current implementation. For older versions check legacy version



Syntax

bool dxDrawLine3D ( float startX, float startY, float startZ, float endX, float endY, float endZ [, int color = 0xFFFFFFFF, float width = 1.0, string stage = "postfx" ] )

Required Arguments

  • startX: The start X position of the 3D line, representing a coordinate in the GTA world.
  • startY: The start Y position of the 3D line, representing a coordinate in the GTA world.
  • startZ: The start Z position of the 3D line, representing a coordinate in the GTA world.
  • endX: The end X position of the 3D line, representing a coordinate in the GTA world.
  • endY: The end Y position of the 3D line, representing a coordinate in the GTA world.
  • endZ: The end Z position of the 3D line, representing a coordinate in the GTA world.

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • color: An integer of the hex color, produced using tocolor or 0xAARRGGBB.
  • width: The width/thickness of the line
  • stage: A string representing a stage at which the actual drawcall should happen:
    • prefx - Lines are rendered before the color correction. This stage makes lines look natural to SA but colors could be distorted.
    • postfx - Lines are rendered after the color correction. This stage conveys a color from the function to a screen without distortions.
    • postgui - Lines are rendered after GUI. The line should be drawn on top of or behind any ingame GUI (rendered by CEGUI).

Returns

Returns a true if the operation was successful, false otherwise.

Example

This is a small example of creating 3D Line / "Rope" between vehicle and player.

function makeLineAppear()
	testVehicle = createVehicle ( 411, 0, 0, 5 ) -- Create our test vehicle.
	addEventHandler("onClientRender", root, createLine)        -- onClientRender keeps the 3D Line visible.
end
function createLine ( )
	x1, y1, z1 = getElementPosition ( testVehicle )                       -- Get test vehicles position.
	x2, y2, z2 = getElementPosition ( localPlayer )                  -- Get local players position.
	dxDrawLine3D ( x1, y1, z1, x2, y2, z2, tocolor ( 0, 255, 0, 230 ), 2) -- Create 3D Line between test vehicle and local player.
end
addCommandHandler("line", makeLineAppear)

See Also