Jump to content

a Vehicle Component as an element


JeViCo

Recommended Posts

  • Moderators

They are not mta elements.

But there are functions that can get the position and rotation of them. I am very sure that you have already found them.

Find them if you haven't!

......... ............. ........... .............. ..........

After that.

The function getElementMatrix can help you with the vehicle orientation.

https://wiki.multitheftauto.com/wiki/GetElementMatrix

 

And on that same page there is something that creates a matrix the same way as the function above. But gives you also the ability to get the matrix without using an actual element.

(Last example)

function getElementMatrix(element)
    local rx, ry, rz = getElementRotation(element, "ZXY")
    rx, ry, rz = math.rad(rx), math.rad(ry), math.rad(rz)
    local matrix = {}
    matrix[1] = {}
    matrix[1][1] = math.cos(rz)*math.cos(ry) - math.sin(rz)*math.sin(rx)*math.sin(ry)
    matrix[1][2] = math.cos(ry)*math.sin(rz) + math.cos(rz)*math.sin(rx)*math.sin(ry)
    matrix[1][3] = -math.cos(rx)*math.sin(ry)
    matrix[1][4] = 1
    
    matrix[2] = {}
    matrix[2][1] = -math.cos(rx)*math.sin(rz)
    matrix[2][2] = math.cos(rz)*math.cos(rx)
    matrix[2][3] = math.sin(rx)
    matrix[2][4] = 1
	
    matrix[3] = {}
    matrix[3][1] = math.cos(rz)*math.sin(ry) + math.cos(ry)*math.sin(rz)*math.sin(rx)
    matrix[3][2] = math.sin(rz)*math.sin(ry) - math.cos(rz)*math.cos(ry)*math.sin(rx)
    matrix[3][3] = math.cos(rx)*math.cos(ry)
    matrix[3][4] = 1
	
    matrix[4] = {}
    matrix[4][1], matrix[4][2], matrix[4][3] = getElementPosition(element)
    matrix[4][4] = 1
	
    return matrix
end

 

With this matrix you can attach stuff with a render event.

 

Of course I understand that it might look a little bit complex. But it is really the only way without doing very complex calculations.

  • Thanks 1
Link to comment
  • Scripting Moderators
5 hours ago, IIYAMA said:

They are not mta elements.

But there are functions that can get the position and rotation of them. I am very sure that you have already found them.

Find them if you haven't!

......... ............. ........... .............. ..........

After that.

The function getElementMatrix can help you with the vehicle orientation.

https://wiki.multitheftauto.com/wiki/GetElementMatrix

 

And on that same page there is something that creates a matrix the same way as the function above. But gives you also the ability to get the matrix without using an actual element.

(Last example)


function getElementMatrix(element)
    local rx, ry, rz = getElementRotation(element, "ZXY")
    rx, ry, rz = math.rad(rx), math.rad(ry), math.rad(rz)
    local matrix = {}
    matrix[1] = {}
    matrix[1][1] = math.cos(rz)*math.cos(ry) - math.sin(rz)*math.sin(rx)*math.sin(ry)
    matrix[1][2] = math.cos(ry)*math.sin(rz) + math.cos(rz)*math.sin(rx)*math.sin(ry)
    matrix[1][3] = -math.cos(rx)*math.sin(ry)
    matrix[1][4] = 1
    
    matrix[2] = {}
    matrix[2][1] = -math.cos(rx)*math.sin(rz)
    matrix[2][2] = math.cos(rz)*math.cos(rx)
    matrix[2][3] = math.sin(rx)
    matrix[2][4] = 1
	
    matrix[3] = {}
    matrix[3][1] = math.cos(rz)*math.sin(ry) + math.cos(ry)*math.sin(rz)*math.sin(rx)
    matrix[3][2] = math.sin(rz)*math.sin(ry) - math.cos(rz)*math.cos(ry)*math.sin(rx)
    matrix[3][3] = math.cos(rx)*math.cos(ry)
    matrix[3][4] = 1
	
    matrix[4] = {}
    matrix[4][1], matrix[4][2], matrix[4][3] = getElementPosition(element)
    matrix[4][4] = 1
	
    return matrix
end

 

With this matrix you can attach stuff with a render event.

 

Of course I understand that it might look a little bit complex. But it is really the only way without doing very complex calculations.

why not use oop?

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

  • Like 1
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...