openGL moving a shape PROBLEM - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

openGL moving a shape PROBLEM

em-kayem-kay Posts: 3Member


Hi there.
Im trying to write a code of moving circles but Im facing a problem in the moving. Heres the code :


[code]#include
#include
#include
#include
#include
#include

double r=600/4,delta=1/r;
float xc=0,yc=0,a=40,k=5,phy=0,z=0.3,d=0.1;

void drawcircle(double x0,double y0,double r)
{
double x,y;
double th=0;
while(th<=80*atan(1.0))
{
th=th+delta;
x=r*cos(th)+x0;
y=r*sin(th)+y0;
glColor3f(0.0,0,0);
glPointSize(4);
glBegin(GL_POINTS);
glVertex2d(x,y);
glEnd();
}
}

void handleResize(int w,int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,(double)w/(double)h,1.0,200.0);
}
float angle = 30.0f;
void myStyleInit(int red,int green,int blue)
{
glClearColor(red,green,blue,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glPointSize(3);
gluOrtho2D(-150.0, 150.0,-150.0,150.0);
}


void drawScene()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0,0);
glPointSize(3);
drawcircle(800/2,600/2,r);
drawcircle(800/2,600/2,(3*r)/4);
drawcircle(800/2,600/2,r/2);
drawcircle(800/2,600/2,r/4);
drawcircle(800/2,600/2,r/8);
glFlush();
glutSwapBuffers();

}

void move(int state)
{
if(xc>=150-a || xc<=-150+a)
{
z*=-1;
xc+=z;
yc+=d;
phy+=0.01;
}
if(yc>=150-a || yc<=-150+a)
{
d*=-1;
xc+=z;
yc+=d;
phy+=0.01;
}
else
{
xc+=z;
yc+=d;
phy+=0.01;
}
glutPostRedisplay();
glutTimerFunc(1,move,0);
}
int main()
{
int mainWindow;
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(300,200);
glutInitWindowSize(900,900);
mainWindow = glutCreateWindow("Stress Ball");
myStyleInit(1,1,1);
glutDisplayFunc(drawScene);
glutTimerFunc(1,move,0);
glutMainLoop();
}[/code]

Wat should I do ?
Sign In or Register to comment.