#pragma comment(lib, “libGLES_CM.lib”)
#pragma comment(lib, “ug.lib”)
#include “ug.h”
#define PIOVER180 0.01745329252
int t;
int velocity0 = 5;
float velocity0x, velocity0y, velocity0z;
float positionx, positiony, positionz;
float angle1, angle2;
float getNewPosition[] = {
positionx,
positiony,
positionz
};
void init()
{
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepthf(1.0f);
}
void trajectory(int);
void display(UGWindow uwin)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
ugluLookAtf(
0.0f, 0.0f, 2.0f,
0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f);
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
ugSolidSpheref(0.1f, 25, 25);
for(t=0; t<100; t++)
{
trajectory(t);
glPushMatrix();
{
glTranslatef(getNewPosition[0], getNewPosition[1], getNewPosition[2]);
}
glPopMatrix();
glFlush ();
ugSwapBuffers(uwin);
}
}
void trajectory(int t)
{
angle1 = 45;
angle2 = 90;
velocity0x = float(velocity0 * sin(angle1*PIOVER180)*sin(angle2*PIOVER180));
velocity0y = float(velocity0 * cos(angle1*PIOVER180));
velocity0z = float(velocity0 * sin(angle1*PIOVER180) * cos(angle2*PIOVER180));
positionx = velocity0x * t;
positiony = float(velocity0y * t - 0.5*9.8*t*t);
positionz = velocity0z * t;
}
void keyboard(UGWindow uwin, int key, int x, int y)
{
switch(key)
{
case ‘q’ : exit(0); break;
case UG_KEY_UP : exit(0); break;
}
}
void reshape(UGWindow uwin, int width, int height)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, width, height);
ugluPerspectivef(45.0f, 1.0f * width / height, 1.0f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void pointer(UGWindow uwin, int button, int state, int x, int y)
{
exit(0);
}
void idle(UGWindow uwin)
{
ugPostRedisplay(uwin);
}
int main()
{
UGCtx ug = ugInit();
UGWindow uwin = ugCreateWindow(ug, "UG_DEPTH", "bullet", 250, 250, 100, 100);
init();
ugDisplayFunc(uwin, display);
ugReshapeFunc(uwin, reshape);
ugKeyboardFunc(uwin, keyboard);
ugPointerFunc(uwin, pointer);
ugIdleFunc(ug, idle);
ugMainLoop(ug);
return 0;
}