From 5159ba952dd3809db8834ed96e0ebe4966a8eea1 Mon Sep 17 00:00:00 2001 From: "Ian Evans (ab8809)" Date: Mon, 9 Sep 2019 14:21:44 +0100 Subject: [PATCH] Update README.md --- Week 3/README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Week 3/README.md b/Week 3/README.md index 0d83eff..e39b9da 100644 --- a/Week 3/README.md +++ b/Week 3/README.md @@ -77,7 +77,7 @@ We can do this by making a new class that we will use for the base class of the > Create a new class using 1 of the 3 methods discussed last week and call it _GameObject_. Make sure it holds the position variable, has both a default constructor and a constructor that takes in a _vec3_ position and has a _Draw_ function. - +
GameObject Example @@ -127,7 +127,7 @@ void GameObject::Draw() > Why did we use protected instead of private? Did you check for your Week 2 homework?
- +
Once this is made, we need to alter the _Cube_ class to allow it to inherit from the _GameObject_ class in the following ways: @@ -137,7 +137,7 @@ Once this is made, we need to alter the _Cube_ class to allow it to inherit from > Do the above alterations to the _Cube_ class. Make sure to try this all yourself before you check against the example below. - +
Cube with inheritance @@ -164,6 +164,7 @@ Cube::Cube(glm::vec3 pos): GameObject(pos) ```
+
Running the project should still show the cubes in the scene. Now the base class is down we can use Polymorphism to further improve our code design. @@ -183,6 +184,7 @@ Instead of just creating instances of the type of the current class such as _Cub > How would you write this pointer line? Have a go before looking at the answer below. +
Cube with inheritance @@ -197,6 +199,7 @@ GameObject* cubePtr2 = new Cube(glm::vec3(1, 0, 0)); ```
+
> Why is this useful? Find out next week! (A hint: It's useful for storing different inherited class types together.)