Making my first 3D engine

Hi, me and my friend are making our first 3D engine on Android, to study OpenGL. We have stumbled on a few questions, that we need some advice with:


  1. We are making first person shooter. So there are enemies and bullets. Currently we update the location of the bullets and enemies each frame in onDrawFrame method with for cycles and we also check the collisions within this double for cycles. Now we have a fague idea of making a sort of a timer in our game. We only have 1 thread where we basically do everything.



    When I tried out JME, I noticed that there was the update(float interpolation) method in many places. What was that interpolation variable for? I remember that it gave the time that had passed between frames, and in FlagRushTutorial that variable was used to move the vehicle.



    What kind of advice can You give me based on what I wrote?

    We need to figure out a way to control and measure how fast bullets and monsters are moving.

The variable is called "tpf" which stands for "time per frame". It's the time spent, in seconds, to handle the last frame.

If your game runs at constant 60 fps, tpf would equal 1/60 (or 0.016~, which is 16.6~ milliseconds). If you want an object to move 100 units per second, you multiply 100 by the tpf to get the time to move per frame.

I Thank You for quick reply! Yes, that makes sense. But Should I run a separate thread that measures the time between frames. Or should I use System.currentMillis(). Like:



float tp=0f;

int a;

public void drawFrame(){ //method that gets called constantly

    a = System.currentMillis();

    monster.update(tpf);

    //Do lots of opengl stuff

    tpf=a-System.currentMillis()/1000;

}

Talking about frames i think you should have a look at Killer Game Programing in java. is an e book.



Killer Game Programming in Java



That's the website for the e book.



If i remember correctly chapter 2 talks about ways to calculate the time between frames using different timers and i think it might help you.

Ok, tx.



Since I'm doing it on Android, I'll stick to System.currentMillis(), I read from that book that it has some flaws, but It's the only kind of timer I know how to use at the moment to get the time between frames.

Yeah, System.currentTimeMillis should be fine on android. It's only on windows where you have issues with it really (it rounds to the nearest 17~ ms so it isnt really accurate).