physics v1.1
This commit is contained in:
parent
7b79815188
commit
65c009e3af
BIN
obj/entities.o
BIN
obj/entities.o
Binary file not shown.
BIN
obj/move.o
BIN
obj/move.o
Binary file not shown.
|
@ -111,7 +111,7 @@ void translatePlayer(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) {
|
||||||
//printf("(%lf %lf) (%lf %lf) (%lf %lf)\n", vx, camvx, vy, camvy, vz, camvz);
|
//printf("(%lf %lf) (%lf %lf) (%lf %lf)\n", vx, camvx, vy, camvy, vz, camvz);
|
||||||
if(true) {
|
if(true) {
|
||||||
double oldvx = camvx;
|
double oldvx = camvx;
|
||||||
camvx += vx/dtime;
|
camvx = vx/dtime;
|
||||||
camx -= oldvx*dtime;
|
camx -= oldvx*dtime;
|
||||||
camx += camvx*dtime;
|
camx += camvx*dtime;
|
||||||
noResetSpeed = true;
|
noResetSpeed = true;
|
||||||
|
@ -121,15 +121,15 @@ void translatePlayer(float dtime, int* hp, int* dmg, entity* ent, cube_0* ret) {
|
||||||
camvy += vy/dtime;
|
camvy += vy/dtime;
|
||||||
camy -= oldvy*dtime;
|
camy -= oldvy*dtime;
|
||||||
camy += camvy*dtime;
|
camy += camvy*dtime;
|
||||||
noResetSpeed = true;
|
|
||||||
}
|
}
|
||||||
if(true) {
|
if(true) {
|
||||||
double oldvz = camvz;
|
double oldvz = camvz;
|
||||||
camvz += vz/dtime;
|
camvz = vz/dtime;
|
||||||
camz -= oldvz*dtime;
|
camz -= oldvz*dtime;
|
||||||
camz += camvz*dtime;
|
camz += camvz*dtime;
|
||||||
noResetSpeed = true;
|
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) {
|
||||||
|
|
16
src/move.c
16
src/move.c
|
@ -25,6 +25,7 @@ double min_dist = 0.7;
|
||||||
double friction = 0.8;
|
double friction = 0.8;
|
||||||
double gravity_factor = 9.8;
|
double gravity_factor = 9.8;
|
||||||
bool noResetSpeed = false;
|
bool noResetSpeed = false;
|
||||||
|
bool noFriction = false;
|
||||||
// ---------------------------------------------------------------------------------------------------- //
|
// ---------------------------------------------------------------------------------------------------- //
|
||||||
|
|
||||||
int player_hp;
|
int player_hp;
|
||||||
|
@ -123,34 +124,43 @@ bool is_colliding(float dtime) {
|
||||||
void movePlayerG(double dtime) {
|
void movePlayerG(double dtime) {
|
||||||
camx += camvx*dtime;
|
camx += camvx*dtime;
|
||||||
noResetSpeed = false;
|
noResetSpeed = false;
|
||||||
|
noFriction = false;
|
||||||
if(is_colliding(dtime)) {
|
if(is_colliding(dtime)) {
|
||||||
camx -= camvx*dtime;
|
camx -= camvx*dtime;
|
||||||
if(!noResetSpeed) {
|
if(!noResetSpeed) {
|
||||||
camvx = 0.0;
|
camvx = 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
camvx = camvx*(1-dtime*friction);
|
if(!noFriction) {
|
||||||
|
camvx = camvx*(1-dtime*friction);
|
||||||
|
}
|
||||||
|
|
||||||
camvy -= gravity_factor*dtime;
|
camvy -= gravity_factor*dtime;
|
||||||
camy += camvy*dtime;
|
camy += camvy*dtime;
|
||||||
noResetSpeed = false;
|
noResetSpeed = false;
|
||||||
|
noFriction = false;
|
||||||
if(is_colliding(dtime)) {
|
if(is_colliding(dtime)) {
|
||||||
camy -= camvy*dtime;
|
camy -= camvy*dtime;
|
||||||
if(!noResetSpeed) {
|
if(!noResetSpeed) {
|
||||||
camvy = 0.0;
|
camvy = 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
camvy = camvy*(1-dtime*friction);
|
if(!noFriction) {
|
||||||
|
camvy = camvy*(1-dtime*friction);
|
||||||
|
}
|
||||||
|
|
||||||
camz += camvz*dtime;
|
camz += camvz*dtime;
|
||||||
noResetSpeed = false;
|
noResetSpeed = false;
|
||||||
|
noFriction = false;
|
||||||
if(is_colliding(dtime)) {
|
if(is_colliding(dtime)) {
|
||||||
camz -= camvz*dtime;
|
camz -= camvz*dtime;
|
||||||
if(!noResetSpeed) {
|
if(!noResetSpeed) {
|
||||||
camvz = 0.0;
|
camvz = 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
camvz = camvz*(1-dtime*friction);
|
if(!noFriction) {
|
||||||
|
camvz = camvz*(1-dtime*friction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void teleport_on_edge() {
|
void teleport_on_edge() {
|
||||||
|
|
|
@ -148,5 +148,6 @@ extern float rectDefault[18];
|
||||||
extern int triCount;
|
extern int triCount;
|
||||||
|
|
||||||
extern bool noResetSpeed;
|
extern bool noResetSpeed;
|
||||||
|
extern bool noFriction;
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue