SpriteFrameCache Class Reference

#include <spritecache.h>

Collaboration diagram for SpriteFrameCache:

Collaboration graph
[legend]
List of all members.

Public Member Functions

Surface GetFlippedSurfaceForAngle (double angle) const
Surface GetSurfaceForAngle (double angle) const
 SpriteFrameCache ()
void CreateRotationCache (Surface &surface, unsigned int cache_size)
void CreateFlippingCache (Surface &surface)

Public Attributes

Surface flipped_surface

Private Attributes

bool use_rotation
std::vector< Surfacerotated_surface
std::vector< Surfacerotated_flipped_surface

Detailed Description

Definition at line 34 of file spritecache.h.


Constructor & Destructor Documentation

SpriteFrameCache::SpriteFrameCache (  ) 

Definition at line 30 of file spritecache.cpp.

00030                                    {
00031   use_rotation = false;
00032 }


Member Function Documentation

void SpriteFrameCache::CreateFlippingCache ( Surface surface  ) 

Definition at line 68 of file spritecache.cpp.

00069 {
00070   assert (flipped_surface.IsNull());
00071   flipped_surface = surface.RotoZoom( 0.0, -1.0, 1.0, SMOOTHING_OFF);
00072   if (use_rotation)
00073   {
00074     assert (rotated_surface.size() != 0);
00075     assert (rotated_flipped_surface.size() == 0);
00076     rotated_flipped_surface.push_back( flipped_surface );
00077     const unsigned int n = rotated_surface.size();
00078     for(unsigned int i=1 ; i<n; i++)
00079     {
00080       double angle = 2 * M_PI * (1 - (float) i / (float) n);
00081       rotated_flipped_surface.push_back( surface.RotoZoom(angle, -1.0, 1.0, SMOOTHING_ON) );
00082     }
00083   }
00084 }

Here is the call graph for this function:

void SpriteFrameCache::CreateRotationCache ( Surface surface,
unsigned int  cache_size 
)

Definition at line 34 of file spritecache.cpp.

00034                                                                                    {
00035   assert (use_rotation == false);
00036   use_rotation = true;
00037 
00038   rotated_surface.push_back( surface );
00039   for(unsigned int i=1 ; i< cache_size ; i++){
00040     double angle = 2* M_PI * (1 /* to inverte rotation angle */ - static_cast<double>(i) / static_cast<double>(cache_size));
00041     rotated_surface.push_back( surface.RotoZoom(angle, 1.0, 1.0, SMOOTHING_ON) );
00042   }
00043 }

Here is the call graph for this function:

Surface SpriteFrameCache::GetFlippedSurfaceForAngle ( double  angle  )  const

Definition at line 45 of file spritecache.cpp.

00046 {
00047   double angle_tmp = angle;
00048   while(angle_tmp >= 2 * M_PI)
00049     angle_tmp -= 2 * M_PI;
00050   while(angle_tmp < 0.0)
00051     angle_tmp += 2 * M_PI;
00052   int index = static_cast<uint>(angle_tmp*static_cast<double>(rotated_flipped_surface.size()) / (2*M_PI));
00053   return rotated_flipped_surface[index];
00054 }

Surface SpriteFrameCache::GetSurfaceForAngle ( double  angle  )  const

Definition at line 56 of file spritecache.cpp.

00057 {
00058   double angle_tmp = angle;
00059   while(angle_tmp >= 2 * M_PI)
00060     angle_tmp -= 2 * M_PI;
00061   while(angle_tmp < 0.0)
00062     angle_tmp += 2 * M_PI;
00063 
00064   int index = static_cast<uint>(angle_tmp*static_cast<double>(rotated_surface.size()) / (2*M_PI));
00065   return rotated_surface[index];
00066 }


Member Data Documentation

Surface SpriteFrameCache::flipped_surface

Definition at line 41 of file spritecache.h.

std::vector<Surface> SpriteFrameCache::rotated_flipped_surface [private]

Definition at line 38 of file spritecache.h.

std::vector<Surface> SpriteFrameCache::rotated_surface [private]

Definition at line 37 of file spritecache.h.

bool SpriteFrameCache::use_rotation [private]

Definition at line 36 of file spritecache.h.


The documentation for this class was generated from the following files:
Generated on Mon Jan 1 14:18:32 2007 for Wormux by  doxygen 1.4.7