Compare commits
No commits in common. "e161db3807fcc2ad7e169b2af892be2c4a31c191" and "1859c47de2378bc9cc523b3a7d2ba2664d6d2b5a" have entirely different histories.
e161db3807
...
1859c47de2
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.
179
src/base.c
179
src/base.c
|
@ -90,7 +90,7 @@ int convex_seg(int x1, int x2, double theta) {
|
|||
}
|
||||
|
||||
double convex_pt(double a, double b, double theta) {
|
||||
return (a+(b-a)*theta);
|
||||
return (a+(b-a)*theta) ;
|
||||
}
|
||||
|
||||
double convex_tri(double a, double tha, double b, double thb, double c, double thc) {
|
||||
|
@ -119,33 +119,33 @@ bool is_an_integer(char c) {
|
|||
|
||||
pt_2d vect_diff(pt_2d p1, pt_2d p2) {
|
||||
pt_2d res;
|
||||
res.x = p2.x - p1.x;
|
||||
res.y = p2.y - p1.y;
|
||||
res.z = p2.z - p1.z;
|
||||
res.x = p2.x - p1.x ;
|
||||
res.y = p2.y - p1.y ;
|
||||
res.z = p2.z - p1.z ;
|
||||
return res;
|
||||
}
|
||||
|
||||
double dot2D(pt_2d p1, pt_2d p2) {
|
||||
return p1.x * p2.x + p1.y * p2.y;
|
||||
return p1.x * p2.x + p1.y * p2.y ;
|
||||
}
|
||||
|
||||
double dot3D(pt_2d p1, pt_2d p2) {
|
||||
return p1.x * p2.x + p1.y * p2.y + p1.z * p2.z;
|
||||
return p1.x * p2.x + p1.y * p2.y + p1.z * p2.z ;
|
||||
}
|
||||
|
||||
double to_double(int n) {
|
||||
return (double)n;
|
||||
return (double)n ;
|
||||
}
|
||||
|
||||
int to_int(double n) {
|
||||
return (int)n;
|
||||
return (int)n ;
|
||||
}
|
||||
|
||||
int line_count(char* filename) {
|
||||
FILE* ptr = fopen(filename, "r");
|
||||
char c = 'd';
|
||||
|
||||
int n = 0;
|
||||
int n = 0 ;
|
||||
while(c != EOF) {
|
||||
if(c == '\n') {
|
||||
n += 1;
|
||||
|
@ -157,11 +157,11 @@ int line_count(char* filename) {
|
|||
}
|
||||
|
||||
int str_to_int(char* s) {
|
||||
int res = 0;
|
||||
int i = 0;
|
||||
int res = 0 ;
|
||||
int i = 0 ;
|
||||
while(s[i] != '\0' && is_an_integer(s[i])) {
|
||||
res *= 10;
|
||||
res += (int)s[i] - 48;
|
||||
res *= 10 ;
|
||||
res += (int)s[i] - 48 ;
|
||||
i++;
|
||||
};
|
||||
return res;
|
||||
|
@ -177,57 +177,57 @@ bool str_equal(char* s1, char* s2) {
|
|||
// ------------------------------------------------------------------------------------------------ //
|
||||
|
||||
cube_0* create_cube_0(double x, double y, double z, double w, double h, double d, double hz_a, double vt_a, int r, int g, int b) {
|
||||
cube_0* cb = malloc(sizeof(cube_0));
|
||||
cb->red = r;
|
||||
cb->green = g;
|
||||
cb->blue = b;
|
||||
cb->x = x;
|
||||
cb->y = y;
|
||||
cb->z = z;
|
||||
cb->w = w;
|
||||
cb->h = h;
|
||||
cb->d = d;
|
||||
cb->hz_angle = hz_a;
|
||||
cb->vt_angle = vt_a;
|
||||
return cb;
|
||||
cube_0* cb = malloc(sizeof(cube_0)) ;
|
||||
cb->red = r ;
|
||||
cb->green = g ;
|
||||
cb->blue = b ;
|
||||
cb->x = x ;
|
||||
cb->y = y ;
|
||||
cb->z = z ;
|
||||
cb->w = w ;
|
||||
cb->h = h ;
|
||||
cb->d = d ;
|
||||
cb->hz_angle = hz_a ;
|
||||
cb->vt_angle = vt_a ;
|
||||
return cb ;
|
||||
}
|
||||
|
||||
void fill_cube_0(cube_0* cb, double x, double y, double z, double w, double h, double d, double hz_a, double vt_a, int r, int g, int b) {
|
||||
cb->red = r;
|
||||
cb->green = g;
|
||||
cb->blue = b;
|
||||
cb->x = x;
|
||||
cb->y = y;
|
||||
cb->z = z;
|
||||
cb->w = w;
|
||||
cb->h = h;
|
||||
cb->d = d;
|
||||
cb->hz_angle = hz_a;
|
||||
cb->vt_angle = vt_a;
|
||||
cb->red = r ;
|
||||
cb->green = g ;
|
||||
cb->blue = b ;
|
||||
cb->x = x ;
|
||||
cb->y = y ;
|
||||
cb->z = z ;
|
||||
cb->w = w ;
|
||||
cb->h = h ;
|
||||
cb->d = d ;
|
||||
cb->hz_angle = hz_a ;
|
||||
cb->vt_angle = vt_a ;
|
||||
}
|
||||
|
||||
cube create_cube(double x, double y, double z, double w, double h, double d, double hz_a, double vt_a, int r, int g, int b) {
|
||||
cube cb = malloc(sizeof(cube_0));
|
||||
cb = create_cube_0(x, y, z, w, h, d, hz_a, vt_a, r, g, b);
|
||||
cb = create_cube_0(x, y, z, w, h, d, hz_a, vt_a, r, g, b) ;
|
||||
return cb;
|
||||
}
|
||||
|
||||
void free_cube(cube c) {
|
||||
free(c);
|
||||
free(c) ;
|
||||
}
|
||||
|
||||
teleporter* create_teleporter(
|
||||
double x, double y, double z, double w, double h, double d, double hz_a, double vt_a, int r, int g, int b,
|
||||
int chx_dest, int chy_dest, double x_dest, double y_dest, double z_dest
|
||||
) {
|
||||
teleporter* tp = malloc(sizeof(teleporter));
|
||||
tp->dest_chx = chx_dest;
|
||||
tp->dest_chy = chy_dest;
|
||||
tp->dest_x = x_dest;
|
||||
tp->dest_y = y_dest;
|
||||
tp->dest_z = z_dest;
|
||||
teleporter* tp = malloc(sizeof(teleporter)) ;
|
||||
tp->dest_chx = chx_dest ;
|
||||
tp->dest_chy = chy_dest ;
|
||||
tp->dest_x = x_dest ;
|
||||
tp->dest_y = y_dest ;
|
||||
tp->dest_z = z_dest ;
|
||||
tp->hitbox = create_cube_0(x, y, z, w, h, d, hz_a, vt_a, r, g, b);
|
||||
return tp;
|
||||
return tp ;
|
||||
}
|
||||
|
||||
void copy_cube(cube_0* src, cube_0* dest) {
|
||||
|
@ -264,82 +264,91 @@ double distance_pt_seg_3d(double x, double y, double z, double sx, double sy, do
|
|||
((ex - sx) * (ex - sx) + (ey - sy) * (ey - sy) + (ez - sz) * (ez - sz))
|
||||
);
|
||||
if(theta >= 0.0 && theta <= 1.0) {
|
||||
return (distance_pt_pt_3d(x, y, z, convex_pt(sx, ex, theta), convex_pt(sy, ey, theta), convex_pt(sz, ez, theta)));
|
||||
return (distance_pt_pt_3d(x, y, z, convex_pt(sx, ex, theta), convex_pt(sy, ey, theta), convex_pt(sz, ez, theta))) ;
|
||||
} else if (theta < 0.0) {
|
||||
return (distance_pt_pt_3d(x, y, z, sx, sy, sz));
|
||||
return (distance_pt_pt_3d(x, y, z, sx, sy, sz)) ;
|
||||
} else {
|
||||
return (distance_pt_pt_3d(x, y, z, ex, ey, ez));
|
||||
return (distance_pt_pt_3d(x, y, z, ex, ey, ez)) ;
|
||||
}
|
||||
}
|
||||
|
||||
double distance_pt_cube_axis(double coord, double begin, double end) {
|
||||
if(coord < begin) {
|
||||
return (begin);
|
||||
return (begin-coord) ;
|
||||
} else if(coord > end) {
|
||||
return (end);
|
||||
return (coord-end) ;
|
||||
} else {
|
||||
return (coord);
|
||||
return 0.0 ;
|
||||
}
|
||||
}
|
||||
|
||||
double distance_pt_cube_axis_max(double coord, double begin, double end) {
|
||||
if(coord < (begin+end)/2) {
|
||||
return absf(end-coord) ;
|
||||
} else {
|
||||
return absf(begin-coord) ;
|
||||
}
|
||||
}
|
||||
|
||||
double distance_pt_cube_aligned_3d(double x0, double y0, double z0, double cx, double cy, double cz, double cw, double ch, double cd) {
|
||||
double clx = distance_pt_cube_axis(x0, cx, cx+cw);
|
||||
double cly = distance_pt_cube_axis(y0, cy, cy+ch);
|
||||
double clz = distance_pt_cube_axis(z0, cz, cz+cd);
|
||||
return sqrt((x0-clx)*(x0-clx) + (y0-cly)*(y0-cly) + (z0-clz)*(z0-clz));
|
||||
return (distance_pt_cube_axis(x0, cx, cx+cw)+distance_pt_cube_axis(y0, cy, cy+ch)+distance_pt_cube_axis(z0, cz, cz+cd)) ;
|
||||
}
|
||||
|
||||
double distance_pt_cube_aligned_3d_max(double x0, double y0, double z0, double cx, double cy, double cz, double cw, double ch, double cd) {
|
||||
return (distance_pt_cube_axis_max(x0, cx, cx+cw)+distance_pt_cube_axis_max(y0, cy, cy+ch)+distance_pt_cube_axis_max(z0, cz, cz+cd)) ;
|
||||
}
|
||||
|
||||
double distance_pt_cube_0_3d(double x0, double y0, double z0, cube_0* c) {
|
||||
// places the origin at the center of the cube
|
||||
double x = x0 - (c->x + c->w/2.0);
|
||||
double y = y0 - (c->y + c->h/2.0);
|
||||
double z = z0 - (c->z + c->d/2.0);
|
||||
double x = x0 - (c->x + c->w/2.0) ;
|
||||
double y = y0 - (c->y + c->h/2.0) ;
|
||||
double z = z0 - (c->z + c->d/2.0) ;
|
||||
|
||||
// rotate the point : y then x
|
||||
double xry = x*cos(c->hz_angle) + z*sin(c->hz_angle);
|
||||
double yry = y;
|
||||
double zry = z*cos(c->hz_angle) - x*sin(c->hz_angle);
|
||||
double xry = x*cos(c->hz_angle) + z*sin(c->hz_angle) ;
|
||||
double yry = y ;
|
||||
double zry = z*cos(c->hz_angle) - x*sin(c->hz_angle) ;
|
||||
|
||||
double xrx = xry;
|
||||
double yrx = yry*cos(c->vt_angle) - zry*sin(c->vt_angle);
|
||||
double zrx = zry*cos(c->vt_angle) + yry*sin(c->vt_angle);
|
||||
double xrx = xry ;
|
||||
double yrx = yry*cos(c->vt_angle) - zry*sin(c->vt_angle) ;
|
||||
double zrx = zry*cos(c->vt_angle) + yry*sin(c->vt_angle) ;
|
||||
|
||||
// now the cube and pt are aligned, and (0, 0, 0) is at the cube's (bary)center
|
||||
return distance_pt_cube_aligned_3d(xrx, yrx, zrx, -c->w/2.0, -c->h/2.0, -c->d/2.0, c->w, c->h, c->d);
|
||||
return distance_pt_cube_aligned_3d(xrx, yrx, zrx, -c->w/2.0, -c->h/2.0, -c->d/2.0, c->w, c->h, c->d) ;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------ //
|
||||
|
||||
void project_to_camera(double x0, double y0, double z0, double* rx, double* ry, double* rz) {
|
||||
// align pt to (0, 0, 0)
|
||||
double x = x0 - camx;
|
||||
double y = y0 - camy;
|
||||
double z = z0 - camz;
|
||||
double x = x0 - camx ;
|
||||
double y = y0 - camy ;
|
||||
double z = z0 - camz ;
|
||||
|
||||
// rotate (y)
|
||||
double xry = x*cos(rot_hz) - z*sin(rot_hz);
|
||||
double yry = y;
|
||||
double zry = z*cos(rot_hz) + x*sin(rot_hz);
|
||||
double xry = x*cos(rot_hz) - z*sin(rot_hz) ;
|
||||
double yry = y ;
|
||||
double zry = z*cos(rot_hz) + x*sin(rot_hz) ;
|
||||
|
||||
// rotate (x)
|
||||
if(rx != NULL) {*rx = xry;}
|
||||
if(ry != NULL) {*ry = yry*cos(rot_vt) + zry*sin(rot_vt);}
|
||||
if(rz != NULL) {*rz = zry*cos(rot_vt) - yry*sin(rot_vt);}
|
||||
if(rx != NULL) {*rx = xry ;}
|
||||
if(ry != NULL) {*ry = yry*cos(rot_vt) + zry*sin(rot_vt) ;}
|
||||
if(rz != NULL) {*rz = zry*cos(rot_vt) - yry*sin(rot_vt) ;}
|
||||
}
|
||||
|
||||
void project_to_cube(double x0, double y0, double z0, double* rx, double* ry, double* rz, cube_0* c) {
|
||||
// align pt to (0, 0, 0)
|
||||
double x = x0 - (c->x + c->w/2.0);
|
||||
double y = y0 - (c->y + c->h/2.0);
|
||||
double z = z0 - (c->z + c->d/2.0);
|
||||
double x = x0 - (c->x + c->w/2.0) ;
|
||||
double y = y0 - (c->y + c->h/2.0) ;
|
||||
double z = z0 - (c->z + c->d/2.0) ;
|
||||
|
||||
// rotate (y)
|
||||
double xry = x*cos(c->hz_angle) + z*sin(c->hz_angle);
|
||||
double yry = y;
|
||||
double zry = z*cos(c->hz_angle) - x*sin(c->hz_angle);
|
||||
double xry = x*cos(c->hz_angle) + z*sin(c->hz_angle) ;
|
||||
double yry = y ;
|
||||
double zry = z*cos(c->hz_angle) - x*sin(c->hz_angle) ;
|
||||
|
||||
// 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(rz != NULL) {*rz = c->z + c->d/2.0 + zry*cos(c->vt_angle) + yry*sin(c->vt_angle);}
|
||||
}
|
||||
|
@ -360,14 +369,14 @@ void add_entity(entity** arr, int* memlen, int* len, entity* ent) {
|
|||
entity** newarr = malloc(sizeof(entity*)*2*(*memlen));
|
||||
for(int k = 0; k < *len; k++) {
|
||||
newarr[k] = malloc(sizeof(entity));
|
||||
newarr[k] = arr[k];
|
||||
newarr[k] = arr[k] ;
|
||||
free(arr[k]);
|
||||
}
|
||||
free(*arr);
|
||||
arr = newarr;
|
||||
arr = newarr ;
|
||||
*memlen *= 2;
|
||||
}
|
||||
free(arr[*len]);
|
||||
arr[*len] = ent;
|
||||
arr[*len] = ent ;
|
||||
*len += 1;
|
||||
}
|
|
@ -48,8 +48,13 @@ double distance_pt_pt_3d(double x0, double y0, double z0, double x1, double y1,
|
|||
double distance_pt_pt_2d_sq(double x0, double y0, double x1, double y1);
|
||||
double distance_pt_pt_3d_sq(double x0, double y0, double z0, double x1, double y1, double z1);
|
||||
double distance_pt_seg_3d(double x, double y, double z, double sx, double sy, double sz, double ex, double ey, double ez);
|
||||
double distance_pt_cube_axis(double coord, double begin, double end);
|
||||
double distance_pt_cube_aligned_3d(double x0, double y0, double z0, double cx, double cy, double cz, double cw, double ch, double cd);
|
||||
double distance_pt_cube_0_3d(double x0, double y0, double z0, cube_0* c);
|
||||
|
||||
double distance_pt_cube_axis_max(double coord, double begin, double end);
|
||||
double distance_pt_cube_aligned_3d_max(double x0, double y0, double z0, double cx, double cy, double cz, double cw, double ch, double cd);
|
||||
|
||||
void remove_entity(entity** arr, int* memlen, int* len, int index);
|
||||
void add_entity(entity** arr, int* memlen, int* len, entity* ent);
|
||||
|
||||
|
|
|
@ -68,8 +68,7 @@ void gl_renderTriangle(unsigned int shaderProgram, unsigned int VAO, unsigned in
|
|||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
}
|
||||
|
||||
//double near = 0.4 ;
|
||||
double near = 0.0 ;
|
||||
double near = 0.4 ;
|
||||
double far = 10.0 ;
|
||||
|
||||
double top = 1.0 ;
|
||||
|
|
|
@ -57,25 +57,25 @@ void update_entities(float dtime) {
|
|||
// ------------------------------------------------------------------------------------------------------------------------------------------------ //
|
||||
|
||||
void speen(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) {
|
||||
ret->hz_angle += ((double)dtime)*1.5;
|
||||
ret->hz_angle += ((double)dtime)*15.0;
|
||||
}
|
||||
|
||||
void speen2(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) {
|
||||
ret->hz_angle += ((double)dtime)*2.5;
|
||||
ret->hz_angle += ((double)dtime)*22.5;
|
||||
if((int)(5.0*ret->hz_angle) != (int)(5.0*(ret->hz_angle - ((double)dtime)*22.5))) {
|
||||
double dx = (x+w/2 - camx);
|
||||
double dy = (y+h/2 - camy);
|
||||
double dz = (z+d/2 - camz);
|
||||
double total = sqrt(dx*dx + dy*dy + dz*dz);
|
||||
dx = 17.0*dx/total;
|
||||
dy = 17.0*dy/total;
|
||||
dz = 17.0*dz/total;
|
||||
dx = 170.0*dx/total;
|
||||
dy = 170.0*dy/total;
|
||||
dz = 170.0*dz/total;
|
||||
appendProj(x+w/2, y+h/2, z+d/2, 0.1, 0.1, 0.1, -dx, -dy, -dz, 0.0, 0.0, 0.0, 255, 0, 0, 10, 3.0);
|
||||
}
|
||||
}
|
||||
|
||||
void speen3(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) {
|
||||
ret->vt_angle += ((double)dtime)*2.5;
|
||||
ret->vt_angle += ((double)dtime)*22.5;
|
||||
}
|
||||
|
||||
// metad{1,2,3} = og pos
|
||||
|
@ -105,12 +105,31 @@ void detectHit(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) {
|
|||
}
|
||||
|
||||
void translatePlayer(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) {
|
||||
double dx = 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 dy = 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 dz = 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)));
|
||||
//fx += dx/(dtime*dtime);
|
||||
fy += dy/(dtime*dtime);
|
||||
//fz += dz/(dtime*dtime);
|
||||
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;
|
||||
}
|
||||
if(true) {
|
||||
double oldvz = camvz;
|
||||
camvz = vz/dtime;
|
||||
camz -= oldvz*dtime;
|
||||
camz += camvz*dtime;
|
||||
noResetSpeed = true;
|
||||
}
|
||||
noFriction = 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) {
|
||||
|
|
|
@ -342,7 +342,7 @@ int main_alt() {
|
|||
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
|
||||
// -------------------------------------------------------------------------------
|
||||
processInput(window, delta);
|
||||
movePlayerG(delta);
|
||||
movePlayerG(deltad);
|
||||
teleport_on_edge();
|
||||
update_entities(delta);
|
||||
updateProj(delta);
|
||||
|
|
175
src/move.c
175
src/move.c
|
@ -21,16 +21,13 @@ double fov = 90.0;
|
|||
double creative_speed = 0.3;
|
||||
double speed = 8.0;
|
||||
double vtmult = 1.5;
|
||||
double min_dist = 0.1;
|
||||
double min_dist = 0.7;
|
||||
double friction = 0.8;
|
||||
double gravity_factor = 9.8;
|
||||
bool noResetSpeed = false;
|
||||
bool noFriction = false;
|
||||
// ---------------------------------------------------------------------------------------------------- //
|
||||
|
||||
double fx;
|
||||
double fy;
|
||||
double fz;
|
||||
bool updateForces = false;
|
||||
|
||||
int player_hp;
|
||||
|
||||
bool stop_evetything;
|
||||
|
@ -51,13 +48,10 @@ int draw_type;
|
|||
int fade_dmg;
|
||||
|
||||
bool has_changed;
|
||||
int collisionVal = 0;
|
||||
|
||||
double room_width;
|
||||
double room_depth;
|
||||
|
||||
double sq2;
|
||||
|
||||
void init_csts() {
|
||||
camx = 2.0;
|
||||
camy = 5.0;
|
||||
|
@ -72,7 +66,6 @@ void init_csts() {
|
|||
fade_dmg = 0;
|
||||
room_width = 16.0;
|
||||
room_depth = 16.0;
|
||||
sq2 = sqrt(2);
|
||||
stop_evetything = false;
|
||||
tan_fov = tan((fov * 3.14159 / 180.0) / 2.0);
|
||||
}
|
||||
|
@ -90,111 +83,16 @@ void set_player_coords(int old_chx, int old_chy) {
|
|||
}
|
||||
}
|
||||
|
||||
pt_2d surface[3];
|
||||
pt_2d directors[2];
|
||||
pt_2d normal;
|
||||
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};
|
||||
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};
|
||||
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};
|
||||
} 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};
|
||||
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};
|
||||
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};
|
||||
} 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};
|
||||
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};
|
||||
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};
|
||||
}
|
||||
}
|
||||
|
||||
void getDirectors() {
|
||||
directors[0] = (pt_2d){.x = surface[1].x - surface[0].x, .y = surface[1].y - surface[0].y, .z = surface[1].z - surface[0].z};
|
||||
directors[1] = (pt_2d){.x = surface[2].x - surface[0].x, .y = surface[2].y - surface[0].y, .z = surface[2].z - surface[0].z};
|
||||
}
|
||||
|
||||
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.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;
|
||||
normal.y /= norm;
|
||||
normal.z /= norm;
|
||||
}
|
||||
|
||||
void normalize(pt_2d* p) {
|
||||
double norm = sqrt(p->x*p->x + p->y*p->y + p->z*p->z);
|
||||
p->x /= norm;
|
||||
p->y /= norm;
|
||||
p->z /= norm;
|
||||
}
|
||||
|
||||
void updateF(cube_0* cb, double dtime) {
|
||||
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;
|
||||
getDirectors();
|
||||
getNormal();
|
||||
if(d%2==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};
|
||||
normalize(&vtdt);
|
||||
normalize(&vt);
|
||||
if(
|
||||
(dot3D(vt, normal) <= 0.0 && dot3D(vtdt, normal) >= 0.0) ||
|
||||
(dot3D(vt, normal) >= 0.0 && dot3D(vtdt, normal) <= 0.0)
|
||||
) {
|
||||
printf("%d\n", d);
|
||||
double normv = sqrt(camvx*camvx + camvy*camvy + camvz*camvz);
|
||||
|
||||
double alpha = acos(dot3D(normal, (pt_2d){.x = camvx, .y = camvy, .z = camvz})/normv);
|
||||
double beta = 3.1415926535 - 2*alpha;
|
||||
double nu = sqrt(2)*normv*sqrt(1-cos(beta));
|
||||
|
||||
pt_2d u = (pt_2d){.x = normal.x*nu, .y = normal.y*nu, .z = normal.z*nu};
|
||||
|
||||
camvx += u.x;
|
||||
camvy += u.y;
|
||||
camvz += u.z;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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]);
|
||||
if(dist <= min_dist) {
|
||||
if(updateForces) {
|
||||
updateF(current_room->map[k], (double)dtime);
|
||||
}
|
||||
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);
|
||||
if(dist <= min_dist) {
|
||||
if(updateForces) {
|
||||
updateF(current_room->tps[k]->hitbox, (double)dtime);
|
||||
}
|
||||
int old_chx = player_chx;
|
||||
int old_chy = player_chy;
|
||||
player_chx = current_room->tps[k]->dest_chx;
|
||||
|
@ -215,10 +113,6 @@ bool is_colliding(float dtime) {
|
|||
(*current_room->ents[k]->onDeath)(dtime);
|
||||
}
|
||||
remove_entity(current_room->ents, ¤t_room->ent_memlen, ¤t_room->ent_len, k);
|
||||
} else {
|
||||
if(updateForces) {
|
||||
updateF(current_room->ents[k]->pos, (double)dtime);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -227,37 +121,46 @@ bool is_colliding(float dtime) {
|
|||
return false;
|
||||
}
|
||||
|
||||
void movePlayerG(float dtime) {
|
||||
updateForces = true;
|
||||
fx = 0.0;
|
||||
fy = 0.0;
|
||||
fz = 0.0;
|
||||
void movePlayerG(double dtime) {
|
||||
camx += camvx*dtime;
|
||||
noResetSpeed = false;
|
||||
noFriction = false;
|
||||
if(is_colliding(dtime)) {
|
||||
camx -= camvx*dtime;
|
||||
if(!noResetSpeed) {
|
||||
camvx = 0.0;
|
||||
}
|
||||
}
|
||||
if(!noFriction) {
|
||||
camvx = camvx*(1-dtime*friction);
|
||||
}
|
||||
|
||||
camvy -= gravity_factor*dtime;
|
||||
|
||||
double delx = camvx*dtime;
|
||||
double dely = camvy*dtime;
|
||||
double delz = camvz*dtime;
|
||||
camx += delx;
|
||||
camy += dely;
|
||||
camz += delz;
|
||||
if(is_colliding(dtime)) {
|
||||
printf("HIT\n");
|
||||
//printf("[%lf, %lf, %lf]\n{%lf, %lf, %lf}\n\n", fx, fy, fz, camvx, camvy, camvz);
|
||||
}
|
||||
camx -= delx;
|
||||
camy -= dely;
|
||||
camz -= delz;
|
||||
//printf("%lf | %lf | %lf\n", fx, fy, fz);
|
||||
|
||||
updateForces = false;
|
||||
camvx += fx*dtime;
|
||||
camvy += fy*dtime;
|
||||
camvz += fz*dtime;
|
||||
//printf("%lf | %lf | %lf\n\n", camvx, camvy, camvz);
|
||||
camx += camvx*dtime;
|
||||
camy += camvy*dtime;
|
||||
noResetSpeed = false;
|
||||
noFriction = false;
|
||||
if(is_colliding(dtime)) {
|
||||
camy -= camvy*dtime;
|
||||
if(!noResetSpeed) {
|
||||
camvy = 0.0;
|
||||
}
|
||||
}
|
||||
if(!noFriction) {
|
||||
camvy = camvy*(1-dtime*friction);
|
||||
}
|
||||
|
||||
camz += camvz*dtime;
|
||||
noResetSpeed = false;
|
||||
noFriction = false;
|
||||
if(is_colliding(dtime)) {
|
||||
camz -= camvz*dtime;
|
||||
if(!noResetSpeed) {
|
||||
camvz = 0.0;
|
||||
}
|
||||
}
|
||||
if(!noFriction) {
|
||||
camvz = camvz*(1-dtime*friction);
|
||||
}
|
||||
}
|
||||
|
||||
void teleport_on_edge() {
|
||||
|
|
|
@ -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
|
|
@ -147,10 +147,7 @@ extern float rectDefault[18];
|
|||
|
||||
extern int triCount;
|
||||
|
||||
extern bool updateForces;
|
||||
|
||||
extern double fx;
|
||||
extern double fy;
|
||||
extern double fz;
|
||||
extern bool noResetSpeed;
|
||||
extern bool noFriction;
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue