@@ -810,6 +810,44 @@ static void CG_Portal( centity_t *cent ) {
810
810
}
811
811
812
812
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
+
813
851
/*
814
852
=========================
815
853
CG_AdjustPositionForMover
@@ -821,6 +859,8 @@ void CG_AdjustPositionForMover(const vec3_t in, int moverNum, int fromTime, int
821
859
centity_t * cent ;
822
860
vec3_t oldOrigin , origin , deltaOrigin ;
823
861
vec3_t oldAngles , angles , deltaAngles ;
862
+ vec3_t matrix [3 ], transpose [3 ];
863
+ vec3_t org , org2 , move2 ;
824
864
825
865
if ( moverNum <= 0 || moverNum >= ENTITYNUM_MAX_NORMAL ) {
826
866
VectorCopy ( in , out );
@@ -844,9 +884,17 @@ void CG_AdjustPositionForMover(const vec3_t in, int moverNum, int fromTime, int
844
884
VectorSubtract ( origin , oldOrigin , deltaOrigin );
845
885
VectorSubtract ( angles , oldAngles , deltaAngles );
846
886
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
+
847
896
VectorAdd ( in , deltaOrigin , out );
848
897
VectorAdd ( angles_in , deltaAngles , angles_out );
849
- // FIXME: origin change when on a rotating object
850
898
}
851
899
852
900
0 commit comments