Sign in to follow this  
Followers 0
mouseboyx

Help calculating euler angles from halo up and front vectors

m_object=get_object_memory(vehicle_object_id)
obj_front_x = read_float(m_object + 0x74) 
obj_front_y = read_float(m_object + 0x78) 
obj_front_z = read_float(m_object + 0x7C) 
obj_up_x = read_float(m_object + 0x80)
obj_up_y = read_float(m_object + 0x84) 
obj_up_z = read_float(m_object + 0x88)

The offsets above give two 3D vectors, a front vector which is essentially pointing down the vehicles nose or front, and an up vector which always points towards the vehicles roof.

Video for helping visualize the vectors (up vector in red, front vector in blue):

 

It seems like one of the euler angles can be calculated using math.atan2() (correct me if I'm wrong), but I'm unsure about the other two:

euler_z=math.atan2(obj_front_Y,obj_front_x) --this seems to be correct
--euler_x=?
--euler_y=?

I'm looking for the complete math that would be used to calculate these angles, I've searched for this problem here and the answers are helpful, like how the vectors have been mislabeled in an offsets list, and how to calculate these vectors from the starting point of euler angles, but not this specific question.  From what I'm reading a rotation matrix would help in solving this problem, but I'm uneducated on that topic.

 

A hacky workaround that I've done out of ignorance is to calculate the euler angles on vehicle spawn, (since mostly but not always a vehicle spawns with only one dimensional rotation) then each game tick add the pitch,yaw,roll velocity values to those euler angles, because the velocity values are in radians.  --Unsure if this will always work but I'd rather have a math based solution rather than relying on something like this.

 

Edit:

@Sunstriker7 Helped me find a solution to the underlying problem as well as a possibility finding the other two angles, and the condition of gimbal lock.  I should have mentioned that the end result of wanting to know euler angles was to apply them to a library called three.js.  However three.js has a lookAt() method that can be supplied with an up vector and a vector to look at.  That method essentially solves the problem without having to know the angles, or work around gimbal locking.

Edited by mouseboyx
Kavawuvi and Sunstriker7 like this

Share this post


Link to post
Share on other sites

Tiddy-bits:

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
Sign in to follow this  
Followers 0
  • Recently Browsing   0 members

    No registered users viewing this page.