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 x, int y, int v, float t);
int xcalc(float v, float t, float ti);
int ycalc(float v, float t, float ti);
void DrawTank(int x,int y);
float DR(float x);
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(5,5,60,45);
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(int x, int y, int v, float t){
float time=.01; int tx=0,ty=0;
printf("Drawing Trajectory: From Point (%d,%d); Velocity %d; Angle %d\n", x,y,v,t);
t = DR(t);
printf("Angle: %d", t);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0,0,0);
glBegin(GL_POINTS);
while (ty>=0) {
tx=xcalc((float)v,(float)t,time);
ty=ycalc((float)v,(float)t,time);
printf("Point drawn at (%d,%d)\n",tx,ty);
glVertex2i(tx,ty);
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();
}
float DR(float x){
return x * (3.14/180);
}