void CalcPixels2(double Edges[3][2], int **Pixels, int *counter) { int i; double minX=10000000,maxX=-10000000,minY=100000000,maxY=-100000000; for (i=0;i<3;i++){ Edges[i][0] = round(Edges[i][0]); Edges[i][1] = round(Edges[i][1]); } for (i=0;i<3;i++){ if (Edges[i][0]<minX){ minX = Edges[i][0]; } if (Edges[i][0]>maxX){ maxX = Edges[i][0]; } if (Edges[i][1]<minY){ minY = Edges[i][1]; } if (Edges[i][1]>maxY){ maxY = Edges[i][1]; } } *counter = 0; int A01 = Edges[0][1] - Edges[1][1], B01 = Edges[1][0] - Edges[0][0]; int A12 = Edges[1][1] - Edges[2][1], B12 = Edges[2][0] - Edges[1][0]; int A20 = Edges[2][1] - Edges[0][1], B20 = Edges[0][0] - Edges[2][0]; struct Point2D p = { minX, minY }; struct Point2D v0 = { Edges[0][0], Edges[0][1]}; struct Point2D v1 = { Edges[1][0], Edges[1][1]}; struct Point2D v2 = { Edges[2][0], Edges[2][1]}; int w0_row = orient2d(v1, v2, p); int w1_row = orient2d(v2, v0, p); int w2_row = orient2d(v0, v1, p); for (p.y = minY; p.y <= maxY; p.y++) { int w0 = w0_row; int w1 = w1_row; int w2 = w2_row; for (p.x = minX; p.x <= maxX; p.x++) { if (w0 >= 0 && w1 >= 0 && w2 >= 0){ Pixels[*counter][0] = p.x; Pixels[*counter][1] = p.y; *counter+=1; } else if(len2d(v1,v2,p)<0.99){ Pixels[*counter][0] = p.x; Pixels[*counter][1] = p.y; *counter+=1; } else if(len2d(v2,v0,p)<0.99){ Pixels[*counter][0] = p.x; Pixels[*counter][1] = p.y; *counter+=1; } else if(len2d(v0,v1,p)<0.99){ Pixels[*counter][0] = p.x; Pixels[*counter][1] = p.y; *counter+=1; } w0 += A12; w1 += A20; w2 += A01; } w0_row += B12; w1_row += B20; w2_row += B01; } }
//! Affects an array of particles. void CParticlePushAffector::affect(u32 now, SParticle* particlearray, u32 count) { // if this is the first time the affector has been executed if( LastTime == 0 ) { // just record the time and return as we cannot calculate a delta LastTime = now; return; } // calculate the time delta based on the amount of time that has passed between frames f32 timeDelta = ( now - LastTime ) / 1000.0f; // record the time so we can calculate the next delta LastTime = now; // if this affector is disabled we have nothing to do if (!Enabled) return; // itterate all of the particles for(u32 i=0; i<count; ++i) { /* calculate the direction of effect ( even if this is a distant effect we still need this to calculate the strength of the effect */ core::vector3df direction = particlearray[i].pos - CenterOfEffect; f32 distance = direction.getLength() - NearestDistanceOfEffect; // if we are within the field of effect if (( distance >= 0.0f ) && ( distance < FurthestDistanceOfEffect )) { f32 strength; core::vector3df AppliedStrengthOfEffect = StrengthOfEffect; /* if this is a torus effect then its X, Z effect is modulated between the distant and near */ // if there is no near distance if ( NearestDistanceOfEffect == 0.0f ) { /* calculate the strength based on the distance from the center of the effect and the amount of time that has passed */ strength = timeDelta * (1.0f - ( distance / FurthestDistanceOfEffect )); } else { /* calculate the strength based on the halfway distance between the near and far distance from the center of the effect and the amount of time that has passed */ strength = timeDelta * (1.0f - ( fabs(distance * 2.0f - FurthestDistanceOfEffect ) / FurthestDistanceOfEffect )); } // if there is a column distance if ( ColumnDistanceOfEffect != 0.0f ) { core::vector2df len2d( fabs( direction.X ), fabs( direction.Z )); strength *= ( ColumnDistanceOfEffect - len2d.getLength()) / ColumnDistanceOfEffect; } // if this is a distant effect if ( !DistantEffect ) { // all particles are affected in the same way particlearray[i].pos += AppliedStrengthOfEffect * strength; } else { // particles are affected individually dependant on their relation to the center of effect particlearray[i].pos += direction.normalize() * AppliedStrengthOfEffect * strength; } } } }