PDA

View Full Version : Rotation problem

Chandrou
05-20-2011, 01:41 AM
Hi,

For my school project, i have to display the rotation of a sphere with x,y and z axes. I have no problem with the rotation glRotated and the axis angles. The function reads the angles from a file i opened with fopen.It seems to work fine but when i'm changing the angles , we can see the rotation but it displays 6 axes instead of 3 axes : I have each axes twice.
Here is my code for the function draw and my main:

void DRAW()

{
float x,y,z,angle = 0;
convert(&amp;position,&amp;position2,&amp;position3);
angle = position3.angle;
//Sleep(500);

x=position2.x;
y=position2.y;
z=position2.z;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

//The modelview matrix is choosen
glMatrixMode(GL_MODELVIEW);

//Creates a viewing matrix derived from an eye point, a reference point indicating the center of the scene and an up vector
gluLookAt(4,4,4,0,0,0,0,0,1);

glPushMatrix();

glTranslated(-1,-1,-1);

glColor3f(1,1,1);

glBindTexture(GL_TEXTURE_2D, texture[1]);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
//the plan where the sphere is

glTexCoord2d(0.0,0.0);
glVertex3f(-6.0,0.0,1.0);

glTexCoord2d(1.0,0.0);
glVertex3f(0.0,-6.0,1.0);

glTexCoord2d(1.0,1.0);
glVertex3f(6.0,0.0,0.0);

glTexCoord2d(0.0,1.0);
glVertex3f(0.0,6.0,0.0);

glEnd();

glPopMatrix();

glPushMatrix();

//Rotation of the sphere
glRotatef(angle, x, y, z);

glBindTexture(GL_TEXTURE_2D, texture[0]);

glLineWidth (4.0);

glBegin (GL_LINES);

glColor3f (1,0,0);glVertex2i(0,1);glVertex2i(0,3);

glEnd();

glBegin (GL_LINES);

glColor3f (0,1,0);glVertex2i(1,0);glVertex2i(3,0);

glEnd();

glBegin (GL_LINES);

glColor3f (0,0,1); glVertex3i(0,0,1);glVertex3i(0,0,3);

glEnd();

glBegin(GL_LINES);

glColor3f(0.5,0.5,0.5);

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);

glTexGeni(GL_T, GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

gluSphere(Boule,1,25,25);

glEnd();

glPopMatrix();

glFlush();

glutSwapBuffers();

//Marks the current or specified window as needing to be redisplayed

glutPostRedisplay();

}

int main( int argc, char *argv[ ])
{
coordinates *Position = NULL;
coordinates *PositionEnd = NULL;
coordinates *MemoryPosition = NULL;
char trame[20];
int result;

Position = (coordinates*)malloc(sizeof(coordinates));
PositionEnd = (coordinates*)malloc(sizeof(coordinates));

Position->pNextPosition = PositionEnd;
Position->pPreviousPosition = PositionEnd;
PositionEnd->pNextPosition = NULL;
PositionEnd->pPreviousPosition = Position;
INIT_INTERFACE_GRAPHIQUE(argc,argv);

file = fopen("acquisitions.txt", "r");

if(file == NULL)
{
printf("The file was not created");
}
else
{
printf("The file is opened and is in read only mode\n");
}

file2 = fopen("acquisitions2.csv", "w+");

if(file2 == NULL)
{
printf("The file 2 was not created\n");
}
else
{
printf("The file 2 has been created and is in write mode\n");

}

fseek(file,0,SEEK_SET);
fseek(file2,0,SEEK_SET);

while (ftell(file) != SEEK_END)
{

result = SetBuffer(Position, PositionEnd, file);

if (result != FRAME_OK) break;

MemoryPosition = Position;

while (Position!=NULL)
{
fseek(file2,0,SEEK_CUR);
sprintf(trame,"%d;%d;%d\n",Position->x, Position->y, Position->z);
fprintf(file2,"%s",trame);
Position = Position->pNextPosition;

}

Position = MemoryPosition;
FreeBuffer(Position, PositionEnd);
Position->x = PositionEnd->x;
Position->y = PositionEnd->y;
Position->z = PositionEnd->z;
}

fclose(file);
fclose(file2);
file2 = fopen("acquisitions2.csv","r");
fseek(file2,0,SEEK_SET);

glutDisplayFunc(DRAW);
glutReshapeFunc(RESHAPE);
glutMainLoop();

glDisable(GL_TEXTURE_2D);
fclose(file2);

return 0 ;

Could somebody help me please ?

Regards,
Chandra.

ps : excuse my poor english...