Utils_TurnTowards

This commit is contained in:
krystalgamer 2024-08-07 20:09:57 +02:00
parent 5f85acffed
commit f24412ed63
2 changed files with 36 additions and 3 deletions

View File

@ -67,3 +67,6 @@ if (x == -1){
worse code
- classes/structures with other inner structures/arrays will have weird indexing (i.e SEntry in CMenu)
using structures/classes can change code gen - check Utils_turnsTowards, it was using eax,cx on the += and -= statements with i16 but when replace with CSVector it fixed it.

View File

@ -460,10 +460,40 @@ void Utils_VblankProcessing(void)
printf("Utils_VblankProcessing(void)");
}
// @SMALLTODO
void Utils_TurnTowards(CSVector, CSVector*, CSVector*, CSVector, i32)
// @Ok
// @Matching
void Utils_TurnTowards(
CSVector Current,
CSVector *AngVel,
CSVector *AngAcc,
CSVector Ideal,
i32 accfactor)
{
printf("void Utils_TurnTowards(CSVector, CSVector*, CSVector*, CSVector, i32)");
CSVector angDiff;
angDiff.vx = Ideal.vx - Current.vx;
angDiff.vy = Ideal.vy - Current.vy;
if ( angDiff.vx < -2048 )
angDiff.vx += 4096;
if ( angDiff.vx > 2048 )
angDiff.vx -= 4096;
if ( angDiff.vy < -2048 )
angDiff.vy += 4096;
if ( angDiff.vy > 2048 )
angDiff.vy -= 4096;
if ( angDiff.vx || angDiff.vy )
{
AngAcc->vx = (accfactor * angDiff.vx) >> 8;
AngAcc->vy = (accfactor * angDiff.vy) >> 8;
}
else
{
AngVel->vx = 0;
AngVel->vy = 0;
}
}
// @NotOk