collision animation sprite

void timer(int val)
	screen += 0.1667f;
	if (screen >= 1.0f)
		screen = 1.0f;
	glutTimerFunc(500, timer, 0);

void drawcollision_one()

	glBindTexture(GL_TEXTURE_2D, texture[3]);

	glTexCoord3f(0.0f + screen, 0.0f, 0.0f);

	glVertex3f(0.5f, -0.5f, 0.0f);
	glTexCoord3f(0.167f + screen, 0.0f, 0.0f);

	glVertex3f(0.5f, 0.5f, 0.0f);
	glTexCoord3f(0.167f + screen, 1.0f, 0.0f);

	glVertex3f(-0.5f, 0.5f, 0.0f);
	glTexCoord3f(0.0f + screen, 1.0f, 0.0f);

	glVertex3f(-0.5f, -0.5f, 0.0f);


void coll_plane_one()
	//draw bullet
	float x = -5.0f + horizontal;
	float y = 0.0f + vertical;
	float oWidth = 1.0f;
	float oHeight = 1.0f;
	//draw plane
	float xTwo = 5.0f + horizontal_one;
	float yTwo = 0.0f + vertical_one;
	float oTwoWidth = 1.0f;
	float oTwoHeight = 1.0f;

	if (checkCollide(x, y, oWidth, oHeight, xTwo, yTwo, oTwoWidth, oTwoHeight) == 1)

I am attempting to animate a sprite sheet using an AABB collision detection function. I only get a static sprite to be drawn when the planes collide.

can I get some help on this problem, let me know if you need more explanation.

For best results, ask a specific OpenGL-related question.

See the Forum Posting Guidelines for other tips.

Well I have a peculiar problem. When I set my global variable screen=0.0f and I put my drawcollision_one() function in my display function it only draws a static collision sprite. However when I set my screen=0.0001f and I put my drawcollision_one() in my display function it draws an animated collision sprite. Also when I use my screen=-0.0f variable and I put my drawcollision_one() function in my collision detection function it draws a static collision sprite. However when I use my screen=0.0001f variable it does not draw anything when the drawcollision_one() function is in my collision detection function. What I want is to draw the animated collision sprite when the collision detection function is used. Let me know if you need further explanation.I am using freeglut 3.0.0 and SOIL in my program.

This is still not an OpenGL question.

You’re just saying your program doesn’t do what you want it to (and what you want it to do isn’t clear), instead of asking a question about how a particular GL call works or why it’s throwing an error.

I’d suggest you cut back your program until it works consistently (e.g. disconnect the collision and timer pieces and just wire up your drawcollision function directly to your display function). Build-up gradually. If you find some behavior you don’t understand and it relates to an OpenGL call, then ask that specific question.

I am confused about what the glutTimerFunc functions actually does. I will do some research on the topic.

well what I want it to do is animate a collision sprite when I put drawcollision_one() in my collision detection function.

That doesn’t really work very well, because to animate it, you need to redraw the screen over some period of time with an updated collision appearance. And what about any other animations you might have going at the time --do they just freeze while “that” collision is being animated?

For this reason and others, I would suggest separating these two concerns: 1) detect a collision, and 2) render the collision animation. When your collision detection function detects a collision, have it create a “collision event” with the relevant state about that collision (location, time, etc.). Then, elsewhere, inside your display function, loop through the active collision events, and render the appearance of each collision event appropriate for that frame.

This has a number of advantages, including your collision detection processing need not happen in a routine called by your display() function.

thanks, can I ask what “collision event” actually is?

It’s just a packet of state (think struct) that collects any data about the collision that you’ll need elsewhere (e.g. in your display function when displaying the animated collision sprite).

well I have stubbed out some code

#include <iostream>

using namespace std;

int main()
	float screen = 0.001f;

	for (int i = 1; i <= 6; i++)
		screen += 0.1667f;
		cout << screen << endl;
	return 0;

when I set the screen variable to 0.001f the collision animation works ok, but when I set the screen variable to 0.0f the collision sprite only draws the first collision sprite. when I change the screen variable in my stubbed out code I get almost the same values, I just don’t see where the problem is.

is there anyway to slow down my glutIdleFunc function animation speed.

this is an opengl question, can l get some help?

While your code uses OpenGL, you’re not asking an OpenGL question.

Rather than asking “how does this OpenGL concept work” or “why is this OpenGL API working the way it is”, you’re asking folks to figure out why your code doesn’t work.

You need to understand how your code works. If you’re unsure, step through it in a debugger and/or add print statements to show what’s going on with key values (e.g. screen in your case). Once you boil your question down to confusion with how an OpenGL API or concept works, and you aren’t able resolve this question by reading tutorials or the spec, feel free to post your question here!