Google
Web alhem.net
Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Grid Class Reference

#include <Grid.h>

List of all members.

Public Member Functions

 Grid ()
 ~Grid ()
void ReCalculate ()
void SetSize (int, int)
void SetBase (int)
void SetDirection (Event::Facing *)
void SetPosition (Event::Position *)
int GetBase ()
int GetWidth ()
int GetHeight ()
void GetXY (int x, int y, int *cx, int *cy, int *elevation)
int GetHBase ()
double Sin (int)

Private Attributes

int m_x
int m_y
int m_base
int m_hbase
int m_left
int m_right
int m_top
int m_bottom
int m_w
int m_h
double m_sin [360]
int m_riktning
int m_xpos
int m_ypos


Detailed Description

File ......... Grid.h Published .... 2005-02-07 Author ....... grymse@alhem.net

Definition at line 30 of file Grid.h.


Constructor & Destructor Documentation

Grid::Grid  ) 
 

File ......... Grid.cpp Published .... 2005-02-07 Author ....... grymse@alhem.net

Definition at line 34 of file Grid.cpp.

References m_sin, and ReCalculate().

00035 :m_x(640) 00036 ,m_y(480) 00037 ,m_base(40) 00038 ,m_hbase( (int)(cos(2 * M_PI * 30 / 360) * (double)m_base) ) 00039 ,m_left(0) 00040 ,m_right(0) 00041 ,m_top(0) 00042 ,m_bottom(0) 00043 ,m_w(0) 00044 ,m_h(0) 00045 ,m_riktning(-1) 00046 ,m_xpos(-1) 00047 ,m_ypos(-1) 00048 { 00049 ReCalculate(); 00050 for (double d = 0; d < 360; d++) 00051 { 00052 m_sin[(int)d] = sin(2 * M_PI * d / 360); 00053 } 00054 }

Grid::~Grid  ) 
 

Definition at line 57 of file Grid.cpp.

00058 { 00059 }


Member Function Documentation

int Grid::GetBase  ) 
 

Definition at line 122 of file Grid.cpp.

References m_base.

Referenced by MainWindow::DecreaseBase(), MainWindow::Draw(), and MainWindow::IncreaseBase().

00123 { 00124 return m_base; 00125 }

int Grid::GetHBase  ) 
 

Definition at line 178 of file Grid.cpp.

References m_hbase.

Referenced by MainWindow::Draw().

00179 { 00180 return m_hbase; 00181 }

int Grid::GetHeight  ) 
 

Definition at line 134 of file Grid.cpp.

References m_h.

Referenced by MainWindow::Draw().

00135 { 00136 return m_h; 00137 }

int Grid::GetWidth  ) 
 

Definition at line 128 of file Grid.cpp.

References m_w.

Referenced by MainWindow::Draw().

00129 { 00130 return m_w; 00131 }

void Grid::GetXY int  x,
int  y,
int *  cx,
int *  cy,
int *  elevation
 

Definition at line 140 of file Grid.cpp.

References GetXY(), m_base, m_hbase, m_x, m_y, and mandel_color().

Referenced by MainWindow::Draw(), and GetXY().

00141 { 00142 // center is at [0,0] 00143 // 00144 // 0,0 1,0 2,0 3,0 00145 // 0,1 1,1 2,1 3,1 00146 // 0,2 1,2 2,2 3,2 00147 // 0,3 1,3 2,3 3,3 00148 // 00149 00150 *cx = m_x / 2 + x * m_base; 00151 if (y % 2) 00152 { 00153 *cx = *cx + m_base / 2; 00154 } 00155 *cy = m_y / 2 + y * m_hbase; 00156 00157 // hojdjustering 00158 /* 00159 *elevation = 0; 00160 double dist = sqrt(x * x + y * y); 00161 if (!x && !y) 00162 { 00163 *elevation = -20; 00164 } 00165 if ((x == 2 || x == 3) && (y == 2 || y == 3)) 00166 { 00167 *elevation = 10; 00168 } 00169 if (dist > 4) 00170 { 00171 *elevation = -dist * 2; 00172 } 00173 */ 00174 *elevation = mandel_color(x,y); 00175 }

void Grid::ReCalculate  ) 
 

Definition at line 62 of file Grid.cpp.

References DEB, m_base, m_bottom, m_h, m_hbase, m_left, m_right, m_top, m_w, m_x, m_y, and MAX_ELEVATION.

Referenced by Grid(), SetBase(), and SetSize().

00063 { 00064 double hstep = cos(2 * M_PI * 30 / 360); 00065 00066 DEB( 00067 for (double h = 0; h <= 180; h += 45) 00068 { 00069 printf("cos(%.0f) = %f\n", h, cos(2 * M_PI * h / 360)); 00070 printf("sin(%.0f) = %f\n", h, sin(2 * M_PI * h / 360)); 00071 }) 00072 m_hbase = (int)(hstep * (double)m_base); 00073 00074 m_w = ((m_x - m_base/2) / 2) / m_base; 00075 m_w = m_w * 2 + 1; 00076 00077 m_h = (m_y / 2) / m_hbase; 00078 m_h = m_h * 2 + 1; 00079 00080 while (m_x / 2 + m_left * m_base >= 0) 00081 { 00082 m_left--; 00083 } 00084 while (m_x / 2 + m_right * m_base < m_x) 00085 { 00086 m_right++; 00087 } 00088 #define MAX_ELEVATION 255 00089 while (m_y / 2 + m_top * m_hbase >= 0 - MAX_ELEVATION) 00090 { 00091 m_top--; 00092 } 00093 while (m_y / 2 + m_bottom * m_hbase < m_y + MAX_ELEVATION) 00094 { 00095 m_bottom++; 00096 } 00097 DEB( 00098 printf("Resolution %d x %d with a base of %d gives\n",m_x,m_y,m_base); 00099 printf(" base = %d\n",m_hbase); 00100 printf(" width = %d\n",m_w); 00101 printf(" height = %d\n",m_h); 00102 printf(" X %d..%d\n",m_left,m_right); 00103 printf(" Y %d..%d\n",m_top,m_bottom);) 00104 }

void Grid::SetBase int   ) 
 

Definition at line 115 of file Grid.cpp.

References m_base, ReCalculate(), and SetBase().

Referenced by MainWindow::DecreaseBase(), MainWindow::IncreaseBase(), MainWindow::MainWindow(), and SetBase().

00116 { 00117 m_base = b; 00118 ReCalculate(); 00119 }

void Grid::SetDirection Event::Facing *   ) 
 

Definition at line 190 of file Grid.cpp.

References m_riktning, and SetDirection().

Referenced by SetDirection().

00191 { 00192 m_riktning = e -> GetRiktning(); 00193 }

void Grid::SetPosition Event::Position *   ) 
 

Definition at line 196 of file Grid.cpp.

References m_xpos, m_ypos, and SetPosition().

Referenced by SetPosition().

00197 { 00198 m_xpos = e -> GetX(); 00199 m_ypos = e -> GetY(); 00200 }

void Grid::SetSize int  ,
int 
 

Definition at line 107 of file Grid.cpp.

References m_x, m_y, ReCalculate(), and SetSize().

Referenced by MainWindow::MainWindow(), and SetSize().

00108 { 00109 m_x = x; 00110 m_y = y; 00111 ReCalculate(); 00112 }

double Grid::Sin int   ) 
 

Definition at line 184 of file Grid.cpp.

References m_sin, and Sin().

Referenced by MainWindow::Draw(), and Sin().

00185 { 00186 return m_sin[x % 360]; 00187 }


Member Data Documentation

int Grid::m_base [private]
 

Definition at line 53 of file Grid.h.

Referenced by GetBase(), GetXY(), ReCalculate(), and SetBase().

int Grid::m_bottom [private]
 

Definition at line 58 of file Grid.h.

Referenced by ReCalculate().

int Grid::m_h [private]
 

Definition at line 60 of file Grid.h.

Referenced by GetHeight(), and ReCalculate().

int Grid::m_hbase [private]
 

Definition at line 54 of file Grid.h.

Referenced by GetHBase(), GetXY(), and ReCalculate().

int Grid::m_left [private]
 

Definition at line 55 of file Grid.h.

Referenced by ReCalculate().

int Grid::m_right [private]
 

Definition at line 56 of file Grid.h.

Referenced by ReCalculate().

int Grid::m_riktning [private]
 

Definition at line 62 of file Grid.h.

Referenced by SetDirection().

double Grid::m_sin[360] [private]
 

Definition at line 61 of file Grid.h.

Referenced by Grid(), and Sin().

int Grid::m_top [private]
 

Definition at line 57 of file Grid.h.

Referenced by ReCalculate().

int Grid::m_w [private]
 

Definition at line 59 of file Grid.h.

Referenced by GetWidth(), and ReCalculate().

int Grid::m_x [private]
 

Definition at line 51 of file Grid.h.

Referenced by GetXY(), ReCalculate(), and SetSize().

int Grid::m_xpos [private]
 

Definition at line 63 of file Grid.h.

Referenced by SetPosition().

int Grid::m_y [private]
 

Definition at line 52 of file Grid.h.

Referenced by GetXY(), ReCalculate(), and SetSize().

int Grid::m_ypos [private]
 

Definition at line 64 of file Grid.h.

Referenced by SetPosition().


The documentation for this class was generated from the following files:
Generated for SDL C++ GUI by doxygen 1.3.6