# question8: last year's exam

Announcements Last Post
myUnisa availability 21 to 24 March 2019 03/17/2019 02:24PM
SoC Curricula 09/30/2017 01:08PM
Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
School of Computing Short Learning Programmes 11/24/2014 08:37AM
Unisa contact information 07/28/2011 01:28PM
 question8: last year's exam October 05, 2006 11:57AM IP/Host: 81.52.163.--- Registered: 13 years ago Posts: 18 Rating: 0
Hi everyone,
Please can someone help with question 8 of last year's exam?
I seem unable to position the light point correctly!! It is rotated with the sphere!!
 Re: question8: last year's exam October 13, 2006 09:17PM IP/Host: 198.54.202.--- Registered: 13 years ago Posts: 78 Rating: 0
#include <GL/glut.h>
#include <math.h>

void earth()
{
float x, y, z, thet, phi;
float c = 3.14159/180.0;

for (phi = -90.0; phi <= 90.0; phi += 20.0)
{
for (thet = -180.0; thet <= 180.0; thet += 20.0)
{
x = sin(c*thet)*cos(c*phi);
y = cos(c*thet)*cos(c*phi);
z = sin(c*phi);
glNormal3f(x, y, z); // just need 1 normal for flat shading
glVertex3f(x, y, z);

x = sin(c*thet) * cos(c*(phi+20.0));
y = cos(c*thet) * cos(c*(phi+20.0));
z = sin(c*(phi+20.0));
glVertex3f(x, y, z);
}
glEnd();
}
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glRotatef(105, 1.0, 0.0, 0.0);
earth();

glFlush();
}

void reshape(int w, int h)
{
glViewport(0, 0, w, h);

glMatrixMode(GL_PROJECTION);

if (w <= h)
glOrtho(-2.0, 2.0, -2.0*(GLfloat)h/w, 2.0*(GLfloat)h/w, -10.0, 10.0);
else
glOrtho(-2.0*(GLfloat)w/h, 2.0*(GLfloat)w/h, -2.0, 2.0, -10.0, 10.0);

glMatrixMode(GL_MODELVIEW);
}

void init()
{
glEnable(GL_DEPTH_TEST);

// enable lighting
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

// set the shading model to flat

// position the light before any transformations take place
GLfloat pos[] = {0.0, 0.0, 2.0, 0.0};
glLightfv(GL_LIGHT0, GL_POSITION, pos);

glClearColor(1.0, 1.0, 1.0, 1.0);
// glColor3f(0.0, 0.0, 0.0); // optional

// glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // optional
glPolygonMode(GL_FRONT, GL_FILL);
}

int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500);

glutCreateWindow("sphere";

glutReshapeFunc(reshape);
glutDisplayFunc(display);

init();

glutMainLoop();

return 0;
}
Sorry, only registered users may post in this forum.