# getElementBoundingBox acording to rotation

## Recommended Posts

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

#### Share this post

##### Link to post

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

#### Share this post

##### Link to post

Edit: Forget it, got the awnser, thanks for your help! (Was using bad positions)

Edited by XeroxMTA

#### Share this post

##### Link to post

Well im here again!

Thought was fixed but nope, there's some problem when calculating the boundingbox with "rotation" that way...

You can see results here: http://imgur.com/a/nl5zd.

It doesn't gets a good rectangle, only on certain "fixed" rotations as 0,90,180,270,360.

Any idea of what to do then?

#### Share this post

##### Link to post

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.

#### Share this post

##### Link to post

What im exactly searching for on it?

Is there any other way to do something like it for a render function? (i mean without being to heavy).

#### Share this post

##### Link to post

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