Jump to content

getElementBoundingBox acording to rotation

Recommended Posts

  • MTA Team

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


Link to comment
  • MTA Team


--[[ Draw a fancy bounding box:
    |\   /|
    | \ / |
    |  x  |
    | / \ |
    |/   \|
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")

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
Link to comment

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...