Raised This Month: $ Target: $400
 0% 

Solved Get Shorter Angle Rotation


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 11-06-2020 , 12:44   Get Shorter Angle Rotation
Reply With Quote #1



Can anyone be so kind write me a simple code from the pic above.
I want to rotate from RED to BLUE without taking the long blue path,
instead i want to rotate thru the YELLOW path let say 45 degree to 340 degree the shorter way.

I cant explain this in better english so it like if the the yellow path is shorter than the blue path then go thru the zero degree?
Because subtract this number always give full rotation regardless since the number reset at 360.

Here some love and hug for appreciation of your time ===>>>

this backup attachment is the same as pic above
Attached Images
File Type: jpg degree.jpg (59.0 KB, 35 views)
__________________
If i happen to insulted you unintentionally,
it was me and Google Translate who did it.

Last edited by GsiX; 11-07-2020 at 08:57. Reason: Giving some lovely hug
GsiX is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 11-06-2020 , 13:06   Re: Get Shorter Angle Rotation
Reply With Quote #2

Here is my humble code, it works but if i stand at zero PHD degree or close to zero to the object, it choose to rotate full blasst PHD degree.

Here some more love and hug ===>>>

PHP Code:
void Think_Directionint entityfloat pos_entity[3], float pos_owner[3] )
{
    
float pos_buff[3];
    
pos_buff[0] = pos_owner[0];
    
pos_buff[1] = pos_owner[1];
    
pos_buff[2] = pos_entity[2];    // we set the pos at same height to please my imagination, noting more.
    //SetArray3DFloat( pos_owner[0], pos_owner[1], pos_entity[2], pos_buff );
    
    
float ang_entity[3];
    
float ang_guide[3];
    
GetEntAngleentityang_entity0.0);    // get the object current world angle
    
MakeVectorFromPointspos_entitypos_buffang_guide );
    
NormalizeVectorang_guideang_guide );
    
GetVectorAnglesang_guideang_guide );    // get the world angle between the object and me
    
    
float tolerance 2.0// we allow this much of angle over shoot/error
    
float direction ang_guide[1] - ang_entity[1];
    if( 
direction > (tolerance * -1.0 ) && direction tolerance )    // dont compare with zero value to rest as we might not catch the exact number
    
{
        
direction 0.0;    // tell the object to rest/stop rotate as it reach the nose facing me.
    
}
    
    
// negative value turn right/cw
    // positive value turn left/ccw
    
float force FORCE_ROTATE direction;
    
    if( 
g_fForceDirection[entity] != force )
    {
        
g_fForceDirection[entity] = force;
        
SetThrusterTorqueg_iPetTroque[entity], force ); // whatever value we get, set it to the rotation force
        
if( g_fForceDirection[entity] == FORCE_NONE && g_fForceForward[entity] == FORCE_NONE )
        {
            
EmitSoundToAllSND_TIMEOUTentitySNDCHAN_AUTO );
        }
    }

__________________
If i happen to insulted you unintentionally,
it was me and Google Translate who did it.

Last edited by GsiX; 11-06-2020 at 13:58. Reason: my head about to blow, stop asking reason
GsiX is offline
GsiX
gee, six eggs
Join Date: Aug 2012
Location: Land Below The Wind
Old 11-07-2020 , 08:57   Re: Get Shorter Angle Rotation
Reply With Quote #3

Found this by Kyle and it work like a charm.
It always give you shorter direction to rotate either negative or positive from 0' to 180' ( cw or ccw);

Solution 1 as follow:
PHP Code:
function AngleDifferenceangle1angle2 )
{
    
let diff = ( Math.ceil(angle2 angle1) + 180 ) % 360 180;
    return ( 
diff < -180 diff 360 diff );

solution 2:
Spoiler


solution 3:
Spoiler


solution 4:
Spoiler


last spoiler:
Spoiler
__________________
If i happen to insulted you unintentionally,
it was me and Google Translate who did it.

Last edited by GsiX; 11-07-2020 at 09:10. Reason: Giving my last hug and love..
GsiX is offline
Reply



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 00:42.


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