Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Renderer/Renderer.h@46:824ec81ff578, 2019-05-08 (annotated)
- Committer:
- el17cd
- Date:
- Wed May 08 18:17:59 2019 +0000
- Revision:
- 46:824ec81ff578
- Parent:
- 37:524b91130885
Potentiometer now changes screen contrast for use on other devices.; Final Submission.; I have read and agreed with the Statement of Academic Integrity.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17cd | 31:e681177037ef | 1 | #include "mbed.h" |
el17cd | 31:e681177037ef | 2 | #include "N5110.h" |
el17cd | 31:e681177037ef | 3 | #ifndef FACE_H |
el17cd | 31:e681177037ef | 4 | #define FACE_H |
el17cd | 31:e681177037ef | 5 | #include "Face.h" |
el17cd | 31:e681177037ef | 6 | #endif |
el17cd | 31:e681177037ef | 7 | #ifndef CUBE_H |
el17cd | 31:e681177037ef | 8 | #define CUBE_H |
el17cd | 31:e681177037ef | 9 | #include "Cube.h" |
el17cd | 31:e681177037ef | 10 | #endif |
el17cd | 31:e681177037ef | 11 | |
el17cd | 32:9c250eda7f3f | 12 | /** Face class |
el17cd | 37:524b91130885 | 13 | *@brief A class used to instantiate a Renderer object, this class provides an interface from the game to the display. Each Face of all the Cube objects will be passed to the Renderer |
el17cd | 37:524b91130885 | 14 | for it to be rasterised and its outlines drawn. |
el17cd | 32:9c250eda7f3f | 15 | *@author Christopher Doel |
el17cd | 32:9c250eda7f3f | 16 | *@date April, 2019 |
el17cd | 32:9c250eda7f3f | 17 | */ |
el17cd | 31:e681177037ef | 18 | class Renderer { |
el17cd | 31:e681177037ef | 19 | private: |
el17cd | 31:e681177037ef | 20 | float fov; |
el17cd | 31:e681177037ef | 21 | Cube selectionCube; |
el17cd | 35:fe3956825bd8 | 22 | /** Projects the 3D x coordinate to 2D perspective |
el17cd | 31:e681177037ef | 23 | *@param The 3d x coordinate as a float |
el17cd | 31:e681177037ef | 24 | *@param The 3d z coordinate as a float |
el17cd | 31:e681177037ef | 25 | *@returns The 2D perspective fo the x coordinate |
el17cd | 31:e681177037ef | 26 | */ |
el17cd | 36:6fbafc8bed80 | 27 | float xTo2D(float x, float z); |
el17cd | 35:fe3956825bd8 | 28 | /** Projects the 3D y coordinate to 2D perspective |
el17cd | 31:e681177037ef | 29 | *@param The 3d y coordinate as a float |
el17cd | 31:e681177037ef | 30 | *@param The 3d z coordinate as a float |
el17cd | 31:e681177037ef | 31 | *@returns The 2D perspective of the y coordinate |
el17cd | 31:e681177037ef | 32 | */ |
el17cd | 36:6fbafc8bed80 | 33 | float yTo2D(float y, float z); |
el17cd | 46:824ec81ff578 | 34 | public: |
el17cd | 46:824ec81ff578 | 35 | Renderer(); |
el17cd | 46:824ec81ff578 | 36 | /** Initialises the LCD and sets the field of view |
el17cd | 46:824ec81ff578 | 37 | */ |
el17cd | 46:824ec81ff578 | 38 | void init(); |
el17cd | 35:fe3956825bd8 | 39 | /** Draws the games horizon line |
el17cd | 31:e681177037ef | 40 | *@param The angle of the horizon determined by the joystick position |
el17cd | 31:e681177037ef | 41 | */ |
el17cd | 36:6fbafc8bed80 | 42 | void drawHorizon(float angle); |
el17cd | 36:6fbafc8bed80 | 43 | /** Draw an individual face |
el17cd | 36:6fbafc8bed80 | 44 | *@param The face object |
el17cd | 36:6fbafc8bed80 | 45 | *@param The angle of the face object as a float |
el17cd | 36:6fbafc8bed80 | 46 | */ |
el17cd | 31:e681177037ef | 47 | void drawFace(Face *face, float angle); |
el17cd | 35:fe3956825bd8 | 48 | /** Draw an individual face |
el17cd | 31:e681177037ef | 49 | *@param The face object |
el17cd | 31:e681177037ef | 50 | *@param The angle of the face object as a float |
el17cd | 31:e681177037ef | 51 | */ |
el17cd | 31:e681177037ef | 52 | void rasterizeFace(float (&points)[4][3], Face *face); |
el17cd | 35:fe3956825bd8 | 53 | /** Draw an individual face |
el17cd | 31:e681177037ef | 54 | *@param The pointer to an array containing the verticies of the face |
el17cd | 31:e681177037ef | 55 | *@param The integer difference between the top horizontal edge x coordinates |
el17cd | 31:e681177037ef | 56 | *@param The integer difference between right vertical edge y coordinates |
el17cd | 31:e681177037ef | 57 | *@param The integer difference between bottom horizontal edge x coordinates |
el17cd | 31:e681177037ef | 58 | *@param The integer difference between left horizontal edge y coordinates |
el17cd | 31:e681177037ef | 59 | */ |
el17cd | 36:6fbafc8bed80 | 60 | void drawFillLines(float (&points)[4][3], int diffX2, int stepBottomY, |
el17cd | 36:6fbafc8bed80 | 61 | int stepTopX, int stepTopY); |
el17cd | 35:fe3956825bd8 | 62 | /** Draw the outline of the face |
el17cd | 31:e681177037ef | 63 | *@param The pointer to an array containing the verticies of the face |
el17cd | 31:e681177037ef | 64 | */ |
el17cd | 36:6fbafc8bed80 | 65 | void drawFaceOutline(float (&points)[4][3]); |
el17cd | 35:fe3956825bd8 | 66 | /** Draw all faces within a face array |
el17cd | 31:e681177037ef | 67 | *@param The pointer to an array of face objects |
el17cd | 31:e681177037ef | 68 | *@param The number of faces as an integer |
el17cd | 31:e681177037ef | 69 | *@param The angle of the faces as a float |
el17cd | 31:e681177037ef | 70 | */ |
el17cd | 36:6fbafc8bed80 | 71 | void drawAllFaces(Face *faceArray, int noOfFaces, float angle); |
el17cd | 35:fe3956825bd8 | 72 | /** Checks whether any area of the face is on the screen |
el17cd | 31:e681177037ef | 73 | *@param The pointer to an array containing the verticies of the face |
el17cd | 31:e681177037ef | 74 | */ |
el17cd | 36:6fbafc8bed80 | 75 | bool checkOnScreen(float (&Points)[4][3]); |
el17cd | 35:fe3956825bd8 | 76 | /** Prints a string at a desired location on the screen |
el17cd | 31:e681177037ef | 77 | *@param The pointer to an array of characters of the string |
el17cd | 31:e681177037ef | 78 | *@param The x coordinate to draw the string as an integer |
el17cd | 31:e681177037ef | 79 | *@param The y coordinate to draw the string as an integer |
el17cd | 31:e681177037ef | 80 | */ |
el17cd | 36:6fbafc8bed80 | 81 | void print(const char *text, int x, int y); |
el17cd | 35:fe3956825bd8 | 82 | /** Prints a score at a desired location on the screen |
el17cd | 31:e681177037ef | 83 | *@param The value of the score as an integer |
el17cd | 31:e681177037ef | 84 | *@param The x coordinate to draw the score as an integer |
el17cd | 31:e681177037ef | 85 | *@param The y coordinate to draw the score as an integer |
el17cd | 31:e681177037ef | 86 | */ |
el17cd | 36:6fbafc8bed80 | 87 | void printScore(int score, int x, int y); |
el17cd | 36:6fbafc8bed80 | 88 | /** Clears the display |
el17cd | 36:6fbafc8bed80 | 89 | */ |
el17cd | 31:e681177037ef | 90 | void clear(); |
el17cd | 36:6fbafc8bed80 | 91 | /** Refreshes the display |
el17cd | 31:e681177037ef | 92 | */ |
el17cd | 31:e681177037ef | 93 | void refresh(); |
el17cd | 36:6fbafc8bed80 | 94 | /** Turns off the display |
el17cd | 31:e681177037ef | 95 | */ |
el17cd | 31:e681177037ef | 96 | void turnOff(); |
el17cd | 35:fe3956825bd8 | 97 | /** Draws the screen after the user has collided with a cube |
el17cd | 31:e681177037ef | 98 | *@param The selected option as an integer |
el17cd | 31:e681177037ef | 99 | *@param The high score as an integer |
el17cd | 31:e681177037ef | 100 | */ |
el17cd | 46:824ec81ff578 | 101 | void setContrast(float contrast); |
el17cd | 36:6fbafc8bed80 | 102 | void drawDeathScreen(int selection, int highScore); |
el17cd | 35:fe3956825bd8 | 103 | /** Draws the death menus buttons |
el17cd | 31:e681177037ef | 104 | */ |
el17cd | 36:6fbafc8bed80 | 105 | void drawDeathButtons(); |
el17cd | 35:fe3956825bd8 | 106 | /** Draws the games home screen |
el17cd | 31:e681177037ef | 107 | *@param The selected option as an integer |
el17cd | 31:e681177037ef | 108 | */ |
el17cd | 36:6fbafc8bed80 | 109 | void drawHomeScreen(int selection); |
el17cd | 35:fe3956825bd8 | 110 | /** Draws the home menus buttons |
el17cd | 31:e681177037ef | 111 | */ |
el17cd | 36:6fbafc8bed80 | 112 | void drawHomeButtons(); |
el17cd | 35:fe3956825bd8 | 113 | /** Draws the cube which indicates the selected button on the menus |
el17cd | 31:e681177037ef | 114 | *@param The x coordinate of where to draw the cube as an integer |
el17cd | 31:e681177037ef | 115 | *@param The y coordinate of where to draw the cube as an integer |
el17cd | 31:e681177037ef | 116 | *@param The z coordinate of where to draw the cube as an integer |
el17cd | 31:e681177037ef | 117 | *@param The rotation speed multiplier of the cube as an integer |
el17cd | 31:e681177037ef | 118 | */ |
el17cd | 36:6fbafc8bed80 | 119 | void drawSelectionCube(int x, int y, int z, int rotationSpeed); |
el17cd | 35:fe3956825bd8 | 120 | /** Draws the first help screen |
el17cd | 31:e681177037ef | 121 | */ |
el17cd | 36:6fbafc8bed80 | 122 | void drawHelpScreen1(); |
el17cd | 36:6fbafc8bed80 | 123 | /** Draws the second help screen |
el17cd | 36:6fbafc8bed80 | 124 | */ |
el17cd | 31:e681177037ef | 125 | void drawHelpScreen2(); |
el17cd | 36:6fbafc8bed80 | 126 | /** Draws the third help screen |
el17cd | 31:e681177037ef | 127 | */ |
el17cd | 31:e681177037ef | 128 | void drawHelpScreen3(); |
el17cd | 35:fe3956825bd8 | 129 | /** Draws the third help screen |
el17cd | 31:e681177037ef | 130 | */ |
el17cd | 31:e681177037ef | 131 | void drawHelpScreen4(); |
el17cd | 31:e681177037ef | 132 | }; |
el17cd | 31:e681177037ef | 133 |