Jump to content

getElementBoundingBox acording to rotation


Recommended Posts

Posted (edited)

Hey there, is there anyway to get an element bounding box with its rotation?

How to do it?

Thanks for reading and hope you can awnser my question.

Edit: Is posible to get it when an element is not streamed?

Edited by XeroxMTA
  • MTA Team
Posted

You need OOP enabled:

function getElementRotatedBoundingBox(element)
    local elementMatrix = element:getMatrix()
    local minX, minY, minZ, maxX, maxY, maxZ = element:getBoundingBox()
    local minVector = elementMatrix:transformPosition(Vector3(minX, minY, minZ))
    local maxVector = elementMatrix:transformPosition(Vector3(maxX, maxY, maxZ))
    return minVector, maxVector
end

 

Posted

You could check the editor resource, it does this too.

But depending on what you are trying to do, this matrix calculations might be too heavy, e.g. when doing it in a render function.

  • MTA Team
Posted (edited)

8FDkeV7.png

--[[ Draw a fancy bounding box:
    c-----d
    |\   /|
    | \ / |
    |  x  |
    | / \ |
    |/   \|
    a-----b
]]
local minX, minY, minZ, maxX, maxY, maxZ = vehicle:getBoundingBox()

local a = vehicleMatrix:transformPosition(Vector3(minX, minY, maxZ))
drawTextOnWorldPosition("a", a)
local b = vehicleMatrix:transformPosition(Vector3(maxX, minY, maxZ))
drawTextOnWorldPosition("b", b)
local c = vehicleMatrix:transformPosition(Vector3(minX, maxY, maxZ))
drawTextOnWorldPosition("c", c)
local d = vehicleMatrix:transformPosition(Vector3(maxX, maxY, maxZ))
drawTextOnWorldPosition("d", d)

dxDrawLine3D(c, d, 0xFFFF0000, 1.0)
dxDrawLine3D(a, b, 0xFFFF0000, 1.0)
dxDrawLine3D(c, a, 0xFFFF0000, 1.0)
dxDrawLine3D(d, b, 0xFFFF0000, 1.0)
dxDrawLine3D(a, d, 0xFFFF0000, 1.0)
dxDrawLine3D(b, c, 0xFFFF0000, 1.0)
function drawTextOnWorldPosition(text, vecPosition)
    local x, y = getScreenFromWorldPosition(vecPosition)

    if x and y then
        dxDrawText(text, x, y, nil, nil, 0xFFFFFFFF, 2.0, "default-bold", "center", "center")
    end
end

You didn't tell me what you want to do, my previous code segment only solved the question in the first post.

Edited by Necktrox

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...