glutSpecialFunc is what you'll actually use to receive arrow key input in GLUT (dunno why they're two separate functions, but it's how the API was designed). The man page will tell you everything you need to know. If you're not familiar with man pages, open Terminal.app and type "man glutSpecialFunc".

So I've included that code. I have a few variables that need changing due to that code, e.g.

Code:

shipPosX=shipPosX+10

I tried replacing the printf() statements with that one, but I get errors? I think It's because my variables aren't global, but I don't understand how to make them global. How would I do this, or is there an easier way to do it?

It sounds like you need a stronger foundation in language concepts before moving on, or you'll keep running into problems like these and not understanding why or having a good way to figure it out without asking for help. This book would be an excellent investment.

ThemsAllTook Wrote:glutSpecialFunc is what you'll actually use to receive arrow key input in GLUT (dunno why they're two separate functions, but it's how the API was designed).

Oh hey, after putting together a little example code for mikey in another thread, I recalled why one couldn't just use glutSpecialFunc for everything: They reused some of the same ASCII constants for things like arrow keys! I wonder why they did that?

OK, I've got a simple 2D scene with a slightly detailed box with an arrow indicating the direction, and I thought some sort of bullet would be cool. How would I implement the Space Bar or Cmd key into my code?

PS. I've been learning more about C, and got out a book from my local library.

PPS. I Won't be attempting a 3D engine anytime soon, but - just out of interest - I noticed there was a 3-digit coordinate reference for my triangle, if I was building a 3D environment, could I just add a Z-Axis, and a keyboard controller? Is it as easy as that?

mikey Wrote:OK, I've got a simple 2D scene with a slightly detailed box with an arrow indicating the direction, and I thought some sort of bullet would be cool. How would I implement the Space Bar or Cmd key into my code?

mikey Wrote:PPS. I Won't be attempting a 3D engine anytime soon, but - just out of interest - I noticed there was a 3-digit coordinate reference for my triangle, if I was building a 3D environment, could I just add a Z-Axis, and a keyboard controller? Is it as easy as that?

Right, in a 3D environment you make use of the z-axis. You'd probably also want to set up a perspective projection and use depth testing.

Quote:Right, in a 3D environment you make use of the z-axis. You'd probably also want to set up a perspective projection and use depth testing

Honestly, do you think (I would really like to) I would be capable of starting a 3D environment: A plane? maybe a cube or two in the centre of that plane? I mean, perspective and depth testing can't be too hard?

Also, you should only call glutSwapBuffers(); once. You have another call in fire(), which you should remove.

Finally, do be sure to study that code I put together for you in that other thread. It will help you greatly with your keyboard input, which you will no doubt find useful since your laser beam will only appear for one frame with your current technique. And my example also includes a little Boolean typedef you can use instead of 1 or 0.

mikey Wrote:Honestly, do you think (I would really like to) I would be capable of starting a 3D environment: A plane? maybe a cube or two in the centre of that plane? I mean, perspective and depth testing can't be too hard?

You have a lot more to learn to be able to tackle it. To see what I mean by that, here's how you draw a spinning colored cube with lighting and depth testing (Controls: move with w, a, s, d, q, a, and reset with r. Toggle coloring with c):