Raised This Month: $12 Target: $400
 3% 

Rotating Aircraft ( drone )


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Natsheh
Veteran Member
Join Date: Sep 2012
Old 05-23-2022 , 12:59   Rotating Aircraft ( drone )
Reply With Quote #1

Currently i've a drone, i am trying to rotate the drone depending on pressing some keys i heard that i can use the rodrigues 3d rotation formula and this is what i tried so far....

Code:
#define SquareRoot(%1) floatsqroot(%1)
#define Sine(%1) floatsin(%1,degrees)
#define Cosine(%1) floatcos(%1,degrees)

RotationAroundAxis( Float:v[3], Float:fAxis[3], Float: fAngle )
{
	new Float:fCross[3], Float:fvReturn[3], Float:d[3], Float:r[3];

	for(new i; i < 3; i++)
	{
		d[i] = xs_vec_dot( fAxis, v ) * fAxis[i];
		r[i] = v[i] - d[i];
	}

	xs_vec_cross(fAxis, r, fCross);

	for(new i; i < 3; i++)
	{
		fvReturn[i] = d[i] + r[i] * Cosine(fAngle) + fCross[i] * Sine(fAngle);
	}

	xs_vec_copy(fvReturn, v);
	return 0;
}



public fw_drone_brain(ent)
{
	static iOwner;
	iOwner = entity_get_int(ent, DRONE_OWNER);
	
	static iButtons, Float:fOrigin[3], Float:fvAngles[3], Float:fVector[3], Float:fVelocity[3] = {0.0, 0.0, 0.0}, Float:fSpeed, Float:fMaxSpeed;
	fMaxSpeed = entity_get_float(ent, EV_FL_maxspeed);
	fSpeed = entity_get_float(ent, EV_FL_speed);
	iButtons = get_user_button(iOwner);
	entity_get_vector(ent, EV_VEC_velocity, fVelocity);
	entity_get_vector(ent, EV_VEC_angles, fvAngles);
	entity_get_vector(ent, EV_VEC_origin, fOrigin);
	
	if(xs_vec_len(fVelocity) > 0.0)
	{
		message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
		write_byte(22)
		write_short(ent)
		write_short(smoke)
		write_byte(1)
		write_byte(10)
		write_byte(200)
		write_byte(200)
		write_byte(200)
		write_byte(128)
		message_end()
		
		set_pev(ent, pev_frame, 1);
		set_pev(ent, pev_framerate, 1.0);
	}
	else
	{
		set_pev(ent, pev_frame, 0);
		set_pev(ent, pev_framerate, 0.0);
	}
	
	switch( entity_get_int(ent, DRONE_CURRENT_STATUS) )
	{
		case DRONE_STANDBY:
		{
			static target;
			get_user_aiming(iOwner, target)
			if(target == ent && iButtons & IN_USE && !(pev(iOwner, pev_oldbuttons) & IN_USE))
			{
				attach_drone_player(iOwner, ent);
			}
			
			entity_set_float(ent, EV_FL_nextthink, get_gametime() + 0.01);
		}
		case DRONE_CONTROL:
		{
			if(iButtons & IN_FORWARD)
			{
				entity_set_float(ent, EV_FL_speed, (fSpeed = floatmin(fSpeed + 10.0, fMaxSpeed)));
			}
			else if(iButtons & IN_BACK)
			{
				entity_set_float(ent, EV_FL_speed, (fSpeed = floatmax(fSpeed - 10.0, 0.0)));
			}

			if(fSpeed > 0.0)
			{
				angle_vector(fvAngles, ANGLEVECTOR_FORWARD, fVector);
				xs_vec_mul_scalar(fVector, fSpeed, fVelocity);
			}

			static Float:fvForward[3], Float:fvRight[3], Float:fvUP[3];
			angle_vector(fvAngles, ANGLEVECTOR_FORWARD, fvForward);
			angle_vector(fvAngles, ANGLEVECTOR_RIGHT, fvRight);
			xs_vec_neg(fvRight, fvRight);
			angle_vector(fvAngles, ANGLEVECTOR_UP, fvUP);

			if(iButtons & IN_MOVERIGHT || iButtons & IN_RIGHT)
			{
				g_user_rotation_angle[iOwner][2] += 5.0;

				xs_vec_copy(fvRight, fVector);
				RotationAroundAxis(fVector, fvForward, g_user_rotation_angle[iOwner][2]);
				xs_vec_normalize(fVector, fVector);
				xs_vec_cross(fVector, fvForward, fvUP);
				xs_vec_cross(fvUP, fVector, fVector);
				vector_to_angle(fVector, fvAngles);
			}
			else if(iButtons & IN_MOVELEFT || iButtons & IN_LEFT)
			{
				g_user_rotation_angle[iOwner][2] += -5.0;

				xs_vec_mul_scalar(fvRight, 10.0, fVector);
				RotationAroundAxis(fVector, fvForward, g_user_rotation_angle[iOwner][2]);
				xs_vec_normalize(fVector, fVector);
				xs_vec_cross(fVector, fvForward, fvUP);
				xs_vec_cross(fvUP, fVector, fVector);
				vector_to_angle(fVector, fvAngles);
			}
			else if(iButtons & IN_JUMP)
			{
				g_user_rotation_angle[iOwner][0] += 5.0;

				xs_vec_mul_scalar(fvForward, 10.0, fVector);
				RotationAroundAxis(fVector, fvRight, g_user_rotation_angle[iOwner][0]);
				xs_vec_normalize(fVector, fVector);
				xs_vec_cross(fVector, fvRight, fvUP);
				xs_vec_cross(fvUP, fvRight, fVector);
				vector_to_angle(fVector, fvAngles);
			}
			else if(iButtons & IN_DUCK)
			{
				g_user_rotation_angle[iOwner][0] += -5.0;

				xs_vec_mul_scalar(fvForward, 10.0, fVector);
				RotationAroundAxis(fVector, fvRight, g_user_rotation_angle[iOwner][0]);
				xs_vec_normalize(fVector, fVector);
				xs_vec_cross(fVector, fvRight, fvUP);
				xs_vec_cross(fvUP, fvRight, fVector);
				vector_to_angle(fVector, fvAngles);
			}

			// lets make sure the plane doesn't exceed the maximum speed limits.
			if(xs_vec_len(fVelocity) > fMaxSpeed)
			{
				xs_vec_normalize(fVelocity, fVelocity);
				xs_vec_mul_scalar(fVelocity, fMaxSpeed, fVelocity);
			}

			fVelocity[2] *= -1.0;
			entity_set_vector(ent, EV_VEC_angles, fvAngles);
			entity_set_vector(ent, EV_VEC_velocity, fVelocity);
			entity_set_float(ent, EV_FL_nextthink, get_gametime() + 0.1);
		}
		case DRONE_KILL:
		{
			// more stuff to think about
		}
	}
}
__________________
@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-23-2022 at 13:00.
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 05-23-2022 , 13:46   Re: Rotating Aircraft ( drone )
Reply With Quote #2

Your question is?
__________________
HamletEagle is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 05-23-2022 , 17:45   Re: Rotating Aircraft ( drone )
Reply With Quote #3

Quote:
Originally Posted by HamletEagle View Post
Your question is?
How to properly rotate an entity using the keyboard arrows ( A & D ) Rolling ( SPACE & CTRL ) pitching respecting to the entity's direction.
__________________
@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
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

Forum Jump


All times are GMT -4. The time now is 03:28.


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