commit:ed537b5851e68c5730dab4c0d93421a66e6726e1
author:Chip Black
committer:Chip Black
date:Thu May 19 02:01:11 2011 -0500
parents:bdad36145ef42f2a44b58cc544846b4b34a6ca4f
Fix hard-coded screen size; increase number of pixels.
diff --git a/src/Pixel.cpp b/src/Pixel.cpp
line changes: +3/-3
index 5a27aee..5bb9ed0
--- a/src/Pixel.cpp
+++ b/src/Pixel.cpp
@@ -3,9 +3,9 @@
 #include <GLES/gl.h>
 #include "SDL.h"
 
-Pixel::Pixel(void) {
-	this->x = (rand() / (float)RAND_MAX) * 320.0;
-	this->y = (rand() / (float)RAND_MAX) * 400.0;
+Pixel::Pixel(SDL_Surface* screen) {
+	this->x = (rand() / (float)RAND_MAX) * screen->w;
+	this->y = (rand() / (float)RAND_MAX) * screen->h;
 	this->vx = (rand() / (float)RAND_MAX) * 10.0 - 5.0;
 	this->vy = (rand() / (float)RAND_MAX) * 10.0 - 5.0;
 	this->lastupdate = SDL_GetTicks();

diff --git a/src/Pixel.h b/src/Pixel.h
line changes: +1/-1
index 932b009..e5705c4
--- a/src/Pixel.h
+++ b/src/Pixel.h
@@ -10,7 +10,7 @@ public:
 	float x, y;
 	float vx, vy;
 
-	Pixel(void);
+	Pixel(SDL_Surface* screen);
 	~Pixel(void);
 	void accel(float x, float y);
 	void update();

diff --git a/src/swarm.cpp b/src/swarm.cpp
line changes: +10/-18
index 78d5133..a990927
--- a/src/swarm.cpp
+++ b/src/swarm.cpp
@@ -5,7 +5,10 @@
 #include "SDL.h"
 #include "PDL.h"
 #include "Pixel.h"
-#define NPIXELS 2000
+
+#define NPIXELS 2500
+#define SCREENW 320
+#define SCREENH 480
 
 SDL_Surface* screen;               // Screen surface
 Uint16 mx, my;
@@ -28,7 +31,7 @@ void init() {
 	glClearColor(0.5f, 0.5f, 0.5f, 0.0f);
 	glMatrixMode(GL_PROJECTION);
 	glLoadIdentity();
-	glOrthof(0.0f, 320.0f, 400.0f, 0.0f, -1.0f, 1.0f);
+	glOrthof(0.0f, (float)screen->w, (float)screen->h, 0.0f, -1.0f, 1.0f);
 	glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
 
 	// Initialize vertices
@@ -38,13 +41,13 @@ void init() {
 	glVertexPointer(3, GL_FLOAT, 0, vertices);
 
 	// Center cursor
-	mx = 160;
-	my = 200;
+	mx = screen->w / 2;
+	my = screen->h / 2;
 
 	// Initialize pixel objects
 	pixels = new Pixel*[NPIXELS];
 	for (int x = 0; x < NPIXELS; x++) {
-		pixels[x] = new Pixel();
+		pixels[x] = new Pixel(screen);
 	}
 
 }
@@ -120,12 +123,13 @@ int main(int argc, char** argv)
     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
 
     // Set the video mode to full screen with OpenGL-ES support
-    screen = SDL_SetVideoMode(320, 400, 0, SDL_OPENGL);
+    screen = SDL_SetVideoMode(SCREENW, SCREENH, 0, SDL_OPENGL);
     if (!screen) {
 		printf("Could not initialize video!\n");
 		exit(1);
     }
     printf("width: %d, height, %d\n", screen->w, screen->h);
+	printf("Starting up with %d pixels\n", NPIXELS);
 
 #if WIN32
     // Load the desktop OpenGL-ES emulation library
@@ -146,18 +150,6 @@ int main(int argc, char** argv)
 			SDL_WaitEvent(NULL);
         while (SDL_PollEvent(&Event)) {
             switch (Event.type) {
-                // List of keys that have been pressed
-                case SDL_KEYDOWN:
-                    switch (Event.key.keysym.sym) {
-                        // Escape forces us to quit the app
-                        // this is also sent when the user makes a back gesture
-                        case SDLK_ESCAPE:
-                            Event.type = SDL_QUIT;
-                            break;
-                        default:
-                            break;
-                    }
-                    break;
 				case SDL_MOUSEMOTION:
 					mx = Event.motion.x;
 					my = Event.motion.y;