static float G_MissileTimePowerReduce( gentity_t *self, int fullPower, int halfLife, powerReduce_t type ) { int lifetime = level.time - self->creationTime; float travelled; float divider = 1; // allow disabling via the half-life setting if ( halfLife < 1 ) { return 1.0f; } switch ( type ) { case PR_INVERSE_SQUARE: travelled = lifetime + fullPower - halfLife; if ( travelled > halfLife * 1.25 ) // approx. point at which the two graphs meet { divider = Q_rsqrt( travelled / halfLife ); } else if ( travelled >= 0 ) { divider = travelled / halfLife; divider = cos( divider * divider / 3.375 ); } break; case PR_COSINE: // curve is from -halfLife to fullPower, with a quarter-cycle being 0…fullPower travelled = lifetime - halfLife; divider = cos( travelled * M_PI / 2.0f / ( fullPower + 1 - halfLife ) ); divider = MAX( 0.0f, divider ); break; case PR_END: break; } return divider; }
/*====================================================================================================*/ void AHRS_GetQ( Quaternion *pNumQ ) { fp32 ErrX, ErrY, ErrZ; fp32 AccX, AccY, AccZ; fp32 GyrX, GyrY, GyrZ; fp32 Normalize; static fp32 exInt = 0.0f, eyInt = 0.0f, ezInt = 0.0f; Gravity V; // 加速度归一化 Normalize = Q_rsqrt(squa(sensor.acc.averag.x)+ squa(sensor.acc.averag.y) +squa(sensor.acc.averag.z)); AccX = sensor.acc.averag.x*Normalize; AccY = sensor.acc.averag.y*Normalize; AccZ = sensor.acc.averag.z*Normalize; // 提取重力分量 V = Quaternion_vectorGravity(&NumQ); // 向量差乘 ErrX = (AccY*V.z - AccZ*V.y); ErrY = (AccZ*V.x - AccX*V.z); ErrZ = (AccX*V.y - AccY*V.x); exInt = exInt + ErrX * KiDef; eyInt = eyInt + ErrY * KiDef; ezInt = ezInt + ErrZ * KiDef; GyrX = Rad(sensor.gyro.averag.x) + KpDef * VariableParameter(ErrX) * ErrX + exInt; GyrY = Rad(sensor.gyro.averag.y) + KpDef * VariableParameter(ErrY) * ErrY + eyInt; GyrZ = Rad(sensor.gyro.averag.z) + KpDef * VariableParameter(ErrZ) * ErrZ + ezInt; // 一阶龙格库塔法, 更新四元数 Quaternion_RungeKutta(&NumQ, GyrX, GyrY, GyrZ, SampleRateHalf); // 四元数归一化 Quaternion_Normalize(&NumQ); }
static void RB_DrawOrientedSurfaceSprites( shaderStage_t *stage, shaderCommands_t *input) { int curindex, curvert; vec3_t dist; float triarea, minnormal; vec2_t vec1to2, vec1to3; vec3_t v1,v2,v3; float a1,a2,a3; float l1,l2,l3; vec2_t fog1, fog2, fog3; float posi, posj; float step; float fa,fb,fc; vec3_t curpoint; float width, height; float alpha, alphapos, thisspritesfadestart, light; byte randomindex2; vec2_t fogv; float cutdist=stage->ss->fadeMax*rangescalefactor, cutdist2=cutdist*cutdist; float fadedist=stage->ss->fadeDist*rangescalefactor, fadedist2=fadedist*fadedist; assert(cutdist2 != fadedist2); float inv_fadediff = 1.0/(cutdist2-fadedist2); // The faderange is the fraction amount it takes for these sprites to fade out, assuming an ideal fade range of 250 float faderange = FADE_RANGE/(cutdist-fadedist); if (faderange > 1.0) { // Don't want to force a new fade_rand faderange = 1.0; } if (stage->ss->facing) { // Faceup sprite. minnormal = 0.99f; } else { // Normal oriented sprite minnormal = 0.5f; } // Quickly calc all the alphas for each vertex for (curvert=0; curvert<input->numVertexes; curvert++) { // Calc alpha at each point VectorSubtract(ssViewOrigin, input->xyz[curvert], dist); SSVertAlpha[curvert] = 1.0 - (VectorLengthSquared(dist) - fadedist2) * inv_fadediff; } for (curindex=0; curindex<input->numIndexes-2; curindex+=3) { curvert = input->indexes[curindex]; VectorCopy(input->xyz[curvert], v1); if (input->normal[curvert][2] < minnormal) { continue; } l1 = input->vertexColors[curvert][2]; a1 = SSVertAlpha[curvert]; fog1[0] = *((float *)(tess.svars.texcoords[0])+(curvert<<1)); fog1[1] = *((float *)(tess.svars.texcoords[0])+(curvert<<1)+1); curvert = input->indexes[curindex+1]; VectorCopy(input->xyz[curvert], v2); if (input->normal[curvert][2] < minnormal) { continue; } l2 = input->vertexColors[curvert][2]; a2 = SSVertAlpha[curvert]; fog2[0] = *((float *)(tess.svars.texcoords[0])+(curvert<<1)); fog2[1] = *((float *)(tess.svars.texcoords[0])+(curvert<<1)+1); curvert = input->indexes[curindex+2]; VectorCopy(input->xyz[curvert], v3); if (input->normal[curvert][2] < minnormal) { continue; } l3 = input->vertexColors[curvert][2]; a3 = SSVertAlpha[curvert]; fog3[0] = *((float *)(tess.svars.texcoords[0])+(curvert<<1)); fog3[1] = *((float *)(tess.svars.texcoords[0])+(curvert<<1)+1); if (a1 <= 0.0 && a2 <= 0.0 && a3 <= 0.0) { continue; } // Find the area in order to calculate the stepsize vec1to2[0] = v2[0] - v1[0]; vec1to2[1] = v2[1] - v1[1]; vec1to3[0] = v3[0] - v1[0]; vec1to3[1] = v3[1] - v1[1]; // Now get the cross product of this sum. triarea = vec1to3[0]*vec1to2[1] - vec1to3[1]*vec1to2[0]; triarea=fabs(triarea); if (triarea <= 1.0) { // Insanely small abhorrent triangle. continue; } step = stage->ss->density * Q_rsqrt(triarea); randomindex = (byte)(v1[0]+v1[1]+v2[0]+v2[1]+v3[0]+v3[1]); randominterval = (byte)(v1[0]+v2[1]+v3[2])|0x03; // Make sure the interval is at least 3, and always odd for (posi=0; posi<1.0; posi+=step) { for (posj=0; posj<(1.0-posi); posj+=step) { fa=posi+randomchart[randomindex]*step; randomindex += randominterval; if (fa>1.0) continue; fb=posj+randomchart[randomindex]*step; randomindex += randominterval; if (fb>(1.0-fa)) continue; fc = 1.0-fa-fb; // total alpha, minus random factor so some things fade out sooner. alphapos = a1*fa + a2*fb + a3*fc; // Note that the alpha at this point is a value from 1.0 to 0.0, but represents when to START fading thisspritesfadestart = faderange + (1.0-faderange) * randomchart[randomindex]; randomindex += randominterval; // Find where the alpha is relative to the fadestart, and calc the real alpha to draw at. alpha = 1.0 - ((thisspritesfadestart-alphapos)/faderange); randomindex += randominterval; if (alpha > 0.0) { if (alpha > 1.0) alpha=1.0; if (SSUsingFog) { fogv[0] = fog1[0]*fa + fog2[0]*fb + fog3[0]*fc; fogv[1] = fog1[1]*fa + fog2[1]*fb + fog3[1]*fc; } VectorScale(v1, fa, curpoint); VectorMA(curpoint, fb, v2, curpoint); VectorMA(curpoint, fc, v3, curpoint); light = l1*fa + l2*fb + l3*fc; if (SSAdditiveTransparency) { // Additive transparency, scale light value // light *= alpha; light = (128 + (light*0.5))*alpha; alpha = 1.0; } randomindex2 = randomindex; width = stage->ss->width*(1.0 + (stage->ss->variance[0]*randomchart[randomindex2])); height = stage->ss->height*(1.0 + (stage->ss->variance[1]*randomchart[randomindex2++])); if (randomchart[randomindex2++]>0.5) { width = -width; } if (stage->ss->fadeScale!=0 && alphapos < 1.0) { width *= 1.0 + (stage->ss->fadeScale*(1.0-alphapos)); } if (SSUsingFog) { RB_OrientedSurfaceSprite(curpoint, width, height, (byte)light, (byte)(alpha*255.0), fogv, stage->ss->facing); } else { RB_OrientedSurfaceSprite(curpoint, width, height, (byte)light, (byte)(alpha*255.0), NULL, stage->ss->facing); } totalsurfsprites++; } } } } }
static void RB_DrawVerticalSurfaceSprites( shaderStage_t *stage, shaderCommands_t *input) { int curindex, curvert; vec3_t dist; float triarea; vec2_t vec1to2, vec1to3; vec3_t v1,v2,v3; float a1,a2,a3; float l1,l2,l3; vec2_t fog1, fog2, fog3; vec2_t winddiff1, winddiff2, winddiff3; float windforce1, windforce2, windforce3; float posi, posj; float step; float fa,fb,fc; vec3_t curpoint; float width, height; float alpha, alphapos, thisspritesfadestart, light; byte randomindex2; vec2_t skew={0,0}; vec2_t fogv; vec2_t winddiffv; float windforce=0; qboolean usewindpoint = (qboolean) !! (curWindPointActive && stage->ss->wind > 0); float cutdist=stage->ss->fadeMax*rangescalefactor, cutdist2=cutdist*cutdist; float fadedist=stage->ss->fadeDist*rangescalefactor, fadedist2=fadedist*fadedist; assert(cutdist2 != fadedist2); float inv_fadediff = 1.0/(cutdist2-fadedist2); // The faderange is the fraction amount it takes for these sprites to fade out, assuming an ideal fade range of 250 float faderange = FADE_RANGE/(cutdist-fadedist); if (faderange > 1.0) { // Don't want to force a new fade_rand faderange = 1.0; } // Quickly calc all the alphas and windstuff for each vertex for (curvert=0; curvert<input->numVertexes; curvert++) { VectorSubtract(ssViewOrigin, input->xyz[curvert], dist); SSVertAlpha[curvert] = 1.0 - (VectorLengthSquared(dist) - fadedist2) * inv_fadediff; } // Wind only needs initialization once per tess. if (usewindpoint && !tess.SSInitializedWind) { for (curvert=0; curvert<input->numVertexes;curvert++) { // Calc wind at each point dist[0]=input->xyz[curvert][0] - curWindPoint[0]; dist[1]=input->xyz[curvert][1] - curWindPoint[1]; step = (dist[0]*dist[0] + dist[1]*dist[1]); // dist squared if (step >= (float)(WINDPOINT_RADIUS*WINDPOINT_RADIUS)) { // No wind SSVertWindDir[curvert][0] = 0; SSVertWindDir[curvert][1] = 0; SSVertWindForce[curvert]=0; // Should be < 1 } else { if (step<1) { // Don't want to divide by zero SSVertWindDir[curvert][0] = 0; SSVertWindDir[curvert][1] = 0; SSVertWindForce[curvert] = curWindPointForce * stage->ss->wind; } else { step = Q_rsqrt(step); // Equals 1 over the distance. SSVertWindDir[curvert][0] = dist[0] * step; SSVertWindDir[curvert][1] = dist[1] * step; step = 1.0 - (1.0 / (step * WINDPOINT_RADIUS)); // 1- (dist/maxradius) = a scale from 0 to 1 linearly dropping off SSVertWindForce[curvert] = curWindPointForce * stage->ss->wind * step; // *step means divide by the distance. } } } tess.SSInitializedWind = qtrue; } for (curindex=0; curindex<input->numIndexes-2; curindex+=3) { curvert = input->indexes[curindex]; VectorCopy(input->xyz[curvert], v1); if (stage->ss->facing) { // Hang down if (input->normal[curvert][2] > -0.5) { continue; } } else { // Point up if (input->normal[curvert][2] < 0.5) { continue; } } l1 = input->vertexColors[curvert][2]; a1 = SSVertAlpha[curvert]; fog1[0] = *((float *)(tess.svars.texcoords[0])+(curvert<<1)); fog1[1] = *((float *)(tess.svars.texcoords[0])+(curvert<<1)+1); winddiff1[0] = SSVertWindDir[curvert][0]; winddiff1[1] = SSVertWindDir[curvert][1]; windforce1 = SSVertWindForce[curvert]; curvert = input->indexes[curindex+1]; VectorCopy(input->xyz[curvert], v2); if (stage->ss->facing) { // Hang down if (input->normal[curvert][2] > -0.5) { continue; } } else { // Point up if (input->normal[curvert][2] < 0.5) { continue; } } l2 = input->vertexColors[curvert][2]; a2 = SSVertAlpha[curvert]; fog2[0] = *((float *)(tess.svars.texcoords[0])+(curvert<<1)); fog2[1] = *((float *)(tess.svars.texcoords[0])+(curvert<<1)+1); winddiff2[0] = SSVertWindDir[curvert][0]; winddiff2[1] = SSVertWindDir[curvert][1]; windforce2 = SSVertWindForce[curvert]; curvert = input->indexes[curindex+2]; VectorCopy(input->xyz[curvert], v3); if (stage->ss->facing) { // Hang down if (input->normal[curvert][2] > -0.5) { continue; } } else { // Point up if (input->normal[curvert][2] < 0.5) { continue; } } l3 = input->vertexColors[curvert][2]; a3 = SSVertAlpha[curvert]; fog3[0] = *((float *)(tess.svars.texcoords[0])+(curvert<<1)); fog3[1] = *((float *)(tess.svars.texcoords[0])+(curvert<<1)+1); winddiff3[0] = SSVertWindDir[curvert][0]; winddiff3[1] = SSVertWindDir[curvert][1]; windforce3 = SSVertWindForce[curvert]; if (a1 <= 0.0 && a2 <= 0.0 && a3 <= 0.0) { continue; } // Find the area in order to calculate the stepsize vec1to2[0] = v2[0] - v1[0]; vec1to2[1] = v2[1] - v1[1]; vec1to3[0] = v3[0] - v1[0]; vec1to3[1] = v3[1] - v1[1]; // Now get the cross product of this sum. triarea = vec1to3[0]*vec1to2[1] - vec1to3[1]*vec1to2[0]; triarea=fabs(triarea); if (triarea <= 1.0) { // Insanely small abhorrent triangle. continue; } step = stage->ss->density * Q_rsqrt(triarea); randomindex = (byte)(v1[0]+v1[1]+v2[0]+v2[1]+v3[0]+v3[1]); randominterval = (byte)(v1[0]+v2[1]+v3[2])|0x03; // Make sure the interval is at least 3, and always odd rightvectorcount = 0; for (posi=0; posi<1.0; posi+=step) { for (posj=0; posj<(1.0-posi); posj+=step) { fa=posi+randomchart[randomindex]*step; randomindex += randominterval; fb=posj+randomchart[randomindex]*step; randomindex += randominterval; rightvectorcount=(rightvectorcount+1)&3; if (fa>1.0) continue; if (fb>(1.0-fa)) continue; fc = 1.0-fa-fb; // total alpha, minus random factor so some things fade out sooner. alphapos = a1*fa + a2*fb + a3*fc; // Note that the alpha at this point is a value from 1.0 to 0.0, but represents when to START fading thisspritesfadestart = faderange + (1.0-faderange) * randomchart[randomindex]; randomindex += randominterval; // Find where the alpha is relative to the fadestart, and calc the real alpha to draw at. alpha = 1.0 - ((thisspritesfadestart-alphapos)/faderange); if (alpha > 0.0) { if (alpha > 1.0) alpha=1.0; if (SSUsingFog) { fogv[0] = fog1[0]*fa + fog2[0]*fb + fog3[0]*fc; fogv[1] = fog1[1]*fa + fog2[1]*fb + fog3[1]*fc; } if (usewindpoint) { winddiffv[0] = winddiff1[0]*fa + winddiff2[0]*fb + winddiff3[0]*fc; winddiffv[1] = winddiff1[1]*fa + winddiff2[1]*fb + winddiff3[1]*fc; windforce = windforce1*fa + windforce2*fb + windforce3*fc; } VectorScale(v1, fa, curpoint); VectorMA(curpoint, fb, v2, curpoint); VectorMA(curpoint, fc, v3, curpoint); light = l1*fa + l2*fb + l3*fc; if (SSAdditiveTransparency) { // Additive transparency, scale light value // light *= alpha; light = (128 + (light*0.5))*alpha; alpha = 1.0; } randomindex2 = randomindex; width = stage->ss->width*(1.0 + (stage->ss->variance[0]*randomchart[randomindex2])); height = stage->ss->height*(1.0 + (stage->ss->variance[1]*randomchart[randomindex2++])); if (randomchart[randomindex2++]>0.5) { width = -width; } if (stage->ss->fadeScale!=0 && alphapos < 1.0) { width *= 1.0 + (stage->ss->fadeScale*(1.0-alphapos)); } if (stage->ss->vertSkew != 0) { // flrand(-vertskew, vertskew) skew[0] = height * ((stage->ss->vertSkew*2.0f*randomchart[randomindex2++])-stage->ss->vertSkew); skew[1] = height * ((stage->ss->vertSkew*2.0f*randomchart[randomindex2++])-stage->ss->vertSkew); } if (usewindpoint && windforce > 0 && stage->ss->wind > 0.0) { if (SSUsingFog) { RB_VerticalSurfaceSpriteWindPoint(curpoint, width, height, (byte)light, (byte)(alpha*255.0), stage->ss->wind, stage->ss->windIdle, fogv, stage->ss->facing, skew, winddiffv, windforce); } else { RB_VerticalSurfaceSpriteWindPoint(curpoint, width, height, (byte)light, (byte)(alpha*255.0), stage->ss->wind, stage->ss->windIdle, NULL, stage->ss->facing, skew, winddiffv, windforce); } } else { if (SSUsingFog) { RB_VerticalSurfaceSprite(curpoint, width, height, (byte)light, (byte)(alpha*255.0), stage->ss->wind, stage->ss->windIdle, fogv, stage->ss->facing, skew); } else { RB_VerticalSurfaceSprite(curpoint, width, height, (byte)light, (byte)(alpha*255.0), stage->ss->wind, stage->ss->windIdle, NULL, stage->ss->facing, skew); } } totalsurfsprites++; } } } } }
static void RB_DrawEffectSurfaceSprites( shaderStage_t *stage, shaderCommands_t *input) { int curindex, curvert; vec3_t dist; float triarea, minnormal; vec2_t vec1to2, vec1to3; vec3_t v1,v2,v3; float a1,a2,a3; float l1,l2,l3; float posi, posj; float step; float fa,fb,fc; float effecttime, effectpos; float density; vec3_t curpoint; float width, height; float alpha, alphapos, thisspritesfadestart, light; byte randomindex2; float cutdist=stage->ss->fadeMax*rangescalefactor, cutdist2=cutdist*cutdist; float fadedist=stage->ss->fadeDist*rangescalefactor, fadedist2=fadedist*fadedist; float fxalpha = stage->ss->fxAlphaEnd - stage->ss->fxAlphaStart; qboolean fadeinout=qfalse; assert(cutdist2 != fadedist2); float inv_fadediff = 1.0/(cutdist2-fadedist2); // The faderange is the fraction amount it takes for these sprites to fade out, assuming an ideal fade range of 250 float faderange = FADE_RANGE/(cutdist-fadedist); if (faderange > 1.0f) { // Don't want to force a new fade_rand faderange = 1.0f; } if (stage->ss->facing) { // Faceup sprite. minnormal = 0.99f; } else { // Normal oriented sprite minnormal = 0.5f; } // Make the object fade in. if (stage->ss->fxAlphaEnd < 0.05 && stage->ss->height >= 0.1 && stage->ss->width >= 0.1) { // The sprite fades out, and it doesn't start at a pinpoint. Let's fade it in. fadeinout=qtrue; } if (stage->ss->surfaceSpriteType == SURFSPRITE_WEATHERFX) { // This effect is affected by weather settings. if (curWeatherAmount < 0.01) { // Don't show these effects return; } else { density = stage->ss->density / curWeatherAmount; } } else { density = stage->ss->density; } // Quickly calc all the alphas for each vertex for (curvert=0; curvert<input->numVertexes; curvert++) { // Calc alpha at each point VectorSubtract(ssViewOrigin, input->xyz[curvert], dist); SSVertAlpha[curvert] = 1.0f - (VectorLengthSquared(dist) - fadedist2) * inv_fadediff; // Note this is the proper equation, but isn't used right now because it would be just a tad slower. // Formula for alpha is 1.0f - ((len-fade)/(cut-fade)) // Which is equal to (1.0+fade/(cut-fade)) - (len/(cut-fade)) // So mult=1/(cut-fade), and base=(1+fade*mult). // SSVertAlpha[curvert] = fadebase - (VectorLength(dist) * fademult); } for (curindex=0; curindex<input->numIndexes-2; curindex+=3) { curvert = input->indexes[curindex]; VectorCopy(input->xyz[curvert], v1); if (input->normal[curvert][2] < minnormal) { continue; } l1 = input->vertexColors[curvert][2]; a1 = SSVertAlpha[curvert]; curvert = input->indexes[curindex+1]; VectorCopy(input->xyz[curvert], v2); if (input->normal[curvert][2] < minnormal) { continue; } l2 = input->vertexColors[curvert][2]; a2 = SSVertAlpha[curvert]; curvert = input->indexes[curindex+2]; VectorCopy(input->xyz[curvert], v3); if (input->normal[curvert][2] < minnormal) { continue; } l3 = input->vertexColors[curvert][2]; a3 = SSVertAlpha[curvert]; if (a1 <= 0.0f && a2 <= 0.0f && a3 <= 0.0f) { continue; } // Find the area in order to calculate the stepsize vec1to2[0] = v2[0] - v1[0]; vec1to2[1] = v2[1] - v1[1]; vec1to3[0] = v3[0] - v1[0]; vec1to3[1] = v3[1] - v1[1]; // Now get the cross product of this sum. triarea = vec1to3[0]*vec1to2[1] - vec1to3[1]*vec1to2[0]; triarea=fabs(triarea); if (triarea <= 1.0f) { // Insanely small abhorrent triangle. continue; } step = density * Q_rsqrt(triarea); randomindex = (byte)(v1[0]+v1[1]+v2[0]+v2[1]+v3[0]+v3[1]); randominterval = (byte)(v1[0]+v2[1]+v3[2])|0x03; // Make sure the interval is at least 3, and always odd for (posi=0; posi<1.0f; posi+=step) { for (posj=0; posj<(1.0-posi); posj+=step) { effecttime = (tr.refdef.time+10000.0*randomchart[randomindex])/stage->ss->fxDuration; effectpos = (float)effecttime - (int)effecttime; randomindex2 = randomindex+effecttime; randomindex += randominterval; fa=posi+randomchart[randomindex2++]*step; if (fa>1.0f) continue; fb=posj+randomchart[randomindex2++]*step; if (fb>(1.0-fa)) continue; fc = 1.0-fa-fb; // total alpha, minus random factor so some things fade out sooner. alphapos = a1*fa + a2*fb + a3*fc; // Note that the alpha at this point is a value from 1.0f to 0.0, but represents when to START fading thisspritesfadestart = faderange + (1.0-faderange) * randomchart[randomindex2]; randomindex2 += randominterval; // Find where the alpha is relative to the fadestart, and calc the real alpha to draw at. alpha = 1.0f - ((thisspritesfadestart-alphapos)/faderange); if (alpha > 0.0f) { if (alpha > 1.0f) alpha=1.0f; VectorScale(v1, fa, curpoint); VectorMA(curpoint, fb, v2, curpoint); VectorMA(curpoint, fc, v3, curpoint); light = l1*fa + l2*fb + l3*fc; randomindex2 = randomindex; width = stage->ss->width*(1.0f + (stage->ss->variance[0]*randomchart[randomindex2])); height = stage->ss->height*(1.0f + (stage->ss->variance[1]*randomchart[randomindex2++])); width = width + (effectpos*stage->ss->fxGrow[0]*width); height = height + (effectpos*stage->ss->fxGrow[1]*height); // If we want to fade in and out, that's different than a straight fade. if (fadeinout) { if (effectpos > 0.5) { // Fade out alpha = alpha*(stage->ss->fxAlphaStart+(fxalpha*(effectpos-0.5)*2.0)); } else { // Fade in alpha = alpha*(stage->ss->fxAlphaStart+(fxalpha*(0.5-effectpos)*2.0)); } } else { // Normal fade alpha = alpha*(stage->ss->fxAlphaStart+(fxalpha*effectpos)); } if (SSAdditiveTransparency) { // Additive transparency, scale light value // light *= alpha; light = (128 + (light*0.5))*alpha; alpha = 1.0; } if (randomchart[randomindex2]>0.5f) { width = -width; } if (stage->ss->fadeScale!=0 && alphapos < 1.0f) { width *= 1.0f + (stage->ss->fadeScale*(1.0-alphapos)); } if (stage->ss->wind>0.0f && curWindSpeed > 0.001) { vec3_t drawpoint; VectorMA(curpoint, effectpos*stage->ss->wind, curWindBlowVect, drawpoint); RB_EffectSurfaceSprite(drawpoint, width, height, (byte)light, (byte)(alpha*255.0f), stage->ss->fxDuration, stage->ss->facing); } else { RB_EffectSurfaceSprite(curpoint, width, height, (byte)light, (byte)(alpha*255.0f), stage->ss->fxDuration, stage->ss->facing); } totalsurfsprites++; } } } } }
void engine_move_actors (Context* context) { static int ticks = ANIM_LEN; Player* player = context->engine->player; if (player->v_buf->v == NULL) { return; } if ( player->target_x < 0 || ( player->target_x == *player->x && player->target_y == *player->y ) ) { player->anim = 0; player->v_buf->v->bitmap = player->anims[0]; return; } Fixed vector_x = player->vector_x; Fixed vector_y = player->vector_y; if (player->recalculate) { vector_x = FIXED_FROM_INT(player->target_x) - player->real_x; vector_y = FIXED_FROM_INT(player->target_y) - player->real_y; Fixed dist = FIXED_FROM_FLOAT( Q_rsqrt( FIXED_TO_FLOAT( FIXED_MUL(vector_x, vector_x) + FIXED_MUL(vector_y, vector_y) ) ) ); vector_x = FIXED_MUL(vector_x, dist); vector_y = FIXED_MUL(vector_y, dist); player->vector_x = vector_x; player->vector_y = vector_y; player->recalculate = 0; } player->real_x += FIXED_MUL(vector_x, FIXED_FROM_INT(PLAYER_SPEED)); player->real_y += FIXED_MUL(vector_y, FIXED_FROM_INT(PLAYER_SPEED)); if (ticks >= ANIM_LEN) { ticks = 0; player->anim++; if (vector_x > 0 && player->anim > 2) { player->anim = 2; } else if (vector_x < 0 && player->anim > 4) { player->anim = 4; } else if (vector_x < 0 && player->anim < 3) { player->anim = 3; } player->v_buf->v->bitmap = player->anims[player->anim]; } if ( (vector_x > 0 && FIXED_TO_FLOAT(player->real_x) >= player->target_x) || (vector_x <= 0 && FIXED_TO_FLOAT(player->real_x) < player->target_x) ) { player->real_x = FIXED_FROM_INT(player->target_x); player->v_buf->v->bitmap = player->anims[0]; player->anim = 0; } if ( (vector_y > 0 && FIXED_TO_FLOAT(player->real_y) > player->target_y) || (vector_y < 0 && FIXED_TO_FLOAT(player->real_y) < player->target_y) ) { player->real_y = FIXED_FROM_INT(player->target_y); } *player->x = FIXED_TO_INT(player->real_x); *player->y = FIXED_TO_INT(player->real_y); engine_update_box(player, context->engine); ticks++; }