From 93352eb49f73a9508ddb42158fe4dd0641080875 Mon Sep 17 00:00:00 2001 From: "Ian Evans (ab8809)" Date: Mon, 9 Sep 2019 14:21:14 +0100 Subject: [PATCH] Update README.md --- Week 4/README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Week 4/README.md b/Week 4/README.md index 5076e6f..5833a69 100644 --- a/Week 4/README.md +++ b/Week 4/README.md @@ -161,15 +161,18 @@ Now this works, we can look into using the arrow keys. > Replace the _case 'w':_ line with _case GLUT_KEY_UP:_. What happens? +
Answer It worked with 'w' before but now does not work... This is because glut has two functions for keyboard input callbacks. We are using _glutKeyboardFunc(...)_ but for arrow keys and other special keys we need to use _glutSpecialFunc(...)_.
+
Put 'w' back in the switch statement and make another callback function for the special keys. Make sure to register the callback in the _main_ function (like what has been done for _glutKeyboardFunc_. (You might have to look into what are the callback arguments for this - https://www.opengl.org/resources/libraries/glut/spec3/node54.html) Try it yourself first and check your result against the example below. +
Special Keys Example @@ -200,7 +203,7 @@ void keySpecialInput(int key, int x, int y) glutSpecialFunc(keySpecialInput); ```
- +
## Updating @@ -224,15 +227,18 @@ void Cube::Update() ``` Nothing happened! Why is this? Think about it and check the answer. +
Answer We never call the _Update_ function anywhere so the function (and the code inside the function) is never ran! To fix this, we need to think about where the call could go... We have an _idle_ function that we can do this in. (Why? That's a homework task!)
+
Look at the answer if you have not already. How would we fix the issue? Try it yourself before you see the code answer below. Your cubes should fall (while the other objects stay still) if done right. +
Code answer @@ -248,6 +254,7 @@ Look at the answer if you have not already. How would we fix the issue? Try it y } ```
+
## The use of delta time @@ -271,6 +278,7 @@ The way to do this is to work out delta time, which is the amount of time that h Once you have done this (or get stuck after a while), look at the completed code below. +
Update with delta time @@ -320,6 +328,7 @@ void idle() } ```
+
Let us now work out the actual delta time between frames and use this value for our _Update_ function. FreeGLUT gives us a function for this via _glutGet(GLUT_ELAPSED_TIME)_ which gives us the number of milliseconds since the first call of _glutGet_. @@ -400,6 +409,7 @@ We don't want each instance of GameObject to have a copy of both maps, as this w Try it yourself before you look at the code example below. +
Code Example @@ -417,6 +427,7 @@ class GameObject ```
+
As they are static variables, you will need to create the one instance the class holds. Add this to the top (after the _#include_) of the GameObject C++ file. Note the _GameObject::_ before the variable names which shows they are for the overall class and not each instance.