From 33a899d6dd02618aca8c4d13c5f4040f3e5c2ee2 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Sat, 15 Sep 2018 11:53:21 -0500 Subject: [PATCH] Fix predicting entity origin on rotating mover Based on G_TryPushingEntity() in code/game/g_mover.c. --- code/cgame/cg_ents.c | 50 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/code/cgame/cg_ents.c b/code/cgame/cg_ents.c index 7629f0b8..ec8b02ff 100644 --- a/code/cgame/cg_ents.c +++ b/code/cgame/cg_ents.c @@ -664,6 +664,44 @@ static void CG_Portal( centity_t *cent ) { } +/* +================ +CG_CreateRotationMatrix +================ +*/ +void CG_CreateRotationMatrix(vec3_t angles, vec3_t matrix[3]) { + AngleVectors(angles, matrix[0], matrix[1], matrix[2]); + VectorInverse(matrix[1]); +} + +/* +================ +CG_TransposeMatrix +================ +*/ +void CG_TransposeMatrix(vec3_t matrix[3], vec3_t transpose[3]) { + int i, j; + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + transpose[i][j] = matrix[j][i]; + } + } +} + +/* +================ +CG_RotatePoint +================ +*/ +void CG_RotatePoint(vec3_t point, vec3_t matrix[3]) { + vec3_t tvec; + + VectorCopy(point, tvec); + point[0] = DotProduct(matrix[0], tvec); + point[1] = DotProduct(matrix[1], tvec); + point[2] = DotProduct(matrix[2], tvec); +} + /* ========================= CG_AdjustPositionForMover @@ -675,6 +713,8 @@ void CG_AdjustPositionForMover(const vec3_t in, int moverNum, int fromTime, int centity_t *cent; vec3_t oldOrigin, origin, deltaOrigin; vec3_t oldAngles, angles, deltaAngles; + vec3_t matrix[3], transpose[3]; + vec3_t org, org2, move2; if ( moverNum <= 0 || moverNum >= ENTITYNUM_MAX_NORMAL ) { VectorCopy( in, out ); @@ -698,9 +738,17 @@ void CG_AdjustPositionForMover(const vec3_t in, int moverNum, int fromTime, int VectorSubtract( origin, oldOrigin, deltaOrigin ); VectorSubtract( angles, oldAngles, deltaAngles ); + // origin change when on a rotating object + CG_CreateRotationMatrix( deltaAngles, transpose ); + CG_TransposeMatrix( transpose, matrix ); + VectorSubtract( in, oldOrigin, org ); + VectorCopy( org, org2 ); + CG_RotatePoint( org2, matrix ); + VectorSubtract( org2, org, move2 ); + VectorAdd( deltaOrigin, move2, deltaOrigin ); + VectorAdd( in, deltaOrigin, out ); VectorAdd( angles_in, deltaAngles, angles_out ); - // FIXME: origin change when on a rotating object }