Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.