示例#1
0
文件: draw.c 项目: stuydw/polygons
  /*======== void add_sphere() ==========
Inputs: struct matrix * points
double cx
double cy
double r
double step
Returns:

adds all the points for a sphere with center
(cx, cy) and radius r.

should call generate_sphere to create the
necessary points

jdyrlandweaver
====================*/
  void add_sphere( struct matrix * points,
double cx, double cy, double r,
double step ) {
    struct matrix * temp;
    int lt, lng;
    // int num_steps = (int) (1.0 / step); why does this break?
    double f = 1.0 / step;
    int num_steps = (int) f;
    int fg = num_steps + 1;
    temp = new_matrix(4, num_steps * (num_steps + 1));
    generate_sphere(temp, cx, cy, r, step);
    for (lt = 0 ; lt <= num_steps - 1 ; lt++) {
      for (lng = 0 ; lng <= num_steps - 1; lng++) {
        add_polygon(points, temp->m[0][lt * fg +lng % fg],
                    temp->m[1][lt * fg + lng % fg],
                    temp->m[2][lt* fg + lng % fg],
                    temp->m[0][((lt + 1) % num_steps) * fg + (lng + 1) % fg],
                    temp->m[1][((lt + 1) % num_steps)* fg + (lng + 1) % fg],
                    temp->m[2][((lt + 1) % num_steps)* fg + (lng + 1) % fg],
                    temp->m[0][lt * fg + (lng + 1) % fg],
                    temp->m[1][lt * fg + (lng + 1) % fg],
                    temp->m[2][lt * fg + (lng + 1) % fg]);
        add_polygon(points, temp->m[0][lt * fg + lng],
                    temp->m[1][lt * fg +lng], temp->m[2][lt * fg + lng],
                    temp->m[0][((lt + 1) % num_steps) * fg + lng],
                    temp->m[1][((lt + 1) % num_steps) * fg + lng],
                    temp->m[2][((lt + 1) % num_steps) * fg + lng],
                    temp->m[0][((lt + 1) % num_steps) * fg + (lng + 1) % fg],
                    temp->m[1][((lt + 1) % num_steps) * fg + (lng + 1) % fg],
                    temp->m[2][((lt + 1) % num_steps) * fg + (lng + 1) % fg]);
      }
    }
  }
示例#2
0
文件: draw.c 项目: stuydw/polygons
/*======== void add_sphere() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r
	    double step  
  Returns: 

  adds all the points for a sphere with center 
  (cx, cy) and radius r.

  should call generate_sphere to create the
  necessary points

  jdyrlandweaver
  ====================*/
void add_sphere( struct matrix * points, 
		 double cx, double cy, double r, 
		 double step ) {

  struct matrix * temp;
  int lat, longt;
  int index;
  double ns;
  int num_steps;
 
  ns = 1.0 / step;
  num_steps = (int)ns;

  temp = new_matrix( 4, num_steps * (num_steps+1) );
  //generate the points on the sphere
  generate_sphere( temp, cx, cy, r, step );
  num_steps++;
  int latStop, longStop, latStart, longStart;
  latStart = 0;
  latStop = num_steps-1;
  longStart = 0;
  longStop = num_steps;
  
  for ( lat = latStart; lat < latStop; lat++ ) {
    for ( longt = longStart; longt < longStop; longt++ ) {
      
      index = lat * (num_steps) + longt;
      add_edge(points,
	       temp->m[0][index], temp->m[1][index], temp->m[2][index],
	       temp->m[0][index], temp->m[1][index], temp->m[2][index]);
    }
  }
}
示例#3
0
文件: draw.c 项目: nspektor/3dHW
/*======== void add_sphere() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r
	    double step  
  Returns: 

  adds all the points for a sphere with center 
  (cx, cy) and radius r.

  should call generate_sphere to create the
  necessary points

  jdyrlandweaver
  ====================*/
void add_sphere( struct matrix * points, 
		 double cx, double cy, double r, 
		 double step ) {
  generate_sphere(points, cx, cy, r, step);
  int i = 0;
  for(i = 0; i< points->lastcol; i++){
    add_edge(points,points->m[0][i], points->m[1][i], points->m[2][i], points->m[0][i], points->m[1][i], points->m[2][i]);
  }
}
示例#4
0
文件: draw.c 项目: stuydw/3d
/*======== void add_sphere() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r
	    double step  
  Returns: 

  adds all the points for a sphere with center 
  (cx, cy) and radius r.

  should call generate_sphere to create the
  necessary points

  jdyrlandweaver
  ====================*/
void add_sphere( struct matrix * points, 
		 double cx, double cy, double r, 
		 double step ) {

    int i;
    struct matrix *tmp = new_matrix(4, 2);
    generate_sphere(tmp, cx, cy, r, step);
    for (i = 0; i < tmp->lastcol; i++)
        add_edge(points, tmp->m[0][i], tmp->m[1][i], tmp->m[2][i], tmp->m[0][i], tmp->m[1][i], tmp->m[2][i]);
}
/*
 * void spawn_next_ball();
 *
 * checks if the system has enough mass to spawn the new ball
 */
void spawn_next_ball() {
	//printf("%f/%f till next spawn\n", mass_of_system, next_ball_mass);
	if( mass_of_system >= next_ball_mass ) {
		all_spheres.resize(all_spheres.size()+1);
		all_spheres.push_back( generate_sphere(1) );
		mass_of_system -= next_ball_mass; 
		next_ball_radius = random_radius();
		next_ball_mass = get_mass( next_ball_radius );
	}
}
/*
 * void gfxinit();
 *
 * initializes the system prior to animating
 */
void gfxinit() {
	mass_of_system = 0.0;
	balls = NUMBER_OF_BALLS;
	all_spheres.resize(balls);
	
	current = 0.0;
	// LIGHTING 	
    GLfloat lightpos[4] = { 1.0, 0.0, 1.0, 1.0 };     // light position
    GLfloat lightamb[4] = { 0.0, 0.0, 0.0, 1.0 };     // ambient colour
    GLfloat lightdif[4] = { 1.0, 1.0, 1.0, 1.0 };     // diffuse colour
    GLfloat global_ambient[4] = {0.2, 0.2, 0.2, 1};

    glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
    // set the ambient light colour
    glLightfv(GL_LIGHT0, GL_AMBIENT, lightamb);
    // set the diffuse light colour
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightdif);
	// global ambient
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);
	// turn on lighting
    glEnable(GL_LIGHTING);
    // enable light 0, all the other lights are off
    glEnable(GL_LIGHT0);

    // enable the depth buffer
    glEnable(GL_DEPTH_TEST);
   
    glMatrixMode(GL_PROJECTION);
    gluPerspective(60.0, 16/9., 0.1, 500.0);
    //glOrtho(-5.0,5.0,-5.0,5.0,1.0,20.0);
	glMatrixMode(GL_MODELVIEW);
    //gluLookAt(x, y, z, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
	
	
	//glRasterPos2i(10, 10);
	//glColor3f(1.0f, 1.0f, 1.0f);
	//glutBitmapString(GLUT_BITMAP_HELVETICA_18, (const unsigned char*)"dog");

	glEnable ( GL_COLOR_MATERIAL ) ;
	glColorMaterial ( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ) ;
	glShadeModel(GL_SMOOTH);

	srand(time(NULL));	// seed for rand() calls

	// create all spheres for the initial system state
	int k;
	for( k = 0; k < all_spheres.size(); k++ ) { //setup all ball settings
		//printf("%d\n",k);
		all_spheres[k] = generate_sphere(0);
	}
	next_ball_radius = random_radius();
	next_ball_mass = get_mass( next_ball_radius ); 
}
示例#7
0
文件: draw.c 项目: hrxiao/graphics05
/*======== void add_sphere() ==========
	Inputs:   struct matrix * points
						double cx
			double cy
			double r
			double step  
	Returns: 

	adds all the points for a sphere with center 
	(cx, cy) and radius r.

	should call generate_sphere to create the
	necessary points

	jdyrlandweaver
	====================*/
	void add_sphere( struct matrix * points, 
		double cx, double cy, double r, 
		int step ) {

		struct matrix * temp;
		int lat, longt;
		int index, index2;
		double x, y, z;
		int num_steps;
		
		num_steps = MAX_STEPS / step;

		temp = new_matrix( 4, num_steps * num_steps );
	//generate the points on the sphere
		generate_sphere( temp, cx, cy, r, step );

		int latStop, longStop, latStart, longStart;
		latStart = 0;
		latStop = num_steps;
		longStart = 0;
		longStop = num_steps;

		for ( lat = latStart; lat < latStop; lat++ ) {
			for ( longt = longStart; longt * 2 < longStop; longt++ ) {
				
				index = lat * num_steps + longt;
				index2 = index + num_steps;
				if (lat == latStop - 1) {				
					index2 = latStart * num_steps + longt;
				}
				add_polygon(points, temp->m[0][index],
					temp->m[1][index],
					temp->m[2][index],
					temp->m[0][index2 + 1],
					temp->m[1][index2 + 1],
					temp->m[2][index2 + 1],
					temp->m[0][index2],
					temp->m[1][index2],
					temp->m[2][index2]);			
				add_polygon(points, temp->m[0][index],
					temp->m[1][index],
					temp->m[2][index],
					temp->m[0][index + 1],
					temp->m[1][index + 1],
					temp->m[2][index + 1],
					temp->m[0][index2 + 1],
					temp->m[1][index2 + 1],
					temp->m[2][index2 + 1]);
			}
		}
		free_matrix(temp);
}
示例#8
0
文件: draw.c 项目: kmejia/4-Graphics
/*======== void add_sphere() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r
	    double step  
  Returns: 

  adds all the points for a sphere with center 
  (cx, cy) and radius r.

  should call generate_sphere to create the
  necessary points

  jdyrlandweaver
  ====================*/
void add_sphere( struct matrix * points, 
		 double cx, double cy, double r, 
		 double step ) {
  //a dummy is made that calls generete_sphere()
  struct matrix* dummy = new_matrix(4,1);
  generate_sphere(dummy, cx,cy, r, step);
  //dummy holds the points, and they are placd as edges into points,aka the 
  //correct one when drawing
  int n;
  for(n=0; n<(dummy->lastcol) ;n++){
    add_edge(points, dummy->m[0][n],dummy->m[1][n],dummy->m[2][n],
	     dummy->m[0][n],dummy->m[1][n],dummy->m[2][n]);
  }
}
示例#9
0
文件: draw.c 项目: stuydw/3d
/*======== void add_sphere() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r
	    double step  
  Returns: 

  adds all the points for a sphere with center 
  (cx, cy) and radius r.

  should call generate_sphere to create the
  necessary points

  jdyrlandweaver
  ====================*/
void add_sphere( struct matrix * points, 
		 double cx, double cy, double r, 
		 double step ) {
  struct matrix * tmp = new_matrix( 4, 20 );
  int i;
  generate_sphere( tmp, cx, cy, r, step );
  for( i = 0; i < tmp->lastcol; i++ ) {
    double x, y, z;
    x = tmp->m[ 0 ][ i ];
    y = tmp->m[ 1 ][ i ];
    z = tmp->m[ 2 ][ i ];
    add_edge( points, x, y, z, x, y, z );
  }
  free_matrix( tmp );
}
示例#10
0
文件: draw.c 项目: stuydw/polygons
  /*======== void add_sphere() ==========
    Inputs:   struct matrix * points
    double cx
    double cy
    double r
    double step  
    Returns: 

    adds all the points for a sphere with center 
    (cx, cy) and radius r.

    should call generate_sphere to create the
    necessary points

    jdyrlandweaver
    ====================*/
  void add_sphere( struct matrix * points, 
		   double cx, double cy, double r, 
		   double step ) {

    struct matrix * temp;
    int lat, longt;
    int index;
    double ns;
    int num_steps;
 
    ns = 1.0 / step;
    num_steps = (int)ns;

    temp = new_matrix( 4, num_steps * (num_steps+1) );
    //generate the points on the sphere
    generate_sphere( temp, cx, cy, r, step );
    int latStop, longStop, latStart, longStart;
    latStart = 0;
    latStop = num_steps-1;
    longStart = 0;
    longStop = num_steps-1;
    index = num_steps+1;
  
    for ( lat = latStart; lat <= latStop; lat++ ) {
      for ( longt = longStart; longt <= longStop; longt++ ) {
	add_polygon(points,
		    temp->m[0][lat*index+longt%index], 
		    temp->m[1][lat*index+longt%index], 
		    temp->m[2][lat*index+longt%index],
		    temp->m[0][((lat+1) % num_steps)*index+(longt+1) % index],
		    temp->m[1][((lat+1) % num_steps)*index+(longt+1) % index],
		    temp->m[2][((lat+1) % num_steps)*index+(longt+1) % index],
		    temp->m[0][lat*index+(longt+1) % index],
		    temp->m[1][lat*index+(longt+1) % index],
		    temp->m[2][lat*index+(longt+1) % index]);
	add_polygon(points,
		    temp->m[0][lat*index+longt],
		    temp->m[1][lat*index+longt],
		    temp->m[2][lat*index+longt],
		    temp->m[0][((lat+1) % num_steps)*index + longt],
		    temp->m[1][((lat+1) % num_steps)*index + longt],
		    temp->m[2][((lat+1) % num_steps)*index + longt],
		    temp->m[0][((lat+1) % num_steps)*index + (longt+1) % index],
		    temp->m[1][((lat+1) % num_steps)*index + (longt+1) % index],
		    temp->m[2][((lat+1) % num_steps)*index + (longt+1) % index]);  
      }
    }
  }
/*
 * void gfxinit();
 *
 * initializes the system prior to animating
 */
void gfxinit() {
	balls = NUMBER_OF_BALLS;
	all_spheres.resize(balls);
	
	current = 0.0;
	// LIGHTING 	
    GLfloat lightpos[4] = { 1.0, 0.0, 1.0, 1.0 };     // light position
    GLfloat lightamb[4] = { 0.0, 0.0, 0.0, 1.0 };     // ambient colour
    GLfloat lightdif[4] = { 1.0, 1.0, 1.0, 1.0 };     // diffuse colour
    GLfloat global_ambient[4] = {0.2, 0.2, 0.2, 1};

    glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
    // set the ambient light colour
    glLightfv(GL_LIGHT0, GL_AMBIENT, lightamb);
    // set the diffuse light colour
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightdif);
	// global ambient
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);
	// turn on lighting
    glEnable(GL_LIGHTING);
    // enable light 0, all the other lights are off
    glEnable(GL_LIGHT0);

    // enable the depth buffer
    glEnable(GL_DEPTH_TEST);
   
    glMatrixMode(GL_PROJECTION);
    //gluPerspective(60.0, 16/9., 1.0, 20.0);
    glOrtho(-5.0,5.0,-5.0,5.0,1.0,20.0);
	glMatrixMode(GL_MODELVIEW);
    gluLookAt(0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

	glEnable ( GL_COLOR_MATERIAL ) ;
	glColorMaterial ( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ) ;
	glShadeModel(GL_SMOOTH);

	srand(time(NULL));	// seed for rand() calls

	// create all spheres for the initial system state
	int k;
	for( k = 0; k < all_spheres.size(); k++ ) { //setup all ball settings
		//printf("%d\n",k);
		all_spheres[k] = generate_sphere();
	}
}
示例#12
0
文件: draw.c 项目: stuydw/3d
/*======== void add_sphere() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r
	    double step  
  Returns: 

  adds all the points for a sphere with center 
  (cx, cy) and radius r.

  should call generate_sphere to create the
  necessary points

  jdyrlandweaver
  ====================*/
void add_sphere( struct matrix * points, 
		 double cx, double cy, double r, 
		 double step ) {
  int length = 1 / pow(step, 2);
  if((length % 2) == 1)
    length++;
  struct matrix *temp = new_matrix(4,length);
  generate_sphere(temp, cx, cy, r, step);
  double x, y, z;
  int t;
  for(t=0;t<temp->lastcol; t++){
    x = temp->m[0][t];
    y = temp->m[1][t];
    z = temp->m[2][t];
    add_edge(points, x, y, z, x, y, z);
  }
  free_matrix(temp);
}
示例#13
0
文件: draw.c 项目: stuydw/polygons
/*======== void add_sphere() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r
	    double step  
  Returns: 

  adds all the points for a sphere with center 
  (cx, cy) and radius r.

  should call generate_sphere to create the
  necessary points

  jdyrlandweaver
  ====================*/
void add_sphere( struct matrix * points, 
		 double cx, double cy, double r, 
		 double step ) {

  struct matrix * temp;
  int lat, longt;
  double ns;
  int steps;
 
  ns = 1.0 / step;
  steps = (int)ns;

  temp = new_matrix( 4, (steps) * (steps+1) );

  //generate the points on the sphere
  generate_sphere( temp, cx, cy, r, step );
  for(lat = 0; lat < steps; lat++){
    for(longt = 0; longt < steps; longt++){
      add_polygon(points,
		  temp->m[0][(lat * (steps + 1)) + (longt % (steps + 1))],
		  temp->m[1][(lat * (steps + 1)) + (longt % (steps + 1))],
		  temp->m[2][(lat * (steps + 1)) + (longt % (steps + 1))],
		  temp->m[0][(((lat + 1) % steps) * (steps + 1)) + ((longt + 1) % (steps + 1))],
		  temp->m[1][(((lat + 1) % steps) * (steps + 1)) + ((longt + 1) % (steps + 1))],
		  temp->m[2][(((lat + 1) % steps) * (steps + 1)) + ((longt + 1) % (steps + 1))],
		  temp->m[0][(lat * (steps + 1)) + ((longt + 1) % (steps + 1))],
		  temp->m[1][(lat * (steps + 1)) + ((longt + 1) % (steps + 1))],
		  temp->m[2][(lat * (steps + 1)) + ((longt + 1) % (steps + 1))]);
      add_polygon(points,
		  temp->m[0][(lat * (steps + 1)) + longt],
		  temp->m[1][(lat * (steps + 1)) + longt],
		  temp->m[2][(lat * (steps + 1)) + longt],
		  temp->m[0][(((lat + 1) % steps) * (steps + 1)) + longt],
		  temp->m[1][(((lat + 1) % steps) * (steps + 1)) + longt],
		  temp->m[2][(((lat + 1) % steps) * (steps + 1)) + longt],

		  temp->m[0][(((lat + 1) % steps) * (steps + 1)) + ((longt+1) % (steps + 1))],
		  temp->m[1][(((lat + 1) % steps) * (steps + 1)) + ((longt+1) % (steps + 1))],
		  temp->m[2][(((lat + 1) % steps) * (steps + 1)) + ((longt+1) % (steps + 1))]);
    }
  }

}
示例#14
0
文件: draw.c 项目: Wayez/polygon
/*======== void add_sphere() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r
	    double step  
  Returns: 

  adds all the points for a sphere with center 
  (cx, cy) and radius r.

  should call generate_sphere to create the
  necessary points

  jdyrlandweaver
  ====================*/
void add_sphere( struct matrix * points, 
		 double cx, double cy, double r, 
		 int step ) {

  struct matrix * temp;
  int lat, longt;
  int index;
  double x, y, z;
  int num_steps;
  
  num_steps = MAX_STEPS / step;

  temp = new_matrix( 4, num_steps * num_steps );
  //generate the points on the sphere
  generate_sphere( temp, cx, cy, r, step );

  int latStop, longStop, latStart, longStart;
  latStart = 0;
  latStop = num_steps;
  longStart = 0;
  longStop = num_steps;
  
  for ( lat = latStart; lat < latStop; lat++ ) {
    for ( longt = longStart; longt < longStop; longt++ ) {
      
      index = lat * num_steps + longt;
      add_polygon(points, temp->m[0][index], temp->m[1][index], temp->m[2][index],
      temp->m[0][index + 1], temp->m[1][index + 1], temp->m[2][index + 1],
      temp->m[0][index + num_steps+ 1], temp->m[1][index + num_steps+ 1], temp->m[2][index + num_steps+ 1]);
      
      add_polygon(points, temp->m[0][index], temp->m[1][index], temp->m[2][index],
      temp->m[0][index + num_steps + 1], temp->m[1][index + num_steps+ 1], temp->m[2][index + num_steps+ 1],
      temp->m[0][index + num_steps], temp->m[1][index + num_steps], temp->m[2][index + num_steps]);
      /*add_edge( points, temp->m[0][index],
		temp->m[1][index],
		temp->m[2][index],
		temp->m[0][index] + 1,
		temp->m[1][index] + 1,
		temp->m[2][index] );*/
    }//end points only
  }
  free_matrix(temp);
}
/*
 * void keystroke(unisgned char c, int x, int y);
 *
 * The keystroke function handles user input to modify how the animation
 * performs. Also allows the user to quit
 */
void keystroke(unsigned char c, int x, int y) {
	switch(c) {
		case 97:	// [a] for add ball
		{
		balls++;
		all_spheres.resize(balls);
		struct sphere ball;
		ball = generate_sphere();
		all_spheres.push_back(ball);
		}
			break;
		case 113:		// [q] is quit
			exit(0);
			break;
		case 110:
			glutIdleFunc(animate);
			break;
	}
}
示例#16
0
文件: draw.c 项目: akratsios/points3d
/*======== void add_sphere() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r
	    double step  
  Returns: 

  adds all the points for a sphere with center 
  (cx, cy) and radius r.

  should call generate_sphere to create the
  necessary points

  jdyrlandweaver
  ====================*/
void add_sphere( struct matrix * points, 
								 double cx, double cy, double r, 
								 double step ) {

	
  int col;
  struct matrix *temp;
	
  temp = new_matrix(4,1);
	generate_sphere(temp, cx, cy, r, step);
	for(col = 0; col < temp->cols; col++) {
		add_edge(points,
						 temp->m[0][col],
						 temp->m[1][col],
						 temp->m[2][col],
						 temp->m[0][col],
						 temp->m[1][col],
						 temp->m[2][col]);
	}
}
示例#17
0
/*
 * void keystroke(unisgned char c, int x, int y);
 *
 * The keystroke function handles user input to modify how the animation
 * performs. Also allows the user to quit
 */
void keystroke(unsigned char c, int x, int y) {
	switch(c) {
		case 97:	// [a] for add ball
		{
			//balls++;
			all_spheres.resize(all_spheres.size()+1);
			//sphere ball;
			//ball = generate_sphere(0);
			//printf("\nKEY PRESS SPAWN\n\n");
			//print_sphere(&ball);
			//all_spheres.push_back(ball);
			all_spheres.push_back( generate_sphere(0) );
		}
			break;
		case 99:	// [c] collisions response mode
			response = (response == 0) ? 1 : 0;
			break;
		case 100:
			dust_shown = ( dust_shown ) ? 0 : 1;
			break;
		case 119: // [w] forward
			deltaMove = 0.5;
			break;
		case 114: // [r] relfection on/off
			reflection = (reflection) ? 0 : 1;
			break;
		case 115: // [s] back
			deltaMove = -0.5;
			break;
		case 116: // [t] text
			showText = (showText) ? 0 : 1; 
			break;
		case 113:		// [q] is quit
			exit(0);
			break;
		case 110:
			glutIdleFunc(animate);
			break;
	}
}
示例#18
0
void init()
{
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glShadeModel(GL_SMOOTH);
    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    glEnable(GL_BLEND);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
 
    glPointSize(1.7f);
    
    srand((unsigned)time(NULL));

    int size = 1600;

    scene_object::color_type color(0.1, 0.5, 1.0, 1.0);

    generate_sphere(g_object_sphere, color, 0.5f, size);
    generate_torus(g_object_torus, color, 0.5f, 0.1f, size);
    generate_cube(g_object_cube, color, 1.0f, size);
    generate_lines(g_object_lines, color, 0.5f, size);
    generate_spiral(g_object_spiral, color, 0.5f, size);
    generate_paraboloid(g_object_paraboloid, color, 0.5f, size);
    generate_chaos(g_object_chaos, color, 0.5f, size);
    
    g_objects.push_back(g_object_sphere);
    g_objects.push_back(g_object_torus);
    g_objects.push_back(g_object_lines);
    g_objects.push_back(g_object_cube);
    g_objects.push_back(g_object_spiral);
    g_objects.push_back(g_object_paraboloid);
    g_objects.push_back(g_object_chaos);

    g_object = g_objects[g_object_index];

    std::cout << "Number of points in the object : " << g_object.points.size() << std::endl;

    g_move_delta = 1.0f / MORPHING_STEPS;
}
示例#19
0
文件: generate.c 项目: Jylam/oric
int main(int argc, char*argv[]) {

    double x=100.0f, y=0.0f, z=100.0f;
    double x2, y2, z2;
    double x3, y3, z3;
    double xr, yr, zr;
    double px, py;
    double angle_x = 0.0f, angle_y = 0.0f, angle_z = 0.0f;
    double cam_x = 0.0f, cam_y = 0.0f, cam_z = -150.0f;
    int quit=0, curframe = 0, outsize=0;
    char *outbuf = NULL;
    unsigned int size = 0;
    SDL_Window *window;
    SDL_Renderer *renderer;
    SDL_Event e;
    //generate_sphere(15, 10, 15);
    generate_sphere(10, 8, 5);
    SDL_CreateWindowAndRenderer(WIDTH, HEIGHT, 0, &window, &renderer);

    printf("unsigned char anim[] = {\n");

    while(!quit) {
        while (SDL_PollEvent(&e)){
            //If user closes the window
            if (e.type == SDL_QUIT){
                quit = 1;
            }
            //If user presses any key
            if (e.type == SDL_KEYDOWN){
                quit = 1;
            }
            //If user clicks the mouse
            if (e.type == SDL_MOUSEBUTTONDOWN){
                quit = 1;
            }
        }

        //        printf("Frame %d\n", curframe);
        int p;
        char tmpstr[1000];
        int visible = 0;
        outbuf = calloc(1,1);
        for(p = 0; p < vert_size; p+=3) {
            x = vertices[p];
            y = vertices[p+1];
            z = vertices[p+2];

            rotateX(x,  y,  z,  &x2, &y2, &z2, (angle_x*M_PI/180.0f));
            rotateY(x2, y2, z2, &x3, &y3, &z3, (angle_y*M_PI/180.0f));
            rotateZ(x3, y3, z3, &xr, &yr, &zr, (angle_z*M_PI/180.0f));

            xr-=cam_x;
            yr-=cam_y;
            zr-=cam_z;

            yr*=6.0f;
            xr/=1.f;

            px = xr * FOV / zr;
            py = yr * FOV / zr;
            px+=(double)WIDTH/2.0f;
            py+=(double)HEIGHT/2.0f;
            // void qsort (void *array, size_t count, size_t size, comparison_fn_t compare)
        }

        for(p = 0; p < vert_size; p+=3) {

            if(zr+cam_z<=100.0f) {
                px = xr * FOV / zr;
                py = yr * FOV / zr;
                px+=(double)WIDTH/2.0f;
                py+=(double)HEIGHT/2.0f;
                if(px>=2.0f && px<=WIDTH && py>=0.0f && py<=HEIGHT) {
                    unsigned int address = 0xa000 + (((unsigned int)px)+(((unsigned int)py)*40));
                    SDL_RenderDrawPoint(renderer, px, py); //Renders on middle of screen.
                    //        printf( "\t%f\t%f\t%f\n", px, py, zr);
                    //    sprintf(tmpstr, "%u,%u,%u, ", (unsigned int)px, (unsigned int)py, (unsigned int)zr);
                    //sprintf(tmpstr, "0x%02X,0x%02X, /* %d %d */", address&0xFF, address>>8, ((unsigned int)px),((unsigned int)py));
                    sprintf(tmpstr, "0x%02X,0x%02X,\n", ((unsigned int)px),((unsigned int)py));
                    size+=2;
                    outsize+=strlen(tmpstr)+1;
                    outbuf = realloc(outbuf, outsize);
                    strncat(outbuf, tmpstr, 1000);
                    visible++;
                }
            } else {
            }
        }
        size++;
        printf("%u,%s // Offset %d\n", visible*2, outbuf, size);
        free(outbuf);
        outbuf = NULL;
        visible = 0;
        angle_x+= 1.0;
        angle_y+= 3;
        angle_z+= sin(curframe*M_PI/180.0);

        if(curframe>=200) {
            quit = 1;
        }
        //if(angle_z >= 360.0f) {
        //    angle_x = angle_y = angle_z = 0.0f;
        //    quit = 1;
        //}
        if(angle_x>=360.0f) angle_x = 0.0f;
        if(angle_y>=360.0f) angle_y = 0.0f;
        if(angle_z>=360.0f) angle_z = 0.0f;

        SDL_RenderPresent(renderer);
        SDL_RenderClear(renderer);
//            SDL_Delay(50);
        curframe++;
    }
    printf("};// Size %d\n", size);
    return 0;
}
示例#20
0
文件: draw.c 项目: stuydw/mdl
/*======== void add_sphere() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r
	    double step  
  Returns: 

  adds all the points for a sphere with center 
  (cx, cy) and radius r.

  should call generate_sphere to create the
  necessary points

  jdyrlandweaver
  ====================*/
void add_sphere( struct matrix * points, 
		 double cx, double cy, double cz, double r, 
		 double step ) {

  struct matrix * temp;
  int lat, longt;
  int index;
  double ns;
  int num_steps;
 
  ns = 1.0 / step;
  num_steps = (int)ns;

  temp = new_matrix( 4, num_steps * (num_steps+1) );
  //generate the points on the sphere
  generate_sphere( temp, cx, cy, cz, r, step );
  num_steps++;
  int latStop, longStop, latStart, longStart;
  latStart = 0;
  latStop = num_steps-1;
  longStart = 0;
  longStop = num_steps-1;
  
  for ( lat = latStart; lat < latStop; lat++ ) {
    for ( longt = longStart; longt < longStop; longt++ ) {
      
      index = lat * (num_steps) + longt;

      if ( lat == num_steps - 2) {
	add_polygon( points, temp->m[0][index],
		     temp->m[1][index],
		     temp->m[2][index],
		     temp->m[0][longt],
		     temp->m[1][longt],
		     temp->m[2][longt],
		     temp->m[0][longt+1],
		     temp->m[1][longt+1],
		     temp->m[2][longt+1]);
	if ( longt != num_steps - 2 ) {
	  add_polygon( points, 
		       temp->m[0][longt+1],
		       temp->m[1][longt+1],
		       temp->m[2][longt+1],
		       temp->m[0][index+1],
		       temp->m[1][index+1],
		       temp->m[2][index+1],
		       temp->m[0][index],
		       temp->m[1][index],
		       temp->m[2][index]);
	}
      }//end edge case
      else {	
	add_polygon( points, temp->m[0][index],
		     temp->m[1][index],
		     temp->m[2][index],
		     temp->m[0][index+num_steps],
		     temp->m[1][index+num_steps],
		     temp->m[2][index+num_steps],
		     temp->m[0][index+num_steps+1],
		     temp->m[1][index+num_steps+1],
		     temp->m[2][index+num_steps+1]);
	if ( longt != num_steps - 2 ) {
	  add_polygon( points, 
		       temp->m[0][index+num_steps+1],
		       temp->m[1][index+num_steps+1],
		       temp->m[2][index+num_steps+1],
		       temp->m[0][index+1],
		       temp->m[1][index+1],
		       temp->m[2][index+1],
		       temp->m[0][index],
		       temp->m[1][index],
		       temp->m[2][index]);
	}
      }//end not last full rotation
    }
  }
}
示例#21
0
/*======== void add_sphere() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r
	    double step  
  Returns: 

  adds all the points for a sphere with center 
  (cx, cy) and radius r.

  should call generate_sphere to create the
  necessary points

  jdyrlandweaver
  ====================*/
void add_sphere( struct matrix * points, 
		 double cx, double cy, double r, 
		 int step ) {

  struct matrix * temp;
  int lat, longt;
  int index;
  double x, y, z;
  int num_steps;
  
  num_steps = MAX_STEPS / step;

  temp = new_matrix( 4, num_steps * num_steps );
  //generate the points on the sphere
  generate_sphere( temp, cx, cy, r, step );

  int latStop, longStop, latStart, longStart;
  latStart = 0;
  latStop = num_steps;
  longStart = 0;
  longStop = num_steps;
  index = 0;

  /*print_points(temp);

  printf("\n\n\n\n\n\n\n\n");
  */
  int tmp = 0;
  
  for ( lat = latStart; lat < latStop; lat++ ) {
    if (tmp == (num_steps - 1)) {
      for ( longt = longStart; longt < longStop; longt++ ) { // 1 is longStop
	//      index = lat * (num_steps+1) + longt;
	if (index % num_steps == (num_steps - 1)) {
	  add_polygon( points,
		       temp->m[0][index],
		       temp->m[1][index],
		       temp->m[2][index],
		       temp->m[0][index % num_steps],
		       temp->m[1][index % num_steps],
		       temp->m[2][index % num_steps],
		       temp->m[0][0],
		       temp->m[1][0],
		       temp->m[2][0]
		       );
	  add_polygon( points,
		       temp->m[0][index],
		       temp->m[1][index],
		       temp->m[2][index],
		       temp->m[0][0],
		       temp->m[1][0],
		       temp->m[2][0],
		       temp->m[0][index - (num_steps - 1)],
		       temp->m[1][index - (num_steps - 1)],
		       temp->m[2][index - (num_steps - 1)]
		       );
	}
	else {
	  add_polygon( points,
		       temp->m[0][index],
		       temp->m[1][index],
		       temp->m[2][index],
		       temp->m[0][(index % num_steps)],
		       temp->m[1][(index % num_steps)],
		       temp->m[2][(index % num_steps)],
		       temp->m[0][(index % num_steps) + 1],
		       temp->m[1][(index % num_steps) + 1],
		       temp->m[2][(index % num_steps) + 1]
		       );
	  add_polygon( points,
		       temp->m[0][index],
		       temp->m[1][index],
		       temp->m[2][index],
		       temp->m[0][(index % num_steps) + 1],
		       temp->m[1][(index % num_steps) + 1],
		       temp->m[2][(index % num_steps) + 1],
		       temp->m[0][index + 1],
		       temp->m[1][index + 1],
		       temp->m[2][index + 1]
		       );
	}
	index += 1;
      }

   }
    else{
      for ( longt = longStart; longt < longStop; longt++ ) { // 1 is longStop
	//	printf("index: %d\n", index);
	//      index = lat * (num_steps+1) + longt;
	if (index % num_steps == (num_steps - 1)) {
	  /*	  printf("Special case\n");
	  printf("connection indices: %f, %f, %f\n", index, index + num_steps, index + 1);
	  printf("connection indices: %f, %f, %f\n", index, index + 1, index - (num_steps - 1));
	  printf("index point: %f, %f, %f\n", temp->m[0][index] , temp->m[1][index], temp->m[2][index]);
	  printf("index + num_steps point, %f, %f, %f\n", temp->m[0][index + num_steps], temp->m[1][index + num_steps], temp->m[2][index + num_steps]);
	  printf("NEXT\n");*/
	  add_polygon( points,
		       temp->m[0][index],
		       temp->m[1][index],
		       temp->m[2][index],
		       temp->m[0][index + num_steps],
		       temp->m[1][index + num_steps],
		       temp->m[2][index + num_steps],
		       temp->m[0][index + 1],
		       temp->m[1][index + 1],
		       temp->m[2][index + 1]
		       );
	  add_polygon( points,
		       temp->m[0][index],
		       temp->m[1][index],
		       temp->m[2][index],
		       temp->m[0][index + 1],
		       temp->m[1][index + 1],
		       temp->m[2][index + 1],
		       temp->m[0][index - (num_steps - 1)],
		       temp->m[1][index - (num_steps - 1)],
		       temp->m[2][index - (num_steps - 1)]
		       );
	}
	else {
	  /*	  printf("index point: %f, %f, %f\n", temp->m[0][index], temp->m[1][index], temp->m[2][index]);
	  printf("index + num_steps point, %f, %f, %f\n", temp->m[0][index + num_steps], temp->m[1][index + num_steps], temp->m[2][index + num_steps]);
	  printf("connection indices: %f, %f, %f\n", index, index + num_steps, index + num_steps + 1);
	  printf("connection indices: %f, %f, %f\n", index, index + num_steps + 1, index + 1);*/
	  //	  printf("NEXT\n");
	  add_polygon( points,
		       temp->m[0][index],
		       temp->m[1][index],
		       temp->m[2][index],
		       temp->m[0][index + num_steps],
		       temp->m[1][index + num_steps],
		       temp->m[2][index + num_steps],
		       temp->m[0][index + num_steps + 1],
		       temp->m[1][index + num_steps + 1],
		       temp->m[2][index + num_steps + 1]
		       );
	  add_polygon( points,
		       temp->m[0][index],
		       temp->m[1][index],
		       temp->m[2][index],
		       temp->m[0][index + num_steps + 1],
		       temp->m[1][index + num_steps + 1],
		       temp->m[2][index + num_steps + 1],
		       temp->m[0][index + 1],
		       temp->m[1][index + 1],
		       temp->m[2][index + 1]
		       );
	}
	index += 1;
      }
    }
    tmp += 1;
  }
      
      /*      add_edge( points,
	      temp->m[0][index],
	      temp->m[1][index],
	      temp->m[2][index],
	      temp->m[0][index + 1],
	      temp->m[1][index + 1],
	      temp->m[2][index] );
      */
  //end points only

  /*  printf("\n\n\n\n");
      print_matrix(points);*/

  free_matrix(temp);
}
示例#22
0
文件: draw.c 项目: Zilby/Stuy-Stuff
/*======== void add_sphere() ==========
  Inputs:   struct matrix * points
            double cx
	    double cy
	    double r
	    double step  
  Returns: 

  adds all the points for a sphere with center 
  (cx, cy) and radius r.

  should call generate_sphere to create the
  necessary points

  jdyrlandweaver
  ====================*/
void add_sphere( struct matrix * points, 
		 double cx, double cy, double cz, double r, 
		 int step ) {

  struct matrix * temp;
  int lat, longt;
  int index;
  int num_steps, num_points;
  double px0, px1, px2, px3;
  double py0, py1, py2, py3;
  double pz0, pz1, pz2, pz3;

  num_steps = MAX_STEPS / step;
  num_points = num_steps * (num_steps + 1);
  
  temp = new_matrix( 4, num_points);
  //generate the points on the sphere
  generate_sphere( temp, cx, cy, cz, r, step );

  int latStop, longStop, latStart, longStart;
  latStart = 0;
  latStop = num_steps;
  longStart = 0;
  longStop = num_steps;

  num_steps++;

  for ( lat = latStart; lat < latStop; lat++ ) {
    for ( longt = longStart; longt < longStop; longt++ ) {
      
      index = lat * num_steps + longt;

      px0 = temp->m[0][ index ];
      py0 = temp->m[1][ index ];
      pz0 = temp->m[2][ index ];
      
      px1 = temp->m[0][ (index + num_steps) % num_points ];
      py1 = temp->m[1][ (index + num_steps) % num_points ];
      pz1 = temp->m[2][ (index + num_steps) % num_points ];

      px3 = temp->m[0][ index + 1 ];
      py3 = temp->m[1][ index + 1 ];
      pz3 = temp->m[2][ index + 1 ];

      if (longt != longStop - 1) {
	px2 = temp->m[0][ (index + num_steps + 1) % num_points ];
	py2 = temp->m[1][ (index + num_steps + 1) % num_points ];
	pz2 = temp->m[2][ (index + num_steps + 1) % num_points ];
      }
      else {
	px2 = temp->m[0][ (index + 1) % num_points ];
	py2 = temp->m[1][ (index + 1) % num_points ];
	pz2 = temp->m[2][ (index + 1) % num_points ];
      }

      if (longt != 0)
	add_polygon( points, px0, py0, pz0, px1, py1, pz1, px2, py2, pz2 );
      if (longt != longStop - 1)
	add_polygon( points, px2, py2, pz2, px3, py3, pz3, px0, py0, pz0 );
    }
  }
}