diff options
author | Aki <please@ignore.pl> | 2022-04-01 21:23:39 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-04-01 21:23:39 +0200 |
commit | 3c487c5cd69c53d6fea948643c0a76df03516605 (patch) | |
tree | 72730c7b8b26a5ef8fc9a987ec4c16129efd5aac /StarsEx/RLoc.cpp | |
parent | 8f353abd0bfe18baddd8a8250ab7c4f2d1c83a6e (diff) | |
download | starshatter-3c487c5cd69c53d6fea948643c0a76df03516605.zip starshatter-3c487c5cd69c53d6fea948643c0a76df03516605.tar.gz starshatter-3c487c5cd69c53d6fea948643c0a76df03516605.tar.bz2 |
Moved Stars45 to StarsEx
Diffstat (limited to 'StarsEx/RLoc.cpp')
-rw-r--r-- | StarsEx/RLoc.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/StarsEx/RLoc.cpp b/StarsEx/RLoc.cpp new file mode 100644 index 0000000..911c4ea --- /dev/null +++ b/StarsEx/RLoc.cpp @@ -0,0 +1,86 @@ +/* Starshatter: The Open Source Project + Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors + Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors + Copyright (c) 1997-2006, Destroyer Studios LLC. + + AUTHOR: John DiCamillo + + + OVERVIEW + ======== + Navigation Point class implementation +*/ + +#include "RLoc.h" +#include "Random.h" + +// +----------------------------------------------------------------------+ + +RLoc::RLoc() + : rloc(0), dex(0), dex_var(5.0e3f), az(0), az_var(3.1415f), el(0), el_var(0.1f) +{ } + +RLoc::RLoc(const Point& l, double d, double dv) + : loc(l), base_loc(l), rloc(0), dex((float) d), dex_var((float) dv), + az(0), az_var(3.1415f), el(0), el_var(0.1f) +{ } + +RLoc::RLoc(RLoc* l, double d, double dv) + : rloc(l), dex((float) d), dex_var((float) dv), + az(0), az_var(3.1415f), el(0), el_var(0.1f) +{ } + +RLoc::RLoc(const RLoc& r) + : loc(r.loc), base_loc(r.base_loc), rloc(r.rloc), + dex(r.dex), dex_var(r.dex_var), + az(r.az), az_var(r.az_var), + el(r.el), el_var(r.el_var) +{ } + +RLoc::~RLoc() +{ } + +// +----------------------------------------------------------------------+ + +const Point& +RLoc::Location() +{ + if (rloc || dex > 0) Resolve(); + return loc; +} + +// +----------------------------------------------------------------------+ + +void +RLoc::Resolve() +{ + if (rloc) { + base_loc = rloc->Location(); + rloc = 0; + } + + if (dex > 0) { + double d = dex + Random(-dex_var, dex_var); + double a = az + Random(-az_var, az_var); + double e = el + Random(-el_var, el_var); + + Point p = Point(d * sin(a), + d * -cos(a), + d * sin(e)); + + loc = base_loc + p; + dex = 0; + } + else { + loc = base_loc; + } +} + +// +----------------------------------------------------------------------+ + +void +RLoc::SetBaseLocation(const Point& l) +{ + base_loc = l; + loc = l; +} |