X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=course%2Fsemester2%2Fpprog%2Fassignment1%2Fnbody.c;h=077616077531277fa27a41c4bee19091a36fbd94;hb=1612d2449b7c9e4fa202adac00cda23700df44c7;hp=5891d141f06a16ab28dc9c2fd79a6cf4735dde6a;hpb=4aead302e9872ec0a42724a61589275569c4e783;p=matches%2Fhonours.git diff --git a/course/semester2/pprog/assignment1/nbody.c b/course/semester2/pprog/assignment1/nbody.c index 5891d141..07761607 100644 --- a/course/semester2/pprog/assignment1/nbody.c +++ b/course/semester2/pprog/assignment1/nbody.c @@ -1,7 +1,8 @@ -// nbody.cpp : Template program for N-body -// Copyright UWA, 2012 - -#define _ANSI_SOURCE +/** + * @file nbody.c + * @author Sam Moore (20503628) 2012 + * @purpose N-Body simulator - Definition of simulation functions; single threaded version + */ #include #include @@ -12,42 +13,6 @@ #include #include -#define M_PI 3.14159265358979323846264338327950288 /* pi */ -#define WIDTH 800 -#define HEIGHT 800 -#define POINT_SIZE 1 -#define POSITION_X 112 -#define POSITION_Y 20 -#define WORLD_LEFT -10000 -#define WORLD_RIGHT 10000 -#define WORLD_BOTTOM -10000 -#define WORLD_TOP 10000 -#define VIEW_ANGLE 45 -#define RHO 100 -#define WORLD_NEAR 0.1 -#define WORLD_FAR 1000000 -#define BALL_SIZE 0.5 -#define REFRESH_RATE 0.001 -#define LINE_SIZE 1000 -#define G 6.67428E-11 -#define DELTA_T 0.05 - -#define square(x) ((x)*(x)) - -typedef struct { - double mass; - double X; - double Y; - double Z; - double Vx; - double Vy; - double Vz; - double Fx; - double Fy; - double Fz; - int color; -} Particle; - double previousTime, eyeTheta, eyePhi, eyeRho; float look[3]; int windowWidth, windowHeight, upY; @@ -58,71 +23,7 @@ Particle *body; int N; int numberOfProcessors=1; -/* - * Initialization of graphics - */ -void Init(void) { - - glClearColor(1.0,1.0,1.0,0.0); - glColor3f(0.0f, 0.0f, 0.0f); - glPointSize(POINT_SIZE); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - /*init lighting */ - - GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; - GLfloat mat_shininess[] = { 50.0 }; - GLfloat light_position[] = { 1.0, 1.0, 0.0, 0.0 }; - glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); - glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); - glLightfv(GL_LIGHT0, GL_POSITION, light_position); - glColorMaterial(GL_FRONT,GL_DIFFUSE); // Set Color Capability - - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glEnable(GL_DEPTH_TEST); - - glEnable(GL_COLOR_MATERIAL); // Enable color - - double displayRatio = 1.0 * WIDTH / HEIGHT; - windowWidth = WIDTH; - windowHeight = HEIGHT; - previousTime = clock(); - eyeTheta = 0; - eyePhi = 0.5 * M_PI; - eyeRho = RHO; - upY = 1; - look[0] = 0; - look[1] = 0; - look[2] = 0; - gluPerspective(VIEW_ANGLE, displayRatio, WORLD_NEAR, WORLD_FAR); -} - -/* - * This function redraws the screen after the positions of particles - * have been updated - */ -void Display(void) { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - gluLookAt(eyeRho * sin(eyePhi) * sin(eyeTheta), eyeRho * cos(eyePhi), - eyeRho * sin(eyePhi) * cos(eyeTheta), - look[0], look[1], look[2], 0, upY, 0); - - for (int i = 0; i < N; i++) { - //glClearColor(1.0,1.0,1.0,0.0); - glColor3f(0.0f, body[i].mass/1e11*100, 0.0f); - //glColor3f(1.0f, 0.0f, 0.0f); - glPushMatrix(); // to save the current matrix - glTranslated(SCALE*body[i].X, SCALE*body[i].Y, SCALE*body[i].Z); - glutSolidSphere (BALL_SIZE, 10, 10); - glPopMatrix(); // restore the previous matrix - } - glFlush(); -} /* * Prints the body on screen