Compare commits
3 Commits
1859c47de2
...
e161db3807
Author | SHA1 | Date |
---|---|---|
|
e161db3807 | |
|
1fe7b14d86 | |
|
8e9d3fe513 |
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.
23
src/base.c
23
src/base.c
|
@ -274,28 +274,19 @@ double distance_pt_seg_3d(double x, double y, double z, double sx, double sy, do
|
||||||
|
|
||||||
double distance_pt_cube_axis(double coord, double begin, double end) {
|
double distance_pt_cube_axis(double coord, double begin, double end) {
|
||||||
if(coord < begin) {
|
if(coord < begin) {
|
||||||
return (begin-coord) ;
|
return (begin);
|
||||||
} else if(coord > end) {
|
} else if(coord > end) {
|
||||||
return (coord-end) ;
|
return (end);
|
||||||
} else {
|
} else {
|
||||||
return 0.0 ;
|
return (coord);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 distance_pt_cube_aligned_3d(double x0, double y0, double z0, double cx, double cy, double cz, double cw, double ch, double cd) {
|
||||||
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 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);
|
||||||
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 sqrt((x0-clx)*(x0-clx) + (y0-cly)*(y0-cly) + (z0-clz)*(z0-clz));
|
||||||
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) {
|
double distance_pt_cube_0_3d(double x0, double y0, double z0, cube_0* c) {
|
||||||
|
|
|
@ -48,13 +48,8 @@ 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_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_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_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_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 remove_entity(entity** arr, int* memlen, int* len, int index);
|
||||||
void add_entity(entity** arr, int* memlen, int* len, entity* ent);
|
void add_entity(entity** arr, int* memlen, int* len, entity* ent);
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,8 @@ void gl_renderTriangle(unsigned int shaderProgram, unsigned int VAO, unsigned in
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
double near = 0.4 ;
|
//double near = 0.4 ;
|
||||||
|
double near = 0.0 ;
|
||||||
double far = 10.0 ;
|
double far = 10.0 ;
|
||||||
|
|
||||||
double top = 1.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) {
|
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)*15.0;
|
ret->hz_angle += ((double)dtime)*1.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
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)*22.5;
|
ret->hz_angle += ((double)dtime)*2.5;
|
||||||
if((int)(5.0*ret->hz_angle) != (int)(5.0*(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 dx = (x+w/2 - camx);
|
||||||
double dy = (y+h/2 - camy);
|
double dy = (y+h/2 - camy);
|
||||||
double dz = (z+d/2 - camz);
|
double dz = (z+d/2 - camz);
|
||||||
double total = sqrt(dx*dx + dy*dy + dz*dz);
|
double total = sqrt(dx*dx + dy*dy + dz*dz);
|
||||||
dx = 170.0*dx/total;
|
dx = 17.0*dx/total;
|
||||||
dy = 170.0*dy/total;
|
dy = 17.0*dy/total;
|
||||||
dz = 170.0*dz/total;
|
dz = 17.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);
|
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) {
|
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)*22.5;
|
ret->vt_angle += ((double)dtime)*2.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
// metad{1,2,3} = og pos
|
// metad{1,2,3} = og pos
|
||||||
|
@ -105,31 +105,12 @@ 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) {
|
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 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 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 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 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)));
|
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)));
|
||||||
//printf("(%lf %lf) (%lf %lf) (%lf %lf)\n", vx, camvx, vy, camvy, vz, camvz);
|
//fx += dx/(dtime*dtime);
|
||||||
if(true) {
|
fy += dy/(dtime*dtime);
|
||||||
double oldvx = camvx;
|
//fz += dz/(dtime*dtime);
|
||||||
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) {
|
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.)
|
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
|
||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
processInput(window, delta);
|
processInput(window, delta);
|
||||||
movePlayerG(deltad);
|
movePlayerG(delta);
|
||||||
teleport_on_edge();
|
teleport_on_edge();
|
||||||
update_entities(delta);
|
update_entities(delta);
|
||||||
updateProj(delta);
|
updateProj(delta);
|
||||||
|
|
173
src/move.c
173
src/move.c
|
@ -21,13 +21,16 @@ double fov = 90.0;
|
||||||
double creative_speed = 0.3;
|
double creative_speed = 0.3;
|
||||||
double speed = 8.0;
|
double speed = 8.0;
|
||||||
double vtmult = 1.5;
|
double vtmult = 1.5;
|
||||||
double min_dist = 0.7;
|
double min_dist = 0.1;
|
||||||
double friction = 0.8;
|
double friction = 0.8;
|
||||||
double gravity_factor = 9.8;
|
double gravity_factor = 9.8;
|
||||||
bool noResetSpeed = false;
|
|
||||||
bool noFriction = false;
|
|
||||||
// ---------------------------------------------------------------------------------------------------- //
|
// ---------------------------------------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
double fx;
|
||||||
|
double fy;
|
||||||
|
double fz;
|
||||||
|
bool updateForces = false;
|
||||||
|
|
||||||
int player_hp;
|
int player_hp;
|
||||||
|
|
||||||
bool stop_evetything;
|
bool stop_evetything;
|
||||||
|
@ -48,10 +51,13 @@ int draw_type;
|
||||||
int fade_dmg;
|
int fade_dmg;
|
||||||
|
|
||||||
bool has_changed;
|
bool has_changed;
|
||||||
|
int collisionVal = 0;
|
||||||
|
|
||||||
double room_width;
|
double room_width;
|
||||||
double room_depth;
|
double room_depth;
|
||||||
|
|
||||||
|
double sq2;
|
||||||
|
|
||||||
void init_csts() {
|
void init_csts() {
|
||||||
camx = 2.0;
|
camx = 2.0;
|
||||||
camy = 5.0;
|
camy = 5.0;
|
||||||
|
@ -66,6 +72,7 @@ void init_csts() {
|
||||||
fade_dmg = 0;
|
fade_dmg = 0;
|
||||||
room_width = 16.0;
|
room_width = 16.0;
|
||||||
room_depth = 16.0;
|
room_depth = 16.0;
|
||||||
|
sq2 = sqrt(2);
|
||||||
stop_evetything = false;
|
stop_evetything = false;
|
||||||
tan_fov = tan((fov * 3.14159 / 180.0) / 2.0);
|
tan_fov = tan((fov * 3.14159 / 180.0) / 2.0);
|
||||||
}
|
}
|
||||||
|
@ -83,16 +90,111 @@ 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) {
|
bool is_colliding(float dtime) {
|
||||||
for(int k = 0; k < current_room->map_size; k++) {
|
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) {
|
if(dist <= min_dist) {
|
||||||
|
if(updateForces) {
|
||||||
|
updateF(current_room->map[k], (double)dtime);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(int k = 0; k < current_room->tps_size; k++) {
|
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) {
|
if(dist <= min_dist) {
|
||||||
|
if(updateForces) {
|
||||||
|
updateF(current_room->tps[k]->hitbox, (double)dtime);
|
||||||
|
}
|
||||||
int old_chx = player_chx;
|
int old_chx = player_chx;
|
||||||
int old_chy = player_chy;
|
int old_chy = player_chy;
|
||||||
player_chx = current_room->tps[k]->dest_chx;
|
player_chx = current_room->tps[k]->dest_chx;
|
||||||
|
@ -113,6 +215,10 @@ bool is_colliding(float dtime) {
|
||||||
(*current_room->ents[k]->onDeath)(dtime);
|
(*current_room->ents[k]->onDeath)(dtime);
|
||||||
}
|
}
|
||||||
remove_entity(current_room->ents, ¤t_room->ent_memlen, ¤t_room->ent_len, k);
|
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;
|
return true;
|
||||||
|
@ -121,46 +227,37 @@ bool is_colliding(float dtime) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void movePlayerG(double dtime) {
|
void movePlayerG(float dtime) {
|
||||||
camx += camvx*dtime;
|
updateForces = true;
|
||||||
noResetSpeed = false;
|
fx = 0.0;
|
||||||
noFriction = false;
|
fy = 0.0;
|
||||||
if(is_colliding(dtime)) {
|
fz = 0.0;
|
||||||
camx -= camvx*dtime;
|
|
||||||
if(!noResetSpeed) {
|
|
||||||
camvx = 0.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!noFriction) {
|
|
||||||
camvx = camvx*(1-dtime*friction);
|
|
||||||
}
|
|
||||||
|
|
||||||
camvy -= gravity_factor*dtime;
|
camvy -= gravity_factor*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;
|
double delx = camvx*dtime;
|
||||||
noResetSpeed = false;
|
double dely = camvy*dtime;
|
||||||
noFriction = false;
|
double delz = camvz*dtime;
|
||||||
|
camx += delx;
|
||||||
|
camy += dely;
|
||||||
|
camz += delz;
|
||||||
if(is_colliding(dtime)) {
|
if(is_colliding(dtime)) {
|
||||||
camz -= camvz*dtime;
|
printf("HIT\n");
|
||||||
if(!noResetSpeed) {
|
//printf("[%lf, %lf, %lf]\n{%lf, %lf, %lf}\n\n", fx, fy, fz, camvx, camvy, camvz);
|
||||||
camvz = 0.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!noFriction) {
|
|
||||||
camvz = camvz*(1-dtime*friction);
|
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
|
camz += camvz*dtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
void teleport_on_edge() {
|
void teleport_on_edge() {
|
||||||
|
|
|
@ -5,6 +5,6 @@ void init_csts();
|
||||||
bool is_colliding(float dtime);
|
bool is_colliding(float dtime);
|
||||||
|
|
||||||
void teleport_on_edge();
|
void teleport_on_edge();
|
||||||
void movePlayerG(double dtime);
|
void movePlayerG(float dtime);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -147,7 +147,10 @@ extern float rectDefault[18];
|
||||||
|
|
||||||
extern int triCount;
|
extern int triCount;
|
||||||
|
|
||||||
extern bool noResetSpeed;
|
extern bool updateForces;
|
||||||
extern bool noFriction;
|
|
||||||
|
extern double fx;
|
||||||
|
extern double fy;
|
||||||
|
extern double fz;
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue