src/graphic/effects.h File Reference

#include <SDL.h>
#include "sprite.h"

Include dependency graph for effects.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

SpriteWaveSurface (Surface &a, unsigned int nbr_frames, unsigned int duration, float wave_amp, float wave_per)
void Rebound (Sprite *spr, int &y, uint t0, uint per, int dy_max)
void Gelatine (int &y, int &stretch_y, uint t0, uint amp, uint dur, uint per)


Function Documentation

void Gelatine ( int &  y,
int &  stretch_y,
uint  t0,
uint  amp,
uint  dur,
uint  per 
)

Definition at line 104 of file effects.cpp.

00105 {
00106   uint dt = Time::GetInstance()->Read() - t0;
00107   if(dt >= dur)
00108   {
00109     y = 0;
00110     stretch_y = 0;
00111     return;
00112   }
00113 
00114   //Amplitude decrease linearly with time
00115   amp = amp * (dur - dt) / dur;
00116 
00117   //Scale
00118   stretch_y = (int)(sin((float)per * (float)dt * 2.0 * M_PI / (float)dur) * (float)amp);
00119 
00120   //Offset
00121   if(stretch_y < 0.0)
00122   {
00123     y = stretch_y;
00124     stretch_y = -stretch_y;
00125   }
00126   else
00127   {
00128     y = 0;
00129   }
00130 }

Here is the call graph for this function:

void Rebound ( Sprite spr,
int &  y,
uint  t0,
uint  per,
int  dy_max 
)

Definition at line 70 of file effects.cpp.

00071 {
00072   float scale_x, scale_y;
00073   int spr_w, spr_h;
00074   uint dt = (Time::GetInstance()->Read() - t0) % per;
00075 
00076   spr->Scale(1.0,1.0);
00077   spr_w = spr->GetWidth();
00078   spr_h = spr->GetHeight();
00079   dy = 0;
00080 
00081   //sprite at bottom:
00082   if( dt < per / 4 )
00083   {
00084     float dt2 = ((per / 4) - dt) / ((float)per / 4.0);    
00085     scale_y =        2.0*dt2*dt2 - 2.0*dt2 + 1.0;
00086     scale_x = 2.0 - (2.0*dt2*dt2 - 2.0*dt2 + 1.0);
00087     dy = 0;
00088     spr->Scale(scale_x,scale_y);
00089     return;
00090   }
00091 
00092   dt -= per/4;
00093   float dt2 = ((3*per/4)-dt)/(3.0*per/4.0);
00094   dy += (int)((-4.0*dt2*dt2 + 4.0*dt2) * dy_max);
00095 }

Here is the call graph for this function:

Here is the caller graph for this function:

Sprite* WaveSurface ( Surface a,
unsigned int  nbr_frames,
unsigned int  duration,
float  wave_amp,
float  wave_per 
)

Definition at line 34 of file effects.cpp.

00034                                                                                                                {
00035         Sprite* sprite = new Sprite;
00036         Point2i newSize = a.GetSize() + Point2i(2 * (int)wave_amp, 0);
00037         
00038     sprite->SetSize(newSize);
00039         for(unsigned int f=0; f < nbr_frames; f++){
00040                 Surface b(newSize, SDL_SWSURFACE|SDL_SRCALPHA );
00041                 b.Fill(0x00000000);
00042                 b.SetAlpha(SDL_SRCALPHA, 0);
00043                 a.Lock();
00044                 b.Lock();
00045                 for(int x = 0; x < a.GetWidth(); x++){
00046                         for(int y = 0; y < a.GetHeight(); y++){
00047                                 Uint32 col = a.GetPixel(x, y);
00048                                 Uint8 r, g, bl, al;
00049                                 a.GetRGBA(col, r, g, bl, al);
00050                                 col = b.MapRGBA(r, g, bl, al);
00051 
00052                                 float t = (float)nbr_frames * sin(M_PI*(float)f/(float)nbr_frames);
00053                                 unsigned int wave_x = (unsigned int)(x+(wave_amp*(1+sin(((float)t*wave_per*2.0*M_PI/(float)nbr_frames)*(float)y*2.0*M_PI/(float)a.GetHeight()))));
00054                                 b.PutPixel(wave_x, y, col);
00055                         }
00056                 }
00057                 a.Unlock();
00058                 b.Unlock();     
00059 
00060                 sprite->AddFrame(b, duration / nbr_frames);
00061         }
00062         return sprite;
00063 }

Here is the call graph for this function:


Generated on Mon Jan 1 13:13:19 2007 for Wormux by  doxygen 1.4.7