AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Entity rotation around an arbitrary axis (https://forums.alliedmods.net/showthread.php?t=335078)

Natsheh 11-06-2021 16:42

Entity rotation around an arbitrary axis
 
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

DJEarthQuake 11-06-2021 21:03

Re: Entity rotation around an arbitrary axis
 
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.

Natsheh 11-07-2021 05:46

Re: Entity rotation around an arbitrary axis
 
Quote:

Originally Posted by DJEarthQuake (Post 2762696)
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 )

JocAnis 11-07-2021 12:29

Re: Entity rotation around an arbitrary axis
 
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

AnimalMonster 11-07-2021 13:49

Re: Entity rotation around an arbitrary axis
 
What didn't work well? in which direction do you rotate when you press these buttons right now?

DJEarthQuake 11-07-2021 23:17

Re: Entity rotation around an arbitrary axis
 
Quote:

Originally Posted by JocAnis (Post 2762761)
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 (Post 2762721)
Actually its called roll ( around the x angle )

If one of the 3 does not do what you thought. There 2 axes left.

https://5ece384f-a-62cb3a1a-s-sites....attredirects=0
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);
https://docs.px4.io/v1.11/images/bas...ts_forward.png

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?

Natsheh 11-09-2021 11:00

Re: Entity rotation around an arbitrary axis
 
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

Natsheh 11-09-2021 15:27

Re: Entity rotation around an arbitrary axis
 
Quote:

Originally Posted by JocAnis (Post 2762761)
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

Natsheh 11-09-2021 15:29

Re: Entity rotation around an arbitrary axis
 
Quote:

Originally Posted by AnimalMonster (Post 2762767)
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

HamletEagle 11-10-2021 04:08

Re: Entity rotation around an arbitrary axis
 
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.


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

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