diff --git a/bin/back b/bin/back index b3e00bb..1326990 100755 Binary files a/bin/back and b/bin/back differ diff --git a/levels/level_02/room_0 b/levels/level_02/room_0 index fd2048d..eb1406b 100644 --- a/levels/level_02/room_0 +++ b/levels/level_02/room_0 @@ -1,5 +1,10 @@ Blocks : -[-16.0, -1.0, -16.0, 32.0, 1.0, 32.0, 0.0, 0.0, 128, 128, 128] +[-16.0, -1.0, -16.0,32.0, 1.0, 32.0, 0.0, 0.0, 128, 128, 128] + +[ -4.0,-10.0, -4.0, 8.0, 2.0, 8.0, 0.0, 0.0, 128, 128, 128] +[ -4.0, -6.5, -2.0, 2.0, 1.0, 2.0, 0.0, 0.3, 128, 128, 128] +[ -4.0, -6.5, 2.0, 2.0, 1.0, 2.0, 0.3, 0.0, 128, 128, 128] + [ -6.0, 10.0, 0.0, 6.0, 2.0, 2.0, 0.0, 0.0, 32, 192, 32] // cp1 [-25.0, 21.0, 18.0, 2.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192] diff --git a/obj/base.o b/obj/base.o index 88d4efb..d0e0339 100644 Binary files a/obj/base.o and b/obj/base.o differ diff --git a/obj/display.o b/obj/display.o index c8839b3..cbd8b94 100644 Binary files a/obj/display.o and b/obj/display.o differ diff --git a/obj/entities.o b/obj/entities.o index 2f8e535..6eb3673 100644 Binary files a/obj/entities.o and b/obj/entities.o differ diff --git a/obj/main.o b/obj/main.o index 0a14127..3982c64 100644 Binary files a/obj/main.o and b/obj/main.o differ diff --git a/obj/move.o b/obj/move.o index 32d526c..d11d61a 100644 Binary files a/obj/move.o and b/obj/move.o differ diff --git a/src/base.c b/src/base.c index b691f2b..af31994 100644 --- a/src/base.c +++ b/src/base.c @@ -398,8 +398,8 @@ void project_to_cube(double x0, double y0, double z0, double* rx, double* ry, do // rotate (x) if(rx != NULL) {*rx = c->x + c->w/2.0 + xry;} - if(ry != NULL) {*ry = c->y + c->h/2.0 + yry*cos(c->vt_angle) - zry*sin(c->vt_angle);} - if(rz != NULL) {*rz = c->z + c->d/2.0 + zry*cos(c->vt_angle) + yry*sin(c->vt_angle);} + if(ry != NULL) {*ry = c->y + c->h/2.0 + yry*cos(c->vt_angle) + zry*sin(c->vt_angle);} + if(rz != NULL) {*rz = c->z + c->d/2.0 + zry*cos(c->vt_angle) - yry*sin(c->vt_angle);} } // ------------------------------------------------------------------------------------------------ // diff --git a/src/display.c b/src/display.c index fe75ae2..74b540e 100644 --- a/src/display.c +++ b/src/display.c @@ -136,8 +136,8 @@ void gl_renderCube(cube_0* c, double offx, double offy, double offz) { scale[1][1] = (float)(c->h); scale[2][2] = (float)(c->d); glm_translate(model, (vec3){(float)(c->x+c->w/2.0+offx), (float)(c->y+c->h/2.0+offy), (float)(c->z+c->d/2.0+offz)}); - glm_rotate(model, (float)(c->vt_angle), (vec3){1.0f, 0.0f, 0.0f}); - glm_rotate(model, (float)(c->hz_angle), (vec3){0.0f, 1.0f, 0.0f}); + glm_rotate(model, (float)(-c->vt_angle), (vec3){1.0f, 0.0f, 0.0f}); + glm_rotate(model, (float)(-c->hz_angle), (vec3){0.0f, 1.0f, 0.0f}); glm_mat2_identity(texShift); texShift[0][0] = (float)(maxd(maxd(c->w, c->h), c->d)/mind(mind(c->w, c->h), c->d)); @@ -194,6 +194,7 @@ void gl_renderAll(room* rtd, double offx, double offy, double offz) { for(int k = 0; k < rtd->map_size; k++) { if(is_visible(rtd->map[k], offx, offy, offz)) { gl_renderCube(rtd->map[k], offx, offy, offz); + //debugMove(rtd->map[k]); } } glBindTexture(GL_TEXTURE_2D, textures[6]); @@ -210,6 +211,7 @@ void gl_renderAll(room* rtd, double offx, double offy, double offz) { glBindTexture(GL_TEXTURE_2D, textures[rtd->ents[k]->tex2]); } gl_renderCube(rtd->ents[k]->pos, offx, offy, offz); + //debugMove(rtd->ents[k]->pos); } } } diff --git a/src/main.c b/src/main.c index 6ca5e7b..1e98fdc 100644 --- a/src/main.c +++ b/src/main.c @@ -690,10 +690,6 @@ int main_alt() { usleep(max(0, interval-(int)(1000000*calc_T))); sim_time += interval_s + maxd(0.0, (double)(interval_s-(calc_T))); - // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.) - glfwSwapBuffers(window); - glfwPollEvents(); - dmgCD = maxf(dmgCD - delta, 0.0f); if(lastDmg != player_hp) { lastDmg = player_hp; @@ -706,6 +702,10 @@ int main_alt() { } incr = 0.0f; + // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.) + glfwSwapBuffers(window); + glfwPollEvents(); + count++; } diff --git a/src/move.c b/src/move.c index 2b31ec4..fff1f9a 100644 --- a/src/move.c +++ b/src/move.c @@ -7,12 +7,16 @@ #include #include #include +#include +#include +#include #include "hash.h" #include "base.h" #include "entities.h" #include "proj.h" #include "move.h" +#include "display.h" #include "music.h" // ---------------------------------------------------------------------------------------------------- // @@ -148,25 +152,31 @@ double p1, p2, p3; void getSF(cube_0* cb, int sf) { if(sf == 0 || sf == 1) { project_to_cube(cb->x + (sf==0)*(cb->w), cb->y , cb->z , &p1, &p2, &p3, cb); - surface[0] = (pt_2d){.x = p1, .y = p2, .z = p3}; + surface[0] = (pt_2d){.x = p1, .y = p2, .z = p3}; + project_to_cube(cb->x + (sf==0)*(cb->w), cb->y + cb->h, cb->z , &p1, &p2, &p3, cb); - surface[1] = (pt_2d){.x = p1, .y = p2, .z = p3}; + surface[1] = (pt_2d){.x = p1, .y = p2, .z = p3}; + project_to_cube(cb->x + (sf==0)*(cb->w), cb->y , cb->z + cb->d, &p1, &p2, &p3, cb); - surface[2] = (pt_2d){.x = p1, .y = p2, .z = p3}; + surface[2] = (pt_2d){.x = p1, .y = p2, .z = p3}; } else if(sf == 2 || sf == 3) { project_to_cube(cb->x , cb->y + (sf==2)*(cb->h), cb->z , &p1, &p2, &p3, cb); - surface[0] = (pt_2d){.x = p1, .y = p2, .z = p3}; + surface[0] = (pt_2d){.x = p1, .y = p2, .z = p3}; + project_to_cube(cb->x + cb->w, cb->y + (sf==2)*(cb->h), cb->z , &p1, &p2, &p3, cb); - surface[1] = (pt_2d){.x = p1, .y = p2, .z = p3}; + surface[1] = (pt_2d){.x = p1, .y = p2, .z = p3}; + project_to_cube(cb->x , cb->y + (sf==2)*(cb->h), cb->z + cb->d, &p1, &p2, &p3, cb); - surface[2] = (pt_2d){.x = p1, .y = p2, .z = p3}; + surface[2] = (pt_2d){.x = p1, .y = p2, .z = p3}; } else { project_to_cube(cb->x , cb->y , cb->z + (sf==4)*(cb->d), &p1, &p2, &p3, cb); - surface[0] = (pt_2d){.x = p1, .y = p2, .z = p3}; + surface[0] = (pt_2d){.x = p1, .y = p2, .z = p3}; + project_to_cube(cb->x + cb->w, cb->y , cb->z + (sf==4)*(cb->d), &p1, &p2, &p3, cb); - surface[1] = (pt_2d){.x = p1, .y = p2, .z = p3}; + surface[1] = (pt_2d){.x = p1, .y = p2, .z = p3}; + project_to_cube(cb->x , cb->y + cb->h, cb->z + (sf==4)*(cb->d), &p1, &p2, &p3, cb); - surface[2] = (pt_2d){.x = p1, .y = p2, .z = p3}; + surface[2] = (pt_2d){.x = p1, .y = p2, .z = p3}; } } @@ -177,7 +187,7 @@ void getDirectors() { void getNormal() { normal.x = directors[0].y*directors[1].z - directors[1].y*directors[0].z; - normal.y = -directors[0].z*directors[1].x + directors[1].z*directors[0].x; + normal.y = directors[0].z*directors[1].x - directors[1].z*directors[0].x; normal.z = directors[0].x*directors[1].y - directors[1].x*directors[0].y; double norm = sqrt(normal.x*normal.x + normal.y*normal.y + normal.z*normal.z); normal.x /= norm; @@ -192,6 +202,31 @@ void normalize(pt_2d* p) { p->z /= norm; } +void debugMove(cube_0* cb) { + for(int d = 0; d < 6; d++) { + cb->x -= min_dist; + cb->y -= min_dist; + cb->z -= min_dist; + cb->w += 2*min_dist; + cb->h += 2*min_dist; + cb->d += 2*min_dist; + getSF(cb, d); + cb->x += min_dist; + cb->y += min_dist; + cb->z += min_dist; + cb->w -= 2*min_dist; + cb->h -= 2*min_dist; + cb->d -= 2*min_dist; + for(int k = 0; k < 3; k++) { + cube_0* cb2 = create_cube_0(surface[k].x-0.1, surface[k].y-0.1, surface[k].z-0.1, 0.2, 0.2, 0.2, 0.0, 0.0, 255, 255, 255); + + gl_renderCube(cb2, 0.0, 0.0, 0.0); + + free(cb2); + } + } +} + void updateF(cube_0* cb, double dtime) { for(int d = 0; d < 6; d++) { cb->x -= min_dist; @@ -209,13 +244,14 @@ void updateF(cube_0* cb, double dtime) { cb->d -= 2*min_dist; getDirectors(); getNormal(); - if(d%2==1) { + if(d==2 || d==5 || d==1) { normal.x *= -1.0; normal.y *= -1.0; normal.z *= -1.0; } - pt_2d vt = (pt_2d){.x = camx-camvx*dtime - surface[0].x, .y = camy-camvy*dtime - surface[0].y, .z = camz-camvz*dtime - surface[0].z}; - pt_2d vtdt = (pt_2d){.x = camx - surface[0].x, .y = camy - surface[0].y, .z = camz - surface[0].z}; + //printf("%lf %lf\n", dot3D(normal, directors[0]), dot3D(normal, directors[1])); + pt_2d vt = (pt_2d){.x = camx-camvx*dtime - surface[0].x, .y = camy-camvy*dtime - surface[0].y, .z = camz-camvz*dtime - surface[0].z}; + pt_2d vtdt = (pt_2d){.x = camx - surface[0].x, .y = camy - surface[0].y, .z = camz - surface[0].z}; normalize(&vtdt); normalize(&vt); if( @@ -252,6 +288,9 @@ bool is_colliding(float dtime) { if(vstd != NULL) { for(int k = 0; k < vstd->map_size; k++) { double dist = distance_pt_cube_0_3d_infinite(camx-2*room_width*w, camy, camz-2*room_depth*h, vstd->map[k]); + //if(vstd->map[k]->vt_angle != 0.0) { + // printf("(%lf)\n", dist); + //} if(dist <= min_dist) { if(updateForces) { updateF(vstd->map[k], (double)dtime); @@ -342,7 +381,7 @@ void movePlayerG(float dtime) { is_clipping = true; if(is_colliding(dtime)) { if(is_clipping) { - player_hp -= (dtime)*clip_dps; + //player_hp -= (dtime)*clip_dps; } //printf("HIT\n"); //printf("[%lf, %lf, %lf]\n{%lf, %lf, %lf}\n\n", fx, fy, fz, camvx, camvy, camvz); diff --git a/src/move.h b/src/move.h index f17ae94..4343d86 100644 --- a/src/move.h +++ b/src/move.h @@ -6,6 +6,8 @@ bool is_colliding(float dtime); void update_buttons(float dtime); +void debugMove(cube_0* cb); + void teleport_on_edge(); void movePlayerG(float dtime);