changeset 2:3e543e31b6eb

adjustment main_GL.cbc
author kent
date Fri, 30 May 2008 00:29:56 +0900
parents 09e774f4433f
children 01290d71ef9c
files main_GL.cbc
diffstat 1 files changed, 26 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/main_GL.cbc	Fri May 30 00:00:49 2008 +0900
+++ b/main_GL.cbc	Fri May 30 00:29:56 2008 +0900
@@ -8,7 +8,8 @@
 #include<OpenGL/glu.h>
 
 #define DEBUGlog(f, args...) \
-	fprintf(stderr, "in %s: "f, __FUNCTION__, ## args)
+	;
+	//fprintf(stderr, "in %s: "f, __FUNCTION__, ## args)
 
 #define W_HEIGHT 480
 #define W_WIDTH 640
@@ -29,6 +30,7 @@
 
 /* for OpenGL Utility.  */
 GLUquadricObj **sphere;
+float DefDistance = 300.0f;
 
 typedef struct
 {
@@ -53,6 +55,7 @@
 __code moveCenter(int count, SDL_Surface *screen, int num);
 __code CenteringVelocity(int count, SDL_Surface *screen, int num);
 __code drawStars(int count, SDL_Surface *screen, int num);
+__code AdjustLooking(float distance, int count, SDL_Surface *screen, int num);
 
 int main(int argc, char **argv)
 {
@@ -191,8 +194,6 @@
 
 	for( i=0; i<num; i++){
 		stars_new[i].weight = stars_old[i].weight;
-		//stars_new[i].rect.h = 5, stars_new[i].rect.w = 5;
-		//stars_old[i].rect.h = 5, stars_old[i].rect.w = 5;
 	}
 
 	goto loop(0, screen, num);
@@ -202,6 +203,7 @@
 {
 	SDL_Event event;
 
+	usleep(80);
 	/* check SDL event.  */
 	while(SDL_PollEvent(&event)){ //Poll events
 		switch(event.type){ //Check event type
@@ -212,16 +214,20 @@
 				//SDL_HWSURFACE | SDL_RESIZABLE); // Create new window
 				//break; //Event handled, fetch next :)
 			case SDL_KEYDOWN:
-				if (event.key.keysym.sym==SDLK_UP && event.key.state==SDL_PRESSED)
-					FIELD *= 2.0;
-				else if (event.key.keysym.sym==SDLK_DOWN && event.key.state==SDL_PRESSED)
-					FIELD /= 2.0;
-				else if (event.key.keysym.sym==SDLK_r && event.key.state==SDL_PRESSED)
-					goto moveCenter(count, screen, num);
-				else if (event.key.keysym.sym==SDLK_v && event.key.state==SDL_PRESSED)
-					goto CenteringVelocity(count, screen, num);
-				else if (event.key.keysym.sym==SDLK_l && event.key.state==SDL_PRESSED)
-					goto AdjustLook(count, screen, num);
+				if (event.key.state==SDL_PRESSED){
+					switch(event.key.keysym.sym){
+						case SDLK_UP:
+							goto AdjustLooking(DefDistance/=1.2, count, screen, num);
+						case SDLK_DOWN:
+							goto AdjustLooking(DefDistance*=1.2, count, screen, num);
+						case SDLK_l:
+							goto AdjustLooking(DefDistance, count, screen, num);
+						case SDLK_q:
+							goto finish(0, num);
+						default:
+							break;
+					}
+				}
 				break;
 			default:
 				break;
@@ -237,32 +243,12 @@
 	}
 }
 
-__code AdjustLook(int count, SDL_Surface *screen, int num)
+__code AdjustLooking(float distance, int count, SDL_Surface *screen, int num)
 {
-	int i;
-	float c0,c1,c2;
-	float v0,v1,v2,v;
-	c0=c1=c2=v0=v1=v2=0;
-
-	for (i=0; i<num; i++){
-		c0 += stars_new[i].r[0];
-		c1 += stars_new[i].r[1];
-		c2 += stars_new[i].r[2];
-	}
-	c0/=3.0; c1/=3.0; c2/=3.0; 
-	for (i=0; i<num; i++){
-		v0 += (stars_new[i].r[0]-c0)*(stars_new[i].r[0]-c0);
-		v1 += (stars_new[i].r[1]-c1)*(stars_new[i].r[1]-c1);
-		v2 += (stars_new[i].r[2]-c2)*(stars_new[i].r[2]-c2);
-	}
-	v = v0+v1+v2;
-	v0 = sqrt(v0); v1 = sqrt(v1); v2 = sqrt(v2);
-	v = sqrt(v);
-
 	glMatrixMode(GL_PROJECTION);
 	glLoadIdentity();
-	gluPerspective( 60.0, (float)screen->w/(float)screen->h, 1.0, v);
-	gluLookAt( v,v,v, 0.0,0.0,0.0, 1.0,0.0,0.0);
+	gluPerspective( 60.0, (float)screen->w/(float)screen->h, 1.0, distance*2.5);
+	gluLookAt( distance,distance,distance, 0.0,0.0,0.0, 1.0,0.0,0.0);
 	glClearColor(0.0, 0.0, 0.0, 0.0);
 	glMatrixMode(GL_MODELVIEW);
 
@@ -389,22 +375,22 @@
 	for (i=0; i<num; i++){
 		glPushMatrix();
 		glTranslatef( stars_new[i].r[0], stars_new[i].r[1], stars_new[i].r[2]);
-		gluSphere( sphere[i], 2.0, 8.0, 8.0 );
+		gluSphere( sphere[i], 2.0, 32.0, 32.0 );
 		glPopMatrix();
 	}
 
 	glColor3d( 1.0, 1.0, 1.0);
 	glBegin(GL_LINES);
 	glVertex3d( 0.0, 0.0, 0.0);
-	glVertex3d( 10.0, 0.0, 0.0);
+	glVertex3d( 200.0, 0.0, 0.0);
 	glEnd();
 	glBegin(GL_LINES);
 	glVertex3d( 0.0, 0.0, 0.0);
-	glVertex3d( 0.0, 10.0, 0.0);
+	glVertex3d( 0.0, 200.0, 0.0);
 	glEnd();
 	glBegin(GL_LINES);
 	glVertex3d( 0.0, 0.0, 0.0);
-	glVertex3d( 0.0, 0.0, 10.0);
+	glVertex3d( 0.0, 0.0, 200.0);
 	glEnd();
 
 	SDL_GL_SwapBuffers();