aboutsummaryrefslogtreecommitdiffstats
path: root/src/objects.cpp
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-04-10 16:39:57 +0000
committerJoursoir <chat@joursoir.net>2021-04-10 16:39:57 +0000
commit887314d01046ed2c00db3eb7b4b227f070501aa1 (patch)
treeb594e1b01f768b7b805000397f2cbe9c8db10b67 /src/objects.cpp
parent97c388c80363a15a0ee49af6df6b2bbf4c5a4af1 (diff)
downloadspace-simulator-887314d01046ed2c00db3eb7b4b227f070501aa1.tar.gz
space-simulator-887314d01046ed2c00db3eb7b4b227f070501aa1.tar.bz2
space-simulator-887314d01046ed2c00db3eb7b4b227f070501aa1.zip
objects: source files move to game folder; use glm PI
Diffstat (limited to 'src/objects.cpp')
-rw-r--r--src/objects.cpp158
1 files changed, 0 insertions, 158 deletions
diff --git a/src/objects.cpp b/src/objects.cpp
deleted file mode 100644
index b1b24bb..0000000
--- a/src/objects.cpp
+++ /dev/null
@@ -1,158 +0,0 @@
-#include <glm/glm.hpp>
-
-#include "objects.hpp"
-#include "graphics/Mesh.hpp"
-#include "graphics/Vertex.hpp"
-
-#define PI 3.1415926535
-
-using namespace glm;
-
-const int cube_num_v = 8;
-Vertex cube_vertices[cube_num_v] = {
- // first 4 - up edge
- { vec3(-1.0f, -1.0f, -1.0f), vec2(0.0f, 0.0f) },
- { vec3(1.0f, -1.0f, -1.0f), vec2(0.0f, 0.0f) },
- { vec3(1.0f, 1.0f, -1.0f), vec2(0.0f, 0.0f) },
- { vec3(-1.0f, 1.0f, -1.0f), vec2(0.0f, 0.0f) },
- { vec3(1.0f, 1.0f, 1.0f), vec2(0.0f, 0.0f) },
- { vec3(-1.0f, 1.0f, 1.0f), vec2(0.0f, 0.0f) },
- { vec3(-1.0f, -1.0f, 1.0f), vec2(0.0f, 0.0f) },
- { vec3(1.0f, -1.0f, 1.0f), vec2(0.0f, 0.0f) }
-};
-
-const int cube_num_i = 12 * 3;
-GLuint cube_indices[cube_num_i] = {
- 0, 1, 2, // up edge
- 0, 2, 3,
- 2, 3, 4, // far edge
- 3, 4, 5,
- 0, 3, 5, // left edge
- 0, 5, 6,
- 0, 6, 7, // near edge
- 0, 1, 7,
- 1, 4, 7, // right edge
- 1, 2, 4,
- 4, 5, 6, // down edge
- 4, 6, 7
-};
-
-Mesh *form_cube()
-{
- return new Mesh(GL_TRIANGLES, cube_vertices, cube_num_v, cube_indices, cube_num_i);
-}
-
-Mesh *form_sphere(int longitude_count, int latitude_count)
-{
- /* The points on the sphere with radius r > 0 and center (x0, y0, z0)...
- ...can be parameterized via:
- {
- x = x0 + R * sin(tetta) * cos(phi)
- y = y0 + R * sin(tetta) * sin(phi)
- z = z0 + R * cos(tetta)
- tetta : [0, PI]; phi : [0, 2PI]
- }
- or:
- {
- x = x0 + R * cos(phi) * cos(tetta)
- y = y0 + R * cos(phi) * sin(tetta)
- z = z0 + R * sin(phi)
- }
- our x0, y0, z0 = 0 */
- int i, j, idx, k1, k2;
- float x, y, z;
- float s, t;
- float radius = 1.0;
-
- // sectors
- float longitude_step = PI / longitude_count;
- float longitude_angle;
-
- // stacks
- float latitude_step = 2 * PI / latitude_count;
- float latitude_angle;
-
- int sphere_num_v = (longitude_count + 1) * (latitude_count + 1);
- Vertex *sphere_vertices = new Vertex[sphere_num_v];
- for(i = 0, idx = 0; i <= longitude_count; i++) {
- longitude_angle = i * longitude_step;
- z = radius * cos(longitude_angle);
-
- for(j = 0; j <= latitude_count; j++) {
- latitude_angle = j * latitude_step;
-
- x = radius * sinf(longitude_angle) * cosf(latitude_angle);
- y = radius * sinf(longitude_angle) * sinf(latitude_angle);
- sphere_vertices[idx].pos_coords = glm::vec3(x, y, z);
-
- s = (float)j / longitude_count;
- t = (float)i / latitude_count;
- sphere_vertices[idx].tex_coords = glm::vec2(s, t);
- idx++;
- }
- }
-
- int sphere_num_i = (longitude_count - 1) * latitude_count * 6;
- GLuint *sphere_indices = new GLuint[sphere_num_i];
- for(i = 0, idx = 0; i < longitude_count; i++) {
- k1 = i * (latitude_count+1);
- k2 = k1 + (latitude_count+1);
-
- for(j = 0; j < latitude_count; j++, k1++, k2++) {
- if(i != 0)
- {
- sphere_indices[idx++] = k1;
- sphere_indices[idx++] = k2;
- sphere_indices[idx++] = k1 + 1;
- }
- if(i != (longitude_count-1))
- {
- sphere_indices[idx++] = k1 + 1;
- sphere_indices[idx++] = k2;
- sphere_indices[idx++] = k2 + 1;
- }
- }
- }
-
- Mesh *sphere = new Mesh(GL_TRIANGLES, sphere_vertices, sphere_num_v,
- sphere_indices, sphere_num_i);
-
- delete[] sphere_vertices;
- delete[] sphere_indices;
- return sphere;
-}
-
-Mesh *form_circle(int angle_count)
-{
- int i, idx, idy;
- float x, y, z;
- float radius = 1.0f;
- float angle_step = 2 * PI / angle_count;
- float angle;
-
- Vertex *circle_vertices = new Vertex[angle_count];
- GLuint *circle_indices = new GLuint[angle_count * 2];
- for(i = 0, idx = 0, idy = 0; i < angle_count; i++) {
- angle = i * angle_step;
- x = radius * cosf(angle);
- y = 0;
- z = radius * sinf(angle);
- circle_vertices[idx].pos_coords = glm::vec3(x, y, z);
- circle_vertices[idx].tex_coords = glm::vec2(0, 0);
- idx++;
-
- if(i != 0) {
- circle_indices[idy++] = i-1;
- circle_indices[idy++] = i;
- }
- }
- circle_indices[idy++] = i-1;
- circle_indices[idy] = 0;
-
- Mesh *circle = new Mesh(GL_LINES, circle_vertices, angle_count,
- circle_indices, angle_count * 2);
-
- delete[] circle_vertices;
- delete[] circle_indices;
- return circle;
-} \ No newline at end of file