rendered paste body/* Basic i/o libraries */
#include <stdio.h>
#include <stdlib.h>
/* OpenGL defines/includes */
#define GLUT_DISABLE_ATEXIT_HACK
#include <stdarg.h>
#include <GL\gl.h>
#include <GL\glu.h>
#include <GL\glut.h>
void MakeWindow(void);
void WindowDisplay(void);
void WindowKeyboard(unsigned char key, int x, int y);
void WindowReshape(int w, int h);
void DrawTrajectory();
int xcalc(float v, float t, float ti);
int ycalc(float v, float t, float ti);
void DrawTank(int x,int y);
int wnd;
int main(int argc, char *argv[])
{
glutInit(&argc, argv); /* Initialize glut */
MakeWindow();
glutMainLoop();
return 0;
}
void MakeWindow(void)
{
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize(500,500);
wnd = glutCreateWindow("Draw");
glClearColor(1,1,1,0); /* set clear color to white */
glutDisplayFunc(WindowDisplay);
glutKeyboardFunc(WindowKeyboard);
glutReshapeFunc(WindowReshape);
}
void WindowDisplay(void)
{
DrawTrajectory();
DrawTank(0,0);
glutSwapBuffers();
}
void WindowKeyboard(unsigned char key, int x, int y)
{
if( key == 'q' || key == 'Q' ) exit(0);
}
void WindowReshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, w, h, 0);
glMatrixMode(GL_MODELVIEW);
}
int xcalc(float v, float t, float ti)
{
return (int) (v*ti)*cos(t);
}
int ycalc(float v, float t, float ti)
{
return (int) (v*ti)*sin(t)-4.905*(ti*ti);
}
void DrawTrajectory(){
float time=.01; int tx,ty;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0,0,0);
glBegin(GL_POINTS);
while (time <= 50) {
glVertex2i(xcalc(50,.785,time),ycalc(50,.785,time));
time=time+.01;
}
glEnd();
}
void DrawTank(int x,int y){
glColor3f(1,0,0);
glBegin(GL_POLYGON);
glVertex2i(x,y);
glVertex2i(x,25+y);
glVertex2i(50+x,25+y);
glVertex2i(50+x,y);
glEnd();
}