## Recommended Posts

Hey,

anyone knows how to make the function https://wiki.multitheftauto.com/wiki/GetElementBoundingBox work with a rotated vehicle/object?

If I get the position of a vehicle and add the values returned by this function, they are only at the correct position if the vehicle isn't rotated.

How do I make it take the rotation into account?

Bonsai

So if I understand right, and you understand my drawing skill of paint  The red is what you can get from the function but you also want to get the blue value to get the purple box in total The red is what you get from the function, if the rotation of the vehicle is 0 (or 180).

When you move, the vehicle moves out of the box, since its not a cube.

The map editor has such a feature too, and it stays in the box even when rotating.

I did not fully check the map editor code yet since I thought there might be some easy solution.

What I'd do then is create a col and attach it to the car. Rotate as the car rotates.

Its not about a col shape or anything like that.

I just need the positions of the corners of the bounding box so I can calculate if it hits something.

As far as I can see getting the bounding box of a vehicle doesn't take the rotation into account, so you only get the accurate points with a Z rotation of 0°.

But in the map editor, the bounding box that appears when selecting an element rotates with the element.

So it definitely is possible somehow, but the code of the map editor for that feature seems to be outdated.

So I thought there might be an easier way to do it.

Matrices turned out to be very bad, performance wise.

Bonsai

51 minutes ago, pa3ck said:

Yes, I also found that before I posted but meanwhile I figured something similar out (attaching 4 dummy elements to get positions) just to test if the idea itself works.

Turned out it doesn't. Have to stick to using processLineOfSight which sadly doesn't let you check a bigger width.

Edited by Bonsai

Do you mean something like this? It's done with Matrices.

Spoiler
```
function dbb( )
for _,v in pairs(getElementsByType( "vehicle" )) do
if v then
local m = v.matrix
local e, s = Vector3(getElementBoundingBox( v )),Vector3(unpack({getElementBoundingBox( v )},4,6))
-- Front
local tfl = m:transformPosition(e.x,s.y,s.z)
local tfr = m:transformPosition(s.x,s.y,s.z)
local bfr = m:transformPosition(s.x,s.y,e.z)
local bfl = m:transformPosition(e.x,s.y,e.z)
dxDrawLine3D( tfl, tfr, tocolor( 255, 255, 255, 255 ),5 )
dxDrawLine3D( tfr, bfr,  tocolor( 255, 255, 255, 255 ),5 )
dxDrawLine3D( bfr, bfl, tocolor( 255, 255, 255, 255 ),5 )
dxDrawLine3D( bfl, tfl, tocolor( 255, 255, 255, 255 ),5 )
-- Back
local tbl = m:transformPosition(e.x,e.y,s.z)
local tbr = m:transformPosition(s.x,e.y,s.z)
local bbr = m:transformPosition(s.x,e.y,e.z)
local bbl = m:transformPosition(e.x,e.y,e.z)
dxDrawLine3D( tbl, tbr, tocolor( 255, 255, 255, 255 ),5 )
dxDrawLine3D( tbr, bbr,  tocolor( 255, 255, 255, 255 ),5 )
dxDrawLine3D( bbr, bbl, tocolor( 255, 255, 255, 255 ),5 )
dxDrawLine3D( bbl, tbl, tocolor( 255, 255, 255, 255 ),5 )

-- Between
dxDrawLine3D( tfl, tbl, tocolor( 255, 255, 255, 255 ),5 )
dxDrawLine3D( tfr, tbr,  tocolor( 255, 255, 255, 255 ),5 )
dxDrawLine3D( bfr, bbr, tocolor( 255, 255, 255, 255 ),5 )
dxDrawLine3D( bfl, bbl, tocolor( 255, 255, 255, 255 ),5 )
end
end
end```

Edited by loki2143

Yes, but it wasn't about the box itself, but the positions of the corners.

I tried doing it with matrices and it worked, but its too slow to do it in a render function sadly.

What do you mean by it's too slow in a render function?

Is it the detection or getting the points?

3 minutes ago, loki2143 said:

What do you mean by it's too slow in a render function?

Is it the detection or getting the points?

Its calculating the points. Oh so how are you currently calculating the points?

I'm not calculating them anymore, I changed to using processLineOfSight again, which works but it would be nice to be able to check a bigger range, like a tube, not just a line.

This interested me.

And how calculate this with processLineOfSight?

Instead of having to calculate if the vehicle bounds are inside of a certain area now I use processLineOfSight to make the area check if the vehicle is touching it.

The idea behind using the bounds was to be able to not just check this small line from processLineOfSight, but a bigger width by getting the distance between vehicle bounds and the area.

Think of it like a tube with a certain diameter. With processLineOfSight I can only check the center of it, but the whole width.