Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


opengl proglem

This topic is 5541 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i am making a spcae invader clone and are havng trouble with the collision detection... my baddies x and y value can be accessed and are found at the very center of them, the bullets, with are only points, have x and y values too but no matter what sorta if statement i use they never seem to actually collide and trigger the if statements, i have done something like this so far for (int b = 0; b < 30; b++) { for (int i = 0; i < 10; i++) { for (GLfloat n = -0.5f; n < 0.6f; n += 0.1f){ for (GLfloat p = -0.5f; p < 0.6f; p += 0.1f){ if ((bad.x - n) == (lastx) && shoot[i] == true && ((bad[b].y - p) == (shooter[i]) bad[b].state = 1; } } } nb: the baddies are an array of 30 objects while the points are stored in an array of 10... thanx heaps if can help me } [edited by - r3n3gad3 on July 26, 2003 4:32:59 AM]

Share this post

Link to post
Share on other sites
This really doesn''t sound like an opengl problem, does it?

Is that your actual source code, or just something that you typed here? Might just be me, but imho it shouldn''t even compile. If I understood the code right, you are comparing the (x,y) of all the bullets with the (x,y) of all baddies. If they are equal, you mark a collision.

If you are using floating point numbers for the coordinates, that is the wrong approach. You should calculate the distance of a bullet to the center of a bad guy, and if it is close enough you can assume it has collided. You don''t have to check the "real" distance, because it will give you a circle-shaped collision zone. Checking x and y distance separately will give you a square/rectangle shaped one, which often is more desirable in games with sprites.

Your collision check is absolutely horrible in some ways (No offence, just trying to point out some errors):
1. You are checking each bullet against each enemy, even if those bullets and enemies don''t exist.
2. You have 4 for-loops inside each other. You are making 30000 checks each frame. That is a lot.
3. The use of && and multiple comparisons make the code quite hard to read.
4. You really should use std::vector or something similar for your bullets and enemies, to avoid checking nonexistent objects.

Share this post

Link to post
Share on other sites
i fail to see where this has anything to do with opengl and why you dont use the source tag to make that half a dozen nested loops readable.

or what are all those things popping up?
lastx, shoot/shooter, n/p?

whats that thing supposed to do? why all those loops (especially for n and p?). do want to just see if anything is hit _right now_ or check for intersection between last frame and this frame?

Share this post

Link to post
Share on other sites
Topic: "opengl proglem"

i am making a spcae invader ...

The following takes 3 seconds to type:
"OpenGL Problem"
I am making a space invader..

Can you honestly say that you even give a shoite about this problem? Or is it possibly so that you have hooked your old typewriter up with a modem, and everytime you make a typo you have to take a new sheet of paper and start over and upload it again through that slow modem? Then I understand that it can be a pain to correct those typos..
Many people have a hard time taking people like that seriously, and why should they waste their time on someone like that? The people at gamedev.net are really cool and help eachother out with all kinds of things, and they deserve more respect than what you just gave to them.

do'nt u a gree? Or do u htink taht ppl shoudl spend thier time de crpyting ur txt?

[edited by - Caminman on July 26, 2003 6:21:43 AM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!