Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private GameClock gameClock;
- gameClock.Initialize(); //Runs first but only once.
- @Override
- public void onDrawFrame(GL10 gl)
- {
- elapsedTime = gameClock.CalculateElapsedTime(); //This is the elapsedTime that is used in setPlayerTimeBasedVelocity() function
- GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
- GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT);
- drawSkyBox();
- drawPlayer();
- drawMaze();
- updateCamera();
- collisionDetectionAndResponse();
- }
- //This method is called from drawPlayer() function.
- private void setPlayerTimeBasedVelocity(float elapsedTime)
- {
- //timeBasedVelocity is the vector that I increase the players position with later on.
- timeBasedVelocity.x = initialVelocity.x * elapsedTime;
- timeBasedVelocity.y = initialVelocity.y * elapsedTime;
- timeBasedVelocity.z = initialVelocity.z * elapsedTime;
- }
- private long t0;
- private long t1;
- private long elapsedTime;
- private final long nanoSecond = 1000000000;
- private final long microSecond = 1000000;
- public void Initialize()
- {
- t0 = System.nanoTime();
- }
- public float CalculateElapsedTime()
- {
- t1 = System.nanoTime();
- elapsedTime = t1 - t0;
- t0 = t1;
- return (float)((double)elapsedTime/(double)nanoSecond);
- }
- //This is how I update my camera based upon the players position which is player.getWorldMidPoint().
- //The eye and center variables are Vector3 variables with x, y and z and belongs to the camera which is used to create the
- //view matrix.
- public void updateCamera()
- {
- center = player.getWorldMidPoint();
- center.y += player.getPlayerRadius().y * 2;
- float angle = -player.getIncrementalRotationAngle();
- float c = (float)Math.cos(Math.toRadians(angle));
- float s = (float)Math.sin(Math.toRadians(angle));
- eye.x = center.x + (s*horizontalDistanceFromPlayer);
- eye.y = center.y + verticalDistanceFromPlayer;
- eye.z = center.z + (c*horizontalDistanceFromPlayer);
- if(player.getPlayerRunningStatus())
- {
- eye.addVector(player.getPlayerTimeBasedVelocity());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment