PDA

View Full Version : Wire Cube, and Cube and GUI



tony_ee81
09-11-2002, 05:26 AM
Hi There,
I just want want to make a wire cube and in this wire cube i also want a small cube and a cylinder.
Then using the GUI i just want to change the position of small cube or cylinder ,inside the big wire cube.
Which technique will be better ,either GLUT & GLUI or Win32.
Please help me, as this is very important.

Regards,

Tony

Gavin
09-11-2002, 05:51 AM
Which are you more comfortable with? As what you need is pretty basic just use the one you are more familiar with.

nexusone
09-11-2002, 06:25 AM
There is not really one better then the other, just which one offers the features you want. But for your simple program any of the above would work well.

GLUT and GLUI are crossplatform and win32 is not. If it is importaint to you that your program run on other operating systems then win32 is not a good choice.



Originally posted by tony_ee81:
Hi There,
I just want want to make a wire cube and in this wire cube i also want a small cube and a cylinder.
Then using the GUI i just want to change the position of small cube or cylinder ,inside the big wire cube.
Which technique will be better ,either GLUT & GLUI or Win32.
Please help me, as this is very important.

Regards,

Tony

tony_ee81
09-12-2002, 11:07 AM
Hi nexusone and all otherGuys,
Is it possible for someone that could send me the code for my problem.Altough i had an idea about this but i just want to change the position of the small cube and cylinder inside the big Wirecube.
Should i use C++ and create Three Objects
1:Big WireCube,
2:Small Soild Cube
3:Cylinder
and then call one by one.
As some time i need only small cube in a big cube so that i can call these objects and some othertime i can call Cylinder in a big cube.

Though my question is just a childish but right now i need help from u guys.
Regards,

Tony

nexusone
09-12-2002, 01:08 PM
Here is a little code maybe will help, just bits of the program needed to do what you ask.

Anymore and I would have writen a the whole thing for you.....

http://www.opengl.org/discussion_boards/ubb/smile.gif




#include<GL\glut.h>

//first define our object varaibles
int wire_cube; // object on/off; 0=off, 1=on
int small_cube;
int cylinder;

GLfloat wire_cube_xyz[3]; // location of our objects
GLfloat small_cube_xyz[3];
GLfloat cylinder_xyz[3];

GLint wire_cube_rotation[3]; // rotation of objects
GLint small_cube_rotation[3];
GLint cylinder_rotation[3];


display()
{


// draw wire cube

glPushMatrix();
glTranslatef(wire_cube_xyz[0],wire_cube_xyz[1],wire_cube_xyz[2]);
glRotatef(wire_cube_rotation[0], 1,0,0);

if (wire_cube == 1) Draw_wire_cube();

glPopMatrix();

// Draw small cube
glPushMatrix();
glTranslatef(small_cube_xyz[0],small_cube_xyz[1],small_cube_xyz[2]);
glRotatef(small_cube_rotation[0], 1,0,0);

if (small_cube == 1) Draw_small_cube();

glPopMatrix();

// Draw cylinder
glPushMatrix();
glTranslatef(cylinder_xyz[0],cylinder_xyz[1],cylinder_xyz[2]);
glRotatef(cylinder_rotation[0], 1,0,0);

if (cylinder == 1) Draw_cylinder();

glPopMatrix();

}

keyboard()
{

if (key == "W") wire_cube = 1;
// repeat to turn on other objects.

}





Originally posted by tony_ee81:
Hi nexusone and all otherGuys,
Is it possible for someone that could send me the code for my problem.Altough i had an idea about this but i just want to change the position of the small cube and cylinder inside the big Wirecube.
Should i use C++ and create Three Objects
1:Big WireCube,
2:Small Soild Cube
3:Cylinder
and then call one by one.
As some time i need only small cube in a big cube so that i can call these objects and some othertime i can call Cylinder in a big cube.

Though my question is just a childish but right now i need help from u guys.
Regards,

Tony

[This message has been edited by nexusone (edited 09-12-2002).]

[This message has been edited by nexusone (edited 09-12-2002).]

nexusone
09-20-2002, 11:58 AM
Tony, here is an updated code, thought I would post it here also. I will also e-mail this newest version to you.


Has a wire cube, inside the wire cube is a solid cube, colid cone. No cylinder at this time ,just wanted to use glut. later can replace all with glu privitive.
keyboard commands:
[ESC] key quits program
"W" stop/starts wire cube
"S" stop/starts solid cube
"C" stop/starts solid cone




#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


GLfloat wire_cube, solid_cube, solid_cone; // store objects current rotation
static int wire_cube_rotate = 1, solid_cube_rotate = 1, solid_cone_rotate = 1; // store state; 0= no rotation, 1 = rotation


void Sprint( int x, int y, char *st)
{
int l,i;

l=strlen( st );
glRasterPos2i( x, y);
for( i=0; i < l; i++)
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, st[i]);
}

}

static void TimeEvent(int te)
{
int timent;
int i;

glutPostRedisplay();
glutTimerFunc( 100, TimeEvent, 1);
}

void init(void)
{


glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_SMOOTH);
glEnable(GL_DEPTH_TEST);

}


void display(void)
{


glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode (GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, 1, 1.0, 50.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glPushMatrix();// Draw small solid cube
glColor3f(0.0, 1.0, 1.0); // give it a color
glTranslatef( -3.0, 0.0, -20.0); //move it into our our view.
if (solid_cube_rotate == 1) solid_cube++;
if (solid_cube > 360) solid_cube = 0; // check for rotation pass 360, and reset if above.
glRotatef(solid_cube, 0.0, 0.0, 1.0); // rotate on z-axis
glutSolidCube(2.0);
glPopMatrix();

glPushMatrix(); // Draw small solid cone...I stuck with all glut primitives, but later we can replace all with glu primitives.
glColor3f(1.0, 0.0, 1.0);
glTranslatef( 3.0, -1.0, -20.0);
if (solid_cone_rotate == 1) solid_cone++;
if (solid_cone > 360) solid_cone = 0;
glRotatef(solid_cone, 0.0, 0.0, 1.0);
glRotatef(90.0, 0.0, 1.0, 0.0);
glutSolidCone(2.0, 2, 8, 8);
glPopMatrix();

glPushMatrix(); // Draw large wire cube
glColor3f(1.0, 1.0, 1.0);
glTranslatef( 0.0, 0.0, -20.0);
if (wire_cube_rotate == 1) wire_cube++;
if (wire_cube > 360) wire_cube = 0;
glRotatef(wire_cube, 0.0, 0.0, 1.0);
glRotatef(wire_cube, 0.0, 1.0, 0.0);
glutWireCube(10.0);
glPopMatrix();


// easy way to put text on the screen.
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-5.0, 5.0, 5.0, -5.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glColor3f(1.0, 0.5, 0.5);
Sprint(-1, -1, "OpenGL" );


glutSwapBuffers();
}

void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective(60.0,(GLfloat) w/(GLfloat) h, 1.0, 50.0);

}

void keyboard (unsigned char key, int x, int y)
{
switch (key)
{
case 'W':
wire_cube_rotate = abs( wire_cube_rotate - 1); // Toggle rotate on off.
break;
case 'S':
solid_cube_rotate = abs( solid_cube_rotate - 1); // Toggle rotate on off.
break;
case 'C':
solid_cone_rotate = abs( solid_cone_rotate - 1); // Toggle rotate on off.
break;
case 27:
exit(0); // exit program when [ESC] key presseed
break;
default:
break;
}


}


int main(int argc, char** argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (10, 10);
glutCreateWindow (argv[0]);
glutSetWindowTitle("Mike");
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutTimerFunc( 10, TimeEvent, 1);
glutMainLoop();
return 0;
}