checkered pattern

Hi
This program draws ckeckered pattern onto the surface of the sphere.It's for 8*8 .how can i edit it for 16*16.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <cmath>
#include <GL/glut.h>
using namespace std;
void display()
{
	int i ,j=1 , c=1;
	float u=-0.5 , v=0.0 , R=100.0 , p=3.1415;
	const float t=1.0/8.0;
	float poly[12];
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	gluLookAt(0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0);
	for (i=1;i<=8;i++)
	{
		for (j=1;j<=8;++j)
		{
			poly[0]=R*cos(p*u)*cos(2*p*v);
			poly[1]=R*cos(p*u)*sin(2*p*v);
			poly[2]=R*sin(p*u);

			poly[3]=R*cos(p*(u+t))*cos(2*p*v);
			poly[4]=R*cos(p*(u+t))*sin(2*p*v);
			poly[5]=R*sin(p*(u+t));
			poly[6]=R*cos(p*(u+t))*cos(2*p*(v+t));
			poly[7]=R*cos(p*(u+t))*sin(2*p*(v+t));
			poly[8]=R*sin(p*(u+t));
			poly[9]=R*cos(p*u)*cos(2*p*(v+t));
			poly[10]=R*cos(p*u)*sin(2*p*(v+t));
			poly[11]=R*sin(p*u);
			if (c==1) glColor3f(1.0,1.0,0.0);
				if (c==-1) glColor3f(1.0,0.5,0.0);
				c=c* (-1);

				glBegin(GL_QUADS);
				glVertex4f(poly[0],poly[1],poly[2],1.0);
				glVertex4f(poly[3],poly[4],poly[5],1.0);
				glVertex4f(poly[6],poly[7],poly[8],1.0);
				glVertex4f(poly[9],poly[10],poly[11],1.0);

				glEnd();
				v= v+(1.0/8.0);
		}
				u= u+(1.0/8.0);
				v=0.0;
				c=c*(-1);

		}
		glFlush();
	}
	void init()
	{
		glEnable(GL_DEPTH_TEST);
		glClearColor(0.0,0.0,0.0,0.0);
			glColor3f(1.0,0.0,0.0);
			glMatrixMode(GL_PROJECTION);
			glLoadIdentity();
			glOrtho(-200,200,-200,200,-200,200);
			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();
	}
	int main(int argc,char** argv)
	{
		glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH );
	glutInitWindowSize(500,500);
	glutInitWindowPosition(0,0);
	glutCreateWindow("Sphere-Checkered");
	glutDisplayFunc(display);
	init();
	glutMainLoop();

}
Last edited on
On line 9 t has to be 1./16., the two for loops go from 1 to 16, and on lines 41 and 43 replace 1.0/8.0 with t
Topic archived. No new replies allowed.