PDA

View Full Version : can you help about my project =(?



olgaa
05-21-2009, 04:37 PM
hi all...i am new here ...and i have project for tomorrow..honestly i would make thisproject pc genious..but hesaid i wouldnt do it last day and i dont know how i can do it :(..my friend haddone it same project and hesent me codes...i dont wanan give same forteacher..i am sure hewill understand...somebody can change codes as teacher cant understand ? ...i am copying codes here..if somebody helps me i will be so happy...thanks even now..

#include <glut.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <math.h>
#define PI 3.14159265
GLfloat turn = 0.0, E=0.0;
void Wheel_front()
{
double x,y;
glPushMatrix();
glTranslatef(-15.0f,-7.0f,0.0f);
glRotatef(E,0,1,0);
glRotatef(turn,0.0,0.0,1.0);
glColor3f(0.1,0.1,0.1);
glBegin(GL_LINES);
glVertex3f(-4.0f,-4.0f,0.0f);// wheel left
glVertex3f(4.0f,4.0f,0.0f);
glEnd();
glBegin(GL_LINES);
for(int i = 0; i <= 360; i++)
{
x = 6.0 * sin(((double)i) * PI / 50); // wheel left
y = 6.0 * cos(((double)i) * PI / 50);
glVertex2f(x,y);
}
glEnd();//end of wheel left
glPopMatrix();
glPushMatrix();
glTranslatef(-10.0f,10.0f,0.0f);
glRotatef(E,0,1,0);
glRotatef(turn,0.0,0.0,1.0);
glBegin(GL_LINES);
glVertex3f(-4.0f,-4.0f,0.0f); //wheel right
glVertex3f(4.0f,4.0f,0.0f);
glEnd();
glBegin(GL_LINES);
for(int i = 0; i <= 360; i++)
{
x = 6.0 * sin(((double)i) * PI / 50);//wheel right
y = 6.0 * cos(((double)i) * PI / 50);
glVertex2f(x,y);
}
glEnd();// end wheel right
glPopMatrix();
}
void Wheel_back(void)
{
double x,y;
glPushMatrix();
glTranslatef(20.0f,-7.0f,0.0f);//whell left
glRotatef(turn,0.0,0.0,1.0);
glColor3f(0.1,0.1,0.1);
glBegin(GL_LINES);
glVertex3f(-2.0f,-2.0f,0.0f);
glVertex3f(2.0f,2.0f,0.0f);
glEnd();
glBegin(GL_LINES);
for(int i = 1; i <= 360; i++)
{
x = 3.0 * sin(((double)i) * PI / 100);
y = 3.0 * cos(((double)i) * PI / 100);
glVertex2f(x,y);
}
glEnd();//end wheel
glPopMatrix();
glPushMatrix();
glTranslatef(25.0f,10.0f,0.0f);
glRotatef(turn,0.0f,0.0f,1.0f);
glBegin(GL_LINES);
glVertex3f(-2.0f,-2.0f,0.0f);//wheel right
glVertex3f(2.0f,2.0f,0.0f);
glEnd();
glBegin(GL_LINES);
for(int i = 1; i <= 360; i++)
{
x = 3.0 * sin(((float)i) * PI /100);
y = 3.0 * cos(((float)i) * PI /100);
glVertex2f(x,y);
}
glEnd();
glPopMatrix();
}
void BOX(void)
{
glPushMatrix();
glColor3f(0.1,0.1,0.1);
glBegin(GL_LINES);
glVertex2f(-15.21f,-7.2f); //frontline
glVertex2f(-10.0f,10.0f);
glVertex2f(20.0f,-7.01f); //back line
glVertex2f(25.0f,10.01f);
// Box construction
glVertex2f(-25.1f,-5.1f);
glVertex2f(28.1f,-5.1f);
glVertex2f(-20.1f,8.0f);
glVertex2f(33.1f,7.8f);
glVertex2f(-25.1f,-5.1f);
glVertex2f(-20.1f,8.0f);
glVertex2f(28.1f,-5.1f);
glVertex2f(33.1f,7.8f);
glVertex2f(-25.1f,-0.1f);
glVertex2f(28.1f,-0.1f);
glVertex2f(-20.1f,14.0f);
glVertex2f(33.1f,13.8f);
glVertex2f(-25.1f,-0.1f);
glVertex2f(-20.1f,14.0f);
glVertex2f(28.1f,-0.1f);
glVertex2f(33.1f,13.8f);
glVertex2f(-25.1f,-5.1f);
glVertex2f(-25.1f,-0.1f);
glVertex2f(28.1f,-5.1f);
glVertex2f(28.1f,-0.1f);
glVertex2f(-20.1f,8.0f);
glVertex2f(-20.1f,14.0f);
glVertex2f(33.1f,7.8f);
glVertex2f(33.1f,13.8f);
//steering line
glVertex2f(-12.1f,2.1f);
glVertex2f(12.1f,24.1f);
glEnd();// end box
glPopMatrix();
}
void steer(void)
{
glPushMatrix();
glColor3f(0.1,0.1,0.1);
glTranslatef(13.0f,25.0f,0.0f);
glRotatef(40,0,1,0);
glBegin(GL_LINES);
glVertex3f(5.0f,5.0f,0.0f);
glVertex3f(-5.0f,-5.0f,0.0f);
double x,y,z,t;
for(int i = 1; i <= 360; i++)
{
x = 4.0 * sin(((double)i) * PI / 40);
y = 4.0 * cos(((double)i) * PI / 40);
z = 5.0 * sin(((double)i) * PI / 40);
t = 5.0 * cos(((double)i) * PI / 40);
glVertex2f(x,y);
glVertex2f(z,t);
}
glEnd();
glPopMatrix();
}
void Acelerate(void)
{
turn=turn+0.7;
if(turn>=1000.0)
{
turn=turn-1000.0;
}
glutPostRedisplay();
}
void go_back(void)
{
turn=turn-0.2;
if(turn>=1000.0)
{
turn=+1000.0;
}
glutPostRedisplay();
}
void X(void)
{
turn=-0.0;
if(turn>=1000.0)
{
turn=+60.0;
}
glutPostRedisplay();
}
void reshape(int w,int h)
{
glClearColor(1.0,1.0,1.0,1.0);
glShadeModel(GL_FLAT);
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-43.5,43.5,-43.5,43.5,-43.5,43.5);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void keyboard(unsigned char btn_key, int x, int y)
{
switch(btn_key)//turn right and left "Q-W" keys
{
case 'q':
if(E<=35)
{
E=E+2.5;
glutPostRedisplay();
}
else{ E=35; }
break;
case 'w':
if(E>=-35)
{
E=E-2.5;
glutPostRedisplay();
}
else{ E=-35;}
break;
case 'Q':
if(E<=35)
{
E=E+2.5;
glutPostRedisplay();
}
else{ E=35;}
break;
case 'W':
if(E>=-35)
{
E=E-2.5;
glutPostRedisplay();
}
else{E=-35;}
break;
default:
break;
}
}
void mouse(int btn_mouse,int state,int x,int y)
{
switch (btn_mouse)
{
case GLUT_RIGHT_BUTTON://goes straight
if (state == GLUT_DOWN)
{
glutIdleFunc(Acelerate);
}
break;
case GLUT_LEFT_BUTTON://goes back
if (state == GLUT_DOWN)
{
glutIdleFunc(go_back);
}
break;
case GLUT_MIDDLE_BUTTON:
if (state == GLUT_DOWN)
{
glutIdleFunc(X);
}
break;
default : break;
}
}
void Show(void)
{
glClear(GL_COLOR_BUFFER_BIT);
Wheel_front();
Wheel_back();
BOX();
steer();
glutSwapBuffers();
}i
nt main (int argc, char** argv)
{
glutInit (&argc, argv); // Initialize GLUT.
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); // Set display mode.
glutInitWindowSize(480,480);
glutInitWindowPosition (155, 155);
// Set top-left display-window position.
// Set display-window width and height.
glutCreateWindow ("MIDTERM PROJECT"); // Create display window.
// Execute initialization procedure.
glutDisplayFunc (Show);
// Send graphics to display window.
glutReshapeFunc(reshape);
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
glutMainLoop ();
// Display everything and wait.
return 0;
}

Jan
05-21-2009, 04:44 PM
http://www.catb.org/~esr/faqs/smart-questions.html

matchStickMan
05-21-2009, 07:26 PM
Hi Olgaa,

I feel for you. But seriously... :p

Good luck with your project. I don't think we can help you here.