HU/getCursorPosition

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Ez a function visszaadja az egér kurzor aktuális pozícióját. Vegye figyelembe, hogy teljesítményi okok miatt a world pozíció mindig 300 egységnyi távolságra van. If you want the exact world point (similar to onClientClick), use processLineOfSight between the camera position and the worldX/Y/Z result of this function. (Lásd az alábbi példát)

Szintaxis

float, float, float, float, float getCursorPosition ( )

Visszatérési érték

Visszaad 5 értéket: cursorX, cursorY, worldX, worldY, worldZ. Az első két érték a kurzor 2D relatív képernyő koordinátái: cursorX 0-ról indul (a képernyő bal oldala) 1-ig (jobb oldal), cursorY 0-ról indul (teteje) 1-ig (alja). A következő 3 érték a 3D world map koordinátái, amelyekre a kurzor mutat. Ha a kurzor nem jelenik meg, akkor első értékként false értéket ad vissza.

Issues

Issue ID Description
#5226 getCursorPosition() 3D Positions Return Inaccurate, But Nearby Positions - Also Negative WorldZ

Példa

Ez a példa kiírja a chatba a kurzorok aktuális world kordinátáit és a képernyő relatív koordinátáit, mután beírtuk a cursorpos parancsot.

function cursorInfo()
   if isCursorShowing() then -- if the cursor is showing
      local screenx, screeny, worldx, worldy, worldz = getCursorPosition()

      outputChatBox( string.format( "Cursor screen position (relative): X=%.4f Y=%.4f", screenx, screeny ) ) -- make the accuracy of floats 4 decimals
      outputChatBox( string.format( "Cursor world position: X=%.4f Y=%.4f Z=%.4f", worldx, worldy, worldz ) ) -- make the accuracy of floats 4 decimals accurate
   else
      outputChatBox( "Your cursor is not showing." )
   end
end
addCommandHandler( "cursorpos", cursorInfo )


Ez a (nem tesztelt) példa a processLineOfSight-t használva kiszámolja a világ pontos helyét: Figyelmeztetés, ez a script nagy CPU használatát eredményez.

addEventHandler( "onClientRender", root,
    function()
        if isCursorShowing() then
            local screenx, screeny, worldx, worldy, worldz = getCursorPosition()
            local px, py, pz = getCameraMatrix()
            local hit, x, y, z, elementHit = processLineOfSight ( px, py, pz, worldx, worldy, worldz )

            if hit then
                dxDrawText( "Cursor at " .. x .. " " .. y .. " " ..  z, 200, 200 )
                if elementHit then
                    dxDrawText( "Hit element " .. getElementType(elementHit), 200, 220 )
                end
            end
        end
    end
)

Lásd még

Fordította