1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
// physics.cpp: no physics books were hurt nor consulted in the construction of
// this code. All physics computations and constants were invented on the fly
// and simply tweaked until they "felt right", and have no basis in reality.
// Collision detection is simplistic but very robust (uses discrete steps at
// fixed fps).
#include "cube.h"
#import "DynamicEntity.h"
#import "MapModelInfo.h"
// collide with player or monster
bool
plcollide(
DynamicEntity *d, DynamicEntity *o, float &headspace, float &hi, float &lo)
{
|
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
// physics.cpp: no physics books were hurt nor consulted in the construction of
// this code. All physics computations and constants were invented on the fly
// and simply tweaked until they "felt right", and have no basis in reality.
// Collision detection is simplistic but very robust (uses discrete steps at
// fixed fps).
#include "cube.h"
#import "DynamicEntity.h"
#import "Entity.h"
#import "MapModelInfo.h"
// collide with player or monster
bool
plcollide(
DynamicEntity *d, DynamicEntity *o, float &headspace, float &hi, float &lo)
{
|
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
}
return stest;
}
void
mmcollide(DynamicEntity *d, float &hi, float &lo) // collide with a mapmodel
{
loopv(ents)
{
entity &e = ents[i];
if (e.type != MAPMODEL)
continue;
MapModelInfo *mmi = getmminfo(e.attr2);
if (mmi == nil || !mmi.h)
continue;
const float r = mmi.rad + d.radius;
if (fabs(e.x - d.o.x) < r && fabs(e.y - d.o.y) < r) {
float mmz =
(float)(S(e.x, e.y)->floor + mmi.zoff + e.attr3);
if (d.o.z - d.eyeheight < mmz) {
if (mmz < hi)
hi = mmz;
} else if (mmz + mmi.h > lo)
lo = mmz + mmi.h;
}
}
|
|
<
<
>
>
>
|
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
}
return stest;
}
void
mmcollide(DynamicEntity *d, float &hi, float &lo) // collide with a mapmodel
{
for (Entity *e in ents) {
if (e.type != MAPMODEL)
continue;
MapModelInfo *mmi = getmminfo(e.attr2);
if (mmi == nil || !mmi.h)
continue;
const float r = mmi.rad + d.radius;
if (fabs(e.x - d.o.x) < r && fabs(e.y - d.o.y) < r) {
float mmz =
(float)(S(e.x, e.y)->floor + mmi.zoff + e.attr3);
if (d.o.z - d.eyeheight < mmz) {
if (mmz < hi)
hi = mmz;
} else if (mmz + mmi.h > lo)
lo = mmz + mmi.h;
}
}
|