@@ -1825,6 +1825,33 @@ static void R_SortDrawSurfs()
18251825 R_AddDrawViewCmd ( false );
18261826}
18271827
1828+ static void PositionEntityOnTag ( refEntity_t* entity, const refEntity_t* parent, orientation_t * orientation ) {
1829+ // FIXME: allow origin offsets along tag?
1830+ VectorCopy ( parent->origin , entity->origin );
1831+
1832+ for ( int i = 0 ; i < 3 ; i++ ) {
1833+ VectorMA ( entity->origin , orientation->origin [i], parent->axis [i], entity->origin );
1834+ }
1835+
1836+ // had to cast away the const to avoid compiler problems...
1837+ AxisMultiply ( orientation->axis , ( ( refEntity_t* ) parent )->axis , entity->axis );
1838+ entity->backlerp = parent->backlerp ;
1839+ }
1840+
1841+ static void PositionRotatedEntityOnTag ( refEntity_t* entity, const refEntity_t* parent, orientation_t * orientation ) {
1842+ // FIXME: allow origin offsets along tag?
1843+ VectorCopy ( parent->origin , entity->origin );
1844+
1845+ for ( int i = 0 ; i < 3 ; i++ ) {
1846+ VectorMA ( entity->origin , orientation->origin [i], parent->axis [i], entity->origin );
1847+ }
1848+
1849+ // had to cast away the const to avoid compiler problems...
1850+ axis_t tempAxis;
1851+ AxisMultiply ( entity->axis , orientation->axis , tempAxis );
1852+ AxisMultiply ( tempAxis, ( ( refEntity_t* ) parent )->axis , entity->axis );
1853+ }
1854+
18281855/*
18291856=============
18301857R_AddEntitySurfaces
@@ -1889,19 +1916,146 @@ void R_AddEntitySurfaces()
18891916 }
18901917 else
18911918 {
1892- switch ( tr.currentModel ->type )
1893- {
1919+ switch ( tr.currentModel ->type ) {
18941920 case modtype_t ::MOD_MESH:
18951921 R_AddMDVSurfaces ( ent );
18961922 break ;
18971923
18981924 case modtype_t ::MOD_MD5:
1899- R_AddMD5Surfaces ( ent );
1925+ /* Log::Warn("%i %s: old: %i-%i %f new: %i-%i %f | %f %f", ent->e.animationHandle,
1926+ R_GetAnimationByHandle( ent->e.animationHandle )->name, ent->e.startFrame,
1927+ ent->e.endFrame, ent->e.lerp, ent->e.startFrame2, ent->e.endFrame2, ent->e.lerp2,
1928+ ent->e.blendLerp, ent->e.scale ); */
1929+ switch ( ent->e .positionOnTag ) {
1930+ case EntityTag::ON_TAG:
1931+ {
1932+ orientation_t orientation;
1933+ RE_LerpTagET ( &orientation, &tr.refdef .entities [ent->e .attachmentEntity ].e , ent->e .tag .c_str (), 0 );
1934+ PositionEntityOnTag ( &ent->e , &tr.refdef .entities [ent->e .attachmentEntity ].e , &orientation );
1935+ R_RotateEntityForViewParms ( ent, &tr.viewParms , &tr.orientation );
1936+ break ;
1937+ }
1938+
1939+ case EntityTag::ON_TAG_ROTATED:
1940+ {
1941+ orientation_t orientation;
1942+ RE_LerpTagET ( &orientation, &tr.refdef .entities [ent->e .attachmentEntity ].e , ent->e .tag .c_str (), 0 );
1943+ PositionRotatedEntityOnTag ( &ent->e , &tr.refdef .entities [ent->e .attachmentEntity ].e , &orientation );
1944+ R_RotateEntityForViewParms ( ent, &tr.viewParms , &tr.orientation );
1945+ break ;
1946+ }
1947+
1948+ case EntityTag::NONE:
1949+ default :
1950+ break ;
1951+ }
1952+
1953+ if ( ent->e .scale == 0 ) {
1954+ ent->e .scale = 1 ;
1955+ }
1956+ if ( ent->e .animationHandle == 0 ) {
1957+ ent->e .animationHandle = ent->e .animationHandle2 ;
1958+ } else if ( ent->e .animationHandle2 == 0 ) {
1959+ ent->e .animationHandle2 = ent->e .animationHandle ;
1960+ }
1961+
1962+ RE_BuildSkeleton ( &ent->e .skeleton , ent->e .animationHandle , ent->e .startFrame , ent->e .endFrame ,
1963+ ent->e .lerp , ent->e .clearOrigin );
1964+ ent->e .skeleton .scale = ent->e .scale ;
1965+ if ( ent->e .blendLerp > 0.0 ) {
1966+ refSkeleton_t skel;
1967+ RE_BuildSkeleton ( &skel, ent->e .animationHandle2 , ent->e .startFrame2 , ent->e .endFrame2 ,
1968+ ent->e .lerp2 , ent->e .clearOrigin2 );
1969+ RE_BlendSkeleton ( &ent->e .skeleton , &skel, ent->e .blendLerp );
1970+ }
1971+
1972+ for ( const BoneMod& boneMod : ent->e .boneMods ) {
1973+ QuatMultiply2 ( ent->e .skeleton .bones [boneMod.index ].t .rot , boneMod.rotation );
1974+ }
1975+
1976+ if ( ent->e .boundsAdd ) {
1977+ matrix_t mat;
1978+ vec3_t bounds[2 ];
1979+
1980+ MatrixFromAngles ( mat, ent->e .boundsRotation [0 ], ent->e .boundsRotation [1 ], ent->e .boundsRotation [2 ] );
1981+ MatrixTransformBounds ( mat, ent->e .skeleton .bounds [0 ], ent->e .skeleton .bounds [1 ], bounds[0 ], bounds[1 ] );
1982+ BoundsAdd ( ent->e .skeleton .bounds [0 ], ent->e .skeleton .bounds [1 ], bounds[0 ], bounds[1 ] );
1983+ }
1984+
1985+ if ( !( ent->e .renderfx & RF_NORENDER ) ) {
1986+ R_AddMD5Surfaces ( ent );
1987+ }
19001988 break ;
19011989
19021990 case modtype_t ::MOD_IQM:
1903- R_AddIQMSurfaces ( ent );
1991+ {
1992+ /* Log::Warn("%i %s: old: %i-%i %f new: %i-%i %f | %f %f", ent->e.animationHandle,
1993+ R_GetAnimationByHandle( ent->e.animationHandle )->name, ent->e.startFrame,
1994+ ent->e.endFrame, ent->e.lerp, ent->e.startFrame2, ent->e.endFrame2, ent->e.lerp2,
1995+ ent->e.blendLerp, ent->e.scale ); */
1996+ switch ( ent->e .positionOnTag ) {
1997+ case EntityTag::ON_TAG:
1998+ {
1999+ orientation_t orientation;
2000+ RE_LerpTagET ( &orientation, &tr.refdef .entities [ent->e .attachmentEntity ].e , ent->e .tag .c_str (), 0 );
2001+ PositionEntityOnTag ( &ent->e , &tr.refdef .entities [ent->e .attachmentEntity ].e , &orientation );
2002+ R_RotateEntityForViewParms ( ent, &tr.viewParms , &tr.orientation );
2003+ break ;
2004+ }
2005+
2006+ case EntityTag::ON_TAG_ROTATED:
2007+ {
2008+ orientation_t orientation;
2009+ RE_LerpTagET ( &orientation, &tr.refdef .entities [ent->e .attachmentEntity ].e , ent->e .tag .c_str (), 0 );
2010+ PositionRotatedEntityOnTag ( &ent->e , &tr.refdef .entities [ent->e .attachmentEntity ].e , &orientation );
2011+ R_RotateEntityForViewParms ( ent, &tr.viewParms , &tr.orientation );
2012+ break ;
2013+ }
2014+
2015+ case EntityTag::NONE:
2016+ default :
2017+ break ;
2018+ }
2019+
2020+ bool transform = true ;
2021+ if ( ent->e .scale == 0 ) {
2022+ ent->e .scale = 1 ;
2023+ }
2024+ if ( ent->e .animationHandle == 0 ) {
2025+ ent->e .animationHandle = ent->e .animationHandle2 ;
2026+ } else if ( ent->e .animationHandle2 == 0 ) {
2027+ ent->e .animationHandle2 = ent->e .animationHandle ;
2028+ }
2029+
2030+ ent->e .skeleton .scale = ent->e .scale ;
2031+ RE_BuildSkeleton ( &ent->e .skeleton , ent->e .animationHandle , ent->e .startFrame , ent->e .endFrame ,
2032+ ent->e .lerp , ent->e .clearOrigin );
2033+ if ( ent->e .blendLerp > 0.0 ) {
2034+ refSkeleton_t skel;
2035+ RE_BuildSkeleton ( &skel, ent->e .animationHandle2 , ent->e .startFrame2 , ent->e .endFrame2 ,
2036+ ent->e .lerp2 , ent->e .clearOrigin2 );
2037+ RE_BlendSkeleton ( &ent->e .skeleton , &skel, ent->e .blendLerp );
2038+ }
2039+
2040+ for ( const BoneMod& boneMod : ent->e .boneMods ) {
2041+ QuatMultiply2 ( ent->e .skeleton .bones [boneMod.index ].t .rot , boneMod.rotation );
2042+ }
2043+ R_TransformSkeleton ( &ent->e .skeleton , ent->e .scale );
2044+
2045+ if ( ent->e .boundsAdd ) {
2046+ matrix_t mat;
2047+ vec3_t bounds[2 ];
2048+
2049+ MatrixFromAngles ( mat, ent->e .boundsRotation [0 ], ent->e .boundsRotation [1 ], ent->e .boundsRotation [2 ] );
2050+ MatrixTransformBounds ( mat, ent->e .skeleton .bounds [0 ], ent->e .skeleton .bounds [1 ], bounds[0 ], bounds[1 ] );
2051+ BoundsAdd ( ent->e .skeleton .bounds [0 ], ent->e .skeleton .bounds [1 ], bounds[0 ], bounds[1 ] );
2052+ }
2053+
2054+ if ( !( ent->e .renderfx & RF_NORENDER ) ) {
2055+ R_AddIQMSurfaces ( ent );
2056+ }
19042057 break ;
2058+ }
19052059
19062060 case modtype_t ::MOD_BSP:
19072061 R_AddBSPModelSurfaces ( ent );
0 commit comments