fixed bug when vertically-angled cubes resulted in incorrect normal vector calculation
This commit is contained in:
parent
162ea1bd30
commit
f8f90f7824
|
@ -1,5 +1,10 @@
|
||||||
Blocks :
|
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
|
[ -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]
|
[-25.0, 21.0, 18.0, 2.0, 2.0, 2.0, 0.0, 0.0, 192, 192, 192]
|
||||||
|
|
BIN
obj/base.o
BIN
obj/base.o
Binary file not shown.
BIN
obj/display.o
BIN
obj/display.o
Binary file not shown.
BIN
obj/entities.o
BIN
obj/entities.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.
|
@ -398,8 +398,8 @@ void project_to_cube(double x0, double y0, double z0, double* rx, double* ry, do
|
||||||
|
|
||||||
// rotate (x)
|
// rotate (x)
|
||||||
if(rx != NULL) {*rx = c->x + c->w/2.0 + xry;}
|
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(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(rz != NULL) {*rz = c->z + c->d/2.0 + zry*cos(c->vt_angle) - yry*sin(c->vt_angle);}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------ //
|
// ------------------------------------------------------------------------------------------------ //
|
||||||
|
|
|
@ -136,8 +136,8 @@ void gl_renderCube(cube_0* c, double offx, double offy, double offz) {
|
||||||
scale[1][1] = (float)(c->h);
|
scale[1][1] = (float)(c->h);
|
||||||
scale[2][2] = (float)(c->d);
|
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_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->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->hz_angle), (vec3){0.0f, 1.0f, 0.0f});
|
||||||
|
|
||||||
glm_mat2_identity(texShift);
|
glm_mat2_identity(texShift);
|
||||||
texShift[0][0] = (float)(maxd(maxd(c->w, c->h), c->d)/mind(mind(c->w, c->h), c->d));
|
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++) {
|
for(int k = 0; k < rtd->map_size; k++) {
|
||||||
if(is_visible(rtd->map[k], offx, offy, offz)) {
|
if(is_visible(rtd->map[k], offx, offy, offz)) {
|
||||||
gl_renderCube(rtd->map[k], offx, offy, offz);
|
gl_renderCube(rtd->map[k], offx, offy, offz);
|
||||||
|
//debugMove(rtd->map[k]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glBindTexture(GL_TEXTURE_2D, textures[6]);
|
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]);
|
glBindTexture(GL_TEXTURE_2D, textures[rtd->ents[k]->tex2]);
|
||||||
}
|
}
|
||||||
gl_renderCube(rtd->ents[k]->pos, offx, offy, offz);
|
gl_renderCube(rtd->ents[k]->pos, offx, offy, offz);
|
||||||
|
//debugMove(rtd->ents[k]->pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -690,10 +690,6 @@ int main_alt() {
|
||||||
usleep(max(0, interval-(int)(1000000*calc_T)));
|
usleep(max(0, interval-(int)(1000000*calc_T)));
|
||||||
sim_time += interval_s + maxd(0.0, (double)(interval_s-(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);
|
dmgCD = maxf(dmgCD - delta, 0.0f);
|
||||||
if(lastDmg != player_hp) {
|
if(lastDmg != player_hp) {
|
||||||
lastDmg = player_hp;
|
lastDmg = player_hp;
|
||||||
|
@ -706,6 +702,10 @@ int main_alt() {
|
||||||
}
|
}
|
||||||
incr = 0.0f;
|
incr = 0.0f;
|
||||||
|
|
||||||
|
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
|
||||||
|
glfwSwapBuffers(window);
|
||||||
|
glfwPollEvents();
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
67
src/move.c
67
src/move.c
|
@ -7,12 +7,16 @@
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <glad/glad.h>
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <cglm/cglm.h>
|
||||||
|
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
#include "base.h"
|
#include "base.h"
|
||||||
#include "entities.h"
|
#include "entities.h"
|
||||||
#include "proj.h"
|
#include "proj.h"
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
|
#include "display.h"
|
||||||
#include "music.h"
|
#include "music.h"
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------------- //
|
// ---------------------------------------------------------------------------------------------------- //
|
||||||
|
@ -148,25 +152,31 @@ double p1, p2, p3;
|
||||||
void getSF(cube_0* cb, int sf) {
|
void getSF(cube_0* cb, int sf) {
|
||||||
if(sf == 0 || sf == 1) {
|
if(sf == 0 || sf == 1) {
|
||||||
project_to_cube(cb->x + (sf==0)*(cb->w), cb->y , cb->z , &p1, &p2, &p3, cb);
|
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);
|
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);
|
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) {
|
} else if(sf == 2 || sf == 3) {
|
||||||
project_to_cube(cb->x , cb->y + (sf==2)*(cb->h), cb->z , &p1, &p2, &p3, cb);
|
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);
|
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);
|
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 {
|
} else {
|
||||||
project_to_cube(cb->x , cb->y , cb->z + (sf==4)*(cb->d), &p1, &p2, &p3, cb);
|
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);
|
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);
|
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() {
|
void getNormal() {
|
||||||
normal.x = directors[0].y*directors[1].z - directors[1].y*directors[0].z;
|
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;
|
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);
|
double norm = sqrt(normal.x*normal.x + normal.y*normal.y + normal.z*normal.z);
|
||||||
normal.x /= norm;
|
normal.x /= norm;
|
||||||
|
@ -192,6 +202,31 @@ void normalize(pt_2d* p) {
|
||||||
p->z /= norm;
|
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) {
|
void updateF(cube_0* cb, double dtime) {
|
||||||
for(int d = 0; d < 6; d++) {
|
for(int d = 0; d < 6; d++) {
|
||||||
cb->x -= min_dist;
|
cb->x -= min_dist;
|
||||||
|
@ -209,13 +244,14 @@ void updateF(cube_0* cb, double dtime) {
|
||||||
cb->d -= 2*min_dist;
|
cb->d -= 2*min_dist;
|
||||||
getDirectors();
|
getDirectors();
|
||||||
getNormal();
|
getNormal();
|
||||||
if(d%2==1) {
|
if(d==2 || d==5 || d==1) {
|
||||||
normal.x *= -1.0;
|
normal.x *= -1.0;
|
||||||
normal.y *= -1.0;
|
normal.y *= -1.0;
|
||||||
normal.z *= -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};
|
//printf("%lf %lf\n", dot3D(normal, directors[0]), dot3D(normal, directors[1]));
|
||||||
pt_2d vtdt = (pt_2d){.x = camx - surface[0].x, .y = camy - surface[0].y, .z = camz - surface[0].z};
|
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(&vtdt);
|
||||||
normalize(&vt);
|
normalize(&vt);
|
||||||
if(
|
if(
|
||||||
|
@ -252,6 +288,9 @@ bool is_colliding(float dtime) {
|
||||||
if(vstd != NULL) {
|
if(vstd != NULL) {
|
||||||
for(int k = 0; k < vstd->map_size; k++) {
|
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]);
|
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(dist <= min_dist) {
|
||||||
if(updateForces) {
|
if(updateForces) {
|
||||||
updateF(vstd->map[k], (double)dtime);
|
updateF(vstd->map[k], (double)dtime);
|
||||||
|
@ -342,7 +381,7 @@ void movePlayerG(float dtime) {
|
||||||
is_clipping = true;
|
is_clipping = true;
|
||||||
if(is_colliding(dtime)) {
|
if(is_colliding(dtime)) {
|
||||||
if(is_clipping) {
|
if(is_clipping) {
|
||||||
player_hp -= (dtime)*clip_dps;
|
//player_hp -= (dtime)*clip_dps;
|
||||||
}
|
}
|
||||||
//printf("HIT\n");
|
//printf("HIT\n");
|
||||||
//printf("[%lf, %lf, %lf]\n{%lf, %lf, %lf}\n\n", fx, fy, fz, camvx, camvy, camvz);
|
//printf("[%lf, %lf, %lf]\n{%lf, %lf, %lf}\n\n", fx, fy, fz, camvx, camvy, camvz);
|
||||||
|
|
|
@ -6,6 +6,8 @@ bool is_colliding(float dtime);
|
||||||
|
|
||||||
void update_buttons(float dtime);
|
void update_buttons(float dtime);
|
||||||
|
|
||||||
|
void debugMove(cube_0* cb);
|
||||||
|
|
||||||
void teleport_on_edge();
|
void teleport_on_edge();
|
||||||
void movePlayerG(float dtime);
|
void movePlayerG(float dtime);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue