Bonsai

getElementBoundingBox with rotation

Recommended Posts

So if I understand right, and you understand my drawing skill of paint xD

Naamloos.png

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

Naamloosb888a.png

Share this post


Link to post

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.

 

Share this post


Link to post

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

Share this post


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

Share this post


Link to post

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

Share this post


Link to post

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.

Share this post


Link to post

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

Is it the detection or getting the points?

Share this post


Link to post
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. :(

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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.