• Create Account

Indignant

Member Since 06 Dec 2012
Offline Last Active Apr 03 2013 03:22 AM

In Topic: Animating a wheel.

10 December 2012 - 04:02 AM

Hello!
First of all, because here we are talking about a spinning wheel, we should probably describe initial speed as degree per frame. So, say if the initial speed is x degree/frame, the the speed in n th frame should be S(n) = x - a(n^2). To make the wheel spin, you just need to call the correct function to rotate the wheel object S degree every frame. Here is some pseudo code(display() is the disply loop that should be called in every game loop ):

int frame = 0;
double Si = 0;
double S = 0;

display() {
//draw background
if (S > 0) {
S = Si - a*frame*frame;
frame++;
if (S > 0) {
rotate S degrees;
}
} else { //end of game, call what you should call }
swapBuffer();
}

Just my two sents, maybe -a(x^2) is not a good option, because it causes the wheel to slow down faster at the end. In a wheel game like this, usually the last few seconds are the most exciting ones, so maybe you should simply use S(n) = x- a*n instead.

int frame = 0;
double S = 0;

display() {
//draw background
if (S > 0) {
S -= a;
if (S > 0) {
rotate S degrees;
}
} else { //end of game, call what you should call }
swapBuffer();
}

to start the spin, simply assign a value(the initial speed) to S.

Hope your lucky wheel get you good luck!

In Topic: How can I use Bullet to affect the graphics

08 December 2012 - 12:58 AM

Can any give some modified code?
Many thanks!!!

In Topic: Planning to Make a "Ballance-like" Game, seeking advice...

06 December 2012 - 07:45 AM

Hello Bacterius!

Thanks for your prompt reply. It is very helpful. I will take a closer look at the Bullet and ask when I have new questions. Thanks!

I have a few more questions though:

1)Where should I init the physics engine?

2)Where and how to make the main loop(which is supposed to be excecuted every frame, processe user input, call the phisics engine to update position and speed of objects, and call graphics engine to post redisplay, right?)

3)Should I instantiate objects in game(eg. the ball class mentioned above) in the following main function?
[source lang="cpp"]int main(int argc, char *argv[]){ glutInit(&argc, argv); glutInitWindowSize(640,480); glutInitWindowPosition(10,10); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow("GLUT Shapes"); glutReshapeFunc(resize); glutDisplayFunc(display); glutKeyboardFunc(key); glutIdleFunc(idle); glClearColor(1,1,1,1); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glEnable(GL_LIGHT0); glEnable(GL_NORMALIZE); glEnable(GL_COLOR_MATERIAL); glEnable(GL_LIGHTING); glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess); glutMainLoop(); return EXIT_SUCCESS;}[/source]

4) How can I pass object to physics engine and read it back? (I know this questions is too broad, but if you know any good tutorial/documentations please let me know. Thanks a ton!)