projectile?

Started by
8 comments, last by AAAP 18 years, 4 months ago
Hey guys, Well, i figured i'd try to learn some other stuff in OpenGL, cause 3ds loading wasn't working for me, and i was getting really frustrated. But i have a question. How can i generate a "projectile" in openGL? Obviously, since my game is a medieval fantasy game, there will be arrows, so some system is needed to make prijectiles, using a key command. I know how to do key commands, but not mouse ones. I want to be able to generate an arrow going in a straight line by pressing the right mouse button, so here are my questions. 1) How to generate a particle that resembles a projectile ( rock, arrow, etc. ) 2) How to use the mouse buttons, for example if ( //rightmouspressed ) { // generate arrow particle } Also, how can i "destroy" or "undraw" a 3d object?
Advertisement
Quote:
Also, how can i "destroy" or "undraw" a 3d object?


If you are rendering your scene several times a second, simply don't draw it the next time the scene is rendered.

Ok. But what about the projectiles?
The main ideas are
1) Grab something like DirectInput or SDL, and learn the input commands.
Or use the window's message loop (WM_MOUSEDOWN) inorder to retieve the mouse click.

2) Make a particle system. On mouseclicks, "spawn" a new particle. This usually means adding a new particle (consisting of position, orientation, velocity, and gravity) to some std::vector of particles. Then
every frame, update the velocity vector to include your gravity componet for every particle in the std::vector. When your particle collides with something, erase() it from the std::vector.

Quote:Original post by Khaos Dragon
Quote:
Also, how can i "destroy" or "undraw" a 3d object?


If you are rendering your scene several times a second, simply don't draw it the next time the scene is rendered.


What do you mean by rendering several times a second??
...

Do you understand programming, and what openGL is, as well as how to draw objects?

AfroFire | Brin"The only thing that interferes with my learning is my education."-Albert Einstein
I think your best bet is to start here, and a least go to here (which is a lesson on particle systems).

What you are trying to achieve appears to be way beyond your current competency level.
I think you are confusing OpenGL, standard game logic and an input system. OGL really just draws graphics. It's up to you to determine how to represent arrows, etc and handle the logic for them -- in addition to capturing the keyboard/mouse input. I highly recommend you learn SDL and use it for the input management, and at the very least puzzle out the steps that you think projectile firing will require (collision, entity updating).
Ok, give me a break - i'm no idiot, and yes, i can do OpenGL. I was just confused for a minute about what Khaos Dragon said.
OpenGL is a Graphics Library, it's job isn't to generate projectiles, or anything. It's job is to draw them and perform geometric operations on them.

To "generate a projectile", you'll want to look into dynamic memory allocation/deletion, input, and physics.

Basically, you'll want to know input to know when to create the projectile, then you'll want a class of the projectile which tells it how to behave, and you'll create a dynamic instance of the class when the input is triggered, and when the cycle of the projectile is complete, or it hits something, delete it. The only thing openGL has to do with this, is use the information stored in the projectiles class to decide where and how to draw the projectile to the buffer.

|Example|

that's a projectile / collision demo i started working on today, you can at the very least get a feel for the input handling and physics, and you'll probably get a grasp of how to create/delete instances of a class when you've got a little more experience under your belt.
|aaap.penopticon.com| My website, including game projects. Collaboration/comments are welcome, please visit :)

This topic is closed to new replies.

Advertisement