Jump to content

dxDrawLine3D with rotation


Overkillz

Recommended Posts

Hello dear community, Im haivng an issue which is giving me some troubles. Im trying to project a line 3D between 2 points, the vehicle which is on the air and the ground.

Here is an example how it is drawn and how it is supposed to be drawn (WHITE line is how it is drawn and RED Line is how it should be drawn )

Spoiler

mta-screen_2019-11-01_18-22-08.png

Sadly, I can't figure out how to use the proper maths here.

local x,y,z = getElementPosition(theVehicle)
local rx,ry,rz = getElementRotation(theVehicle)
local ground = getGroundPosition(x,y,z)
dxDrawLine3D(x,y,z,x+rx,y+ry,ground)

 

I hope you can bring me a hand with this problem

Thanks in advance, regards.

Link to comment
  • Discord Moderators

What are you trying to do with this? If you're looking to create a line that is always perpendicular to the vehicle then you can use getElementMatrix

local x1, y1, z1 = getElementPosition(theVehicle)
local m = getElementMatrix(theVehicle)
local x2 = -100 * m[3][1] + m[4][1]
local y2 = -100 * m[3][2] + m[4][2]
local z2 = -100 * m[3][3] + m[4][3]
dxDrawLine3D(x1, y1, z1, x2, y2, z2)

-100 is the length of the projected line, you can use processLineOfSight to find whatever it collides with.

Link to comment

@Zango

Thanks for your help. Yes, I had been looking for creating a line which was orthogonal to the vehicle.

However, Im so curious. I already see that with the Matrix you can get the rotation, offset ...etc of an element.

However, there are somo arrays that I cant figure out how to deal with them.

For what is used each array ? If you can clear me this question. 

Thanks for reading, regards.

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