-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Terrain-relative height proof of concept
- Loading branch information
1 parent
f5da6a7
commit 928884a
Showing
8 changed files
with
512 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include "EntityPosition.h" | ||
#include "Math.h" | ||
#include "Utils.h" | ||
|
||
using namespace ROCKY_NAMESPACE; | ||
using namespace ROCKY_NAMESPACE::util; | ||
|
||
#undef LC | ||
#define LC "[EntityPosition] " | ||
|
||
EntityPosition EntityPosition::INVALID; | ||
|
||
EntityPosition::EntityPosition() | ||
{ | ||
//nop | ||
} | ||
|
||
EntityPosition& | ||
EntityPosition::operator=(EntityPosition&& rhs) | ||
{ | ||
basePosition = rhs.basePosition; | ||
altitude = rhs.altitude; | ||
rhs.basePosition = { }; // invalidate rhs | ||
return *this; | ||
} | ||
|
||
EntityPosition::EntityPosition(const GeoPoint& in_basePosition, double in_altitude) : | ||
basePosition(in_basePosition), | ||
altitude(in_altitude) | ||
{ | ||
//nop | ||
} | ||
|
||
bool | ||
EntityPosition::transform(const SRS& outSRS, EntityPosition& output) const | ||
{ | ||
if (valid() && outSRS.valid()) | ||
{ | ||
GeoPoint outBasePosition; | ||
if (basePosition.transform(outSRS, outBasePosition)) | ||
{ | ||
output = EntityPosition(outBasePosition, altitude); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
bool | ||
EntityPosition::transformInPlace(const SRS& to_srs) | ||
{ | ||
if (valid() && to_srs.valid()) | ||
{ | ||
if (basePosition.transformInPlace(to_srs)) | ||
{ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
#include "json.h" | ||
|
||
namespace ROCKY_NAMESPACE | ||
{ | ||
void to_json(json& j, const EntityPosition& obj) { | ||
if (obj.valid()) { | ||
j = json::object(); | ||
set(j, "basePosition", obj.basePosition); | ||
set(j, "altitude", obj.altitude); | ||
} | ||
} | ||
|
||
void from_json(const json& j, EntityPosition& obj) { | ||
GeoPoint basePosition; | ||
double altitude = 0; | ||
|
||
get_to(j, "basePosition", basePosition); | ||
get_to(j, "altitude", altitude); | ||
|
||
obj = EntityPosition(basePosition, altitude); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* rocky c++ | ||
* Copyright 2024 Pelican Mapping | ||
* MIT License | ||
*/ | ||
#pragma once | ||
|
||
#include <rocky/GeoPoint.h> | ||
|
||
namespace ROCKY_NAMESPACE | ||
{ | ||
/** | ||
* A georeferenced 3D point with terrain-relative altitude | ||
*/ | ||
class ROCKY_EXPORT EntityPosition | ||
{ | ||
public: | ||
GeoPoint basePosition; | ||
double altitude; | ||
|
||
//! Constructs an empty (and invalid) EntityPosition. | ||
EntityPosition(); | ||
|
||
//! Constructs a EntityPosition | ||
EntityPosition(const GeoPoint& srs, double altitude); | ||
|
||
//! Destruct | ||
~EntityPosition() { } | ||
|
||
//! Transforms this EntityPosition into another SRS and puts the | ||
//! output in the "output" | ||
//! @return true upon success, false upon failure | ||
bool transform(const SRS& outSRS, EntityPosition& output) const; | ||
|
||
//! Transforms this point in place to another SRS | ||
bool transformInPlace(const SRS& srs); | ||
|
||
bool operator == (const EntityPosition& rhs) const { | ||
return basePosition == rhs.basePosition && altitude == rhs.altitude; | ||
} | ||
|
||
bool operator != (const EntityPosition& rhs) const { | ||
return !operator==(rhs); | ||
} | ||
|
||
//! Does this object contain a valid geo point? | ||
bool valid() const { | ||
return basePosition.valid(); | ||
} | ||
|
||
public: | ||
static EntityPosition INVALID; | ||
|
||
// copy/move ops | ||
EntityPosition(const EntityPosition& rhs) = default; | ||
EntityPosition& operator=(const EntityPosition& rhs) = default; | ||
EntityPosition(EntityPosition&& rhs) { *this = rhs; } | ||
EntityPosition& operator=(EntityPosition&& rhs); | ||
}; | ||
|
||
|
||
/** | ||
* Base class for any object that has a position on a Map. | ||
*/ | ||
class TerrainRelativePositionedObject | ||
{ | ||
public: | ||
//! Center position of the object | ||
virtual const EntityPosition& objectPosition() const = 0; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.