/* EvalWaveForm Evaluates a given waveForm_t, referencing backEnd.refdef.time directly */ static float EvalWaveForm(const waveForm_t *wf) { float *table; table = TableForFunc(wf->func); return WAVEVALUE(table, wf->base, wf->amplitude, wf->phase, wf->frequency); }
/* ** EvalWaveForm ** ** Evaluates a given waveForm_t, referencing backEnd.refdef.time directly */ static float EvalWaveForm( const waveForm_t *wf ) { float *table; if ( wf->func == GF_NOISE ) { return ( wf->base + R_NoiseGet4f( 0, 0, 0, ( backEnd.refdef.floatTime + wf->phase ) * wf->frequency ) * wf->amplitude ); } else if (wf->func == GF_RAND) { if( GetNoiseTime( backEnd.refdef.time + wf->phase ) <= wf->frequency ) { return (wf->base + wf->amplitude); } else { return wf->base; } } table = TableForFunc( wf->func ); return WAVEVALUE( table, wf->base, wf->amplitude, wf->phase, wf->frequency ); }
/* ======================== RB_CalcDeformVertexes ======================== */ void RB_CalcDeformVertexes( deformStage_t *ds ) { int i; vec3_t offset; float scale; float *xyz = ( float * ) tess.xyz; float *normal = ( float * ) tess.normal; float *table; if ( ds->deformationWave.frequency == 0 ) { scale = EvalWaveForm( &ds->deformationWave ); for ( i = 0; i < tess.numVertexes; i++, xyz += 4, normal += 4 ) { VectorScale( normal, scale, offset ); xyz[0] += offset[0]; xyz[1] += offset[1]; xyz[2] += offset[2]; } } else { table = TableForFunc( ds->deformationWave.func ); for ( i = 0; i < tess.numVertexes; i++, xyz += 4, normal += 4 ) { float off = ( xyz[0] + xyz[1] + xyz[2] ) * ds->deformationSpread; scale = WAVEVALUE( table, ds->deformationWave.base, ds->deformationWave.amplitude, ds->deformationWave.phase + off, ds->deformationWave.frequency ); VectorScale( normal, scale, offset ); xyz[0] += offset[0]; xyz[1] += offset[1]; xyz[2] += offset[2]; } } }
/* ======================== RB_CalcDeformVertexes ======================== */ void RB_CalcDeformVertexes( deformStage_t *ds ) { int i; vec3_t offset; float scale; float *xyz = ( float * ) tess.xyz; uint32_t *normal = tess.normal; float *table; if ( ds->deformationWave.frequency == 0 ) { scale = EvalWaveForm( &ds->deformationWave ); for ( i = 0; i < tess.numVertexes; i++, xyz += 4, normal++ ) { R_VboUnpackNormal(offset, *normal); xyz[0] += offset[0] * scale; xyz[1] += offset[1] * scale; xyz[2] += offset[2] * scale; } } else { table = TableForFunc( ds->deformationWave.func ); for ( i = 0; i < tess.numVertexes; i++, xyz += 4, normal++ ) { float off = ( xyz[0] + xyz[1] + xyz[2] ) * ds->deformationSpread; scale = WAVEVALUE( table, ds->deformationWave.base, ds->deformationWave.amplitude, ds->deformationWave.phase + off, ds->deformationWave.frequency ); R_VboUnpackNormal(offset, *normal); xyz[0] += offset[0] * scale; xyz[1] += offset[1] * scale; xyz[2] += offset[2] * scale; } } }
void RB_CalcDeformVertexes( deformStage_t *ds ) { int i; vector3 offset; float scale; vector3 *xyz = &tess.xyz[0], *normal = &tess.normal[0]; float *table; if ( ds->deformationWave.frequency == 0 ) { scale = EvalWaveForm( &ds->deformationWave ); for ( i = 0; i < tess.numVertexes; i++, xyz++, normal++ ) { VectorScale( normal, scale, &offset ); xyz->x += offset.x; xyz->y += offset.y; xyz->z += offset.z; } } else { table = TableForFunc( ds->deformationWave.func ); for ( i = 0; i < tess.numVertexes; i++, xyz++, normal++ ) { float off = ( xyz->x + xyz->y + xyz->z ) * ds->deformationSpread; scale = WAVEVALUE( table, ds->deformationWave.base, ds->deformationWave.amplitude, ds->deformationWave.phase + off, ds->deformationWave.frequency ); VectorScale( normal, scale, &offset ); xyz->x += offset.x; xyz->y += offset.y; xyz->z += offset.z; } } }
/* ====================== RB_CalcMoveVertexes A deformation that can move an entire surface along a wave path ====================== */ void RB_CalcMoveVertexes( deformStage_t *ds ) { int i; float *xyz; float *table; float scale; vec3_t offset; table = TableForFunc( ds->deformationWave.func ); scale = WAVEVALUE( table, ds->deformationWave.base, ds->deformationWave.amplitude, ds->deformationWave.phase, ds->deformationWave.frequency ); VectorScale( ds->moveVector, scale, offset ); xyz = ( float * ) tess.xyz; for ( i = 0; i < tess.numVertexes; i++, xyz += 4 ) { VectorAdd( xyz, offset, xyz ); } }
/* ======================== RB_CalcDeformVertexes ======================== */ void RB_CalcDeformVertexes( deformStage_t *ds ) { int i; vec3_t offset; float scale; float *xyz = ( float * ) tess.xyz; float *normal = ( float * ) tess.normal; float *table; // Ridah if ( ds->deformationWave.frequency < 0 ) { qboolean inverse = qfalse; vec3_t worldUp; //static vec3_t up = {0,0,1}; if ( VectorCompare( backEnd.currentEntity->e.fireRiseDir, vec3_origin ) ) { VectorSet( backEnd.currentEntity->e.fireRiseDir, 0, 0, 1 ); } // get the world up vector in local coordinates if ( backEnd.currentEntity->e.hModel ) { // world surfaces don't have an axis VectorRotate( backEnd.currentEntity->e.fireRiseDir, backEnd.currentEntity->e.axis, worldUp ); } else { VectorCopy( backEnd.currentEntity->e.fireRiseDir, worldUp ); } // don't go so far if sideways, since they must be moving VectorScale( worldUp, 0.4 + 0.6 * Q_fabs( backEnd.currentEntity->e.fireRiseDir[ 2 ] ), worldUp ); ds->deformationWave.frequency *= -1; if ( ds->deformationWave.frequency > 999 ) { // hack for negative Z deformation (ack) inverse = qtrue; ds->deformationWave.frequency -= 999; } table = TableForFunc( ds->deformationWave.func ); for ( i = 0; i < tess.numVertexes; i++, xyz += 4, normal += 4 ) { float off = ( xyz[ 0 ] + xyz[ 1 ] + xyz[ 2 ] ) * ds->deformationSpread; float dot; scale = WAVEVALUE( table, ds->deformationWave.base, ds->deformationWave.amplitude, ds->deformationWave.phase + off, ds->deformationWave.frequency ); dot = DotProduct( worldUp, normal ); if ( dot * scale > 0 ) { if ( inverse ) { scale *= -1; } VectorMA( xyz, dot * scale, worldUp, xyz ); } } if ( inverse ) { ds->deformationWave.frequency += 999; } ds->deformationWave.frequency *= -1; } // done. else if ( ds->deformationWave.frequency == 0 ) { scale = EvalWaveForm( &ds->deformationWave ); for ( i = 0; i < tess.numVertexes; i++, xyz += 4, normal += 4 ) { VectorScale( normal, scale, offset ); xyz[ 0 ] += offset[ 0 ]; xyz[ 1 ] += offset[ 1 ]; xyz[ 2 ] += offset[ 2 ]; } } else { table = TableForFunc( ds->deformationWave.func ); for ( i = 0; i < tess.numVertexes; i++, xyz += 4, normal += 4 ) { float off = ( xyz[ 0 ] + xyz[ 1 ] + xyz[ 2 ] ) * ds->deformationSpread; scale = WAVEVALUE( table, ds->deformationWave.base, ds->deformationWave.amplitude, ds->deformationWave.phase + off, ds->deformationWave.frequency ); VectorScale( normal, scale, offset ); xyz[ 0 ] += offset[ 0 ]; xyz[ 1 ] += offset[ 1 ]; xyz[ 2 ] += offset[ 2 ]; } } }