-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this prototype works with xbox controller, typing in the terminal window is working but nothing more, no backspace yet.
- Loading branch information
Showing
13 changed files
with
982 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "2d-engine.h" | ||
|
||
/* detect if a point is in a convex polygon: | ||
* 1 = true // 0 = false | ||
* IMPORTANT: if the point is on an edge, | ||
* return true*/ | ||
int pointInConvexPoly (struct vec2 point, struct poly *poly){ | ||
/* method: calculate determinant for each edge | ||
* to know if the point is on the left or right side. | ||
* if the point is on the same side of all edges then | ||
* it is in the poly */ | ||
|
||
long det; | ||
/* edge [AB] */ | ||
struct vec2 vertex_A; | ||
struct vec2 vertex_B; | ||
char sign; | ||
|
||
/* last edge (last vertex to first vertex) */ | ||
vertex_A = poly->vertex_array[poly->vertex_len -1]; | ||
vertex_B = poly->vertex_array[0]; | ||
|
||
det = (point.y - vertex_A.y)*(vertex_B.x - vertex_A.x) | ||
- (point.x - vertex_A.x)*(vertex_B.y - vertex_A.y); | ||
|
||
if( det == 0 ) | ||
/* if the first det is null, we | ||
* must look for the sign of the second det */ | ||
sign = 0; | ||
else | ||
/* all det must have the same sign than the first det */ | ||
sign = (det > 0) * 2 -1; | ||
|
||
for (int i = 1; i < poly->vertex_len; i++) { | ||
vertex_A = poly->vertex_array[i-1]; | ||
vertex_B = poly->vertex_array[i]; | ||
|
||
det = (point.y - vertex_A.y)*(vertex_B.x - vertex_A.x) | ||
- (point.x - vertex_A.x)*(vertex_B.y - vertex_A.y); | ||
|
||
if (sign == 0) | ||
/* if the first det was zero | ||
* get the sign of all det */ | ||
sign = (det > 0) * 2 -1; | ||
else | ||
/* if different sign */ | ||
if ((det * sign) < 0) | ||
return 0; | ||
} | ||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef TWODENGINE_H | ||
#define TWODENGINE_H | ||
|
||
struct vec2 { | ||
char x; | ||
char y; | ||
}; | ||
|
||
struct poly { | ||
char vertex_len; | ||
struct vec2 *vertex_array; | ||
}; | ||
|
||
int pointInConvexPoly (struct vec2 point, struct poly *poly); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
######################### | ||
# customise these | ||
CFILES := main.c input.c config.c graphics.c 2d-engine.c free-selection-keyboard.c | ||
PROG := prog | ||
CFLAGS := -Wall -Wextra -g | ||
LDFLAGS := -lSDL2 | ||
######################## | ||
|
||
# -MMD generates dependencies while compiling | ||
CFLAGS += -MMD | ||
CC := gcc | ||
|
||
OBJFILES := $(CFILES:.c=.o) | ||
DEPFILES := $(CFILES:.c=.d) | ||
|
||
$(PROG) : $(OBJFILES) | ||
$(LINK.o) $(LDFLAGS) -o $@ $^ | ||
|
||
clean : | ||
rm -f $(PROG) $(OBJFILES) $(DEPFILES) | ||
|
||
-include $(DEPFILES) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef CONFIG_H | ||
#define CONFIG_H | ||
|
||
#include <stdbool.h> | ||
|
||
#include "input.h" | ||
|
||
struct mapping { | ||
struct btn btn_east; | ||
struct btn btn_west; | ||
struct btn btn_north; | ||
struct btn btn_left; | ||
|
||
struct btn left_bumper; | ||
struct btn right_bumper; | ||
|
||
struct joy joy_L; | ||
struct joy joy_R; | ||
|
||
bool rumble; | ||
}; | ||
|
||
#endif |
Oops, something went wrong.