Voila j'ai passé l'après midi a chercher d'ou vient mon problème sans succès.
je tente même de faire des affichages console avant et après incrémentation, rien n'y fait :
printf("avant : %4d",camy);
camy+=8.0;
printf("apres : %4d\n",camy);
voici donc le code, pour que vous puissiez voir de vos yeux, moi je comprend plus rien :
visual C++ 6
#include <windows.h>
#include <math.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glut.h>
#include <stdio.h>
static GLfloat g_nearPlane = 1;
static GLfloat g_farPlane = 1000;
int frame,time,timebase=0;
float fps;
char fpstxt[10];
bool lPress,rPress;
int mouseX,mouseY;
int rollX=0,rollY=0;
GLuint solList;
int nbtriangle;
const float PI = 3.1415926536;
double radian= 180/PI;
float rotatex=0,rotatey=0,rotatez=0;
float camx=0,camy=0,camz=0;
// =======================================
void sol()
{
solList = glGenLists(1);
glNewList(solList, GL_COMPILE);
float z=0.0;
float pasj=0.2;
float pasi=0.2;
nbtriangle=0;
for (float j=0; j<16; j=j+pasj)
{
for(float i=0; i<16; i=i+pasi)
{
glColor3f(1.0, 0.0, 0.0);
glVertex3f(i, j, z);
glVertex3f(i, j+pasj, z);
glVertex3f(i+pasi, j, z);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(i, j+pasj, z);
glVertex3f(i+pasi, j+pasj, z);
glVertex3f(i+pasi, j, z);
nbtriangle+=2;
}
}
glEndList();
}
// ----------------------------------------
void init()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
}
// ----------------------------------------
void printFPS(void)
{
frame++;
time=glutGet(GLUT_ELAPSED_TIME);
if (time - timebase > 1000)
{
fps=frame*1000.0/(time-timebase);
sprintf(fpstxt,"FPS: %4.2f triangle : %4d",fps, nbtriangle);
glutSetWindowTitle(fpstxt);
timebase = time;
frame = 0;
}
}
// ---------------------------------------
void mouse(int button, int state, int x, int y)
{
switch (button)
{
case GLUT_LEFT_BUTTON:
if (state == GLUT_DOWN)
{
lPress=1;
mouseX=x;
mouseY=y;
//printf("Bt G : %4d %4d\n",x,y);
}
else
lPress=0;
break;
case GLUT_RIGHT_BUTTON:
if (state == GLUT_DOWN)
{
rPress=1;
mouseX=x;
mouseY=y;
//printf("Bt D : %4d %4d\n",x,y);
}
else
rPress=0;
break;
default:
break;
}
}
// ---------------------------------------
void mousemotion(int x,int y)
{
if (rPress)
{
printf("oldX : %4d / X : %4d oldY : %4d /Y : %4d /Camy : %4d\n", mouseX,x,mouseY,y,camy);
/*if (x<mouseX)
camx-=1;
else
camx+=1;
*/
if (y<mouseY)
{
printf("avant : %4d",camy);
camy+=8.0;
printf("apres : %4d\n",camy);
}
else
camy+=1;
mouseX=x;
mouseY=y;
}
glutPostRedisplay();
}
// ---------------------------------------
void mousePassiveMotion(int x,int y)
{
//printf("Pos : %4d %4d\n",x,y);
}
// ---------------------------------------
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
camx*=cos(rotatex/radian)*cos(rotatey/radian);
camy*=cos(rotatex/radian)*sin(rotatey/radian);
camz*=sin(rotatex/radian);
gluLookAt(camx, camy, 20.0, 8.0, 8.0, 0.0, 0.0, 0.0, 1.0);
glTranslatef(0,0,0);
glBegin(GL_TRIANGLES);
glCallList(solList);
glEnd();
printFPS();
glFlush();
glutSwapBuffers();
glutPostRedisplay();
}
// ---------------------------------------
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (float)w / h, g_nearPlane, g_farPlane);
glMatrixMode(GL_MODELVIEW);
}
// ---------------------------------------
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowPosition(100,100);
glutInitWindowSize(800,600);
glutCreateWindow("Vince");
init();sol();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMouseFunc(mouse);
glutMotionFunc(mousemotion);
glutPassiveMotionFunc(mousePassiveMotion);
glutMainLoop();
return(0);
}
Merci de votre aide.
Afficher la suite