Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/glew.h>
- #include <GLFW/glfw3.h>
- #include <OpenGL/gl.h>
- #include <OpenGl/glu.h>
- #include <GLUT/glut.h>
- #include <iostream>
- #define _USE_MATH_DEFINES
- #include <math.h>
- #include <stdio.h>
- GLfloat xRotated, yRotated, zRotated;
- GLdouble radius = .3;
- GLfloat xPos = 0;
- GLfloat yPos = 0;
- GLfloat zPos = 0;
- GLfloat vertices[11][3] = {{-1,-1,0},{-.8,-.8,0},{-.6,-.6,0},{-.4,-.4,0},{-.2,-.2,0},{0,0,0},{.2,.2,0},{.4,.4,0},{.6,.6,0},{.8,.8,0}, {1,1,0}};
- int test[4] = {1,2,3,4};
- void display(void);
- void reshape(int x, int y);
- void idle(void)
- {
- //xRotated += 0.3;
- // yRotated += 0.3;
- zRotated += 0.3;
- display();
- }
- int main (int argc, char **argv)
- {
- glutInit(&argc, argv);
- glutInitWindowSize(350,350);
- glutCreateWindow("Solid Sphere");
- xRotated = yRotated = zRotated = 30.0;
- xRotated=43;
- yRotated=350;
- glutDisplayFunc(display);
- glutReshapeFunc(reshape);
- glutIdleFunc(idle);
- glutMainLoop();
- return 0;
- }
- void myWireSphere(float r, int nParal, int nMerid){
- float x,y,z,i,j;
- for (j=0;j<3.14159; j+=3.14159/(nParal+1)){
- glBegin(GL_LINE_LOOP);
- y=(float) (r*cos(j));
- for(i=0; i<2*3.14159; i+=3.1415960){
- x=(float) (r*cos(i)*sin(j));
- z=(float) (r*sin(i)*sin(j));
- glVertex3f(x,y,z);
- }
- glEnd();
- }
- for(j=0; j<3.14159; j+=3.14159/nMerid){
- glBegin(GL_LINE_LOOP);
- for(i=0; i<2*3.14159; i+=3.14159/60){
- x=(float) (r*sin(i)*cos(j));
- y=(float) (r*cos(i));
- z=(float) (r*sin(j)*sin(i));
- glVertex3f(x,y,z);
- }
- glEnd();
- }
- }
- void display(void)
- {
- glMatrixMode(GL_MODELVIEW);
- // clear the drawing buffer.
- glClear(GL_COLOR_BUFFER_BIT);
- // clear the identity matrix.
- glLoadIdentity();
- // traslate the draw by z = -4.0
- // Note this when you decrease z like -8.0 the drawing will looks far , or smaller.
- glTranslatef(0.0,0.0,-5.0);
- // Red color used to draw.
- glColor3f(0.9, 0.3, 0.2);
- // changing in transformation matrix.
- // rotation about X axis
- //Translates sphere to given coordinates
- // glTranslatef(xPos, yPos, zPos);
- // glRotatef(xRotated,1.0,0.0,0.0);
- // rotation about Y axis
- // glRotatef(yRotated,0.0,1.0,0.0);
- // rotation about Z axis
- //glRotatef(zRotated,0.0,1.0,1.0);
- // scaling transfomation
- glScalef(1.0,1.0,1.0);
- glTranslatef(vertices[0][0], vertices[0][1], vertices[0][2]);
- myWireSphere(radius,25,25);
- //glutWireSphere(radius,25,25)
- for (int i = 1; i < sizeof(vertices)/sizeof(vertices[0]); i++) {
- glTranslatef(vertices[i][0] - vertices[i-1][0], vertices[i][1] - vertices[i-1][1], vertices[i][2] - vertices[i-1][2]);
- myWireSphere(radius,25,25);
- }
- // Flush buffers to screen
- glFlush();
- // sawp buffers called because we are using double buffering
- // glutSwapBuffers();
- }
- void reshape(int x, int y)
- {
- if (y == 0 || x == 0) return;
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(39.0,(GLdouble)x/(GLdouble)y,0.6,21.0);
- glMatrixMode(GL_MODELVIEW);
- glViewport(0,0,x,y); //Use the whole window for rendering
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement