diff --git a/bin/back b/bin/back index 40e3e5d..f8ccef3 100755 Binary files a/bin/back and b/bin/back differ diff --git a/obj/base.o b/obj/base.o index 63f4f2c..aa54ece 100644 Binary files a/obj/base.o and b/obj/base.o differ diff --git a/obj/display.o b/obj/display.o index 354547f..dada8b2 100644 Binary files a/obj/display.o and b/obj/display.o differ diff --git a/obj/entities.o b/obj/entities.o index ab81caf..e4805c1 100644 Binary files a/obj/entities.o and b/obj/entities.o differ diff --git a/obj/generation.o b/obj/generation.o index 46427ac..ba5f4b8 100644 Binary files a/obj/generation.o and b/obj/generation.o differ diff --git a/obj/hash.o b/obj/hash.o index ca7f440..3db13e6 100644 Binary files a/obj/hash.o and b/obj/hash.o differ diff --git a/obj/main.o b/obj/main.o index 840cc12..a4d5c43 100644 Binary files a/obj/main.o and b/obj/main.o differ diff --git a/obj/menus.o b/obj/menus.o index 23f4f2b..dfd5e99 100644 Binary files a/obj/menus.o and b/obj/menus.o differ diff --git a/obj/move.o b/obj/move.o index d1f3fa7..4ee80bd 100644 Binary files a/obj/move.o and b/obj/move.o differ diff --git a/obj/proj.o b/obj/proj.o index 1b7bccf..5f63328 100644 Binary files a/obj/proj.o and b/obj/proj.o differ diff --git a/src/entities.c b/src/entities.c index d656566..dd1bc75 100644 --- a/src/entities.c +++ b/src/entities.c @@ -90,7 +90,7 @@ void moving_xyz(double x, double y, double z, double w, double h, double d, doub //printf("%lf %lf %lf\n", ret->x, ret->y, ret->z); } -void detectHit(float dtime, int* hp, int* dmg, cube_0* ret) { +void detectHit(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) { if(ret->red == 193) { ret->red = 0; ret->green = 192; @@ -104,6 +104,34 @@ void detectHit(float dtime, int* hp, int* dmg, cube_0* ret) { } } +void translatePlayer(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) { + double vx = ent->metad4*(cos((double)(ent->metai1*(sim_time+(double)dtime)/ent->metai2 + ent->metai3*3.14159/180.0))-cos((double)(ent->metai1*sim_time/ent->metai2 + ent->metai3*3.14159/180.0))); + double vy = ent->metad5*(cos((double)(ent->metai1*(sim_time+(double)dtime)/ent->metai2 + ent->metai3*3.14159/180.0))-cos((double)(ent->metai1*sim_time/ent->metai2 + ent->metai3*3.14159/180.0))); + double vz = ent->metad6*(cos((double)(ent->metai1*(sim_time+(double)dtime)/ent->metai2 + ent->metai3*3.14159/180.0))-cos((double)(ent->metai1*sim_time/ent->metai2 + ent->metai3*3.14159/180.0))); + //printf("(%lf %lf) (%lf %lf) (%lf %lf)\n", vx, camvx, vy, camvy, vz, camvz); + if(true) { + double oldvx = camvx; + camvx += vx/dtime; + camx -= oldvx*dtime; + camx += camvx*dtime; + noResetSpeed = true; + } + if(true) { + double oldvy = camvy; + camvy += vy/dtime; + camy -= oldvy*dtime; + camy += camvy*dtime; + noResetSpeed = true; + } + if(true) { + double oldvz = camvz; + camvz += vz/dtime; + camz -= oldvz*dtime; + camz += camvz*dtime; + noResetSpeed = true; + } +} + void go_to_player(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, entity* ent, cube_0* ret) { double dx = (x+w/2 - camx); double dy = (y+h/2 - camy); @@ -129,7 +157,7 @@ void go_to_player(double x, double y, double z, double w, double h, double d, do } } -void explodeOnHit(float dtime, int* hp, int* dmg, cube_0* ret) { +void explodeOnHit(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) { player_hp -= (*dmg); if(*dmg != 0) { fade_dmg = 255; diff --git a/src/entities.h b/src/entities.h index ff8a845..e42f81d 100644 --- a/src/entities.h +++ b/src/entities.h @@ -13,7 +13,8 @@ void speen3(double x, double y, double z, double w, double h, double d, double h void moving_xyz(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, entity* ent, cube_0* ret); void go_to_player(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, entity* ent, cube_0* ret); -void detectHit(float dtime, int* hp, int* dmg, cube_0* ret); -void explodeOnHit(float dtime, int* hp, int* dmg, cube_0* ret); +void detectHit(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret); +void explodeOnHit(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret); +void translatePlayer(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret); #endif \ No newline at end of file diff --git a/src/generation.c b/src/generation.c index 1067c2d..f194f45 100644 --- a/src/generation.c +++ b/src/generation.c @@ -63,7 +63,7 @@ void init_ent_generator(int n) { hashtbl_entities[4].id = 4; hashtbl_entities[4].name = "Platform"; hashtbl_entities[4].updatePos = &moving_xyz; - hashtbl_entities[4].onHit = NULL; + hashtbl_entities[4].onHit = &translatePlayer; hashtbl_entities[4].onDeath = NULL; } diff --git a/src/generation.h b/src/generation.h index 63e8605..8baada6 100644 --- a/src/generation.h +++ b/src/generation.h @@ -11,7 +11,7 @@ typedef struct fct_entry { char* name ; void (*updatePos)(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, entity* ent, cube_0* ret) ; // act as velocity function - void (*onHit)(float dtime, int* hp, int* dmg, cube_0* ret) ; + void (*onHit)(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) ; // triggers when object is hit void (*onDeath)(float dtime) ; diff --git a/src/main.c b/src/main.c index 912929b..4456c34 100644 --- a/src/main.c +++ b/src/main.c @@ -20,7 +20,7 @@ #include "display.h" #include "generation.h" -double sim_time ; +double sim_time; int triCount; void processInput(GLFWwindow *window, float dtime) { @@ -43,7 +43,7 @@ void processInput(GLFWwindow *window, float dtime) { */ camvz = -speed*cos(rot_hz)*cos(rot_vt); camvx = -speed*sin(rot_hz)*cos(rot_vt); - camvy = speed*sin(rot_vt); + camvy = vtmult*speed*sin(rot_vt); } if(glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) { /* @@ -73,7 +73,7 @@ void processInput(GLFWwindow *window, float dtime) { }*/ camvz = speed*cos(rot_hz)*cos(rot_vt); camvx = speed*sin(rot_hz)*cos(rot_vt); - camvy = -speed*sin(rot_vt); + camvy = -vtmult*speed*sin(rot_vt); } if(glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) { /*for(int k = 0; k < 10; k++) { @@ -301,10 +301,12 @@ int main_alt() { // ---------------------------------------------------------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------------------------------------------------------- // - int fps = 60 ; - int interval = 1000000/fps ; + int fps = 60; + int interval = 1000000/fps; + double slp_time = 1.0/fps; - float delta; + float delta = 0.0f; + double deltad = 0.0; clock_t finish = clock(); clock_t origin = clock(); @@ -315,7 +317,6 @@ int main_alt() { glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); triCount = 0; - origin = clock(); fflush(stdout); generate_nearby_chunks(1); @@ -333,34 +334,30 @@ int main_alt() { glUseProgram(shaderProgramR); glBindVertexArray(RVAO); - finish = clock(); - delta = ((float)finish - (float)origin)/CLOCKS_PER_SEC; gl_drawInteger(shaderProgramR, (int)(1.0f/(delta)), 0.0f, -0.92f, 0.05, 32, 255, 32, 0.005, -1); gl_drawInteger(shaderProgramR, triCount, 0.0f, 0.92f, 0.04f, 128, 128, 128, 0.005f, 1); gl_drawData(shaderProgramR); // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.) // ------------------------------------------------------------------------------- - finish = clock(); - delta = ((float)finish - (float)origin)/CLOCKS_PER_SEC; processInput(window, delta); - movePlayerG(delta); + movePlayerG(deltad); teleport_on_edge(); update_entities(delta); updateProj(delta); - //printf("%f\n", 1.0f/(delta)); - //printf("%lf, %lf, %lf\n", camx, camy, camz); usleep(max(0, interval-(int)(1000000*delta))); - finish = clock(); - sim_time += ((double)finish - (double)origin)/CLOCKS_PER_SEC; + sim_time += deltad; glfwSwapBuffers(window); glfwPollEvents(); + + finish = clock(); + delta = slp_time+((float)finish - (float)origin)/CLOCKS_PER_SEC; + deltad = slp_time+((double)finish - (double)origin)/CLOCKS_PER_SEC; + origin = clock(); } - //printf("10\n"); - //fflush(stdout); hashtbl_free(visited); free_proj(); free_pool(); diff --git a/src/move.c b/src/move.c index c393bc7..9acdc60 100644 --- a/src/move.c +++ b/src/move.c @@ -18,9 +18,13 @@ // ---------------------------------------------------------------------------------------------------- // double sensitivity = 0.06; double fov = 90.0; -//double speed = 0.22; -double speed = 1000.0; +double creative_speed = 0.3; +double speed = 8.0; +double vtmult = 1.5; double min_dist = 0.7; +double friction = 0.8; +double gravity_factor = 9.8; +bool noResetSpeed = false; // ---------------------------------------------------------------------------------------------------- // int player_hp; @@ -34,11 +38,6 @@ double camz; double camvx; double camvy; double camvz; - -double gravity_factor; - -double friction; - double rot_hz; double rot_vt; @@ -59,8 +58,6 @@ void init_csts() { camvx = 0.0; camvy = 0.0; camvz = 0.0; - friction = 0.0005; - gravity_factor = 20000.0; rot_hz = 0.0; rot_vt = 0.0; draw_type = 0; @@ -109,7 +106,7 @@ bool is_colliding(float dtime) { 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))); + (*current_room->ents[k]->onHit)(dtime, current_room->ents[k]->hitpoints, ¤t_room->ents[k]->damage, current_room->ents[k], &(*(current_room->ents[k]->pos))); if(*(current_room->ents[k]->hitpoints) <= 0) { if(current_room->ents[k]->onDeath != NULL) { (*current_room->ents[k]->onDeath)(dtime); @@ -123,28 +120,37 @@ bool is_colliding(float dtime) { return false; } -void movePlayerG(float dtime) { +void movePlayerG(double dtime) { camx += camvx*dtime; + noResetSpeed = false; if(is_colliding(dtime)) { camx -= camvx*dtime; - camvx = 0.0; + if(!noResetSpeed) { + camvx = 0.0; + } } - camvx *= pow(friction, (double)dtime*10); + camvx = camvx*(1-dtime*friction); camvy -= gravity_factor*dtime; camy += camvy*dtime; + noResetSpeed = false; if(is_colliding(dtime)) { camy -= camvy*dtime; - camvy = 0.0; + if(!noResetSpeed) { + camvy = 0.0; + } } - camvy *= pow(friction, (double)dtime*10); + camvy = camvy*(1-dtime*friction); camz += camvz*dtime; + noResetSpeed = false; if(is_colliding(dtime)) { camz -= camvz*dtime; - camvz = 0.0; + if(!noResetSpeed) { + camvz = 0.0; + } } - camvz *= pow(friction, (double)dtime*10); + camvz = camvz*(1-dtime*friction); } void teleport_on_edge() { diff --git a/src/move.h b/src/move.h index 82a5399..9c3dac1 100644 --- a/src/move.h +++ b/src/move.h @@ -5,6 +5,6 @@ void init_csts(); bool is_colliding(float dtime); void teleport_on_edge(); -void movePlayerG(float dtime); +void movePlayerG(double dtime); #endif \ No newline at end of file diff --git a/src/structure.h b/src/structure.h index 3c283aa..873389f 100644 --- a/src/structure.h +++ b/src/structure.h @@ -36,7 +36,7 @@ typedef struct entity { void (*updatePos)(double x, double y, double z, double w, double h, double d, double hz_angle, double vt_angle, float dtime, struct entity* ent, cube_0* ret); // triggers when object is hit - void (*onHit)(float dtime, int* hp, int* dmg, cube_0* ret); + void (*onHit)(float dtime, int* hp, int* dmg, struct entity* ent, cube_0* ret); // triggers when goes negative (death) void (*onDeath)(float dtime); @@ -104,7 +104,7 @@ extern double camvy; extern double camvz; extern double friction; - +extern double vtmult; extern double gravity_factor; extern double rot_hz; @@ -145,6 +145,8 @@ extern double min_dist; extern float vertices[108]; extern float rectDefault[18]; -extern int triCount ; +extern int triCount; + +extern bool noResetSpeed; #endif \ No newline at end of file diff --git a/templates/room_0 b/templates/room_0 index 6f72078..4117651 100644 --- a/templates/room_0 +++ b/templates/room_0 @@ -13,7 +13,7 @@ Teleporters : [9.0, 1.0, 4.0, 1.0, 4.0, 2.0, 0.0, 0.0, 0, 0, 255; 1, 0] Entities: -[0.0, 14.0, 0.0, 2.0, 1.0, 2.0, 0.0, 0.0, 193, 192, 0, 1, 0, 4, 0.0, 5.0, 0.0, 80, 1, 45] +[0.0, 14.0, 0.0, 2.0, 1.0, 2.0, 0.0, 0.0, 193, 192, 0, 1, 0, 4, 0.0, 5.0, 0.0, 4, 1, 45] Weight : 50 diff --git a/templates/room_5 b/templates/room_5 index 4f47fe1..bf3f484 100644 --- a/templates/room_5 +++ b/templates/room_5 @@ -8,9 +8,9 @@ Teleporters : [-5.0, 1.0, 9.0, 10.0, 2.0, 1.0, 0.0, 0.0, 0, 0, 255; 1, 0] Entities: -[-15.0, 4.0, -15.0, 4.0, 1.0, 4.0, 0.0, 0.0, 192, 128, 192, 10, 0, 4, 0.0, 5.0, 0.0, 50, 1, 90] -[-5.0, 9.0, -15.0, 4.0, 1.0, 4.0, 0.0, 0.0, 192, 128, 192, 10, 0, 4, 5.0, 0.0, 0.0, 50, 1, 0] -[0.0, 10.0, -5.0, 4.0, 1.0, 4.0, 0.0, 0.0, 192, 128, 192, 10, 0, 4, 0.0, 0.0, 5.0, 50, 1, 270] +[-15.0, 4.0, -15.0, 4.0, 1.0, 4.0, 0.0, 0.0, 192, 128, 192, 10, 0, 4, 0.0, 5.0, 0.0, 2, 1, 90] +[-5.0, 9.0, -15.0, 4.0, 1.0, 4.0, 0.0, 0.0, 192, 128, 192, 10, 0, 4, 5.0, 0.0, 0.0, 2, 1, 0] +[0.0, 10.0, -5.0, 4.0, 1.0, 4.0, 0.0, 0.0, 192, 128, 192, 10, 0, 4, 0.0, 0.0, 5.0, 2, 1, 270] Weight : 50