Jump to content

[QUESTION] How work getElementMatrix() ?


Salchy

Recommended Posts

Hello writers, good morning. I would like to know more about getElementMatrix, how does it work? What does it mean the data is what is returned to me? According to what I read on the wiki, it returns 4 'tables', with coordinates, but what does each of them mean? Might be interesting for more of an explanation on how matrices work in this game.

We can take as an example, a vehicle.

local vehicle = createVehicle(411, 1892, -2418, 13.5)
setElementFrozen(vehicle, true)

for k, v in pairs(getElementMatrix(vehicle)) do
	outputChatBox("index "..k.." = "..v[1]..", "..v[2]..", "..v[3]..", "..v[4])
end

--[[
Return:

index 1 = 1, -1.7484555314695e-07, 1.7484555314695e-07, 1
index 2 = 1.7484558156866e-07, 1, -1.7484555314695e-07, 1
index 3 = -1.7484552472524e-07, 1.7484558156866e-07, 1, 1
index 4 = 1892, -2418, 13.5, 1
]]

index 4 by deduction gives me the proper position of the vehicle, and what are the rest of the values?

For more information, what I'm trying to do, is to always get the underbody of a vehicle. They told me that I could get it with this function, but without saying anything else. I'm doing math with getElementBoundingBox and getGroundPosition, but I can't get much of it right now, since my coords are getting out of phase when the vehicle is rotating. Perhaps with an explanation of what those values are, I can get closer to the result I'm looking for.

Sorry for the bad grammar, I'm using google translate.

Link to comment
  • Moderators
1 hour ago, Salchy said:

but what does each of them mean?

A matrix is a mixture of a position and orientation(rotation). With as main purpose able to calculating offset. For example you want to place a ramp in front of a vehicle, a matix helps you with that.

But you do NOT need to know how a matrix works, don't waste your time XD.

 

I prefer to use the Matrix class(without oop), instead of getElementMatrix:

local x, y, z = getElementPosition(vehicle)
local xr, yr, zr = getElementRotation(vehicle)

local vehicleMatix = Matrix (Vector3(x, y, z), Vector3(xr, yr, zr)) -- build your matrix with position and rotation

local offset = Vector3(0, 0, 0) -- fill in!

local newPosition = matrix:transformPosition(offset)

iprint(newPosition.x, newPosition.y, newPosition.z)

 

See docs:

https://wiki.multitheftauto.com/wiki/Matrix

 

Utility function:

function getMatrixFromElement (element)
	return Matrix (Vector3(getElementPosition(element)), Vector3(getElementRotation(element)))
end

 

 

 

 

 

 

 

Link to comment

Thanks a lot for your answers guys. Yes, the idea was to understand how it works and what those values are, to know what can be done with it.

I see this opens up a world of immense possibilities, makes it much easier to do offset calculations.

Thank you very much DiSaMe, I appreciate your time and your explanation, very clear.

You can close the topic.

Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...