diff --git a/source/src/physics.cpp b/source/src/physics.cpp index 84cc3980..7b16bc7d 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -159,50 +159,6 @@ bool collide(physent *d, bool spawn, float drop, float rise) return true; } -inline void detectcollision(physent *pl, vec &d, int moveres, float drop, float rise) -{ - const float f = 1.0f/moveres; - - loopi(moveres) // discrete steps collision detection & sliding - { - // try move forward - pl->o.x += f*d.x; - pl->o.y += f*d.y; - pl->o.z += f*d.z; - if(collide(pl, false, drop, rise)) continue; - if(pl->type==ENT_CAMERA) return; - // player stuck, try slide along y axis - pl->o.x -= f*d.x; - if(collide(pl, false, drop, rise)) - { - d.x = 0; - if(pl->type==ENT_BOUNCE) { pl->vel.x = -pl->vel.x; pl->vel.mul(0.7f); } - continue; - }; - pl->o.x += f*d.x; - // still stuck, try x axis - pl->o.y -= f*d.y; - if(collide(pl, false, drop, rise)) - { - d.y = 0; - if(pl->type==ENT_BOUNCE) { pl->vel.y = -pl->vel.y; pl->vel.mul(0.7f); } - continue; - }; - pl->o.y += f*d.y; - // try just dropping down - pl->o.x -= f*d.x; - pl->o.y -= f*d.y; - if(collide(pl, false, drop, rise)) - { - d.y = d.x = 0; - continue; - }; - pl->o.z -= f*d.z; - if(pl->type==ENT_BOUNCE) { pl->vel.z = -pl->vel.z; pl->vel.mul(0.5f); } - break; - }; -}; - VARP(maxroll, 0, 0, 20); // main physics routine, moves a player/monster for a curtime step @@ -320,7 +276,46 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) rise = speed/moveres/1.2f; // extra smoothness when lifting up stairs }; - detectcollision(pl, d, moveres, drop, rise); + const float f = 1.0f/moveres; + + loopi(moveres) // discrete steps collision detection & sliding + { + // try move forward + pl->o.x += f*d.x; + pl->o.y += f*d.y; + pl->o.z += f*d.z; + if(collide(pl, false, drop, rise)) continue; + if(pl->type==ENT_CAMERA) return; + // player stuck, try slide along y axis + pl->o.x -= f*d.x; + if(collide(pl, false, drop, rise)) + { + d.x = 0; + if(pl->type==ENT_BOUNCE) { pl->vel.x = -pl->vel.x; pl->vel.mul(0.7f); } + continue; + }; + pl->o.x += f*d.x; + // still stuck, try x axis + pl->o.y -= f*d.y; + if(collide(pl, false, drop, rise)) + { + d.y = 0; + if(pl->type==ENT_BOUNCE) { pl->vel.y = -pl->vel.y; pl->vel.mul(0.7f); } + continue; + }; + pl->o.y += f*d.y; + // try just dropping down + pl->o.x -= f*d.x; + pl->o.y -= f*d.y; + if(collide(pl, false, drop, rise)) + { + d.y = d.x = 0; + continue; + }; + pl->o.z -= f*d.z; + if(pl->type==ENT_BOUNCE) { pl->vel.z = -pl->vel.z; pl->vel.mul(0.5f); } + break; + }; if(pl->type==ENT_CAMERA) return; else if(pl->type!=ENT_BOUNCE) diff --git a/source/src/renderextras.cpp b/source/src/renderextras.cpp index 904b658f..528e9b12 100644 --- a/source/src/renderextras.cpp +++ b/source/src/renderextras.cpp @@ -606,7 +606,7 @@ void renderbounceents() { t -= p->timetolife-2000; z -= t*t/4000000000.0f*t; - } + }; break; }; }; @@ -617,7 +617,7 @@ void renderbounceents() VARP(gibnum, 0, 6, 1000); VARP(gibttl, 0, 5000, 15000); -VARP(gibspeed, 1, 5, 20); +VARP(gibspeed, 1, 30, 100); void addgib(playerent *d) { @@ -630,27 +630,31 @@ void addgib(playerent *d) p->owner = d; p->millis = lastmillis; p->timetolife = gibttl+rnd(10)*100; - p->bouncestate = GIB; - p->gravity = 20; - p->o = d->o; p->o.z -= d->aboveeye; - float gibvelangle = (float) rnd(360); - float speed = (float) gibspeed; - p->vel.x = sinf(gibvelangle)*speed*rnd(1000)/1000.0f; - p->vel.y = cosf(gibvelangle)*speed*rnd(1000)/1000.0f; - p->vel.z = speed*rnd(1000)/1000.0f; - p->vel.div(10.0f); + p->yaw = (float)rnd(360); + p->pitch = (float)rnd(360); - p->yaw = (float)rnd(360); - p->pitch = (float)rnd(360); - p->rotspeed = 3.0f; + p->maxspeed = 30.0f; + p->rotspeed = 3.0f; + + const float angle = (float)rnd(360); + const float speed = (float)gibspeed; + + p->vel.x = sinf(RAD*angle)*rnd(1000)/1000.0f; + p->vel.y = cosf(RAD*angle)*rnd(1000)/1000.0f; + p->vel.z = rnd(1000)/1000.0f; + p->vel.mul(gibspeed/100.0f); }; }; +// fixme +void gibtest() { playerent t = *player1; t.o.x = worldpos.x; t.o.y = worldpos.y; addgib(&t); } +COMMAND(gibtest, ARG_NONE); + void loadingscreen() { static Texture *logo = NULL; diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index cfae90a0..d5d28819 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -360,7 +360,6 @@ void throw_nade(playerent *d, const vec &vel, bounceent *p) p->bouncestate = NADE_THROWED; d->thrownademillis = lastmillis; - d->inhandnade = NULL; if(d==player1) @@ -374,16 +373,17 @@ void throw_nade(playerent *d, bounceent *p) { if(!d || !p) return; - float speed = cosf(RAD*d->pitch); - vec vel; - vel.z = sinf(RAD*d->pitch); - vel.x = sinf(RAD*d->yaw)*speed; - vel.y = -cosf(RAD*d->yaw)*speed; - vel.mul(1.7f); + const float speed = cosf(RAD*d->pitch); + vec vel(sinf(RAD*d->yaw)*speed, -cosf(RAD*d->yaw)*speed, sinf(RAD*d->pitch)); + vel.mul(1.5f); throw_nade(d, vel, p); }; +// fixme +VAR(grenadespeed, 0, 27, 100); +VAR(grenaderot, 0, 60, 100); + bounceent *new_nade(playerent *d, int millis = 0) { bounceent *p = newbounceent(); @@ -391,6 +391,8 @@ bounceent *new_nade(playerent *d, int millis = 0) p->millis = lastmillis; p->timetolife = 2000-millis; p->bouncestate = NADE_ACTIVATED; + p->maxspeed = (float)grenadespeed; + p->rotspeed = grenaderot/10.0f; d->inhandnade = p; d->thrownademillis = 0;