Raised This Month: $ Target: $400
 0% 

Entity rotation around an arbitrary axis


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 11-10-2021 , 04:08   Re: Entity rotation around an arbitrary axis
Reply With Quote #10

Here you have to rotation matrices for x, y and z axis, where theta is the rotation angle: https://wikimedia.org/api/rest_v1/me...12353c970aa2df

Then you can rotate the angle vector by multiplying the rotation matrix with it. For example, assuming your vector is [x, y, z](row vector) and you want to multiply by Rx you get: [x * 1 + y * 0 + z * 0, x * 0 + y * cos + z * sin, x * 0 + y * (-sin) + z * cos] = [x, y * cos + z * sin, y * (-sin) + z * cos] which is the formula to compute the rotated vector along x axis. Then convert that back to an angle and set it to your entity. In other words, your rotated vector is:
PHP Code:
//get entity angles and convert them to a vector(original in the pseudocode below)
rotated[0] = original[0]
rotated[1] = original[1] * cos(theta) + original[2] * sin(theta)
rotated[2] = original[1] * (-1) * sin(theta) + original[2] * cos(theta)

//convert rotated back to angle and set it to entity 
Similarly, by computing the matrix multiplication by hand, you can deduce the formula for rotation along y and z axis. It's easier to compute by hand the multiplication and then just build the vector using the resulted formula than actually creating the matrices and implementing matrix multiplication logic.
__________________

Last edited by HamletEagle; 11-10-2021 at 04:12.
HamletEagle is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:32.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode