1
This commit is contained in:
2023-12-13 07:24:15 -05:00
parent d48c2c1096
commit b325d365f5
22 changed files with 0 additions and 1889 deletions

View File

@@ -1,23 +0,0 @@
cmake_minimum_required(VERSION 3.18)
project(SDL3D)
set(CMAKE_CXX_STANDARD 20)
add_executable(SDL3D src/main.cpp
src/types/entity.h
src/types/camera.h
src/engine/world.h
src/engine/engine.h
src/types/vector3.h
src/types/player.h
src/engine/render.h
src/engine/tick.h
src/types/vertex.h
src/types/skybox.h
src/types/moby.h
src/types/animation/scriptedMove.h
src/engine/occlusion.h
)
find_package(OpenGL)
target_link_libraries(SDL3D SDL2 freeimage ${OPENGL_LIBRARIES})

24
LICENSE
View File

@@ -1,24 +0,0 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org>

View File

@@ -1,99 +0,0 @@
# Blender 3.6.4
# www.blender.org
o Cone
v 0.000000 -1.000000 1.000000
v -0.195090 -1.000000 0.980785
v -0.382683 -1.000000 0.923880
v -0.555570 -1.000000 0.831470
v -0.707107 -1.000000 0.707107
v -0.831470 -1.000000 0.555570
v -0.923880 -1.000000 0.382683
v -0.980785 -1.000000 0.195090
v -1.000000 -1.000000 0.000000
v -0.980785 -1.000000 -0.195090
v -0.923880 -1.000000 -0.382683
v -0.831470 -1.000000 -0.555570
v -0.707107 -1.000000 -0.707107
v -0.555570 -1.000000 -0.831470
v -0.382683 -1.000000 -0.923880
v -0.195090 -1.000000 -0.980785
v 0.000000 -1.000000 -1.000000
v 0.195090 -1.000000 -0.980785
v 0.382683 -1.000000 -0.923880
v 0.555570 -1.000000 -0.831470
v 0.707107 -1.000000 -0.707107
v 0.831470 -1.000000 -0.555570
v 0.923880 -1.000000 -0.382683
v 0.980785 -1.000000 -0.195090
v 1.000000 -1.000000 0.000000
v 0.980785 -1.000000 0.195090
v 0.923880 -1.000000 0.382683
v 0.831470 -1.000000 0.555570
v 0.707107 -1.000000 0.707107
v 0.555570 -1.000000 0.831470
v 0.382683 -1.000000 0.923880
v 0.195090 -1.000000 0.980785
v 0.000000 1.000000 0.000000
s 0
f 1 33 2
f 2 33 3
f 3 33 4
f 4 33 5
f 5 33 6
f 6 33 7
f 7 33 8
f 8 33 9
f 9 33 10
f 10 33 11
f 11 33 12
f 12 33 13
f 13 33 14
f 14 33 15
f 15 33 16
f 16 33 17
f 17 33 18
f 18 33 19
f 19 33 20
f 20 33 21
f 21 33 22
f 22 33 23
f 23 33 24
f 24 33 25
f 25 33 26
f 26 33 27
f 27 33 28
f 28 33 29
f 29 33 30
f 30 33 31
f 16 24 32
f 31 33 32
f 32 33 1
f 32 1 2
f 2 3 4
f 4 5 6
f 6 7 8
f 8 9 10
f 10 11 12
f 12 13 14
f 14 15 16
f 16 17 18
f 18 19 20
f 20 21 22
f 22 23 24
f 24 25 26
f 26 27 28
f 28 29 30
f 30 31 32
f 32 2 4
f 4 6 8
f 8 10 12
f 12 14 16
f 16 18 20
f 20 22 24
f 24 26 28
f 28 30 32
f 32 4 8
f 8 12 16
f 16 20 24
f 24 28 32
f 32 8 16

View File

@@ -1,24 +0,0 @@
# Blender v3.6.4 OBJ File: ''
# www.blender.org
o Cube
v 0.900000 0.900000 -0.900000
v 0.900000 -0.900000 -0.900000
v 0.900000 0.900000 0.900000
v 0.900000 -0.900000 0.900000
v -0.900000 0.900000 -0.900000
v -0.900000 -0.900000 -0.900000
v -0.900000 0.900000 0.900000
v -0.900000 -0.900000 0.900000
s off
f 5 3 1
f 3 8 4
f 7 6 8
f 2 8 6
f 1 4 2
f 5 2 6
f 5 7 3
f 3 7 8
f 7 5 6
f 2 4 8
f 1 3 4
f 5 1 2

View File

@@ -1,682 +0,0 @@
# Blender v3.6.4 OBJ File: ''
# www.blender.org
o Sphere
v 0.000000 0.382683 -0.923880
v 0.000000 0.000000 -1.000000
v 0.000000 -0.382683 -0.923880
v 0.000000 -0.923880 -0.382683
v 0.146447 0.923880 -0.353553
v 0.270598 0.707107 -0.653281
v 0.353553 0.382683 -0.853553
v 0.382683 0.000000 -0.923880
v 0.353553 -0.382683 -0.853553
v 0.270598 -0.707107 -0.653281
v 0.146447 -0.923880 -0.353553
v 0.270598 0.923880 -0.270598
v 0.500000 0.707107 -0.500000
v 0.653282 0.382683 -0.653281
v 0.707107 0.000000 -0.707107
v 0.653282 -0.382683 -0.653281
v 0.500000 -0.707107 -0.500000
v 0.270598 -0.923880 -0.270598
v 0.353553 0.923880 -0.146447
v 0.653281 0.707107 -0.270598
v 0.853553 0.382683 -0.353553
v 0.923880 0.000000 -0.382683
v 0.853553 -0.382683 -0.353553
v 0.653281 -0.707107 -0.270598
v 0.353553 -0.923880 -0.146447
v 0.382683 0.923880 0.000000
v 0.707107 0.707107 0.000000
v 0.923880 0.382683 0.000000
v 1.000000 0.000000 0.000000
v 0.923880 -0.382683 0.000000
v 0.707107 -0.707107 0.000000
v 0.382683 -0.923880 0.000000
v 0.353553 0.923880 0.146447
v 0.653281 0.707107 0.270598
v 0.853553 0.382683 0.353554
v 0.923879 0.000000 0.382684
v 0.853553 -0.382683 0.353554
v 0.653281 -0.707107 0.270598
v 0.353553 -0.923880 0.146447
v 0.270598 0.923880 0.270598
v 0.500000 0.707107 0.500000
v 0.653281 0.382683 0.653282
v 0.707107 0.000000 0.707107
v 0.653281 -0.382683 0.653282
v 0.500000 -0.707107 0.500000
v 0.270598 -0.923880 0.270598
v 0.146447 0.923880 0.353553
v 0.270598 0.707107 0.653281
v 0.353553 0.382683 0.853553
v 0.382683 0.000000 0.923880
v 0.353553 -0.382683 0.853553
v 0.270598 -0.707107 0.653281
v 0.146447 -0.923880 0.353553
v -0.000000 0.923880 0.382683
v -0.000000 0.707107 0.707107
v -0.000000 0.382683 0.923879
v -0.000000 0.000000 1.000000
v -0.000000 -0.382683 0.923879
v -0.000000 -0.707107 0.707107
v -0.000000 -0.923880 0.382683
v 0.000000 -1.000000 0.000000
v 0.000000 1.000000 0.000000
v -0.146447 0.923880 0.353553
v -0.270598 0.707107 0.653281
v -0.353554 0.382683 0.853553
v -0.382684 0.000000 0.923879
v -0.353554 -0.382683 0.853553
v -0.270598 -0.707107 0.653281
v -0.146447 -0.923880 0.353553
v -0.270598 0.923880 0.270598
v -0.500000 0.707107 0.500000
v -0.653282 0.382683 0.653281
v -0.707107 0.000000 0.707106
v -0.653282 -0.382683 0.653281
v -0.500000 -0.707107 0.500000
v -0.270598 -0.923880 0.270598
v -0.353553 0.923880 0.146446
v -0.653281 0.707107 0.270598
v -0.853553 0.382683 0.353553
v -0.923880 0.000000 0.382683
v -0.853553 -0.382683 0.353553
v -0.653281 -0.707107 0.270598
v -0.353553 -0.923880 0.146446
v -0.382683 0.923880 -0.000000
v -0.707107 0.707107 -0.000000
v -0.923879 0.382683 -0.000000
v -1.000000 0.000000 -0.000001
v -0.923879 -0.382683 -0.000000
v -0.707107 -0.707107 -0.000000
v -0.382683 -0.923880 -0.000000
v -0.353553 0.923880 -0.146447
v -0.653281 0.707107 -0.270598
v -0.853553 0.382683 -0.353554
v -0.923879 0.000000 -0.382684
v -0.853553 -0.382683 -0.353554
v -0.653281 -0.707107 -0.270598
v -0.353553 -0.923880 -0.146447
v -0.270598 0.923880 -0.270598
v -0.500000 0.707107 -0.500000
v -0.653281 0.382683 -0.653282
v -0.707106 0.000000 -0.707107
v -0.653281 -0.382683 -0.653282
v -0.500000 -0.707107 -0.500000
v -0.270598 -0.923880 -0.270598
v -0.146446 0.923880 -0.353554
v -0.270598 0.707107 -0.653281
v -0.353553 0.382683 -0.853553
v -0.382683 0.000000 -0.923880
v -0.353553 -0.382683 -0.853553
v -0.270598 -0.707107 -0.653281
v -0.146446 -0.923880 -0.353554
v 0.000000 0.923880 -0.382683
v 0.000000 0.707107 -0.707107
v 0.000000 -0.707107 -0.707107
v 0.000000 0.382680 -0.923870
v -0.000000 0.000000 -0.999990
v 0.000000 -0.382680 -0.923870
v -0.000000 -0.923870 -0.382679
v 0.146445 0.923870 -0.353550
v 0.270595 0.707100 -0.653275
v 0.353550 0.382680 -0.853545
v 0.382680 0.000000 -0.923870
v 0.353550 -0.382680 -0.853545
v 0.270595 -0.707100 -0.653275
v 0.146445 -0.923870 -0.353550
v 0.270595 0.923870 -0.270595
v 0.499995 0.707100 -0.499995
v 0.653275 0.382680 -0.653275
v 0.707100 0.000000 -0.707100
v 0.653275 -0.382680 -0.653275
v 0.499995 -0.707100 -0.499995
v 0.270595 -0.923870 -0.270595
v 0.353550 0.923870 -0.146445
v 0.653275 0.707100 -0.270595
v 0.853545 0.382680 -0.353550
v 0.923870 0.000000 -0.382679
v 0.853545 -0.382680 -0.353550
v 0.653275 -0.707100 -0.270595
v 0.353550 -0.923870 -0.146445
v 0.382679 0.923870 0.000000
v 0.707099 0.707100 0.000000
v 0.923870 0.382680 0.000000
v 0.999990 0.000000 0.000000
v 0.923870 -0.382680 0.000000
v 0.707099 -0.707100 0.000000
v 0.382679 -0.923870 0.000000
v 0.353550 0.923870 0.146445
v 0.653275 0.707100 0.270595
v 0.853545 0.382680 0.353550
v 0.923870 -0.000000 0.382680
v 0.853545 -0.382680 0.353550
v 0.653275 -0.707100 0.270595
v 0.353550 -0.923870 0.146445
v 0.270595 0.923870 0.270595
v 0.499995 0.707100 0.499995
v 0.653275 0.382680 0.653275
v 0.707099 -0.000000 0.707100
v 0.653275 -0.382680 0.653275
v 0.499995 -0.707100 0.499995
v 0.270595 -0.923870 0.270595
v 0.146445 0.923870 0.353550
v 0.270595 0.707100 0.653275
v 0.353550 0.382680 0.853545
v 0.382679 0.000000 0.923870
v 0.353550 -0.382680 0.853545
v 0.270595 -0.707100 0.653275
v 0.146445 -0.923870 0.353550
v -0.000000 0.923870 0.382679
v -0.000000 0.707100 0.707099
v -0.000000 0.382680 0.923870
v -0.000000 0.000000 0.999990
v -0.000000 -0.382680 0.923870
v -0.000000 -0.707100 0.707099
v -0.000000 -0.923870 0.382679
v -0.000000 -0.999990 0.000000
v -0.000000 0.999990 -0.000000
v -0.146445 0.923870 0.353550
v -0.270595 0.707100 0.653275
v -0.353550 0.382680 0.853545
v -0.382680 0.000000 0.923870
v -0.353550 -0.382680 0.853545
v -0.270595 -0.707100 0.653275
v -0.146445 -0.923870 0.353550
v -0.270595 0.923870 0.270595
v -0.499995 0.707100 0.499995
v -0.653275 0.382680 0.653275
v -0.707100 0.000000 0.707099
v -0.653275 -0.382680 0.653275
v -0.499995 -0.707100 0.499995
v -0.270595 -0.923870 0.270595
v -0.353550 0.923870 0.146445
v -0.653275 0.707100 0.270595
v -0.853545 0.382680 0.353550
v -0.923870 0.000000 0.382679
v -0.853545 -0.382680 0.353550
v -0.653275 -0.707100 0.270595
v -0.353550 -0.923870 0.146445
v -0.382679 0.923870 -0.000000
v -0.707099 0.707100 -0.000000
v -0.923870 0.382680 -0.000000
v -0.999990 0.000000 -0.000001
v -0.923870 -0.382680 -0.000000
v -0.707099 -0.707100 -0.000000
v -0.382679 -0.923870 -0.000000
v -0.353550 0.923870 -0.146445
v -0.653275 0.707100 -0.270596
v -0.853545 0.382680 -0.353550
v -0.923870 0.000000 -0.382680
v -0.853545 -0.382680 -0.353550
v -0.653275 -0.707100 -0.270596
v -0.353550 -0.923870 -0.146445
v -0.270595 0.923870 -0.270595
v -0.499994 0.707100 -0.499995
v -0.653275 0.382680 -0.653275
v -0.707099 0.000000 -0.707100
v -0.653275 -0.382680 -0.653275
v -0.499994 -0.707100 -0.499995
v -0.270595 -0.923870 -0.270595
v -0.146445 0.923870 -0.353550
v -0.270595 0.707100 -0.653275
v -0.353549 0.382680 -0.853545
v -0.382679 0.000000 -0.923871
v -0.353549 -0.382680 -0.853545
v -0.270595 -0.707100 -0.653275
v -0.146445 -0.923870 -0.353550
v 0.000000 0.923870 -0.382679
v 0.000000 0.707100 -0.707099
v 0.000000 -0.707100 -0.707099
v 0.149243 -0.696300 0.183486
s off
f 114 11 4
f 2 9 3
f 113 7 1
f 112 62 5
f 61 4 11
f 114 9 10
f 1 8 2
f 113 5 6
f 61 11 18
f 9 17 10
f 7 15 8
f 5 13 6
f 10 18 11
f 9 15 16
f 6 14 7
f 5 62 12
f 15 21 22
f 12 20 13
f 17 25 18
f 15 23 16
f 13 21 14
f 12 62 19
f 61 18 25
f 17 23 24
f 24 32 25
f 23 29 30
f 21 27 28
f 19 62 26
f 61 25 32
f 23 31 24
f 21 29 22
f 19 27 20
f 27 35 28
f 26 62 33
f 61 32 39
f 30 38 31
f 28 36 29
f 27 33 34
f 32 38 39
f 29 37 30
f 61 39 46
f 37 45 38
f 36 42 43
f 34 40 41
f 39 45 46
f 36 44 37
f 34 42 35
f 33 62 40
f 40 48 41
f 45 53 46
f 44 50 51
f 41 49 42
f 40 62 47
f 61 46 53
f 45 51 52
f 42 50 43
f 53 59 60
f 50 58 51
f 48 56 49
f 47 62 54
f 61 53 60
f 51 59 52
f 50 56 57
f 47 55 48
f 54 62 63
f 61 60 69
f 59 67 68
f 56 66 57
f 54 64 55
f 59 69 60
f 57 67 58
f 55 65 56
f 68 74 75
f 66 72 73
f 63 71 64
f 69 75 76
f 66 74 67
f 64 72 65
f 63 62 70
f 61 69 76
f 75 83 76
f 73 81 74
f 71 79 72
f 70 62 77
f 61 76 83
f 75 81 82
f 73 79 80
f 70 78 71
f 80 88 81
f 78 86 79
f 77 62 84
f 61 83 90
f 82 88 89
f 80 86 87
f 78 84 85
f 82 90 83
f 61 90 97
f 88 96 89
f 87 93 94
f 84 92 85
f 89 97 90
f 87 95 88
f 85 93 86
f 84 62 91
f 94 100 101
f 91 99 92
f 96 104 97
f 94 102 95
f 92 100 93
f 91 62 98
f 61 97 104
f 96 102 103
f 103 111 104
f 101 109 102
f 99 107 100
f 98 62 105
f 61 104 111
f 103 109 110
f 101 107 108
f 98 106 99
f 106 1 107
f 105 62 112
f 61 111 4
f 110 3 114
f 107 2 108
f 106 112 113
f 110 4 111
f 108 3 109
f 125 228 118
f 123 116 117
f 121 227 115
f 226 119 176
f 175 125 118
f 228 123 117
f 122 115 116
f 227 119 226
f 175 132 125
f 131 123 124
f 129 121 122
f 120 126 119
f 132 124 125
f 130 122 123
f 121 127 120
f 119 126 176
f 136 128 129
f 134 126 127
f 139 131 132
f 137 129 130
f 135 127 128
f 126 133 176
f 175 139 132
f 138 130 131
f 146 138 139
f 144 136 137
f 142 134 135
f 133 140 176
f 175 146 139
f 145 137 138
f 143 135 136
f 134 140 133
f 149 141 142
f 140 147 176
f 175 153 146
f 152 144 145
f 150 142 143
f 148 140 141
f 153 145 146
f 151 143 144
f 175 160 153
f 152 158 151
f 157 149 150
f 155 147 148
f 160 152 153
f 158 150 151
f 156 148 149
f 147 154 176
f 162 154 155
f 167 159 160
f 165 157 158
f 163 155 156
f 154 161 176
f 175 167 160
f 166 158 159
f 164 156 157
f 174 166 167
f 172 164 165
f 170 162 163
f 161 168 176
f 175 174 167
f 166 172 165
f 164 170 163
f 169 161 162
f 168 177 176
f 175 183 174
f 182 172 173
f 171 179 170
f 178 168 169
f 183 173 174
f 181 171 172
f 179 169 170
f 182 188 181
f 180 186 179
f 185 177 178
f 183 189 182
f 188 180 181
f 186 178 179
f 177 184 176
f 175 190 183
f 197 189 190
f 195 187 188
f 193 185 186
f 184 191 176
f 175 197 190
f 196 188 189
f 187 193 186
f 192 184 185
f 202 194 195
f 193 199 192
f 191 198 176
f 175 204 197
f 196 202 195
f 194 200 193
f 199 191 192
f 204 196 197
f 175 211 204
f 210 202 203
f 201 207 200
f 206 198 199
f 204 210 203
f 209 201 202
f 207 199 200
f 198 205 176
f 208 214 207
f 206 212 205
f 218 210 211
f 216 208 209
f 207 213 206
f 205 212 176
f 175 218 211
f 217 209 210
f 225 217 218
f 223 215 216
f 221 213 214
f 212 219 176
f 175 225 218
f 217 223 216
f 215 221 214
f 220 212 213
f 115 220 221
f 219 226 176
f 175 118 225
f 224 117 223
f 116 221 222
f 227 219 220
f 118 224 225
f 117 222 223
f 114 10 11
f 2 8 9
f 113 6 7
f 114 3 9
f 1 7 8
f 113 112 5
f 9 16 17
f 7 14 15
f 5 12 13
f 10 17 18
f 9 8 15
f 6 13 14
f 15 14 21
f 12 19 20
f 17 24 25
f 15 22 23
f 13 20 21
f 17 16 23
f 24 31 32
f 23 22 29
f 21 20 27
f 23 30 31
f 21 28 29
f 19 26 27
f 27 34 35
f 30 37 38
f 28 35 36
f 27 26 33
f 32 31 38
f 29 36 37
f 37 44 45
f 36 35 42
f 34 33 40
f 39 38 45
f 36 43 44
f 34 41 42
f 40 47 48
f 45 52 53
f 44 43 50
f 41 48 49
f 45 44 51
f 42 49 50
f 53 52 59
f 50 57 58
f 48 55 56
f 51 58 59
f 50 49 56
f 47 54 55
f 59 58 67
f 56 65 66
f 54 63 64
f 59 68 69
f 57 66 67
f 55 64 65
f 68 67 74
f 66 65 72
f 63 70 71
f 69 68 75
f 66 73 74
f 64 71 72
f 75 82 83
f 73 80 81
f 71 78 79
f 75 74 81
f 73 72 79
f 70 77 78
f 80 87 88
f 78 85 86
f 82 81 88
f 80 79 86
f 78 77 84
f 82 89 90
f 88 95 96
f 87 86 93
f 84 91 92
f 89 96 97
f 87 94 95
f 85 92 93
f 94 93 100
f 91 98 99
f 96 103 104
f 94 101 102
f 92 99 100
f 96 95 102
f 103 110 111
f 101 108 109
f 99 106 107
f 103 102 109
f 101 100 107
f 98 105 106
f 106 113 1
f 110 109 3
f 107 1 2
f 106 105 112
f 110 114 4
f 108 2 3
f 125 124 228
f 123 122 116
f 121 120 227
f 228 124 123
f 122 121 115
f 227 120 119
f 131 130 123
f 129 128 121
f 120 127 126
f 132 131 124
f 130 129 122
f 121 128 127
f 136 135 128
f 134 133 126
f 139 138 131
f 137 136 129
f 135 134 127
f 138 137 130
f 146 145 138
f 144 143 136
f 142 141 134
f 145 144 137
f 143 142 135
f 134 141 140
f 149 148 141
f 152 151 144
f 150 149 142
f 148 147 140
f 153 152 145
f 151 150 143
f 152 159 158
f 157 156 149
f 155 154 147
f 160 159 152
f 158 157 150
f 156 155 148
f 162 161 154
f 167 166 159
f 165 164 157
f 163 162 155
f 166 165 158
f 164 163 156
f 174 173 166
f 172 171 164
f 170 169 162
f 166 173 172
f 164 171 170
f 169 168 161
f 182 181 172
f 171 180 179
f 178 177 168
f 183 182 173
f 181 180 171
f 179 178 169
f 182 189 188
f 180 187 186
f 185 184 177
f 183 190 189
f 188 187 180
f 186 185 178
f 197 196 189
f 195 194 187
f 193 192 185
f 196 195 188
f 187 194 193
f 192 191 184
f 202 201 194
f 193 200 199
f 196 203 202
f 194 201 200
f 199 198 191
f 204 203 196
f 210 209 202
f 201 208 207
f 206 205 198
f 204 211 210
f 209 208 201
f 207 206 199
f 208 215 214
f 206 213 212
f 218 217 210
f 216 215 208
f 207 214 213
f 217 216 209
f 225 224 217
f 223 222 215
f 221 220 213
f 217 224 223
f 215 222 221
f 220 219 212
f 115 227 220
f 224 228 117
f 116 115 221
f 227 226 219
f 118 228 224
f 117 116 222
l 78 229

3
run.sh
View File

@@ -1,3 +0,0 @@
sleep 0.2
cd /home/william/Documents/GitHub/SDL3D/cmake-build-debug
vblank_mode=0 mangohud --dlsym ./SDL3D

View File

@@ -1,13 +0,0 @@
start 0.0 0.0 0.0
velocity 2
loop 1
position 0.0 0.0 -3.2
angle 32.6 0
position -2.4 0 -1.3
angle 30.3 60.6 0
position -0.26 0.11 -2.5
angle 38.6 6.6 0.0
position -0.64 -3.42 -2.37
angle -8.5 14.6 0
position 0.0 0.0 -3.2
angle 32.6 0 0

View File

@@ -1,4 +0,0 @@
Fullscreen: 0
Resolution: 1024 768
Debug: 0
CameraFOV: 72.5

View File

@@ -1,186 +0,0 @@
#pragma once
#include <cstdint>
#include <cstring>
#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <glm/glm.hpp>
#include <FreeImage.h>
#include <fstream>
enum class GAMESTATE: uint8_t {
NORMAL = 0, //Gameplay.
IN_MAIN_MENU = 1,
IN_PAUSE_MENU = 2,
IN_LEVEL_ANIMATION = 3, //A cutscene which moves entities in the world and cannot be interrupted.
IN_QUIT = 4, //The game should close.
};
class Engine {
public:
GAMESTATE gameState;
bool debug;
SDL_Window *window = nullptr;
bool fullscreen;
uint16_t windowWidth;
uint16_t windowHeight;
ulong tickCount = 0;
float tickDelta = NULL;
ulong frameCount = 0;
float frameDelta = NULL;
uint16_t minimumTickDelta = 15625;
GLenum glError = GL_NO_ERROR;
SDL_GLContext glContext = nullptr;
float nearPlane = 0.01f;
float farPlane = 100.0f;
float fov;
Uint8* keyState = nullptr;
SDL_Event event;
[[nodiscard]] float framerate() const {
return 1.f / this->frameDelta;
}
void takeScreenshot() const {
//Prevent taking a ton of screenshots really fast.
std::string fName = std::to_string(time(nullptr)) + ".bmp";
std::ifstream f (fName, std::ifstream::in);
if(f.good()) {
f.close();
return;
}
f.close();
FreeImage_Initialise();
auto* fbData = new GLubyte[this->windowWidth * this->windowHeight * 3];
glReadPixels(0, 0, this->windowWidth, this->windowHeight, GL_RGB, GL_UNSIGNED_BYTE, fbData);
FIBITMAP* image = FreeImage_ConvertFromRawBits(fbData, this->windowWidth, this->windowHeight, this->windowWidth * 3, 24, 0xFF0000, 0x00FF00, 0x0000FF, false);
FreeImage_Save(FIF_BMP, image, (fName.c_str()), 0);
FreeImage_Unload(image);
delete[] fbData;
FreeImage_DeInitialise();
}
void quit() const {
SDL_DestroyWindow(this->window);
SDL_Quit();
exit(0);
}
static float getGLVersion() {
std::string str = reinterpret_cast<const char *>(glGetString(GL_VERSION));
str.erase(str.begin()+3,str.end());
return std::stof(str);
}
void initGL() {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -0.5f, 0.5f);
gluPerspective(this->fov, this->windowWidth / this->windowHeight, this->nearPlane, this->farPlane);
this->glError = glGetError();
if (glError != GL_NO_ERROR) {
std::cerr << "OpenGL: " << gluErrorString(glError);
exit (1);
}
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if (glError != GL_NO_ERROR) {
std::cerr << "OpenGL: " << gluErrorString(glError);
exit (1);
}
glClearColor(0.f, 0.f, 0.f, 1.f);
glViewport(0,0,this->windowWidth,this->windowHeight);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glDepthMask(GL_TRUE);
glClearDepth(1.0f);
glDisable(GL_CULL_FACE);
//glDepthRange(-0.5f,0.5f);
}
void initVideo() {
Uint32 sdl_initializer_flags = SDL_INIT_VIDEO;// | SDL_INIT_AUDIO;
// Start SDL, check for errors
if (SDL_Init(sdl_initializer_flags) < 0) {
std::cerr << "SDL_Error: " << SDL_GetError() << std::endl;
exit(1);
}
// Create the window, set resizable, check for errors
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 1);
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 4);
SDL_GL_SetSwapInterval(0);
if (!fullscreen)
this->window = SDL_CreateWindow("SDL3D", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, this->windowWidth, this->windowHeight, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
if (fullscreen)
this->window = SDL_CreateWindow("SDL3D", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, this->windowWidth, this->windowHeight, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN);
SDL_SetWindowResizable(this->window,SDL_FALSE);
this->glContext = SDL_GL_CreateContext(window);
if (isless(Engine::getGLVersion(),1.4f)) {
std::cerr << "Driver OpenGL version: " << Engine::getGLVersion() << std::endl;
std::cerr << "OpenGL >= 1.4 is required." << std::endl;
exit(1);
}
if (this->window == nullptr) {
std::cerr << "SDL_Error: " << SDL_GetError() << std::endl;
exit(1);
}
//Seed RNG.
srand(time(nullptr));
}
void debugInfo() const {
if (this->debug) {
std::cout << "Last tick completed in: " << (tickDelta / 1000) << "ms, " << "sleeping " << ((minimumTickDelta - tickDelta) / 1000) << "ms." << std::endl;
std::cout << "Last frame dT: " << this->frameDelta << std::endl;
std::cout << "Framerate: " << framerate() << std::endl;
//std::cout << "EntityCount: " << entityList.list.size() << std::endl;
//std::cout << "Camera Position: " << "X " << entityList.getCamera()->position.x << " Y " << entityList.getCamera()->position.y << " Z " << entityList.getCamera()->position.z << std::endl;
}
}
inline void loadConfig() {
std::ifstream file("../settings.cfg");
if (!file.is_open()) {
std::cerr << "Couldn't load engine config." << std::endl;
this->quit();
return;
}
std::string line;
while (std::getline(file, line)) {
std::istringstream stream(line);
std::string prefix;
stream >> prefix;
if (prefix == "Resolution:")
stream >> windowWidth >> windowHeight;
if (prefix == "Fullscreen:")
stream >> fullscreen;
if (prefix == "Debug:")
stream >> debug;
if (prefix == "CameraFOV:")
stream >> fov;
}
//If we have a window already.
if (window != nullptr) {
SDL_DestroyWindow(this->window);
//Some window managers won't handle destroying and remaking the window with zero delay very well.
std::this_thread::sleep_for(std::chrono::milliseconds(500));
initVideo();
initGL();
}
std::cout << "Resolution: " << windowWidth << "x" << windowHeight << std::endl;
std::cout << "Camera FOV: " << fov << std::endl;
std::cout << "Debug: " << debug << std::endl;
}
};
auto* engine = new(Engine);

View File

@@ -1,11 +0,0 @@
#pragma once
#include "world.h"
namespace Occlusion {
inline void frustumCull() {
if (!world->loaded())
return;
//if ()
}
}

View File

@@ -1,101 +0,0 @@
#pragma once
#include <chrono>
#include <thread>
#include "engine.h"
#include "../types/camera.h"
#include "../types/skybox.h"
#include "world.h"
void process_sdl_events() {
while (SDL_PollEvent(&engine->event)) {
// TODO: Consider switch statements as opposed to ifs
// This adds control flow in the form of "break" statement.
// Which will save checking every single event type unnecessarily
if (engine->event.type == SDL_QUIT) {engine->quit();}
if (engine->event.type == SDL_DROPFILE) {}
// Window Events
if (engine->event.type == SDL_WINDOWEVENT) {
auto window_ev = engine->event.window;
auto ev_type = window_ev.event;
if (ev_type == SDL_WINDOWEVENT_FOCUS_LOST) {}
if (ev_type == SDL_WINDOWEVENT_FOCUS_GAINED) {}
if (ev_type == SDL_WINDOWEVENT_CLOSE) {}
if (ev_type == SDL_WINDOWEVENT_SHOWN) {}
if (ev_type == SDL_WINDOWEVENT_HIDDEN) {}
if (ev_type == SDL_WINDOWEVENT_EXPOSED) {}
if (ev_type == SDL_WINDOWEVENT_MOVED) {}
if (ev_type == SDL_WINDOWEVENT_RESIZED) {}
if (ev_type == SDL_WINDOWEVENT_SIZE_CHANGED) {}
if (ev_type == SDL_WINDOWEVENT_MINIMIZED) {}
if (ev_type == SDL_WINDOWEVENT_MAXIMIZED) {}
if (ev_type == SDL_WINDOWEVENT_RESTORED) {}
if (ev_type == SDL_WINDOWEVENT_ENTER) {}
if (ev_type == SDL_WINDOWEVENT_LEAVE) {}
}
}
}
void pre_render() {
if(engine->frameCount == 0) {
engine->initVideo();
engine->initGL();
auto camera = new(Camera);
world->storeEntity(camera);
getCamera()->position.set(0.0f,-2.0f,-5.0f);
getCamera()->angle.y = 0.0f;
getCamera()->scriptedMove.load("../scriptedMove/default.smov");
auto skybox = new(Skybox);
skybox->draw = true;
world->storeEntity(skybox);
auto player = new(Player);
player->angle = {0,0,0};
world->storeEntity(player);
}
engine->frameCount++;
process_sdl_events();
engine->keyState = const_cast<Uint8 *>(SDL_GetKeyboardState(nullptr));
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
getCamera()->pre_render();
getPlayer()->pre_render();
getSkybox()->pre_render();
}
void render() {
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//*Always* render the camera first.
getCamera()->render();
getSkybox()->render();
getPlayer()->render();
}
void post_render() {
SDL_GL_SwapWindow(engine->window);
getCamera()->post_render();
//Resets all of the transformations for the next frame.
glPopMatrix();
glPushMatrix();
}
[[noreturn]] void render_loop() {
while (true) {
auto start = std::chrono::high_resolution_clock::now();
pre_render();
render();
post_render();
auto stop = std::chrono::high_resolution_clock::now();
float dT = (std::chrono::duration_cast<std::chrono::microseconds>(stop - start).count());
//If we have more than 1000 fps.
if (dT < 1000){
int remaining = 1000 - dT;
std::this_thread::sleep_for(std::chrono::microseconds(remaining));
dT = 1000;
}
engine->frameDelta = dT / 1000000;
}
}

View File

@@ -1,43 +0,0 @@
#pragma once
#include <chrono>
#include <thread>
#include "engine.h"
#include "world.h"
#include "../types/camera.h"
[[noreturn]] void gameTick() {
while (true) {
auto start = std::chrono::high_resolution_clock::now();
//do stuff
engine->tickCount++;
switch (engine->gameState) {
case GAMESTATE::NORMAL:
if(engine->frameCount > 1)
getCamera()->update();
break;
case GAMESTATE::IN_MAIN_MENU:
break;
case GAMESTATE::IN_PAUSE_MENU:
break;
case GAMESTATE::IN_LEVEL_ANIMATION:
break;
case GAMESTATE::IN_QUIT:
engine->quit();
break;
}
//The compiler and/or the cpu would probably fix this on it's own anyways.
//But, always put the simplest condition first in the if statement if it's likely to fail.
if (engine->debug && engine->tickCount % 64 == 0)
engine->debugInfo();
auto stop = std::chrono::high_resolution_clock::now();
//limit to 64 ticks per second.
if ((int) engine->tickDelta < engine->minimumTickDelta)
std::this_thread::sleep_for(
std::chrono::microseconds((uint16_t) engine->minimumTickDelta - (uint16_t) engine->tickDelta));
//Pause without potential deSync issues.
engine->tickDelta = std::chrono::duration_cast<std::chrono::microseconds>(stop - start).count();
}
}

View File

@@ -1,68 +0,0 @@
#pragma once
#include "../types/vertex.h"
#include "../types/entity.h"
class World {
public:
std::string name;
VertexArray levelGeometry;
//TODO
std::vector<Entity*> entityList;
std::vector<VertexArray> entityGeometry;
void storeEntity(Entity* e) {
entityList.push_back(e);
}
[[nodiscard]] inline bool loaded() const {
if (name.empty())
return false;
return true;
}
inline void load(const char* filename) {
std::ifstream file(filename);
if (!file.is_open()) {
std::cout << "File not found: " << filename << std::endl;
engine->quit();
return;
}
std::string line;
while (std::getline(file, line)) {
std::istringstream stream(line);
std::string prefix;
stream >> prefix;
//world name.
if (prefix == "Name:") {
std::string x;
stream >> x;
name = x;
}
else if (prefix == "Geometry:") {
std::string x;
stream >> x;
levelGeometry.load("../models/worlds/"+x);
}
}
//Disable this just for testing.
//if (levelGeometry.name.empty()) {
//std::cout << "Error: No world was loaded?" << std::endl;
//engine->quit();
//}
}
//TODO: Determine the inherited class of the entity and return that pointer instead.
//*Will probably be a pain in the ass*
//Will probably need some kind of forward declaration or per class basis stuff.
inline Entity* getEntityFromUUID(uint16_t UUID) {
for (auto& e : entityList)
if (e->UUID == UUID)
return e;
std::cerr << "Error: Tried to return pointer to entity which is not in the world." << std::endl;
engine->quit();
}
};
World* world = new(World);

View File

@@ -1,9 +0,0 @@
#include <thread>
#include "engine/tick.h"
#include "engine/render.h"
int main() {
engine->loadConfig();
std::thread renderThread(render_loop);
renderThread.join();
gameTick();
}

View File

@@ -1,70 +0,0 @@
#pragma once
#include <vector>
#include <fstream>
#include <sstream>
#include <iostream>
#include "../vector3.h"
#include "../../engine/engine.h"
#include "../../engine/world.h"
//A "scripted move" is a vector of points and angles that function as keyframes.
//A moby will follow *and interpolate* between those points.
class ScriptedMove {
public:
std::vector<Position> positions;
std::vector<Angle> angles;
//We won't even need that many positions anyways.
int16_t index = -1;
Position start = {NULL,NULL,NULL};
float velocity;
float lastDistance;
bool loop = false;
void load(const std::string& filename) {
std::ifstream file(filename);
if (!file.is_open()) {
std::cout << "File not found: " << filename << std::endl;
engine->quit();
return;
}
std::string line;
while (std::getline(file, line)) {
std::istringstream stream(line);
std::string prefix;
stream >> prefix;
if (prefix == "position") {
float x, y, z;
stream >> x >> y >> z;
positions.push_back({x, y, z});
}
else if (prefix == "angle") {
float x, y, z;
stream >> x >> y >> z;
angles.push_back({x, y, z});
}
else if (prefix == "start") {
float x, y, z;
stream >> x >> y >> z;
start.x = x;
start.y = y;
start.z = z;
}
else if (prefix == "velocity") {
float x;
stream >> x;
velocity = x;
}
else if (prefix == "loop") {
bool x;
stream >> x;
loop = x;
}
}
file.close();
}
void reset() {
index = -1;
}
};

View File

@@ -1,110 +0,0 @@
#pragma once
#include "moby.h"
#include "player.h"
#include "../engine/engine.h"
#include <glm/glm.hpp>
#include "../engine/world.h"
enum class CameraMode: uint8_t {
THIRD_PERSON = 0,
FREECAM = 1,
};
class Camera : public Moby {
public:
CameraMode cameraMode = CameraMode::FREECAM;
bool takingScreenshot = false;
void update() {
if (engine->debug && engine->tickCount %64 == 0) {
std::cout << "Camera:" << std::endl;
std::cout << "X: " << position.x << " Y: " << position.y << " Z: " << position.z << std::endl;
std::cout << "Pitch: " << angle.x << " Yaw: " << angle.y << " Roll: " << angle.z << std::endl;
}
}
void pre_render() {
if (engine->keyState[SDL_SCANCODE_0] == 1) {
this->takingScreenshot = true;
}
if (engine->keyState[SDL_SCANCODE_1] == 1)
this->cameraMode = CameraMode::FREECAM;
if (engine->keyState[SDL_SCANCODE_2] == 1)
this->cameraMode = CameraMode::THIRD_PERSON;
if (cameraMode == CameraMode::THIRD_PERSON) {
if (engine->debug)
std::cout << "Calculated Pitch: " << VectorMath::calcAngle(position,getPlayer()->position).x << " Calculated Yaw: " << VectorMath::calcAngle(position,getPlayer()->position).y << std::endl;
this->position = getPlayer()->cameraPoint(2);
//Make the camera pitch down a little bit.
this->position.y += 0.5;
this->angle.x = VectorMath::calcAngle(position,getPlayer()->position).x;
this->angle.y = VectorMath::calcAngle(position,getPlayer()->position).y;
}
if (cameraMode == CameraMode::FREECAM) {
if (engine->keyState[SDL_SCANCODE_S] == 1) {
move(bAngle(),2);
}
if (engine->keyState[SDL_SCANCODE_W] == 1) {
move(fAngle(),2);
}
if (engine->keyState[SDL_SCANCODE_A] == 1) {
move(lAngle(), 2);
}
if (engine->keyState[SDL_SCANCODE_D] == 1) {
move(rAngle(),2);
}
if (engine->keyState[SDL_SCANCODE_SPACE] == 1) {
this->position.y += 5*engine->frameDelta;
}
if (engine->keyState[SDL_SCANCODE_LSHIFT] == 1) {
this->position.y -= 5*engine->frameDelta;
}
if (engine->keyState[SDL_SCANCODE_LEFT] == 1) {
this->angle.y +=75.0f*engine->frameDelta;
}
if (engine->keyState[SDL_SCANCODE_RIGHT] == 1) {
this->angle.y -=75.0f*engine->frameDelta;
}
if (engine->keyState[SDL_SCANCODE_UP] == 1) {
this->angle.x -=75.0f*engine->frameDelta;
}
if (engine->keyState[SDL_SCANCODE_DOWN] == 1) {
this->angle.x +=75.0f*engine->frameDelta;
}
}
doScriptedMovement();
}
void render() {
this->angle.clamp();
glRotatef(angle.x,1.0f, 0.0f, 0.0f);
glRotatef(-angle.y,0.0f, 1.0f, 0.0f);
glTranslatef(0.0f, 0.0f, 0.0f);
gluLookAt(position.x, position.y, position.z, // camera position
position.x, position.y, engine->farPlane+position.z, // target position, We're always *looking at* the far plane straight ahead so the camera never turns around.
upVector.x,upVector.y,upVector.z);
}
void post_render() {
if (this->takingScreenshot) {
engine->takeScreenshot();
takingScreenshot = false;
}
this->ticksAlive++;
}
};
inline Camera* getCamera() {
for (auto& e : world->entityList)
if (auto* c = dynamic_cast<Camera*>(e))
return c;
std::cerr << "Error: Your world must have a camera." << std::endl;
engine->quit();
}

View File

@@ -1,31 +0,0 @@
#pragma once
#include <cstdint>
#include "vector3.h"
class Entity {
public:
bool draw = true;
bool collidable = true;
uint32_t ticksAlive = 0; //At 64tps it'd take 776 days to overflow.
Position position = {0,0,0}; //X Y Z
uint16_t UUID;
Entity() {
//Assign UUID.
//TODO This has the potential to be very slow.
//It'd RNG roll a ton of times. Allocate a char and roll 4 uint8_t's and cast to char
//So the UUID is effectively 4 ascii characters.
int result;
do result = rand();
while (result < 0 || 65535 < result);
UUID = result;
}
void destruct() {
//TODO: Search entity list for this entity and remove it to avoid use-after-free.
delete this;
}
virtual void pre_render() {}
virtual void post_render() {}
virtual void render() {}
virtual ~Entity() = default;
};

View File

@@ -1,105 +0,0 @@
#pragma once
#include "entity.h"
#include "animation/scriptedMove.h"
//Movable Object.
class Moby : public Entity {
public:
//float velocity = 0;
Angle angle = {0,0,0}; //Pitch Yaw Roll, The orientation of the entity in the world,
Angle velAngle = {0,0,0}; //The angle of an entities velocity.
vector3 upVector = {0.0f,1.0f,0.0f};
ScriptedMove scriptedMove;
void move(Angle a, float speed) {
this->position.z += (speed*engine->frameDelta) * a.x;
this->position.y += (speed*engine->frameDelta) * a.y;
this->position.x += (speed*engine->frameDelta) * a.z;
}
//Returns the position we'd be at *if* we did a movement.
Position simulateMove(Angle a, float speed) {
Position p;
p.z = this->position.z += (speed*engine->frameDelta) * a.x;
p.y = this->position.y += (speed*engine->frameDelta) * a.y;
p.x = this->position.x += (speed*engine->frameDelta) * a.z;
return p;
}
//forward angle
Angle fAngle() {
Angle a;
a.x = (cos(glm::radians(this->angle.y)) * cos(glm::radians(this->angle.x)));
a.y = -sin(glm::radians(this->angle.x));
a.z = (sin(glm::radians(this->angle.y)) * cos(glm::radians(this->angle.x)));
return a;
}
//back angle
Angle bAngle() {
Angle a;
a.x = -cos(glm::radians(this->angle.y)) * cos(glm::radians(this->angle.x));
a.y = (sin(glm::radians(this->angle.x)));
a.z = -sin(glm::radians(this->angle.y)) * cos(glm::radians(this->angle.x));
return a;
}
//left angle
Angle lAngle() {
Angle f = fAngle();
Angle a;
a.x = f.y * upVector.z - f.z * upVector.y;
a.y = f.z * upVector.x - f.x * upVector.z;
a.z = f.x * upVector.y - f.y * upVector.x;
return a;
}
Angle rAngle() {
Angle f = fAngle();
Angle a;
a.x = -(f.y * upVector.z - f.z * upVector.y);
a.y = (f.z * upVector.x - f.x * upVector.z);
a.z = -(f.x * upVector.y - f.y * upVector.x);
return a;
}
void doScriptedMovement() {
//If the movement has a set starting position, Then teleport there.
if (scriptedMove.positions.empty())
return;
if (scriptedMove.index == -1 && !scriptedMove.start.operator==({0, 0, 0})) {
this->position = scriptedMove.start;
scriptedMove.index++;
}
//If the movement does not have a starting position
if (scriptedMove.index == -1 && scriptedMove.start.operator==({0,0,0})) {
scriptedMove.index++;
}
scriptedMove.lastDistance = VectorMath::distance(position,scriptedMove.positions[scriptedMove.index]);
//We've reached the end of the movement script.
if (scriptedMove.index + 1 > scriptedMove.positions.size()) {
if (!scriptedMove.loop)
return;
scriptedMove.reset();
}
Angle a = VectorMath::calcAngle(this->position, scriptedMove.positions[scriptedMove.index]).movementAngle();
move(a,scriptedMove.velocity);
//TODO: The angular velocity still isn't qccurate.
angle.x -= (angle.x - scriptedMove.angles[scriptedMove.index].x)*(scriptedMove.velocity)*engine->frameDelta;
angle.y -= (angle.y -scriptedMove.angles[scriptedMove.index].y)*(scriptedMove.velocity)*engine->frameDelta;
angle.z -= (angle.z - scriptedMove.angles[scriptedMove.index].z)*engine->frameDelta;
//If the next movement would make us go passed it.
if (scriptedMove.lastDistance < VectorMath::distance(simulateMove(a,scriptedMove.velocity),scriptedMove.positions[scriptedMove.index])) {
this->position = scriptedMove.positions[scriptedMove.index];
//this->angle = scriptedMove.angles[scriptedMove.index];
scriptedMove.index++;
return;
}
}
};

View File

@@ -1,68 +0,0 @@
#pragma once
#include <iostream>
#include <cmath>
#include "moby.h"
#include "../engine/world.h"
#include "../engine/engine.h"
#include "vertex.h"
class Player : public Moby {
public:
uint8_t health;
uint8_t state;
Position cameraTarget;//The point where the 3rd-person camera will want to look at.
VertexArray geometry;
//Each type of entity will have an "update" function and a "render" function.
//These will be declared in each type of entity and not in the base entity because
//It'll be different for each one.
[[nodiscard]] bool alive() const {
if (health == 0)
return false;
return true;
}
//The "camera point" is the position the camera will want to be while following the player.
//We will probably end up having a different camera point class controlled by the "world".
Position cameraPoint (float distance) {
Position behindPosition = this->position;
Angle reverseDirection = this->bAngle();
behindPosition.x -= reverseDirection.x * distance;
behindPosition.y -= reverseDirection.y * distance;
behindPosition.z -= reverseDirection.z * distance;
return behindPosition;
}
void update() {
//if (engine->tickCount >=10)
//std::cout << "Player* Hopefully: " << scriptedMove.parent->position.x;
}
void pre_render() {
//PLACEHOLDER LOL.
if (engine->frameCount == 1) {
geometry.load("../models/cube.obj");
geometry.scale(0.25f);
position.set(0,-2,0);
}
//Rotate
this->angle.y += 200.0*engine->frameDelta;
}
void render() {
glColor3f(0.75,0.75,0.75);
glPushMatrix();
glRotatef(-angle.x,1.0f, 0.0f, 0.0f);
glRotatef(-angle.y,0.0f, 1.0f, 0.0f);
glTranslatef(position.x ,position.y,position.z);
geometry.draw();
glPopMatrix();
}
};
inline Player* getPlayer() {
for (auto& e : world->entityList)
if (auto* p = dynamic_cast<Player*>(e) )
return p;
std::cerr << "Error: Your world must have a player." << std::endl;
engine->quit();
}

View File

@@ -1,35 +0,0 @@
#pragma once
#include <SDL2/SDL_opengl.h>
#include "../engine/world.h"
#include "moby.h"
#include "camera.h"
#include "vertex.h"
class Skybox : public Entity {
public:
VertexArray geometry;
void pre_render() {
//PLACEHOLDER.
if (engine->frameCount == 1) {
geometry.load("../models/cube.obj");
}
}
void render() {
glColor3f(0.75,0.75,0.75);
glPushMatrix();
glTranslatef(position.x + 4,position.y,position.z);
//geometry.draw();
glPopMatrix();
}
};
inline Skybox* getSkybox() {
for (auto& e : world->entityList)
if (auto* s = dynamic_cast<Skybox*>(e))
return s;
std::cerr << "Error: Your world must have a skybox." << std::endl;
engine->quit();
}

View File

@@ -1,104 +0,0 @@
#pragma once
#include <cstdint>
#include <cmath>
#include <cstdlib>
class vector3{
public:
float x = 0; //pitch
float y = 0; //yaw
float z = 0; //roll
};
class Angle : public vector3 {
public:
bool operator==(const Angle& a) const {
return (x == a.x) && (y == a.y) && (z == a.z);
}
void clamp() {
if (this->x > 89.0f)
this->x = 89.0f;
if (this->x <= -89.0f)
this->x = -89.0f;
//TODO: Make this entirely seamless by getting the amount they rotated passed -180 and +180 by.
if (this->y <= -180.0f)
this->y = 180.0f;
if (this->y >= 180.01f)
this->y = -179.9f;
if (this->z >= 360.0f)
this->z = 0.0;
if(this->z <= -360.0f)
this->z = 0.0;
}
[[nodiscard]] float length() const {
return sqrt(x * x + y * y + z * z);
}
Angle movementAngle() {
Angle a;
a.x = (cos(glm::radians(y)) * cos(glm::radians(x)));
a.y = -sin(glm::radians(x));
a.z = (sin(glm::radians(y)) * cos(glm::radians(x)));
return a;
}
};
class Position : public vector3 {
public:
bool operator==(const Position& p) const {
return (x == p.x) && (y == p.y) && (z == p.z);
}
void set(Position p) {
this->x = p.x;
this->y = p.y;
this->z = p.z;
}
void set(Position* p) {
this->x = p->x;
this->y = p->y;
this->z = p->z;
}
void set(vector3 v) {
this->x = v.x;
this->y = v.y;
this->z = v.z;
}
void set(vector3* v) {
this->x = v->x;
this->y = v->y;
this->z = v->z;
}
void set(float x, float y, float z) {
this->x = x;
this->y = y;
this->z = z;
}
float distanceFrom(Position p) {
return sqrt(pow(this->x - p.x, 2) + pow(this->y - p.y, 2) + pow(this->z - p.z, 2));
}
};
struct Movement {
Angle angle;
Position position;
};
namespace VectorMath {
float distance(Position sP, Position eP) {
return sqrt(pow(eP.x - sP.x, 2) + pow(eP.y - sP.y, 2) + pow(eP.z - sP.z, 2));
}
//Basically an aimbot.
Angle calcAngle(Position sP, Position eP) {
//returned.x = -(asinf((eP.y - sP.y) / distance(sP, eP)) * 180.0f / M_PI);
//returned.y = (atan2f(eP.x - sP.x,eP.z - sP.z) / M_PI * 180.0f);
return {static_cast<float>((-(asinf((eP.y - sP.y) / distance(sP, eP)) * 180.0f / M_PI))),static_cast<float>((atan2f(eP.x - sP.x,eP.z - sP.z) / M_PI * 180.0f)),0};
}
}

View File

@@ -1,76 +0,0 @@
#pragma once
#include <SDL2/SDL_opengl.h>
#include <vector>
#include <iostream>
#include <fstream>
#include <sstream>
#include <SDL2/SDL_opengl.h>
#include <GL/glu.h>
#include <GL/gl.h>
#include "vector3.h"
struct Vertex {
GLfloat x, y, z;
};
class VertexArray {
public:
std::string name;
std::vector<Vertex> vertices;
std::vector<unsigned int> indices;
void scale(GLfloat multiplier) {
for (auto & vertice : vertices) {
vertice.x *= multiplier;
vertice.y *= multiplier;
vertice.z *= multiplier;
}
}
void load(const std::string& filename) {
std::ifstream file(filename);
if (!file.is_open()) {
std::cout << "File not found: " << filename << std::endl;
engine->quit();
return;
}
std::string line;
while (std::getline(file, line)) {
std::istringstream stream(line);
std::string prefix;
stream >> prefix;
if (prefix == "v") {
float x, y, z;
stream >> x >> y >> z;
vertices.push_back({x, y, z});
}
else if (prefix == "f") {
unsigned int v1, v2, v3;
stream >> v1 >> v2 >> v3;
indices.push_back(v1 - 1);
indices.push_back(v2 - 1);
indices.push_back(v3 - 1);
}
else if (prefix == "name") {
std::string x;
stream >> x;
name = x;
}
}
file.close();
}
//Wrong
void draw() {
glBegin(GL_TRIANGLES);
for (size_t i = 0; i < indices.size(); i += 3) {
glVertex3f(vertices[indices[i]].x, vertices[indices[i]].y, vertices[indices[i]].z);
glVertex3f(vertices[indices[i + 1]].x, vertices[indices[i + 1]].y, vertices[indices[i + 1]].z);
glVertex3f(vertices[indices[i + 2]].x, vertices[indices[i + 2]].y, vertices[indices[i + 2]].z);
}
glEnd();
}
};