8000 Fix predicting entity origin on rotating mover · Turtle-Arena/turtle-arena-code@993bea4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 993bea4

Browse files
committed
Fix predicting entity origin on rotating mover
Based on G_TryPushingEntity() in code/game/g_mover.c.
1 parent af0abe2 commit 993bea4

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

code/cgame/cg_ents.c

+49-1
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,44 @@ static void CG_Portal( centity_t *cent ) {
810810
}
811811

812812

813+
/*
814+
================
815+
CG_CreateRotationMatrix
816+
================
817+
*/
818+
void CG_CreateRotationMatrix(vec3_t angles, vec3_t matrix[3]) {
819+
AngleVectors(angles, matrix[0], matrix[1], matrix[2]);
820+
VectorInverse(matrix[1]);
821+
}
822+
823+
/*
824+
================
825+
CG_TransposeMatrix
826+
================
827+
*/
828+
void CG_TransposeMatrix(vec3_t matrix[3], vec3_t transpose[3]) {
829+
int i, j;
830+
for (i = 0; i < 3; i++) {
831+
for (j = 0; j < 3; j++) {
832+
transpose[i][j] = matrix[j][i];
833+
}
834+
}
835+
}
836+
837+
/*
838+
================
839+
CG_RotatePoint
840+
================
841+
*/
842+
void CG_RotatePoint(vec3_t point, vec3_t matrix[3]) {
843+
vec3_t tvec;
844+
845+
VectorCopy(point, tvec);
846+
point[0] = DotProduct(matrix[0], tvec);
847+
point[1] = DotProduct(matrix[1], tvec);
848+
point[2] = DotProduct(matrix[2], tvec);
849+
}
850+
813851
/*
814852
=========================
815853
CG_AdjustPositionForMover
@@ -821,6 +859,8 @@ void CG_AdjustPositionForMover(const vec3_t in, int moverNum, int fromTime, int
821859
centity_t *cent;
822860
vec3_t oldOrigin, origin, deltaOrigin;
823861
vec3_t oldAngles, angles, deltaAngles;
862+
vec3_t matrix[3], transpose[3];
863+
vec3_t org, org2, move2;
824864

825865
if ( moverNum <= 0 || moverNum >= ENTITYNUM_MAX_NORMAL ) {
826866
VectorCopy( in, out );
@@ -844,9 +884,17 @@ void CG_AdjustPositionForMover(const vec3_t in, int moverNum, int fromTime, int
844884
VectorSubtract( origin, oldOrigin, deltaOrigin );
845885
VectorSubtract( angles, oldAngles, deltaAngles );
846886

887+
// origin change when on a rotating object
888+
CG_CreateRotationMatrix( deltaAngles, transpose );
889+
CG_TransposeMatrix( transpose, matrix );
890+
VectorSubtract( in, oldOrigin, org );
891+
VectorCopy( org, org2 );
892+
CG_RotatePoint( org2, matrix );
893+
VectorSubtract( org2, org, move2 );
894+
VectorAdd( deltaOrigin, move2, deltaOrigin );
895+
847896
VectorAdd( in, deltaOrigin, out );
848897
VectorAdd( angles_in, deltaAngles, angles_out );
849-
// FIXME: origin change when on a rotating object
850898
}
851899

852900

0 commit comments

Comments
 (0)
0