Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

WavyPicture.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net)
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  */
00009 #include "WavyPicture.h"
00010 
00011 #include "TimerAgent.h"
00012 
00013 #include <math.h>
00014 
00015 //-----------------------------------------------------------------
00016 /**
00017  * Load surface.
00018  * Default is no waves.
00019  */
00020 WavyPicture::WavyPicture(const Path &file, const V2 &loc)
00021     : Picture(file, loc)
00022 {
00023     m_amp = 0;
00024     m_periode = m_surface->w;
00025     m_speed = 0;
00026 }
00027 //-----------------------------------------------------------------
00028 /**
00029  * Blit entire surface to [x,y].
00030  * Do vertical waves with phase shift.
00031  */
00032 void
00033 WavyPicture::drawOn(SDL_Surface *screen)
00034 {
00035     if (m_amp == 0) {
00036         Picture::drawOn(screen);
00037         return;
00038     }
00039 
00040     //NOTE: Wamp = Wamp_in_orig/2.0
00041     //NOTE: Wspeed = 1.0/Wspd_in_orig
00042     SDL_Rect dest_rect;
00043     SDL_Rect line_rect;
00044     line_rect.w = m_surface->w;
00045     line_rect.h = 1;
00046     SDL_Rect pad;
00047     pad.h = 1;
00048 
00049     float shift = TimerAgent::agent()->getCycles() * m_speed;
00050 
00051     for (int py = 0; py < m_surface->h; ++py) {
00052         //NOTE: C99 has lrintf and sinf
00053         Sint16 shiftX = static_cast<Sint16>(0.5 +
00054                 m_amp * sin(py / m_periode + shift));
00055         line_rect.x = shiftX;
00056         line_rect.y = py;
00057         dest_rect.x = m_loc.getX();
00058         dest_rect.y = m_loc.getY() + py;
00059         SDL_BlitSurface(m_surface, &line_rect, screen, &dest_rect);
00060 
00061         pad.x = (shiftX < 0) ? 0 : m_surface->w - shiftX;
00062         pad.y = py;
00063         pad.w = abs(shiftX);
00064         dest_rect.x = m_loc.getX() + pad.x;
00065         dest_rect.y = m_loc.getY() + py;
00066         SDL_BlitSurface(m_surface, &pad, screen, &dest_rect);
00067     }
00068 }
00069 
00070 

Generated on Wed Jun 1 09:54:32 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2