Hi.
For my final year Computer Science project I need to produce a simulator for a new kind of 3d display. I’m doing this using OpenGL (obviously ). I have a few questions.
-
I need to animate accurately a square/circular screen spinning at 30hz inside the display. Now I can do so, with incrementing the rotation angle with each idle call of the function, but this either doesn’t get the speeds I require, or if I rotate by 150 degrees each frame(which I figured out would get me roughly 30hz at 72 fps)the rotation is anything but smooth. Is there any way to make objects spin very fast and smoothly? (or is there any way I can fake it? It is very important that the screen not only appears to spin smoothly, but actually does go through every degree.)
-
Currently, the OpenGL output consists of the spinning screen, a central glass sphere, and some cones around the sphere representing the beam sources. I’ve set up lights that light up half the sphere, and leave the other half semi-unlit - however, the cones aren’t affected at all by the light. They’re flat shaded (not GL_FLAT) without the proper shading. I do have webspace somewhere, but I’m in uni now and I don’t have the details to upload any pics at the moment.
The code for the objects and lighting is below.
void draw_cones(float srad, float rotang, int no_cones){ //draws all beam sources at specified angles
float rrotang = 0.0; //(remember specified distances/size)
while (no_cones != 0){
glPushMatrix();
glRotatef(rrotang, 0.0, 1.0, 0.0);
glTranslatef(0.0, 0.0, srad-0.1);
glColor4f(1, 1, 1, 0.5);
glutSolidCone(0.25, 0.6, 20.0, 10.0);
glPopMatrix();rrotang = rrotang + rotang; no_cones--;
}
}
void draw_screen(){
glPushMatrix();
glRotatef(axis_rot, 0, 1, 0);glPushMatrix(); //currently fixed screen size glColor4f(0.5, 0.5, 0.5, 0.2); glScalef(1, 1, 0.02); glutSolidCube(0.5); glPopMatrix(); glPushMatrix(); //screen shaft (distorted cube) glColor4f(0.5, 0.5, 0.5, 1); glScalef(1, 50, 0.5); glTranslatef(0, 0.002, 0); glutSolidCube(0.015); glPopMatrix();
glPopMatrix();
axis_rot += 150;
}
void display(void){
float srad = 0.4; //main sphere radius
float rotang = 90.0; //rotation angle between beam sources
int no_cones = 2; //number of beam source conesfps();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
camerapos(srad); glLoadIdentity(); gluLookAt(0.0,0.0,0.0, //camera direction cx,cy,cz, //camera position 0.0,1.0,0.0); //up vector draw_screen(); glColor4f(1, 1, 1, 0.2); glutSolidSphere(srad, 40.0, 40.0); glColor4f(1, 1, 1, 0.2); glutSolidSphere(srad-wall_thickness, 40.0, 40.0); draw_cones(srad, rotang, no_cones); glTranslatef(0.0, 0.0, 5.0); glFlush();
glPopMatrix();
glutSwapBuffers();
}
void lighting(){
GLfloat light_pos = {0.0, 0.0, -1.0, 0.5};
GLfloat light_amb = {0.2, 0.2, 0.2, 0.2};glLightfv(GL_LIGHT0,GL_POSITION, light_pos);
glLightfv(GL_LIGHT0,GL_AMBIENT, light_amb);glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}
void init(){
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
Thanks.
[This message has been edited by Durandal (edited 12-09-2003).]