PDA

View Full Version : TO Kehziah and Michael...I think you can identify my problem with this one..



profbalse
09-16-2003, 07:04 AM
Hi Kehziah and Michael...
Actually, I am simualting the X-ray Environment in 3D for my research...So, my objective is to get the projection displayed on the screen alongwith the 3D object[A cube..initially]..I will present the code below which will be of use for you to reply..I guess..
----These are the values which you should enter in the console------------------------
ENTER THE SCALE DATA FOR THE CUBE[X,Y,Z]:2.0 1.0 1.0
ENTER THE ORIENTATION ANGLE[X,Y,Z]0.0 0.0 0.0

ENTER THE PERSPECTIVE VIEW DATA[A,AR,NV,FV]:48 4 1 10

ENTER THE TRANSLATION DATA:[X,Y,Z]0.0 0.0 -4.0
---------------------------------------------
CODE...BELOW
---------------------------------------------
#include <GL\glut.h>
#include<GL\glu.h>
#include<iostream.h>
#include<process.h>
#include<stdio.h>
//#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
typedef struct
{
GLdouble sx,sy,sz,X,Y,Z,V,tx,ty,tz,nv,fv,ar;
}input;
input in;


void Display()
{ // GLdouble mvm[16];
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glTranslatef(in.tx,in.ty,in.tz); //standard 0.0,0.0,4.0
glRotatef(in.X,1.0,0.0,0.0);
glRotatef(in.Y,0.0,1.0,0.0);
glRotatef(in.Z,0.0,0.0,1.0);
glScalef(in.sx,in.sy,in.sz);
glColor3f(1.0,1.0,0.0); //standard 2.0,1.0,1.0
glutWireCube(1.0);
glTranslatef(0.0,-0.1,0.1);
glutSolidCube(0.09);
glColor3f(0.0,1.0,1.0);
glTranslatef(0.0,-0.01,0.1);
glutSolidCube(0.02);
glColor3f(1.0,0.0,1.0);
glTranslatef(0.0,-0.1,0.1);
glutSolidCube(0.08);
glColor3f(0.0,0.0,1.0);
glTranslatef(0.02,0.1,-0.1);
glutSolidCube(0.082);
glColor3f(1.0,0.0,0.0);
glTranslatef(0.06,0.06,-0.06);
glutSolidCube(0.082);
glColor3f(0.0,0.0,1.0);
glTranslatef(0.0,-0.08,0.1);
glutSolidCube(0.045);
glColor3f(1.0,0.0,1.0);
glTranslatef(0.0,0.08,0.1);
glutSolidCube(0.05);
glFlush();
glutSwapBuffers();
}
void Reshape(int x, int y)
{
if (y == 0 | | x == 0)
return;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(in.V,in.ar,in.nv,in.fv); //standard:48,6,1,10
//glOrtho(0.0,800.0,0.0,600.0);
//glFrustum(-1,1,-1,1,2,20);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0,0,x,y);

}


void KeyPress(unsigned char key,int x,int y)
{
switch(key)
{
case 'a':
in.X=in.X+5;
Display();
break;
case 's':
in.X=in.X-5;
Display();
break;
case 'd':
in.Y=in.Y+5;
Display();
break;
case 'f':
in.Y=in.Y-5;
Display();
break;
case 'z':
in.Z=in.Z+5;
Display();
break;
case 'x':
in.Z=in.Z-5;
Display();
break;
case 'q':
in.sx=in.sx+0.5;
in.sy=in.sy+0.5;
in.sz=in.sz+0.5;
Display();
break;
case 'w':
in.sx=in.sx-0.5;
in.sy=in.sy-0.5;
in.sz=in.sz-0.5;
Display();
break;
case 'e':
in.tx=in.tx+0.5;
in.ty=in.ty+0.5;
in.tz=in.tz+0.5;
Display();
break;
case 'r':
in.tx=in.tx-0.5;
in.ty=in.ty-0.5;
in.tz=in.tz-0.5;
Display();
break;
case 'c':
in.ar=in.ar+5;
Display();
break;
case 'v':
in.ar=in.ar-5;
Display();
break;
case 'l':
in.nv=in.nv+1.0;
Display();
break;
case 'k':
in.nv=in.nv-1.0;
Display();
break;
case 'b':
in.fv=in.fv+1.0;
Display();
break;
case 't':
in.fv=in.fv-1.0;
Display();
break;
case 'g':
in.V=in.V+5.0;
Display();
break;
case 'h':
in.V=in.V-5.0;
Display();
break;
case 'p':
cout<<"\n\n\t"<<"\n X="<<in.X<<"\n Y="<<in.Y<<"\n Z="<<in.Z<<"\n SX="<<in.sx<<"\n SY="<<in.sy<<"\n SZ="<<in.sz<<"\n TX="<<in.tx<<"\n TY="<<in.ty<<"\n TZ="<<in.tz<<"\n V="<<in.V<<"\n AR="<<in.ar<<"\n NV="<<in.nv<<"\n FV="<<in.fv;
glTranslatef(in.tx,in.ty,in.tz);
glRotatef(in.X,1.0,0.0,0.0);
glRotatef(in.Y,0.0,1.0,0.0);
glRotatef(in.Z,0.0,0.0,1.0);
glScalef(in.sx,in.sy,in.sz);
glutWireCube(1.0);
Display();
break;


}
}

int main(int argc, char **argv)
{
cout<<"\nENTER THE SCALE DATA FOR THE CUBE[X,Y,Z]:";
cin>>in.sx>>in.sy>>in.sz;
cout<<"\n ENTER THE ORIENTATION ANGLE[X,Y,Z]";
cin>>in.X>>in.Y>>in.Z;
cout<<"\n ENTER THE PERSPECTIVE VIEW DATA[A,AR,NV,FV]:";
cin>>in.V>>in.ar>>in.nv>>in.fv;
cout<<"\n"<<"ENTER THE TRANSLATION DATA:[X,Y,Z]";
cin>>in.tx>>in.ty>>in.tz;
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(300,300);
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
glutCreateWindow("BeeJay");
glClearColor(0.0,0.0,0.0,0.0);
glutDisplayFunc(Display);
glutReshapeFunc(Reshape);
glutKeyboardFunc(KeyPress);
glutMainLoop();
return 0;
}
---------------------------------------------
I think you guys must have spotte th problem by now..If so, Please lemme know.....Thanks

Ciao

BeeJay