SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 02/10/2017, 07:22 PM   #11
Pottus
Godfather
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 5,424
Reputation: 1238
Default Re: i_quat - Quaternions and spatial geometry

I was taking a look at this and it seems you have a lot of rotation problems solved. I always had trouble with this function.

Code:
CA_RayCastLineAngle(Float:StartX, Float:StartY, Float:StartZ, Float:EndX, Float:EndY, Float:EndZ, &Float:x, &Float:y, &Float:z, &Float:rx, &Float:ry, &Float:rz)
It does work to a certain extent but I could never figure out how to improve the returned rotations so you can rotate the object correctly.

This is used in Texture Studio by the mangle module which rotates objects to the rotation of the a surface.

The main issue is located here.

Code:
int ColAndreasWorld::performRayTestAngle(const btVector3& Start, const btVector3& End, btVector3& Result, btScalar& RX, btScalar& RY, btScalar& RZ, uint16_t& model)
{
	btCollisionWorld::ClosestRayResultCallback RayCallback(Start, End);

	dynamicsWorld->rayTest(Start, End, RayCallback);

	if (RayCallback.hasHit())
	{
		btVector3 Rotation = RayCallback.m_hitNormalWorld;
		RX = -(asin(Rotation.getY())*RADIAN_TO_DEG);
		RY = asin(Rotation.getX())*RADIAN_TO_DEG;
		// I think there is a way to calculate this not sure how yet
		RZ = 0.0;
		Result = RayCallback.m_hitPointWorld;
		model = RayCallback.m_collisionObject->getUserIndex();
		return 1;
	}
	return 0;
}
Maybe you have input that could offer some direction that could be taken to improve this function. If update an objects position/rotation while aiming with a weapon and use this function you will see the issue it has.
Pottus is offline   Reply With Quote
Old 02/10/2017, 07:29 PM   #12
Kar
High-roller
 
Kar's Avatar
 
Join Date: May 2010
Location: Black Asylum
Posts: 3,211
Reputation: 498
Default Re: i_quat - Quaternions and spatial geometry

Thanks for this.

I can finally edit my vehicle objects without the vehicle facing 0.0.
Kar is offline   Reply With Quote
Old 02/10/2017, 10:50 PM   #13
IllidanS4
Banned
 
Join Date: Feb 2013
Posts: 270
Reputation: 85
Default Re: i_quat - Quaternions and spatial geometry

Quote:
Originally Posted by Pottus View Post
Maybe you have input that could offer some direction that could be taken to improve this function. If update an objects position/rotation while aiming with a weapon and use this function you will see the issue it has.
I am not sure what you mean, do you want to align an object with the surface normal of the hit? I don't use ColAndreas, but if that is the case, returning the normal directly would be more practical than Euler angles. If you want to convert that to "some" rotation (there is an infinite number of them that could represent the normal), you can either create that using the product of elementary quaternions (in the correct order), or maybe try this function from my Cinematic Mode:
Code:
stock SetObjectFrontVector(objectid, Float:vx, Float:vy, Float:vz)
{
    new Float:r = VectorSize(vx, vy, vz);
    new Float:rx = acos(vz/r)+90.0;
    new Float:rz = -atan2(vx, vy)+180.0;
    SetObjectRot(objectid, rx, 0.0, rz);
}
But it wasn't tested much, to be honest.
IllidanS4 is offline   Reply With Quote
Old 08/06/2018, 03:01 PM   #14
Sasino97
High-roller
 
Sasino97's Avatar
 
Join Date: Dec 2010
Location: Italy
Posts: 1,438
Reputation: 102
Thumbs up Re: i_quat - Quaternions and spatial geometry

This must be great to create flight instruments for aircrafts.
__________________
  • SA-MP Game Modes and Filter Scripts (PAWN, MySQL) (8 years experience)
  • Windows Applications (WPF, UWP)
  • Android Applications (Java Android SDK, Xamarin)
  • Web Design and Development (Wordpress, WooCommerce, PHP, MySQL)
  • Game Development (Unity3D, GameMaker Studio, LibGDX)
[email protected]
Use this e-mail - don't PM
Sasino97 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
Automatic House Replacement (One last issue to resolve - QUATERNIONS!) [HLF]Southclaw Discussion 25 12/08/2012 02:32 PM


All times are GMT. The time now is 01:11 AM.


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