SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 14/08/2016, 01:19 AM   #1
Nero_3D
High-roller
 
Nero_3D's Avatar
 
Join Date: Jun 2007
Location: Germany
Posts: 3,757
Reputation: 643
Default Rotations.inc

Rotations

Well, nothing new I guess, this include gives you the possibility to convert rotations, all kind of

Functions
PHP Code:
// AroundRelPoint
RotMatrixMatrixAroundRelPoint(Floatmatrix1[4][4], FloatoXFloatoYFloatoZFloatmatrix2[4][4])
RotMatrixQuatAroundRelPoint(Floatmatrix[4][4], FloatoXFloatoYFloatoZFloatwFloatxFloatyFloatz)
RotMatrixEulerAroundRelPoint(Floatmatrix[4][4], FloatoXFloatoYFloatoZFloatrXFloatrYFloatrZeulermodemode euler_samp)
RotMatrixAxisAroundRelPoint(Floatmatrix1[4][4], FloatoXFloatoYFloatoZFloatangleFloataXFloataYFloataZ)
// AroundPoint
RotMatrixMatrixAroundPoint(Floatmatrix1[4][4], FloatxFloatyFloatzFloatmatrix2[4][4])
RotMatrixQuatAroundPoint(Floatmatrix[4][4], FloatxFloatyFloatzFloatwFloatqXFloatqYFloatqZ)
RotMatrixEulerAroundPoint(Floatmatrix[4][4], FloatxFloatyFloatzFloatrXFloatrYFloatrZeulermodemode euler_samp)
RotMatrixAxisAroundPoint(Floatmatrix1[4][4], FloatxFloatyFloatzFloatangleFloataXFloataYFloataZ)
// TranslateMatrix
TranslateMatrix(Floatmatrix[4][4], FloatxFloatyFloatz)
// RotateMatrix
RotateMatrixWithMatrix(Floatmatrix1[4][4], Floatmatrix2[4][4])
RotateMatrixWithQuat(Floatmatrix[4][4], FloatwFloatxFloatyFloatz)
RotateMatrixWithEuler(Floatmatrix[4][4], FloatrXFloatrYFloatrZeulermodemode euler_samp)
RotateMatrixWithAxisAngle(Floatmatrix[4][4], FloatangleFloataXFloataYFloataZ)
// GetTranslationMatrix
GetTranslationMatrix(Floatmatrix[4][4], FloatxFloatyFloatz)
// GetRotationMatrix
GetRotationMatrixFromQuat(Floatmatrix[4][4], FloatwFloatxFloatyFloatz)
GetRotationMatrixFromEuler(Floatmatrix[4][4], FloatrXFloatrYFloatrZeulermodemode euler_samp)
GetRotationMatrixFromAxisAngle(Floatmatrix[4][4], FloatangleFloataXFloataYFloataZ)
// GetQuat
GetQuatFromMatrix(Floatmatrix[][], & Floatw, & Floatx, & Floaty, & Floatz)
GetQuatFromEuler(FloatrXFloatrYFloatrZ, & Floatw, & Floatx, & Floaty, & Floatzeulermodemode euler_samp)
GetQuatFromAxisAngle(FloatangleFloataXFloataYFloataZ, & Floatw, & Floatx, & Floaty, & Floatz)
// GetEuler
GetEulerFromMatrix(Floatmatrix[][], & FloatrX, & FloatrY, & FloatrZeulermodemode euler_samp)
GetEulerFromQuat(FloatwFloatxFloatyFloatz, & FloatrX, & FloatrY, & FloatrZeulermodemode euler_samp)
GetEulerFromEuler(FloatoXFloatoYFloatoZeulermodeomode, & FloatrX, & FloatrY, & FloatrZeulermodemode euler_samp)
GetEulerFromAxisAngle(FloatangleFloataXFloataYFloataZ, & FloatrX, & FloatrY, & FloatrZeulermodemode euler_samp)
// GetAxisAngle
GetAxisAngleFromMatrix(Floatmatrix[][], & Floatangle, & FloataX, & FloataY, & FloataZ)
GetAxisAngleFromQuat(FloatwFloatxFloatyFloatz, & Floatangle, & FloataX, & FloataY, & FloataZ)
GetAxisAngleFromEuler(FloatrXFloatrYFloatrZ, & Floatangle, & FloataX, & FloataY, & FloataZeulermodemode euler_samp)
// Rotate function to get a relative position
// oX, oY, oZ = offsets, oT = Translation (usually only 0.0 or 1.0)
// X, Y, Z = preset these with the center of rotation
MatrixRotate(Floatmatrix[4][4], FloatoXFloatoYFloatoZFloatoT, & FloatX, & FloatY, & FloatZ)
QuatRotate(FloatwFloatxFloatyFloatzFloatoXFloatoYFloatoZ, & FloatX, & FloatY, & FloatZ)
EulerRotate(FloatrXFloatrYFloatrZFloatoXFloatoYFloatoZ, & FloatX, & FloatY, & FloatZeulermodemode euler_samp)
AxisAngleRotate(FloatangleFloataXFloataYFloataZFloatoXFloatoYFloatoZ, & FloatX, & FloatY, & FloatZ)
// Functions for attaching / detaching objects from vehicle
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
Download

GitHub

Examples

Object in front of vehicle
PHP Code:
// object is somewhere globally defined
new
    
FloatwFloatxFloatyFloatz,
    
FloatrXFloatrYFloatrZ,
    
FloatXFloatYFloatZ;

GetVehicleRotationQuat(vehicleidwxyz);
GetVehiclePos(vehicleidXYZ);
// x offset = 0.0, y offset (in front) = 25.0, z offset = 0.0
// Note!, preload X, Y, Z with the center of the rotation!
QuatRotate(wxyz0.025.00.0XYZ);
SetObjectPos(objectXYZ);
// Gets the correct euler angles from the quat
GetEulerFromQuat(wxyzrXrYrZ);
SetObjectRot(objectrXrYrZ); 
Rotation about point of object
PHP Code:
new
    
FloatrX,
    
FloatrY,
    
FloatrZ,
    
FloatoX,
    
FloatoY,
    
FloatoZ,
    
Floatmatrix[4][4]
;
GetObjectPos(objectoXoYoZ);
GetObjectRot(objectrXrYrZ);
// Get rotation Matrix from Euler
GetRotationMatrixFromEuler(matrixrXrYrZ);
// Rotate matrix around relative point of object
// 0.0, 0.0, 1.0 = relative point = 1.0 above object center
// 5.0, 0.0, 0.0 = euler rotation = 5.0 degress in rX direction
RotMatrixEulerAroundRelPoint(matrix0.00.01.05.00.00.0);
// Getting relative point, 0.0, 0.0, 0.0, 1.0 = offsets x, y, z and translation
// because we only need the translation we set, x, y, z offsets to 0.0
MatrixRotate(matrix0.00.00.01.0oXoYoZ);
// set new object pos
SetObjectPos(objectoXoYoZ);
// get euler from matrix
GetEulerFromMatrix(matrixrXrYrZ);
// set new object rot
SetObjectRot(objectrXrYrZ); 
If someone needs a special example I will try to provide it (if possible) and link it to this post

Disclaimer

If something doesn't work, ask, no man is perfect, so is no code
__________________

Last edited by Nero_3D; 19/08/2017 at 05:55 PM.
Nero_3D is offline   Reply With Quote
Old 14/08/2016, 11:11 AM   #2
PT
Godfather
 
PT's Avatar
 
Join Date: Nov 2012
Location: Portugal
Posts: 7,186
Reputation: 775
Default Re: Rotations.inc

You and the maths.. My god xd

Good work
__________________
"Quem caiu e se levantou honrado era e honrado ficou..."


CVU vai voltar e.e


http://steamcommunity.com/id/pt_player/
PT is offline   Reply With Quote
Old 15/08/2016, 01:37 AM   #3
Sanady
High-roller
 
Sanady's Avatar
 
Join Date: May 2012
Location: Los Santos
Posts: 1,467
Reputation: 132
Default Re: Rotations.inc

My god, nice maths. You can really help me with exams joking but really nice maths.
__________________

Sanady is offline   Reply With Quote
Old 01/01/2017, 09:45 PM   #4
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,921
Reputation: 1460
Default Re: Rotations.inc

Hey Nero, super useful looking library here and I'm glad I found it! I've recently decided to refactor a particular module in my project which will rely on setting a pivot point for certain objects (i.e. rotating a panel about the bottom edge instead of the predefined pivot point of the model, which is usually not where I want it!).

This library looks like what I need but I'm no maths person (barely scraped calculus last year!) so I'd love a bit of documentation or more examples for this library! I know most people are interested in vehicle quat rotations so there's plenty on that but none of it really applies to what I want so I'd appreciate some help. Thanks!
__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is offline   Reply With Quote
Old 06/01/2017, 11:59 PM   #5
Nero_3D
High-roller
 
Nero_3D's Avatar
 
Join Date: Jun 2007
Location: Germany
Posts: 3,757
Reputation: 643
Default Re: Rotations.inc

Translation and Rotation function for RotationMatrix added

New functions
PHP Code:
// AroundRelPoint
RotMatrixMatrixAroundRelPoint(Floatmatrix1[4][4], FloatoXFloatoYFloatoZFloatmatrix2[4][4])
RotMatrixQuatAroundRelPoint(Floatmatrix[4][4], FloatoXFloatoYFloatoZFloatwFloatxFloatyFloatz)
RotMatrixEulerAroundRelPoint(Floatmatrix[4][4], FloatoXFloatoYFloatoZFloatrXFloatrYFloatrZeulermodemode euler_samp)
RotMatrixAxisAroundRelPoint(Floatmatrix1[4][4], FloatoXFloatoYFloatoZFloatangleFloataXFloataYFloataZ)
// AroundPoint
RotMatrixMatrixAroundPoint(Floatmatrix1[4][4], FloatxFloatyFloatzFloatmatrix2[4][4])
RotMatrixQuatAroundPoint(Floatmatrix[4][4], FloatxFloatyFloatzFloatwFloatqXFloatqYFloatqZ)
RotMatrixEulerAroundPoint(Floatmatrix[4][4], FloatxFloatyFloatzFloatrXFloatrYFloatrZeulermodemode euler_samp)
RotMatrixAxisAroundPoint(Floatmatrix1[4][4], FloatxFloatyFloatzFloatangleFloataXFloataYFloataZ)
// TranslateMatrix
TranslateMatrix(Floatmatrix[4][4], FloatxFloatyFloatz)
// RotateMatrix
RotateMatrixWithMatrix(Floatmatrix1[4][4], Floatmatrix2[4][4])
RotateMatrixWithQuat(Floatmatrix[4][4], FloatwFloatxFloatyFloatz)
RotateMatrixWithEuler(Floatmatrix[4][4], FloatrXFloatrYFloatrZeulermodemode euler_samp)
RotateMatrixWithAxisAngle(Floatmatrix[4][4], FloatangleFloataXFloataYFloataZ)
// GetTranslationMatrix
GetTranslationMatrix(Floatmatrix[4][4], FloatxFloatyFloatz
__________________
Nero_3D is offline   Reply With Quote
Old 06/02/2017, 06:25 PM   #6
Crayder
High-roller
 
Crayder's Avatar
 
Join Date: Sep 2013
Location: Flames of Hell
Posts: 3,864
Reputation: 589
Default Re: Rotations.inc

Hmm... Wasn't there a lot more comments on this thread? I know I had a discussion about this include here and said how badass it was...
__________________
Those who deserve reputation, do not need to beg for it.
Also, don't expect the help you need when offering reputation, you'll just be attracting Rep Hunters.
Join SA-MP Discord!
Crayder is offline   Reply With Quote
Old 10/02/2017, 01:37 PM   #7
Nero_3D
High-roller
 
Nero_3D's Avatar
 
Join Date: Jun 2007
Location: Germany
Posts: 3,757
Reputation: 643
Default Re: Rotations.inc

Quote:
Originally Posted by Crayder View Post
Hmm... Wasn't there a lot more comments on this thread? I know I had a discussion about this include here and said how badass it was...
Never was but thanks anyways, maybe another thread, 3DTryg from AbyssMorgan ?

I still get this feeling that this include isn't very user friendly but I am not sure how to accomplish a more compact structure within pawn
__________________
Nero_3D is offline   Reply With Quote
Old 10/02/2017, 05:09 PM   #8
Crayder
High-roller
 
Crayder's Avatar
 
Join Date: Sep 2013
Location: Flames of Hell
Posts: 3,864
Reputation: 589
Default Re: Rotations.inc

Quote:
Originally Posted by Nero_3D View Post
Never was but thanks anyways, maybe another thread, 3DTryg from AbyssMorgan ?
YES! Lol...

Quote:
Originally Posted by Nero_3D View Post
I still get this feeling that this include isn't very user friendly but I am not sure how to accomplish a more compact structure within pawn
I think it is user friendly, but it's just not something the majority of the people here are going to use. It's extremely useful for those who know what it is though. I've already used it quite a bit.
__________________
Those who deserve reputation, do not need to beg for it.
Also, don't expect the help you need when offering reputation, you'll just be attracting Rep Hunters.
Join SA-MP Discord!
Crayder is offline   Reply With Quote
Old 10/02/2017, 05:13 PM   #9
AbyssMorgan
Banned
 
Join Date: Apr 2015
Location: Poland
Posts: 1,260
Reputation: 326
Default Re: Rotations.inc

3DTryg.inc partly uses rotations.inc (Internal) I suspect that this include useful for more advanced developers.
Typically create a function that is easy to use by anyone (Not including programmers from my country XD).
AbyssMorgan is offline   Reply With Quote
Old 16/06/2017, 04:44 PM   #10
ball
Huge Clucker
 
ball's Avatar
 
Join Date: Jul 2012
Location: Poznan, Poland
Posts: 288
Reputation: 33
Default Re: Rotations.inc

I am trying to create graffiti object in front of another graffiti object (graffiti tagged), but I don't know how to get position in front of object relative to object's rotation (rx, ry, rz). My actual code

Code:
new Float:lGraffitiX, Float:lGraffitiY, Float:lGraffitiZ, Float:lGraffitiRX, Float:lGraffitiRY, Float:lGraffitiRZ;
GetDynamicObjectPos(Graffiti[tagid][graffiti_object], lGraffitiX, lGraffitiY, lGraffitiZ);
GetDynamicObjectRot(Graffiti[tagid][graffiti_object], lGraffitiRX, lGraffitiRY, lGraffitiRZ);
Use(lGraffitiX, lGraffitiY, lGraffitiZ, lGraffitiRX, lGraffitiRY, lGraffitiRZ, lGraffitiX, lGraffitiY, lGraffitiZ);
Graffiti[tagid][graffiti_object_made] = CreateDynamicObject(18659, lGraffitiX, lGraffitiY, lGraffitiZ, lGraffitiRX, lGraffitiRY, lGraffitiRZ, .interiorid = 0);

Use(Float:oX, Float:oY, Float:oZ, Float:rX, Float:rY, Float:rZ, &Float:x, &Float:y, &Float:z)
{
	new 
    Float: matrix[4][4] 
; 
// Get rotation Matrix from Euler 
GetRotationMatrixFromEuler(matrix, rX, rY, rZ); 
// Rotate matrix around relative point of object 
// 0.0, 0.0, 1.0 = relative point = 1.0 above object center 
// 5.0, 0.0, 0.0 = euler rotation = 5.0 degress in rX direction 
RotMatrixEulerAroundRelPoint(matrix, 0.0, 0.0, 1.0, 5.0, 0.0, 0.0); 
// Getting relative point, 0.0, 0.0, 0.0, 1.0 = offsets x, y, z and translation 
// because we only need the translation we set, x, y, z offsets to 0.0 
MatrixRotate(matrix, 0.0, 0.0, 0.0, 1.0, oX, oY, oZ); 
x = oX;
y = oY;
z = oZ;
}
It works only with one angle, see image below. Grove tag should cover another tag. On the wall it works, but on the ground it does not. Any ideas?

https://i.imgur.com/3DXKHt7.jpg

//EDIT

Done it, I used wrong function. Working code

Code:
GetQuatFromEuler(rx, ry, rz, qw, qx, qy, qz);
QuatRotate(qw, qx, qy, qz, -0.05, 0.0, 0.0, x, y, z);
//use x, y, z
ball is offline   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 01:18 AM.


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