Jump to content

getElementBoundingBox with rotation


Bonsai

Recommended Posts

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.

 

Link to comment
  • 2 weeks later...

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

Link to comment
51 minutes ago, pa3ck said:

Maybe this can help you a bit:

 

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

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

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.

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