Hi Everyone… I have a Little problem with visualization in Opengl…
I know that exist 2 kinds of “proyections” the ortographic one and the “Frustum” one
So… I know how to use ortographic (at least that is what I think). Now I have this code:
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>
#include<stdio.h>
//VARIABLES GLOBALES
long unsigned int ite=0;
long unsigned int i=0;
long unsigned int transciente=0;
double X0=0.0,Y0=0.0,Z0=0.0;
void init(void){
// Light values and coordinates
GLfloat mat_specular[] ={ 1.0f, 1.0f, 1.0f, 1.0f};// { 1.0, 1.0, 1.0, 0.15 };
GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat diffuseLight[] = { 0.7f, 0.7f, 0.7f, 1.0f };
GLfloat mat_shininess[] = { 100.0 };
GLfloat position[] = { 0.5, 0.5, 1.0, 0.0 };
GLfloat ambientLight[] = { 0.3f, 0.3f, 0.3f, 1.0f };
glLightfv(GL_LIGHT0,GL_AMBIENT,ambientLight);
glLightfv(GL_LIGHT0, GL_POSITION, position);
glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuseLight);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f );
/*
glEnable(GL_DEPTH_TEST); // Hidden surface removal
//glFrontFace(GL_CCW); // Counterclockwise polygons face out
//glEnable(GL_CULL_FACE); // Do not calculate inside of jet
// Enable color tracking
glEnable(GL_COLOR_MATERIAL);
// Set material properties to follow glColor values
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
// All materials hereafter have full specular reflectivity
// with a high shine
// Light blue background
glClearColor(0.0f, 0.0f, 1.0f, 1.0f );
glEnable(GL_NORMALIZE);*/
}
void display(void){
double XT,YT,ZT;
//VARIABLES DE LAS FUNCIONES
double H=0.02;
double A=9.0;
double B= 28.8;
double C=(8.0/3.0);
double xmax=0.0,xmin=1e8;
double ymax=0.0,ymin=1e8;
double zmax=0.0,zmin=1e8;
///////////////////////////////////////////////
////////////////// OGL COMMANDS //////////////
///////////////////////////////////////////////
GLfloat mat_solid[] = { 0.75, 0.75, 0.0, 1.0 };
GLfloat mat_zero[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat mat_transparent[] = { 0.0, 0.8, 0.8, 0.6 };
GLfloat mat_emission[] = { 0.0, 0.3, 0.3, 0.6 };
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMaterialfv(GL_FRONT, GL_EMISSION, mat_zero);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_solid);
// glColor3ub((GLubyte)200,(GLubyte)0,(GLubyte)0);
glPushMatrix();
for(i=0;i<ite;i++){
XT= X0 + H*( A * (Y0-X0));
YT= Y0 + H*(X0*(B-Z0)-Y0);
ZT= Z0 + H*( (X0*Y0) -(C*Z0) );
X0=XT;
Y0=YT;
Z0=ZT;
if(i>transciente){
glLoadIdentity();
glTranslatef( (GLfloat) XT, (GLfloat) YT, (GLfloat) ZT);
//glutSolidSphere(10.0,30,30);
glutWireSphere(10.0,30,30);
//CALCULO DE LIMITES DE LA IMAGEN
//calculo xmax y xmin
if(xmax<XT) xmax=XT;
if(xmin>XT) xmin=XT;
//calculo ymax e ymin
if(ymax<YT) ymax=YT;
if(ymin>YT) ymin=YT;
//calculo zmax y zmin
if(zmax<ZT) zmax=ZT;
if(zmin>ZT) zmin=ZT;
}
}
glPopMatrix();
glutSwapBuffers();
printf("%lf,%lf %lf,%lf %lf,%lf
",xmin,xmax,ymin,ymax,zmin,zmax);
}
void mouse(int button, int state, int x, int y)
{
switch (button) {
case GLUT_RIGHT_BUTTON:
exit(0);
break;
default:
break;
}
}
void keyboard(unsigned char key, int x, int y){
switch (key) {
case 'q':
case 'Q':
exit(0);
break;
case 27:
exit(0);
}
}
void reshape(GLsizei w, GLsizei h){
// Prevent a divide by zero
if(h == 0)
h = 1;
// Set Viewport to window dimensions
glViewport(0, 0, w, h);
// Reset projection matrix stack
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-10.0,8.0,-8.0,10.0,1.0,100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(20.0,30.0,50.0,0.0,0.0,0.0,0.0,1.0,0.0);
}
//la ventana que voy a dibujar va a tener Ancho=800,largo=600
int main(int argc, char* argv[]){
FILE *in=NULL;
in=fopen("in.dat","r");
if(in==NULL){
printf("error con el archivo de entrada
");
exit(1);
}
printf("Cargando datos
");
fscanf(in,"%*s %lf",&X0); printf("x0:%lf
",X0);
fscanf(in,"%*s %lf",&Y0); printf("y0:%lf
",Y0);
fscanf(in,"%*s %lf",&Z0); printf("z0:%lf
",Z0);
fscanf(in,"%*s %lu",&ite); printf("Iteraciones: %lu
",ite);
fscanf(in,"%*s %lu",&transciente); printf("trans: %lu
",transciente);
printf("Fin de carga e inicio de operaciones
");
fclose(in);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA| GLUT_DEPTH);
glutInitWindowSize(800,600);
glutCreateWindow("Atractor de Lorentz");
init();
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}
Now I don’t know why If I put in the line where I draw the spheres:
glutWireSphere(1.0,30,30); (for example)
I dont know how to get closer to the “scene”… so I guess I dont see anything… :S
I tried to move the parameters in the Frustum function and the Lookat but I haven found a good way to model this…
Thank you in ad…
PD: The questions is that I dont know what is the relation between the parameters en glFrustum and glLookAt to get a good “view” or and appropiate view in this case… And how could be implemented to any case…