-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_plotter.cpp
More file actions
108 lines (93 loc) · 2.84 KB
/
Copy pathfunction_plotter.cpp
File metadata and controls
108 lines (93 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Thirdparty
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_image.h>
// C++
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cstdlib>
#include <unistd.h>
// Game Engine
#include "vars.hpp"
#include "../../core/misc/include/log.hpp"
#include "../../core/misc/include/colors.h"
#include "../../core/misc/include/fps.h"
#include "../../core/misc/include/mouse.h"
#include "../../core/misc/include/keyboard.h"
#include "../../core/misc/include/events.h"
#include "../../core/misc/include/matrix.hpp"
#include "../../core/ui/include/window.h"
#include "../../core/ui/include/renderer.h"
#include "../../core/ui/include/text.h"
#include "../../core/ui/include/font_paths.hpp"
#include "../../src/2d/include/image.h"
#include "../../src/2d/include/polygons.h"
#include "../../src/2d/include/spritesheet.h"
#include "../../src/2d/include/vector2d.hpp"
#include "../../src/3d/include/vector3d.hpp"
#include "../../src/3d/include/solids.h"
#include "../../src/misc/include/gameobj.h"
#include "../../src/misc/include/rigidbody.h"
bool gameloop = true;
int main() {
system("clear");
debug_b();
success("Application started");
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
error("game.cpp > Couldn't initialize SDL: ");
}
// Create the window
SDL_Window *window = NULL;
create_window(window, "Test", 0, 0, W_W, W_H, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
// Create the renderer
SDL_Renderer *renderer;
create_renderer(window, renderer);
// Initialize text manager
init_ttf();
TTF_Font *roboto = TTF_OpenFont(roboto_path, 10);
// Initialize image manager for PNG format
init_img(IMG_INIT_PNG);
// TODO: implement expression parsing for custom functions
// for now only points
int points[] = {-42, -59, 98, -24, -52, -22, -42, 8, 8, 89, -83, 83, -29, -71, 20, -73, -27, -88, 87, -37, -33, 33, 57, 10};
int n_points = 24;
float pos = 0;
float step = W_W / n_points;
Vector2D vertices[n_points];
for (int i = 0; i < n_points; i++) {
vertices[i] = Vector2D(pos, points[i] + W_H / 2);
pos += step;
}
while (gameloop) {
// Start counting ticks
Uint64 start = SDL_GetTicks();
// Event handler
event_handler(window, gameloop);
// Clear previous frame
renderer_clear(renderer);
// X axis
line(renderer, Vector2D(0, W_H / 2), Vector2D(W_W, W_H / 2));
// Y axis
line(renderer, Vector2D(W_W / 2, 0), Vector2D(W_W / 2, W_H));
// Draw points and connect them
for (int i = 0; i < n_points; i++) {
if (i + 1 != n_points) {
connect(renderer, vertices[i], vertices[i + 1], C_BLUE);
}
point(renderer, vertices[i]);
}
// Cap FPS
cap(start, MAX_FPS, true, renderer, roboto);
// Update renderer
renderer_update(renderer);
}
// End program and clean memory
TTF_CloseFont(roboto);
close_ttf();
close_img();
destroy_renderer(renderer);
destroy_window(window);
SDL_Quit();
success("Application terminated");
}