OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
waypoint.cpp
Go to the documentation of this file.
1#include "waypoint.h"
2
3#include <cmath>
4#include <cstring>
5#include <cctype>
6
7using namespace Tempest;
8
9static std::string upcaseof(std::string_view src) {
10 auto ret = std::string(src);
11 for(auto& i:ret)
12 i=char(std::toupper(i));
13 return ret;
14 }
15
18
19WayPoint::WayPoint(const zenkit::WayPoint &dat)
20 : pos(dat.position.x, dat.position.y, dat.position.z),
21 dir(dat.direction.x, dat.direction.y, dat.direction.z),
22 underWater(dat.under_water),
23 name(upcaseof(dat.name)) {
24 }
25
26WayPoint::WayPoint(const Vec3& pos, std::string_view name)
27 :pos(pos),freePoint(true),name(upcaseof(name)){
28 }
29
30WayPoint::WayPoint(const Vec3& pos, const Vec3& dir, std::string_view name, bool isFp)
31 :pos(pos), dir(dir), freePoint(isFp), name(upcaseof(name)){
32 }
33
35 return freePoint;
36 }
37
39 return conn.size()>0;
40 }
41
42bool WayPoint::checkName(std::string_view n, bool inexact) const {
43 if(n.empty())
44 return false;
45 if(name==n)
46 return true;
47 if(inexact && name.find(n)!=std::string::npos)
48 return true;
49 return false;
50 }
51
52Vec3 WayPoint::position() const {
53 return pos;
54 }
55
56Vec3 WayPoint::direction() const {
57 return dir;
58 }
59
60float WayPoint::qDistTo(float ix, float iy, float iz) const {
61 float dx = pos.x-ix;
62 float dy = pos.y-iy;
63 float dz = pos.z-iz;
64 return dx*dx+dy*dy+dz*dz;
65 }
66
68 int32_t l = int32_t(std::sqrt(qDistTo(w.pos.x,w.pos.y,w.pos.z)));
69 if(l<=0)
70 return;
71 Conn c;
72 c.point = &w;
73 c.len = l;
74 conn.push_back(c);
75 }
76
77bool WayPoint::hasLadderConn(const WayPoint* w) const {
78 if(w!=nullptr && w->ladder!=nullptr && w->ladder==ladder)
79 return true;
80 return false;
81 }
bool isConnected() const
Definition waypoint.cpp:38
Tempest::Vec3 position() const
Definition waypoint.cpp:52
Interactive * ladder
Definition waypoint.h:36
Tempest::Vec3 pos
Definition waypoint.h:31
bool isFreePoint() const
Definition waypoint.cpp:34
std::string name
Definition waypoint.h:35
void connect(WayPoint &w)
Definition waypoint.cpp:67
Tempest::Vec3 dir
Definition waypoint.h:32
bool checkName(std::string_view name, bool inexact=true) const
Definition waypoint.cpp:42
bool hasLadderConn(const WayPoint *w) const
Definition waypoint.cpp:77
float qDistTo(float x, float y, float z) const
Definition waypoint.cpp:60
Tempest::Vec3 direction() const
Definition waypoint.cpp:56
bool freePoint
Definition waypoint.h:34
WayPoint * point
Definition waypoint.h:39
int32_t len
Definition waypoint.h:40
static std::string upcaseof(std::string_view src)
Definition waypoint.cpp:9