SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 11/08/2017, 08:03 PM   #11
Nero_3D
High-roller
 
Nero_3D's Avatar
 
Join Date: Jun 2007
Location: Germany
Posts: 2,850
Reputation: 675
Default Re: Rotations.inc

Added GetVehicleObjectPositionOffset / GetVehicleObjectPositionWorld to calculate the position and rotation from a normal object to an attached object / vice versa

PHP Code:
GetVehicleObjectPositionWorld(vehicleidFloatatt_XFloatatt_YFloatatt_ZFloatatt_rotXFloatatt_rotYFloatatt_rotZ, &FloatX, &FloatY, &FloatZ, &FloatrotX, &FloatrotY, &FloatrotZ)
GetVehicleObjectPositionOffset(vehicleidFloatXFloatYFloatZFloatrotXFloatrotYFloatrotZ, &Floatatt_X, &Floatatt_Y, &Floatatt_Z, &Floatatt_rotX, &Floatatt_rotY, &Floatatt_rotZ
Well, I didn't intend to add functions for special cases but putting these in the example section would be copy and paste
Nero_3D is offline   Reply With Quote
Old 03/12/2017, 01:28 PM   #12
Admigo
High-roller
 
Admigo's Avatar
 
Join Date: Oct 2010
Location: The Netherlands
Posts: 1,840
Reputation: 297
Default Re: Rotations.inc

Do you know how you can get the right rotations of world objects? Like if i copy and paste the world objects from sa-mp map editor it sometimes returns the wrong rotations.
__________________
Follow me on Instagram @brandonvanommen
Admigo is offline   Reply With Quote
Old 04/12/2017, 02:29 AM   #13
Nero_3D
High-roller
 
Nero_3D's Avatar
 
Join Date: Jun 2007
Location: Germany
Posts: 2,850
Reputation: 675
Default Re: Rotations.inc

Quote:
Originally Posted by Admigo View Post
Do you know how you can get the right rotations of world objects? Like if i copy and paste the world objects from sa-mp map editor it sometimes returns the wrong rotations.
Somtimes?, than it is a bug in map editor?, first I would ask JernejL if he knows something about that and why it hasn't been fixed
Getting the right result from a false one is nearly impossible if you don't know how the right one from the false one differ
Nero_3D is offline   Reply With Quote
Old 04/12/2017, 06:27 AM   #14
kennydalglish
Big Clucker
 
Join Date: Dec 2014
Posts: 157
Reputation: 8
Default Re: Rotations.inc

How to make an adequate GetXYInFrontOfPlayer using this library?
kennydalglish is offline   Reply With Quote
Old 04/12/2017, 08:04 AM   #15
AbyssMorgan
Banned
 
Join Date: Apr 2015
Location: Poland
Posts: 1,209
Reputation: 352
Default Re: Rotations.inc

Quote:
Originally Posted by kennydalglish View Post
How to make an adequate GetXYInFrontOfPlayer using this library?
Wrong lib this is library for Rotations/Quaretnions/3D Offsets

You need 3DTryg.inc for coordinates / rotations / vectors / arc / areas / offset
PHP Code:
GetPointInFront2D(Float:x,Float:y,Float:rz,Float:radius,&Float:tx,&Float:ty); 
GetPointInFront3D(Float:x,Float:y,Float:z,Float:rx,Float:rz,Float:radius,&Float:tx,&Float:ty,&Float:tz); 

Float:GetPointInFrontOfPlayer(playerid,&Float:tx,&Float:ty,Float:radius);
Float:GetPointInFrontOfCamera2D(playerid,&Float:tx,&Float:ty,Float:radius);

GetPointInFrontOfCamera3D(playerid,&Float:tx,&Float:ty,&Float:tz,Float:radius,&Float:rx=0.0,&Float:rz=0.0); 

Float:GetPointInFrontOfVehicle2D(vehicleid,&Float:tx,&Float:ty,Float:radius); 
GetPointInFrontOfVehicle3D(vehicleid,&Float:tx,&Float:ty,&Float:tz,Float:radius,&Float:rx=0.0,&Float:rz=0.0); 
AbyssMorgan is offline   Reply With Quote
Old 04/12/2017, 11:01 PM   #16
Nero_3D
High-roller
 
Nero_3D's Avatar
 
Join Date: Jun 2007
Location: Germany
Posts: 2,850
Reputation: 675
Default Re: Rotations.inc

Quote:
Originally Posted by kennydalglish View Post
How to make an adequate GetXYInFrontOfPlayer using this library?
AbyssMorgan is correct, it is not the main purpose of this include
But to answer your question you could use any "Rotate" function
Quote:
MatrixRotate(Float: matrix[4][4], Float: oX, Float: oY, Float: oZ, Float: oT, & Float: X, & Float: Y, & Float: Z)
QuatRotate(Float: w, Float: x, Float: y, Float: z, Float: oX, Float: oY, Float: oZ, & Float: X, & Float: Y, & Float: Z)
EulerRotate(Float: rX, Float: rY, Float: rZ, Float: oX, Float: oY, Float: oZ, & Float: X, & Float: Y, & Float: Z, eulermode: mode = euler_samp)
AxisAngleRotate(Float: angle, Float: aX, Float: aY, Float: aZ, Float: oX, Float: oY, Float: oZ, & Float: X, & Float: Y, & Float: Z)
For players I would suggest EulerRotate because there is only GetPlayerFacingAngle
PHP Code:
new FloatXFloatYFloatZ;
GetPlayerPos(playeridXYZ);
new 
FloatrZ// the only angle you can get is rZ
GetPlayerFacingAngle(playeridrZ); // use 0.0 for rX and rY
// oX (right vector offset) = 0.0, oY (front vector offset) = 5.0, oZ (up vector offset) = 0.0
EulerRotate(0.00.0rZ0.05.00.0XYZ);
// X, Y, Z should now be 5 units before the player 
Anyway this inlude is overkill if you only need GetXYInFrontOfPlayer, actually it would be slower because it takes rX and rY in the calculation, so there is no optimisation if only rZ is present
Just search for GetXYInFrontOfPlayer, it has been asked / posted thousand times
Nero_3D is offline   Reply With Quote
Old 05/12/2017, 03:54 PM   #17
kennydalglish
Big Clucker
 
Join Date: Dec 2014
Posts: 157
Reputation: 8
Default Re: Rotations.inc

Xmm, anyway, you can go outside the landfill. For a reason that I do not understand. How can I fix it?

https://www.youtube.com/watch?v=ZakA...ature=youtu.be

Quote:
Originally Posted by Nero_3D View Post
AbyssMorgan is correct, it is not the main purpose of this include
But to answer your question you could use any "Rotate" function

For players I would suggest EulerRotate because there is only GetPlayerFacingAngle
PHP Code:
new FloatXFloatYFloatZ;
GetPlayerPos(playeridXYZ);
new 
FloatrZ// the only angle you can get is rZ
GetPlayerFacingAngle(playeridrZ); // use 0.0 for rX and rY
// oX (right vector offset) = 0.0, oY (front vector offset) = 5.0, oZ (up vector offset) = 0.0
EulerRotate(0.00.0rZ0.05.00.0XYZ);
// X, Y, Z should now be 5 units before the player 
Anyway this inlude is overkill if you only need GetXYInFrontOfPlayer, actually it would be slower because it takes rX and rY in the calculation, so there is no optimisation if only rZ is present
Just search for GetXYInFrontOfPlayer, it has been asked / posted thousand times
kennydalglish is offline   Reply With Quote
Old 06/12/2017, 12:22 AM   #18
Nero_3D
High-roller
 
Nero_3D's Avatar
 
Join Date: Jun 2007
Location: Germany
Posts: 2,850
Reputation: 675
Default Re: Rotations.inc

Quote:
Originally Posted by kennydalglish View Post
Xmm, anyway, you can go outside the landfill. For a reason that I do not understand. How can I fix it?

https://www.youtube.com/watch?v=ZakA...ature=youtu.be
Well, it is a bug in your code, no clue how you use GetXYInFrontOfPlayer to determine if the player is outside or not but the correct solution for your problem would be to check if the player is inside a polygon
Refer to IsPlayerInPolygon, it can be found in 3DTryg, it is based on ray-casting (wiki)
Still remember that RyDeR`posted the function and ****** said, it has been here for years XD
Nero_3D is offline   Reply With Quote
Old 08/12/2017, 09:47 PM   #19
kennydalglish
Big Clucker
 
Join Date: Dec 2014
Posts: 157
Reputation: 8
Default Re: Rotations.inc

Hey. I tried to make the function of tilting through the timer, but it still does not work correctly. Can you help me?
PHP Code:
SetPlayerTimerEx(playerid"@@CheckPlayerInPolygons"250, -1,  "d"playerid); 
PHP Code:
@@CheckPlayerInPolygons(const playerid);
@@
CheckPlayerInPolygons(const playerid)
{
    new 
Floatx_pos,
        
Floaty_pos,
        
Floatz_pos;
    
GetPlayerPos(playeridx_posy_posz_pos);
    if(!
IsPointInPolygon(x_posy_pos,     {                        42.0,2336.0,
        -
1327.0,2601.0,
        -
1349.0,2675.0,
        -
1397.0,2712.0,
        -
1435.0,2728.0,
        -
1501.0,2737.0,
        -
1560.0,2740.0,
        -
1627.0,2734.0,
        -
1653.0,2718.0,
        -
1639.0,2654.0,
        -
1610.0,2604.0,
        -
1604.0,2547.0,
        -
1596.0,2499.0,
        -
1474.0,2486.0,
        -
1406.0,2521.0,
        -
1337.0,2523.0,
        -
1327.0,2601.0}))
    {
        new 
FloatXFloatYFloatZ;
        
GetPlayerPos(playeridXYZ);
        new 
FloatrZ// the only angle you can get is rZ
        
GetPlayerFacingAngle(playeridrZ); // use 0.0 for rX and rY
        // oX (right vector offset) = 0.0, oY (front vector offset) = 5.0, oZ (up vector offset) = 0.0
        
EulerRotate(0.00.0rZ0.0, -5.00.0XYZ);
        
// X, Y, Z should now be 5 units before the player
        
SetPlayerPos(playeridXYZ);      
    }

Anyway, you can go beyond the polygon

Quote:
Originally Posted by Nero_3D View Post
Well, it is a bug in your code, no clue how you use GetXYInFrontOfPlayer to determine if the player is outside or not but the correct solution for your problem would be to check if the player is inside a polygon
Refer to IsPlayerInPolygon, it can be found in 3DTryg, it is based on ray-casting (wiki)
Still remember that RyDeR`posted the function and ****** said, it has been here for years XD
kennydalglish is offline   Reply With Quote
Old 08/03/2018, 03:02 PM   #20
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,775
Reputation: 619
Default Re: Rotations.inc

I have a small problem with GetRotationMatrixFromEuler.

I'm trying to calculate a quaternion based on z angle (direction) and the surface angle (rx and ry) to apply correct rotations to an NPC Vehicle.

What I do is getting the rotation matrix for the facing angle, and if the surface isn't flat I further rotate the matrix with the x and y rotation.

After that I get the Matrix as Quaternion to use with FCNPC_SetQuaternion.

Code:
new Float:matrix[4][4];
GetRotationMatrixFromEuler(matrix, 0.0, 0.0, rz, euler_samp);
RotateMatrixWithEuler(matrix, surface_rx, surface_ry, 0.0, euler_samp);

GetQuatFromMatrix(matrix, qw, qx, qy, qz);
This works perfectly fine, except when the facing angle is 180.0 (or very close to it). If it's 180.0, the z angle of the returned quaternion is 0.0.

I've removed RotateMatrixWithEuler for testing, however it still happened so it's not that part.

I'm pretty sure that it isn't an issue with FCNPC as I was using another method before which worked (the quaternion is almost the same, except the z angle under these circumstances).

I'm not sure if I'm doing something wrong, but the fact that it works for all other scenarios tells me it should be correct.

Do you have an idea what it could be?

EDIT: I'm now converting the Matrix to Euler angles, and the Euler Angles to a Quaternion. This extra step fixed it.

Last edited by NaS; 09/03/2018 at 04:43 PM.
NaS is online now   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Object rotations thefatshizms Scripting Help 4 21/06/2013 11:27 PM
Rotations With Quaternion BlackAtom Scripting Help 1 23/07/2012 03:28 PM
Object Rotations Arrows73 Help Archive 0 18/07/2011 07:22 PM
Rotations Problems Dragonoir Help Archive 2 03/06/2009 07:38 PM


All times are GMT. The time now is 06:51 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.