Raised This Month: $32 Target: $400
 8% 

Entity rotation around an arbitrary axis


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Natsheh
Veteran Member
Join Date: Sep 2012
Old 11-06-2021 , 16:42   Entity rotation around an arbitrary axis
Reply With Quote #1

I Have a drone i want to rotate the drone depending on the drone forward or right axis for example when holding space(IN_JUMP) or ctrl(IN_DUCK) i want the drone to raise up/down ( rotation around the right axis of the drone ) and when holding a(IN_RIGHT) or d(IN_LEFT) to rotate around the forward access of the drone.

I've tried using the rotation matrix method but sadly failed due not knowing what i am really doing.

what i've tried.


TEST CODE
Spoiler



FULL CODE
Spoiler
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 11-06-2021 at 18:55.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
DJEarthQuake
Veteran Member
Join Date: Jan 2014
Location: Astral planes
Old 11-06-2021 , 21:03   Re: Entity rotation around an arbitrary axis
Reply With Quote #2

Thought we have already been down this avenue once before. It's called YAW. It's not right and left it is positive and negative.
__________________
DJEarthQuake is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 11-07-2021 , 05:46   Re: Entity rotation around an arbitrary axis
Reply With Quote #3

Quote:
Originally Posted by DJEarthQuake View Post
Thought we have already been down this avenue once before. It's called YAW. It's not right and left it is positive and negative.
Actually its called roll ( around the x axis )
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 05-08-2023 at 06:14.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
JocAnis
Veteran Member
Join Date: Jun 2010
Old 11-07-2021 , 12:29   Re: Entity rotation around an arbitrary axis
Reply With Quote #4

yeah can you test with changing other axis? how i remember, these axis are messed up, meaning its not rotating like we think in the real world...im not 100% sure
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
AnimalMonster
Senior Member
Join Date: May 2020
Old 11-07-2021 , 13:49   Re: Entity rotation around an arbitrary axis
Reply With Quote #5

What didn't work well? in which direction do you rotate when you press these buttons right now?
AnimalMonster is offline
DJEarthQuake
Veteran Member
Join Date: Jan 2014
Location: Astral planes
Old 11-07-2021 , 23:17   Re: Entity rotation around an arbitrary axis
Reply With Quote #6

Quote:
Originally Posted by JocAnis View Post
yeah can you test with changing other axis? how i remember, these axis are messed up, meaning its not rotating like we think in the real world...im not 100% sure
The game axis is off from real world. Testing the other axes is reasonable.

Quote:
Originally Posted by Natsheh View Post
Actually its called roll ( around the x angle )
If one of the 3 does not do what you thought. There 2 axes left.


Likely need to do more than 1. Adjust both Yaw and Roll or whatever whenever ever so gradual to make it realistic veering in flight, take off and landing.
Copying from existing vector automates this.
Copy angle from vector.
entity_get_vector(ent,EV_VEC_angles,Axis);


Do you need, the vectors, the angles, or both? In other words. Does it fly as imagined and look off or is it not moving where controlled to go?
__________________
DJEarthQuake is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 11-09-2021 , 11:00   Re: Entity rotation around an arbitrary axis
Reply With Quote #7

Can someone please explain to me step by step how i can roll the drone using a Rotation matrix multiplication and then translate the rotation to the drone origin
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Natsheh
Veteran Member
Join Date: Sep 2012
Old 11-09-2021 , 15:27   Re: Entity rotation around an arbitrary axis
Reply With Quote #8

Quote:
Originally Posted by JocAnis View Post
yeah can you test with changing other axis? how i remember, these axis are messed up, meaning its not rotating like we think in the real world...im not 100% sure
Yeah the rotation works as follows first pitch then yaw and at last roll
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Natsheh
Veteran Member
Join Date: Sep 2012
Old 11-09-2021 , 15:29   Re: Entity rotation around an arbitrary axis
Reply With Quote #9

Quote:
Originally Posted by AnimalMonster View Post
What didn't work well? in which direction do you rotate when you press these buttons right now?
When pressing A or D the drone should rolls left or right, and when pressing space or ctrl the drone should pitch up or down
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
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
Reply



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 09:39.


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