-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cc
125 lines (111 loc) · 3.09 KB
/
test.cc
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* =====================================================================================
*
* Filename: main.cc
*
* Description: A simple fighting game
*
* Version: 1.0
* Created: 21.03.2017 16:39:34
* Revision: none
* Compiler: gcc
*
* Author: Finn Krein, [email protected]; Arvid Krein, [email protected]
* Company: -
*
* =====================================================================================
*/
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <iostream>
#include <stdio.h>
#include <string>
#include <cmath>
#include <vector>
#include "utility.h"
#include "lTexture.h"
#include "physobj.h"
#include "bezier.h"
#include "vec2.h"
#include "stickman.h"
int KASTENGROSSE = 5;
const int FRAMERATE = 25;
SDL_Point SDP(vec2 Point)
{
return {static_cast<int>(std::round(Point.X)),static_cast<int>(std::round(Point.Y))};
}
int main (/*int argc, char* args[])*/)
{
SDL_Window* gWindow;
SDL_Renderer* gRenderer;
init(&gWindow,&gRenderer, SCREEN_HEIGHT, SCREEN_WIDTH);
bool quit=false;
SDL_Event event;
simpleTimer timer;
int mousex;
int mousey;
vec2 P1 = {100,100};
vec2 P2 = {110,100};
vec2 P3 = {110,110};
vec2 P4 = {100,110};
std::array<vec2,4> Ps = {P1,P2,P3,P4};
std::vector<vec2> PHull = hull(Ps);
vec2 K1 = {100,100};
vec2 K2 = {110,100};
vec2 K3 = {110,110};
vec2 K4 = {100,110};
std::array<vec2,4> Ks = {K1,K2,K3,K4};
std::vector<vec2> KHull = hull(Ks);
SDL_Rect PRect;
SDL_Rect drawnRect = {SCREEN_WIDTH/2, SCREEN_HEIGHT/2, 4 ,4};
Bezpath Path;
Path.pushNode({static_cast<float>(SCREEN_WIDTH)/2,static_cast<float>(SCREEN_HEIGHT/2),0,0,60});
Path.pushNode({static_cast<float>(SCREEN_WIDTH)/2+100,static_cast<float>(SCREEN_HEIGHT/2)+70,0,100,0});
while (quit!=true)
{
while(SDL_PollEvent(&event)!=0)
{
if(event.type == SDL_QUIT)
quit=true;
if(event.type == SDL_KEYDOWN)
{
switch (event.key.keysym.sym)
{
case SDLK_r:
Path.rotatePath(drawnRect.x,SCREEN_HEIGHT-drawnRect.y,.1);
break;
}
}
if (event.type == SDL_MOUSEBUTTONDOWN)
{
SDL_GetMouseState(&mousex, &mousey);
drawnRect.x=mousex-KASTENGROSSE/2;
drawnRect.y=mousey-KASTENGROSSE/2;
}
}
if( timer.get() >= (1000/FRAMERATE) )
{
SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
SDL_RenderClear(gRenderer);
SDL_SetRenderDrawColor(gRenderer, 0x00, 0x00, 0x00, 0xFF);
drawBezierPath(gRenderer,Path);
for (int i=0;i<4;i++)
{
PRect = {static_cast<int>(std::round(Ps.at(i).X))-2,SCREEN_HEIGHT-static_cast<int>(std::round(Ps.at(i).Y))-2,4,4};
SDL_RenderFillRect(gRenderer, &PRect);
}
for (std::vector<vec2>::iterator it=PHull.begin();it<PHull.end();it++)
{
SDL_RenderDrawLine(gRenderer,it->X,SCREEN_HEIGHT-it->Y,(PHull.begin()+(it-PHull.begin()+1)%PHull.size())->X,SCREEN_HEIGHT-(PHull.begin()+(it-PHull.begin()+1)%PHull.size())->Y);
}
SDL_RenderDrawRect(gRenderer, &drawnRect);
SDL_RenderPresent(gRenderer);
timer.reset();
}
}
SDL_DestroyWindow(gWindow);
SDL_DestroyRenderer(gRenderer);
gWindow = NULL;
gRenderer = NULL;
return 0;
}