Sign in to follow this  
Beaverbutt8

projectile?

Recommended Posts

Beaverbutt8    100
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?

Share this post


Link to post
Share on other sites
Khaos Dragon    196
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.

Share this post


Link to post
Share on other sites
KulSeran    3267
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.

Share this post


Link to post
Share on other sites
Beaverbutt8    100
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??

Share this post


Link to post
Share on other sites
Ravuya    135
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).

Share this post


Link to post
Share on other sites
AAAP    137
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this