Skip to content

Commit 2875a54

Browse files
committed
marvin: draw vob box
#182
1 parent 26aec10 commit 2875a54

14 files changed

Lines changed: 103 additions & 3 deletions

File tree

game/gothic.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ class Gothic final {
136136
bool doClock() const { return showTime; }
137137
void setClock(bool t) { showTime = t; }
138138

139+
bool doVobBox() const { return vobBox; }
140+
void setVobBox(bool v) { vobBox = v; }
141+
139142
bool isBenchmarkMode() const;
140143
bool isBenchmarkModeCi() const;
141144
void setBenchmarkMode(Benchmark b);
@@ -217,6 +220,7 @@ class Gothic final {
217220
bool desktop = false;
218221
bool showFpsCounter = false;
219222
bool showTime = false;
223+
bool vobBox = false;
220224
Benchmark isBenchmark = Benchmark::None;
221225

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

game/mainwindow.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,14 @@ void MainWindow::paintEvent(PaintEvent& event) {
273273
}
274274
}
275275

276+
if(Gothic::inst().doVobBox() && !Gothic::inst().isDesktop()) {
277+
auto c = Gothic::inst().camera();
278+
if(world!=nullptr && c!=nullptr) {
279+
DbgPainter dbg(p,c->viewProj(),w(),h());
280+
world->drawVobBoxNpcNear(dbg);
281+
}
282+
}
283+
276284
if(auto wx = Gothic::inst().worldView()) {
277285
wx->dbgClusters(p, Vec2(float(w()), float(h())));
278286
}

game/marvin.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Marvin::Marvin() {
5656
%d - integer
5757
%f - floating point number
5858
*/
59+
// http://forenarchiv.worldofplayers.de/thread.php?id=85859&post=45890#45890
5960
cmd = std::vector<Cmd>{
6061
// gdb-like commands
6162
{"p %v", C_PrintVar},
@@ -99,7 +100,7 @@ Marvin::Marvin() {
99100
{"ztoggle showportals", C_Invalid},
100101
{"ztoggle showtraceray", C_Invalid},
101102
{"ztoggle tnl", C_Invalid},
102-
{"ztoggle vobbox", C_Invalid},
103+
{"ztoggle vobbox", C_ToggleVobBox},
103104
{"zvideores %d %d %d", C_Invalid},
104105

105106
// game
@@ -351,6 +352,10 @@ bool Marvin::exec(std::string_view v) {
351352
Gothic::inst().setFRate(!Gothic::inst().doFrate());
352353
return true;
353354
}
355+
case C_ToggleVobBox:{
356+
Gothic::inst().setVobBox(!Gothic::inst().doVobBox());
357+
return true;
358+
}
354359
case C_ToggleTime:{
355360
Gothic::inst().setClock(!Gothic::inst().doClock());
356361
return true;

game/marvin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class Marvin {
2828

2929
// rendering
3030
C_ToggleFrame,
31+
C_ToggleVobBox,
32+
3133
// game
3234
C_ToggleDesktop,
3335
C_ToggleTime,

game/physics/dynamicworld.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "world/bullet.h"
1515
#include "world/world.h"
1616

17+
#include "utils/dbgpainter.h"
18+
1719
const float DynamicWorld::ghostPadding=50-22.5f;
1820
const float DynamicWorld::ghostHeight =140;
1921
const float DynamicWorld::worldHeight =20000;
@@ -976,6 +978,30 @@ const Tempest::Vec3& DynamicWorld::NpcItem::position() const {
976978
return obj->pos;
977979
}
978980

981+
void DynamicWorld::NpcItem::debugDraw(DbgPainter& p) const {
982+
p.setBrush(Tempest::Color(0,1,0));
983+
p.drawPoint(obj->pos);
984+
985+
const auto cen = Tempest::Vec3(obj->pos.x, centerY(), obj->pos.z);
986+
p.setBrush(Tempest::Color(0,0,1));
987+
p.drawPoint(cen);
988+
989+
p.setPen(Tempest::Color(1,1,1));
990+
p.drawLine(cen, cen+Tempest::Vec3(0,25,0));
991+
p.setPen(Tempest::Color(1,1,0));
992+
p.drawLine(cen, cen+Tempest::Vec3(25,0,0));
993+
p.setPen(Tempest::Color(1,0.5f,0));
994+
p.drawLine(cen, cen+Tempest::Vec3(0,0,25));
995+
996+
btVector3 aabb0, aabb1;
997+
obj->getAabb(aabb0, aabb1);
998+
999+
const auto min = Tempest::Vec3(aabb0.x()*100.f, aabb0.y()*100.f, aabb0.z()*100.f);
1000+
const auto max = Tempest::Vec3(aabb1.x()*100.f, aabb1.y()*100.f, aabb1.z()*100.f);
1001+
p.setPen(Tempest::Color(1,0.5f,0));
1002+
p.drawAabb(min, max);
1003+
}
1004+
9791005
bool DynamicWorld::NpcItem::testMove(const Tempest::Vec3& to, CollisionTest& out) {
9801006
if(!obj)
9811007
return false;

game/physics/dynamicworld.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Bullet;
2222
class Npc;
2323
class Item;
2424
class Interactive;
25+
class DbgPainter;
2526

2627
class CollisionWorld;
2728

@@ -85,6 +86,8 @@ class DynamicWorld final {
8586
void setPosition(const Tempest::Vec3& pos);
8687
const Tempest::Vec3& position() const;
8788

89+
void debugDraw(DbgPainter& p) const;
90+
8891
void setEnable(bool e);
8992
void setUserPointer(void* p);
9093

game/utils/dbgpainter.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,36 @@ void DbgPainter::drawLine(const Vec3& a, const Vec3& b) {
5353

5454
painter.drawLine(x0,y0,x1,y1);
5555
}
56+
57+
void DbgPainter::drawPoint(const Tempest::Vec3& a, int radiusPx) {
58+
Vec3 pa = a;
59+
float wa = 1;
60+
mvp.project(pa.x,pa.y,pa.z,wa);
61+
62+
if(wa<0.001f)
63+
return;
64+
65+
pa /= wa;
66+
67+
int x0 = int((pa.x+1.f)*0.5f*float(w));
68+
int y0 = int((pa.y+1.f)*0.5f*float(h));
69+
70+
painter.drawRect(x0-radiusPx,y0-radiusPx, 1+2*radiusPx, 1+2*radiusPx);
71+
}
72+
73+
void DbgPainter::drawAabb(const Tempest::Vec3& min, const Tempest::Vec3& max) {
74+
drawLine(Tempest::Vec3(min.x, min.y, min.z), Tempest::Vec3(max.x, min.y, min.z));
75+
drawLine(Tempest::Vec3(max.x, min.y, min.z), Tempest::Vec3(max.x, min.y, max.z));
76+
drawLine(Tempest::Vec3(max.x, min.y, max.z), Tempest::Vec3(min.x, min.y, max.z));
77+
drawLine(Tempest::Vec3(min.x, min.y, max.z), Tempest::Vec3(min.x, min.y, min.z));
78+
79+
drawLine(Tempest::Vec3(min.x, max.y, min.z), Tempest::Vec3(max.x, max.y, min.z));
80+
drawLine(Tempest::Vec3(max.x, max.y, min.z), Tempest::Vec3(max.x, max.y, max.z));
81+
drawLine(Tempest::Vec3(max.x, max.y, max.z), Tempest::Vec3(min.x, max.y, max.z));
82+
drawLine(Tempest::Vec3(min.x, max.y, max.z), Tempest::Vec3(min.x, max.y, min.z));
83+
84+
drawLine(Tempest::Vec3(min.x, min.y, min.z), Tempest::Vec3(min.x, max.y, min.z));
85+
drawLine(Tempest::Vec3(max.x, min.y, min.z), Tempest::Vec3(max.x, max.y, min.z));
86+
drawLine(Tempest::Vec3(max.x, min.y, max.z), Tempest::Vec3(max.x, max.y, max.z));
87+
drawLine(Tempest::Vec3(min.x, min.y, max.z), Tempest::Vec3(min.x, max.y, max.z));
88+
}

game/utils/dbgpainter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ class DbgPainter {
1212

1313
void drawText(int x, int y, std::string_view txt);
1414
void drawText(const Tempest::Vec3& a, std::string_view txt);
15+
1516
void drawLine(const Tempest::Vec3& a, const Tempest::Vec3& b);
16-
void drawPoint();
17+
void drawPoint(const Tempest::Vec3& a, int radiusPx = 5);
18+
void drawAabb(const Tempest::Vec3& min, const Tempest::Vec3& max);
1719

1820
Tempest::Painter& painter;
1921
const Tempest::Matrix4x4 mvp;

game/world/objects/npc.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ void Npc::postValidate() {
327327
currentInteract = nullptr;
328328
}
329329

330+
void Npc::drawVobBox(DbgPainter& p) const {
331+
physic.debugDraw(p);
332+
}
333+
330334
void Npc::saveAiState(Serialize& fout) const {
331335
fout.write(aniWaitTime,waitTime,faiWaitTime,outWaitTime);
332336
fout.write(uint8_t(aiPolicy));

game/world/objects/npc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ class Npc final {
8282
void load(Serialize& fout, size_t id, std::string_view directory);
8383
void postValidate();
8484

85+
void drawVobBox(DbgPainter& p) const;
86+
8587
bool setPosition (float x,float y,float z);
8688
bool setPosition (const Tempest::Vec3& pos);
8789
void setDirection(const Tempest::Vec3& pos);

0 commit comments

Comments
 (0)