added face culling
This commit is contained in:
parent
38ac44b448
commit
f2c45b45cd
BIN
obj/display.o
BIN
obj/display.o
Binary file not shown.
BIN
obj/main.o
BIN
obj/main.o
Binary file not shown.
BIN
obj/move.o
BIN
obj/move.o
Binary file not shown.
|
@ -73,24 +73,25 @@ mat4 model, view, projection;
|
|||
mat4 scale;
|
||||
float vertices[108];
|
||||
|
||||
// -x ; +x ; -y ; +y ; -z ; +z //
|
||||
void init_vertices() {
|
||||
vertices[0] = -0.5f; vertices[1] = -0.5f; vertices[2] = -0.5f;
|
||||
vertices[3] = -0.5f; vertices[4] = 0.5f; vertices[5] = -0.5f;
|
||||
vertices[6] = -0.5f; vertices[7] = 0.5f; vertices[8] = 0.5f;
|
||||
vertices[9] = -0.5f; vertices[10] = -0.5f; vertices[11] = -0.5f;
|
||||
vertices[12] = -0.5f; vertices[13] = -0.5f; vertices[14] = 0.5f;
|
||||
vertices[15] = -0.5f; vertices[16] = 0.5f; vertices[17] = 0.5f;
|
||||
vertices[12] = -0.5f; vertices[13] = 0.5f; vertices[14] = 0.5f;
|
||||
vertices[15] = -0.5f; vertices[16] = -0.5f; vertices[17] = 0.5f;
|
||||
|
||||
vertices[18] = 0.5f; vertices[19] = -0.5f; vertices[20] = -0.5f;
|
||||
vertices[21] = 0.5f; vertices[22] = 0.5f; vertices[23] = -0.5f;
|
||||
vertices[24] = 0.5f; vertices[25] = 0.5f; vertices[26] = 0.5f;
|
||||
vertices[21] = 0.5f; vertices[22] = 0.5f; vertices[23] = 0.5f;
|
||||
vertices[24] = 0.5f; vertices[25] = 0.5f; vertices[26] = -0.5f;
|
||||
vertices[27] = 0.5f; vertices[28] = -0.5f; vertices[29] = -0.5f;
|
||||
vertices[30] = 0.5f; vertices[31] = -0.5f; vertices[32] = 0.5f;
|
||||
vertices[33] = 0.5f; vertices[34] = 0.5f; vertices[35] = 0.5f;
|
||||
|
||||
vertices[36] = -0.5f; vertices[37] = -0.5f; vertices[38] = -0.5f;
|
||||
vertices[39] = 0.5f; vertices[40] = -0.5f; vertices[41] = -0.5f;
|
||||
vertices[42] = 0.5f; vertices[43] = -0.5f; vertices[44] = 0.5f;
|
||||
vertices[39] = 0.5f; vertices[40] = -0.5f; vertices[41] = 0.5f;
|
||||
vertices[42] = 0.5f; vertices[43] = -0.5f; vertices[44] = -0.5f;
|
||||
vertices[45] = -0.5f; vertices[46] = -0.5f; vertices[47] = -0.5f;
|
||||
vertices[48] = -0.5f; vertices[49] = -0.5f; vertices[50] = 0.5f;
|
||||
vertices[51] = 0.5f; vertices[52] = -0.5f; vertices[53] = 0.5f;
|
||||
|
@ -99,19 +100,19 @@ void init_vertices() {
|
|||
vertices[57] = 0.5f; vertices[58] = 0.5f; vertices[59] = -0.5f;
|
||||
vertices[60] = 0.5f; vertices[61] = 0.5f; vertices[62] = 0.5f;
|
||||
vertices[63] = -0.5f; vertices[64] = 0.5f; vertices[65] = -0.5f;
|
||||
vertices[66] = -0.5f; vertices[67] = 0.5f; vertices[68] = 0.5f;
|
||||
vertices[69] = 0.5f; vertices[70] = 0.5f; vertices[71] = 0.5f;
|
||||
vertices[66] = 0.5f; vertices[67] = 0.5f; vertices[68] = 0.5f;
|
||||
vertices[69] = -0.5f; vertices[70] = 0.5f; vertices[71] = 0.5f;
|
||||
|
||||
vertices[72] = -0.5f; vertices[73] = -0.5f; vertices[74] = -0.5f;
|
||||
vertices[75] = 0.5f; vertices[76] = -0.5f; vertices[77] = -0.5f;
|
||||
vertices[78] = 0.5f; vertices[79] = 0.5f; vertices[80] = -0.5f;
|
||||
vertices[81] = -0.5f; vertices[82] = -0.5f; vertices[83] = -0.5f;
|
||||
vertices[84] = -0.5f; vertices[85] = 0.5f; vertices[86] = -0.5f;
|
||||
vertices[87] = 0.5f; vertices[88] = 0.5f; vertices[89] = -0.5f;
|
||||
vertices[84] = 0.5f; vertices[85] = 0.5f; vertices[86] = -0.5f;
|
||||
vertices[87] = -0.5f; vertices[88] = 0.5f; vertices[89] = -0.5f;
|
||||
|
||||
vertices[90] = -0.5f; vertices[91] = -0.5f; vertices[92] = 0.5f;
|
||||
vertices[93] = 0.5f; vertices[94] = -0.5f; vertices[95] = 0.5f;
|
||||
vertices[96] = 0.5f; vertices[97] = 0.5f; vertices[98] = 0.5f;
|
||||
vertices[93] = 0.5f; vertices[94] = 0.5f; vertices[95] = 0.5f;
|
||||
vertices[96] = 0.5f; vertices[97] = -0.5f; vertices[98] = 0.5f;
|
||||
vertices[99] = -0.5f; vertices[100] = -0.5f; vertices[101] = 0.5f;
|
||||
vertices[102] = -0.5f; vertices[103] = 0.5f; vertices[104] = 0.5f;
|
||||
vertices[105] = 0.5f; vertices[106] = 0.5f; vertices[107] = 0.5f;
|
||||
|
@ -138,14 +139,24 @@ void gl_renderCube(unsigned int shaderProgram, unsigned int fragmentShader, unsi
|
|||
}
|
||||
|
||||
void gl_renderAll(unsigned int shaderProgram, unsigned int fragmentShader, unsigned int VAO, unsigned int VBO, room* rtd, double offx, double offy, double offz) {
|
||||
for(int k = 0; k < rtd->map_size; k++) {
|
||||
gl_renderCube(shaderProgram, fragmentShader, VAO, VBO, rtd->map[k], offx, offy, offz);
|
||||
if(rtd != NULL) {
|
||||
for(int k = 0; k < rtd->map_size; k++) {
|
||||
gl_renderCube(shaderProgram, fragmentShader, VAO, VBO, rtd->map[k], offx, offy, offz);
|
||||
}
|
||||
for(int k = 0; k < rtd->tps_size; k++) {
|
||||
gl_renderCube(shaderProgram, fragmentShader, VAO, VBO, rtd->tps[k]->hitbox, offx, offy, offz);
|
||||
}
|
||||
for(int k = 0; k < rtd->ent_len; k++) {
|
||||
gl_renderCube(shaderProgram, fragmentShader, VAO, VBO, rtd->ents[k].pos, offx, offy, offz);
|
||||
}
|
||||
}
|
||||
for(int k = 0; k < rtd->tps_size; k++) {
|
||||
gl_renderCube(shaderProgram, fragmentShader, VAO, VBO, rtd->tps[k]->hitbox, offx, offy, offz);
|
||||
}
|
||||
for(int k = 0; k < rtd->ent_len; k++) {
|
||||
gl_renderCube(shaderProgram, fragmentShader, VAO, VBO, rtd->ents[k].pos, offx, offy, offz);
|
||||
}
|
||||
|
||||
void gl_renderNearbyChunks(unsigned int shaderProgram, unsigned int fragmentShader, unsigned int VAO, unsigned int VBO, int render_distance) {
|
||||
for(int w = -render_distance; w <= render_distance; w++) {
|
||||
for(int h = -render_distance; h <= render_distance; h++) {
|
||||
gl_renderAll(shaderProgram, fragmentShader, VAO, VBO, hashtbl_find_opt(visited, player_chx+w, player_chy+h), (2.0*room_width)*w, 0.0, (2.0*room_depth)*h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
void gl_renderCube(unsigned int shaderProgram, unsigned int fragmentShader, unsigned int VAO, unsigned int VBO, cube_0* c, double offx, double offy, double offz);
|
||||
void gl_renderAll(unsigned int shaderProgram, unsigned int fragmentShader, unsigned int VAO, unsigned int VBO, room* rtd, double offx, double offy, double offz);
|
||||
void gl_renderNearbyChunks(unsigned int shaderProgram, unsigned int fragmentShader, unsigned int VAO, unsigned int VBO, int render_distance);
|
||||
|
||||
void gl_initRender(unsigned int shaderProgram, unsigned int fragmentShader, unsigned int VAO, unsigned int VBO);
|
||||
void init_vertices();
|
||||
|
|
12
src/main.c
12
src/main.c
|
@ -140,6 +140,8 @@ int main_alt() {
|
|||
}
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_FRONT);
|
||||
glDepthFunc(GL_LESS);
|
||||
|
||||
//printf("%f\n", glDepthRange);
|
||||
|
@ -227,19 +229,19 @@ int main_alt() {
|
|||
glBindVertexArray(VAO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
gl_initRender(shaderProgram, shaderProgram, VAO, VBO);
|
||||
gl_renderAll(shaderProgram, shaderProgram, VAO, VBO, current_room, 0.0, 0.0, 0.0);
|
||||
//gl_renderAll(shaderProgram, shaderProgram, VAO, VBO, current_room, 0.0, 0.0, 0.0);
|
||||
gl_renderNearbyChunks(shaderProgram, shaderProgram, VAO, VBO, 1);
|
||||
gl_renderProj(shaderProgram, shaderProgram, VAO, VBO);
|
||||
|
||||
//printf("01\n");
|
||||
//fflush(stdout);
|
||||
|
||||
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
|
||||
// -------------------------------------------------------------------------------
|
||||
finish = clock();
|
||||
processInput(window, ((float)finish - (float)origin)/CLOCKS_PER_SEC);
|
||||
teleport_on_edge();
|
||||
update_entities(((float)finish - (float)origin)/CLOCKS_PER_SEC);
|
||||
updateProj(((float)finish - (float)origin)/CLOCKS_PER_SEC);
|
||||
printf("%f\n", 1.0f/(((float)origin - (float)finish)/CLOCKS_PER_SEC));
|
||||
printf("%f\n", 1.0f/(((float)finish - (float)origin)/CLOCKS_PER_SEC));
|
||||
//printf("%lf, %lf, %lf\n", camx, camy, camz);
|
||||
|
||||
usleep(interval);
|
||||
|
||||
|
|
101
src/move.c
101
src/move.c
|
@ -17,41 +17,46 @@
|
|||
#include "move.h"
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------- //
|
||||
double sensitivity = 0.06 ;
|
||||
double fov = 90.0 ;
|
||||
double speed = 0.22 ;
|
||||
double min_dist = 0.7 ;
|
||||
double sensitivity = 0.06;
|
||||
double fov = 90.0;
|
||||
double speed = 0.22;
|
||||
double min_dist = 0.7;
|
||||
// ---------------------------------------------------------------------------------------------------- //
|
||||
|
||||
int player_hp ;
|
||||
int player_hp;
|
||||
|
||||
bool stop_evetything;
|
||||
|
||||
double camx ;
|
||||
double camy ;
|
||||
double camz ;
|
||||
double camx;
|
||||
double camy;
|
||||
double camz;
|
||||
|
||||
double rot_hz ;
|
||||
double rot_vt ;
|
||||
double rot_hz;
|
||||
double rot_vt;
|
||||
|
||||
double tan_fov ;
|
||||
double tan_fov;
|
||||
|
||||
int draw_type ;
|
||||
int fade_dmg ;
|
||||
int draw_type;
|
||||
int fade_dmg;
|
||||
|
||||
bool has_changed ;
|
||||
bool has_changed;
|
||||
|
||||
double room_width;
|
||||
double room_depth;
|
||||
|
||||
void init_csts() {
|
||||
camx = 2.0 ;
|
||||
camy = 5.0 ;
|
||||
camz = 2.0 ;
|
||||
rot_hz = 0.0 ;
|
||||
rot_vt = 0.0 ;
|
||||
draw_type = 0 ;
|
||||
player_hp = 1000 ;
|
||||
camx = 2.0;
|
||||
camy = 5.0;
|
||||
camz = 2.0;
|
||||
rot_hz = 0.0;
|
||||
rot_vt = 0.0;
|
||||
draw_type = 0;
|
||||
player_hp = 1000;
|
||||
fade_dmg = 0;
|
||||
stop_evetything = false ;
|
||||
tan_fov = tan((fov * 3.14159 / 180.0) / 2.0) ;
|
||||
room_width = 16.0;
|
||||
room_depth = 16.0;
|
||||
stop_evetything = false;
|
||||
tan_fov = tan((fov * 3.14159 / 180.0) / 2.0);
|
||||
}
|
||||
|
||||
void set_player_coords(int old_chx, int old_chy) {
|
||||
|
@ -62,33 +67,33 @@ void set_player_coords(int old_chx, int old_chy) {
|
|||
camy = current_room->tps[k]->hitbox->y + current_room->tps[k]->hitbox->h +1.5;
|
||||
camz = current_room->tps[k]->hitbox->z + current_room->tps[k]->hitbox->d/2.0;
|
||||
}
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool is_colliding(float dtime) {
|
||||
for(int k = 0; k < current_room->map_size; k++) {
|
||||
double dist = distance_pt_cube_0_3d(camx, camy, camz, current_room->map[k]) ;
|
||||
double dist = distance_pt_cube_0_3d(camx, camy, camz, current_room->map[k]);
|
||||
if(dist <= min_dist) {
|
||||
return true ;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for(int k = 0; k < current_room->tps_size; k++) {
|
||||
double dist = distance_pt_cube_0_3d(camx, camy, camz, current_room->tps[k]->hitbox) ;
|
||||
double dist = distance_pt_cube_0_3d(camx, camy, camz, current_room->tps[k]->hitbox);
|
||||
if(dist <= min_dist) {
|
||||
int old_chx = player_chx ;
|
||||
int old_chy = player_chy ;
|
||||
player_chx = current_room->tps[k]->dest_chx ;
|
||||
player_chy = current_room->tps[k]->dest_chy ;
|
||||
int old_chx = player_chx;
|
||||
int old_chy = player_chy;
|
||||
player_chx = current_room->tps[k]->dest_chx;
|
||||
player_chy = current_room->tps[k]->dest_chy;
|
||||
current_room = hashtbl_find_opt(visited, player_chx, player_chy);
|
||||
set_player_coords(old_chx, old_chy);
|
||||
//resetProj();
|
||||
return true ;
|
||||
resetProj();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for(int k = 0; k < current_room->ent_len; k++) {
|
||||
double dist = distance_pt_cube_0_3d(camx, camy, camz, current_room->ents[k].pos) ;
|
||||
double dist = distance_pt_cube_0_3d(camx, camy, camz, current_room->ents[k].pos);
|
||||
if(dist <= min_dist) {
|
||||
if(current_room->ents[k].onHit != NULL) {
|
||||
(*current_room->ents[k].onHit)(dtime, current_room->ents[k].hitpoints, ¤t_room->ents[k].damage, &(*(current_room->ents[k].pos)));
|
||||
|
@ -99,8 +104,32 @@ bool is_colliding(float dtime) {
|
|||
remove_entity(¤t_room->ents, ¤t_room->ent_memlen, ¤t_room->ent_len, k);
|
||||
}
|
||||
}
|
||||
return true ;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false ;
|
||||
return false;
|
||||
}
|
||||
|
||||
void teleport_on_edge() {
|
||||
if(camx >= room_width) {
|
||||
camx -= 2.0*room_width;
|
||||
player_chx += 1;
|
||||
current_room = hashtbl_find_opt(visited, player_chx, player_chy);
|
||||
resetProj();
|
||||
} else if(camx <= -room_width) {
|
||||
camx += 2.0*room_width;
|
||||
player_chx -= 1;
|
||||
current_room = hashtbl_find_opt(visited, player_chx, player_chy);
|
||||
resetProj();
|
||||
} else if(camz >= room_depth) {
|
||||
camz -= 2.0*room_depth;
|
||||
player_chy += 1;
|
||||
current_room = hashtbl_find_opt(visited, player_chx, player_chy);
|
||||
resetProj();
|
||||
} else if(camz <= -room_depth) {
|
||||
camz += 2.0*room_depth;
|
||||
player_chy -= 1;
|
||||
current_room = hashtbl_find_opt(visited, player_chx, player_chy);
|
||||
resetProj();
|
||||
}
|
||||
}
|
|
@ -4,4 +4,6 @@
|
|||
void init_csts();
|
||||
bool is_colliding(float dtime);
|
||||
|
||||
void teleport_on_edge();
|
||||
|
||||
#endif
|
|
@ -110,8 +110,9 @@ extern int player_hp ;
|
|||
extern int fade_dmg ;
|
||||
|
||||
extern bool stop_evetything ;
|
||||
|
||||
extern double shrink_distance ;
|
||||
extern double room_width ;
|
||||
// no height yet (requires a rewrite oh hashtbl)
|
||||
extern double room_depth ;
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------- //
|
||||
extern double sensitivity ;
|
||||
|
|
Loading…
Reference in New Issue