Skip to content

Commit ac2316d

Browse files
authored
Refactor of translateY and preliminary work on collisions stuff (#908)
* Npc::position -> ::centerPosition in simple cases #605 * more sound cases * Npc::position -> ::centerPosition * more bbox draws and ray-mobsi intersection #182 * dbg bbox for items and new pick-item code * double bboxCol size - seem to be halfed in assets * ray-to-item bbox test * remove Npc::translateY * introduce Npc::collosionCenter * introduce C_Focus::npc_longrange * update object matrix in wld_insertnpc * split show-box vs show-rays * MOBSI: fixup billboards and graves * rework npc-to-mobsi interation * rework npc-to-mobsi interation P2 * cleanups * cleanups * cleanups * remove 'ground' rays for mobsi
1 parent 143bed3 commit ac2316d

32 files changed

Lines changed: 508 additions & 259 deletions

game/game/constants.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ enum Guild: uint32_t {
126126
};
127127

128128
enum {
129-
MAX_AI_USE_DISTANCE = 150
129+
MAX_AI_USE_DISTANCE = 165,
130+
MOBSI_SEARCH_DISTANCE = 100*10,
130131
};
131132

132133
enum {

game/game/gamescript.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,8 @@ void GameScript::fixNpcPosition(Npc& npc, float angle0, float distBias) {
766766
auto pos0 = npc.position();
767767

768768
for(int r = 0; r<=800; r+=20) {
769-
for(float ang = 0; ang<360; ang+=30.f) {
770-
float a = float((ang+angle0)*M_PI/180.0);
769+
for(int ang = 0; ang<360; ang+=30) {
770+
float a = float((float(ang)+angle0)*M_PI/180.0);
771771
float d = float(r)+distBias;
772772
auto p = pos0+Vec3(std::cos(a)*d, 0, std::sin(a)*d);
773773

@@ -776,12 +776,18 @@ void GameScript::fixNpcPosition(Npc& npc, float angle0, float distBias) {
776776
continue;
777777
p.y = ray.v.y;
778778
npc.setPosition(p);
779-
if(!npc.hasCollision())
779+
if(!npc.hasCollision()) {
780+
npc.updateTransform();
780781
return;
782+
}
783+
if(d==0) {
784+
// no need to loop multiple angles, with R of zero
785+
break;
786+
}
781787
}
782788
}
783789

784-
npc.setPosition(pos0);
790+
// npc.setPosition(pos0);
785791
}
786792

787793
void GameScript::eventPlayAni(Npc& npc, std::string_view ani) {
@@ -3384,7 +3390,7 @@ void GameScript::snd_play3d(std::shared_ptr<zenkit::INpc> npcRef, std::string_vi
33843390
return;
33853391
for(auto& c:file)
33863392
c = char(std::toupper(c));
3387-
auto sfx = ::Sound(*owner.world(),::Sound::T_3D,file,npc->position(),0.f,false);
3393+
auto sfx = ::Sound(*owner.world(),::Sound::T_3D,file,npc->centerPosition(),0.f,false);
33883394
sfx.play();
33893395
}
33903396

game/game/movealgo.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -709,14 +709,6 @@ int32_t MoveAlgo::diveTime() const {
709709
bool MoveAlgo::isClose(const Npc& npc, const Npc& p, float dist) {
710710
float len = npc.qDistTo(p);
711711
return (len<dist*dist);
712-
/*
713-
auto dp = npc.position()-p;
714-
dp.y = 0;
715-
float len = dp.quadLength();
716-
if(len<dist*dist)
717-
return true;
718-
return false;
719-
*/
720712
}
721713

722714
bool MoveAlgo::isClose(const Npc& npc, const WayPoint& p) {
@@ -727,20 +719,17 @@ bool MoveAlgo::isClose(const Npc& npc, const WayPoint& p) {
727719
}
728720

729721
bool MoveAlgo::isClose(const Npc& npc, const WayPoint& p, float dist) {
730-
auto px = p.position();
731-
px.y += npc.translateY();
732-
733-
float len = npc.qDistTo(px);
722+
auto dp = p.groundPos - npc.position();
723+
float len = dp.quadLength();
734724
return (len<dist*dist);
735725
}
736726

737727
bool MoveAlgo::isClose(const Npc& npc, const Tempest::Vec3& p, float dist) {
738-
// NOTE: this need to be consistent with current go2 point implementation
739-
auto dp = (p - npc.position());
740-
if(std::abs(dp.y)<250)
741-
dp.y = 0;
728+
auto dp = (p - npc.centerPosition());
742729
float len = dp.quadLength();
743-
return (len<dist*dist);
730+
// NOTE: extra check fo vertical only distances:
731+
// some repair planks are too high (~5 meters) in the air
732+
return (len<dist*dist) || Tempest::Vec2(dp.x,dp.z).quadLength() < 1.f;
744733
}
745734

746735
bool MoveAlgo::startClimb(JumpStatus jump) {

game/game/playercontrol.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,23 @@ void PlayerControl::onRotateMouse(float dAngleX, float dAngleY) {
252252
rotMouseY += dAngleY;
253253
}
254254

255+
void PlayerControl::drawVobRay(DbgPainter& p) const {
256+
auto w = Gothic::inst().world();
257+
if(w==nullptr || w->player()==nullptr)
258+
return;
259+
auto pl = w->player();
260+
auto focus = findFocus(&currentFocus);
261+
if(focus.interactive!=nullptr) {
262+
focus.interactive->drawVobRay(p, *pl);
263+
}
264+
if(focus.item!=nullptr) {
265+
focus.item->drawVobRay(p, *pl);
266+
}
267+
if(focus.npc!=nullptr) {
268+
pl->drawVobRay(p, *focus.npc);
269+
}
270+
}
271+
255272
void PlayerControl::tickFocus() {
256273
currentFocus = findFocus(&currentFocus);
257274
setTarget(currentFocus.npc);
@@ -358,7 +375,7 @@ void PlayerControl::moveFocus(FocusAction act) {
358375
return;
359376

360377
auto vp = c->viewProj();
361-
auto pos = currentFocus.npc->position()+Tempest::Vec3(0,currentFocus.npc->translateY(),0);
378+
auto pos = currentFocus.npc->centerPosition();
362379
vp.project(pos);
363380

364381
Npc* next = nullptr;
@@ -367,7 +384,7 @@ void PlayerControl::moveFocus(FocusAction act) {
367384
auto npc = w->npcById(i);
368385
if(npc->isPlayer())
369386
continue;
370-
auto p = npc->position()+Tempest::Vec3(0,npc->translateY(),0);
387+
auto p = npc->centerPosition();
371388
vp.project(p);
372389

373390
if(std::abs(p.x)>1.f || std::abs(p.y)>1.f || p.z<0.f)
@@ -481,7 +498,7 @@ void PlayerControl::marvinO() {
481498
w->setPlayer(target);
482499
}
483500

484-
Focus PlayerControl::findFocus(Focus* prev) {
501+
Focus PlayerControl::findFocus(const Focus* prev) const {
485502
auto w = Gothic::inst().world();
486503
auto c = Gothic::inst().camera();
487504
if(w==nullptr)

game/game/playercontrol.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
class DialogMenu;
1010
class InventoryMenu;
11+
class DbgPainter;
1112
class World;
1213
class Interactive;
1314
class Npc;
@@ -25,6 +26,8 @@ class PlayerControl final {
2526
bool isPressed(KeyCodec::Action a) const;
2627
void onRotateMouse(float dAngleX, float dAngleY);
2728

29+
void drawVobRay(DbgPainter& p) const;
30+
2831
void changeZoom(int delta);
2932
void tickFocus();
3033
void clearFocus();
@@ -161,7 +164,7 @@ class PlayerControl final {
161164
void toggleWalkMode();
162165
void toggleSneakMode();
163166
void moveFocus(FocusAction act);
164-
Focus findFocus(Focus *prev);
167+
Focus findFocus(const Focus* prev) const;
165168

166169
void clrDraw();
167170
void implMove(uint64_t dt);

game/gothic.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ class Gothic final {
139139
bool doVobBox() const { return vobBox; }
140140
void setVobBox(bool v) { vobBox = v; }
141141

142+
bool doVobRays() const { return vobRays; }
143+
void setVobRays(bool v) { vobRays = v; }
144+
142145
bool isBenchmarkMode() const;
143146
bool isBenchmarkModeCi() const;
144147
void setBenchmarkMode(Benchmark b);
@@ -221,6 +224,7 @@ class Gothic final {
221224
bool showFpsCounter = false;
222225
bool showTime = false;
223226
bool vobBox = false;
227+
bool vobRays = false;
224228
Benchmark isBenchmark = Benchmark::None;
225229

226230
std::string wrldDef, plDef, gameDatDef, ouDef;

game/graphics/effect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Effect::Effect(PfxEmitter&& pfx, std::string_view node)
1616
}
1717

1818
Effect::Effect(const VisualFx& vfx, World& owner, const Npc& src, SpellFxKey key)
19-
:Effect(vfx, owner, src.position(), key) {
19+
:Effect(vfx, owner, src.centerPosition(), key) {
2020
}
2121

2222
Effect::Effect(const VisualFx& v, World& owner, const Vec3& inPos, SpellFxKey k) {

game/graphics/mesh/protomesh.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -318,26 +318,18 @@ size_t ProtoMesh::skinedNodesCount() const {
318318
return ret;
319319
}
320320

321-
Tempest::Matrix4x4 ProtoMesh::mapToRoot(size_t n) const {
322-
Tempest::Matrix4x4 m;
323-
m.identity();
324-
325-
while(n<nodes.size()) {
326-
auto& nx = nodes[n];
327-
auto mx = nx.transform;
328-
mx.mul(m);
329-
m = mx;
330-
n = nx.parentId;
331-
}
332-
return m;
333-
}
334-
335321
size_t ProtoMesh::findNode(std::string_view name, size_t def) const {
336322
if(skeleton==nullptr)
337323
return def;
338324
return skeleton->findNode(name,def);
339325
}
340326

327+
const Vec3* ProtoMesh::bboxCol() const {
328+
if(skeleton==nullptr)
329+
return bbox;
330+
return skeleton->bboxCol;
331+
}
332+
341333
void ProtoMesh::setupScheme(std::string_view s) {
342334
auto sep = s.find("_");
343335
if(sep!=std::string::npos) {

game/graphics/mesh/protomesh.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ class ProtoMesh {
8989
std::string scheme, fname;
9090

9191
size_t skinedNodesCount() const;
92-
Tempest::Matrix4x4 mapToRoot(size_t node) const;
9392
size_t findNode(std::string_view name,size_t def=size_t(-1)) const;
93+
const Tempest::Vec3* bboxCol() const;
9494

9595
private:
9696
void setupScheme(std::string_view s);

game/graphics/mesh/skeleton.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Skeleton::Skeleton(const zenkit::ModelHierarchy& src, const Animation* anim, std
1111
bboxCol[0] = {src.collision_bbox.min.x, src.collision_bbox.min.y, src.collision_bbox.min.z};
1212
bboxCol[1] = {src.collision_bbox.max.x, src.collision_bbox.max.y, src.collision_bbox.max.z};
1313

14+
// bbox size apears to be halfed in source file
15+
bboxCol[0] *= 2.f;
16+
bboxCol[1] *= 2.f;
17+
1418
nodes.resize(src.nodes.size());
1519
tr.resize(src.nodes.size());
1620

@@ -83,7 +87,8 @@ std::string_view Skeleton::defaultMesh() const {
8387
}
8488

8589
float Skeleton::colisionHeight() const {
86-
return std::fabs(bboxCol[1].y-bboxCol[0].y);
90+
// scale by 0.5, to be compatible with old behaviour for now
91+
return std::fabs(bboxCol[1].y-bboxCol[0].y) * 0.5f;
8792
}
8893

8994
void Skeleton::mkSkeleton() {

0 commit comments

Comments
 (0)