mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 13:28:16 +02:00
Modified the world box to render axes in negative space
Also Modified renderDashedLine to accept params for dash len and gap len so we can display negative axes as dashed lines with 500mm dashes and gaps.
This commit is contained in:
parent
53c5c75071
commit
1f08444369
3 changed files with 33 additions and 16 deletions
|
@ -35,17 +35,33 @@ using namespace std;
|
||||||
void renderWorldBox(gpu::Batch& batch) {
|
void renderWorldBox(gpu::Batch& batch) {
|
||||||
auto geometryCache = DependencyManager::get<GeometryCache>();
|
auto geometryCache = DependencyManager::get<GeometryCache>();
|
||||||
|
|
||||||
// Show edge of world
|
// Show center of world
|
||||||
static const glm::vec3 red(1.0f, 0.0f, 0.0f);
|
static const glm::vec3 red(1.0f, 0.0f, 0.0f);
|
||||||
static const glm::vec3 green(0.0f, 1.0f, 0.0f);
|
static const glm::vec3 green(0.0f, 1.0f, 0.0f);
|
||||||
static const glm::vec3 blue(0.0f, 0.0f, 1.0f);
|
static const glm::vec3 blue(0.0f, 0.0f, 1.0f);
|
||||||
static const glm::vec3 grey(0.5f, 0.5f, 0.5f);
|
static const glm::vec3 grey(0.5f, 0.5f, 0.5f);
|
||||||
|
|
||||||
|
static const glm::vec4 DASHED_RED(1.0f, 0.0f, 0.0f, 1.0f);
|
||||||
|
static const glm::vec4 DASHED_GREEN(0.0f, 1.0f, 0.0f, 1.0f);
|
||||||
|
static const glm::vec4 DASHED_BLUE(0.0f, 0.0f, 1.0f, 1.0f);
|
||||||
|
static const float DASH_LENGTH = 0.5;
|
||||||
|
static const float GAP_LENGTH = 0.5;
|
||||||
auto transform = Transform{};
|
auto transform = Transform{};
|
||||||
|
|
||||||
batch.setModelTransform(transform);
|
batch.setModelTransform(transform);
|
||||||
|
|
||||||
geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(TREE_SCALE, 0.0f, 0.0f), red);
|
geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(TREE_SCALE, 0.0f, 0.0f), red);
|
||||||
|
geometryCache->renderDashedLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(-TREE_SCALE, 0.0f, 0.0f), DASHED_RED,
|
||||||
|
DASH_LENGTH, GAP_LENGTH);
|
||||||
|
|
||||||
geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, TREE_SCALE, 0.0f), green);
|
geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, TREE_SCALE, 0.0f), green);
|
||||||
|
geometryCache->renderDashedLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, -TREE_SCALE, 0.0f), DASHED_GREEN,
|
||||||
|
DASH_LENGTH, GAP_LENGTH);
|
||||||
|
|
||||||
geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, TREE_SCALE), blue);
|
geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, TREE_SCALE), blue);
|
||||||
|
geometryCache->renderDashedLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, -TREE_SCALE), DASHED_BLUE,
|
||||||
|
DASH_LENGTH, GAP_LENGTH);
|
||||||
|
|
||||||
geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, TREE_SCALE), glm::vec3(TREE_SCALE, 0.0f, TREE_SCALE), grey);
|
geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, TREE_SCALE), glm::vec3(TREE_SCALE, 0.0f, TREE_SCALE), grey);
|
||||||
geometryCache->renderLine(batch, glm::vec3(TREE_SCALE, 0.0f, TREE_SCALE), glm::vec3(TREE_SCALE, 0.0f, 0.0f), grey);
|
geometryCache->renderLine(batch, glm::vec3(TREE_SCALE, 0.0f, TREE_SCALE), glm::vec3(TREE_SCALE, 0.0f, 0.0f), grey);
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ void GeometryCache::renderSphere(gpu::Batch& batch, float radius, int slices, in
|
||||||
|
|
||||||
int vertices = slices * (stacks - 1) + 2;
|
int vertices = slices * (stacks - 1) + 2;
|
||||||
int indices = slices * (stacks - 1) * NUM_VERTICES_PER_TRIANGULATED_QUAD;
|
int indices = slices * (stacks - 1) * NUM_VERTICES_PER_TRIANGULATED_QUAD;
|
||||||
|
|
||||||
if ((registered && (!_registeredSphereVertices.contains(id) || _lastRegisteredSphereVertices[id] != radiusKey))
|
if ((registered && (!_registeredSphereVertices.contains(id) || _lastRegisteredSphereVertices[id] != radiusKey))
|
||||||
|| (!registered && !_sphereVertices.contains(radiusKey))) {
|
|| (!registered && !_sphereVertices.contains(radiusKey))) {
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ void GeometryCache::renderSphere(gpu::Batch& batch, float radius, int slices, in
|
||||||
qCDebug(renderutils) << "renderSphere()... RELEASING REGISTERED VERTICES BUFFER";
|
qCDebug(renderutils) << "renderSphere()... RELEASING REGISTERED VERTICES BUFFER";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
auto verticesBuffer = std::make_shared<gpu::Buffer>();
|
auto verticesBuffer = std::make_shared<gpu::Buffer>();
|
||||||
if (registered) {
|
if (registered) {
|
||||||
_registeredSphereVertices[id] = verticesBuffer;
|
_registeredSphereVertices[id] = verticesBuffer;
|
||||||
|
@ -128,7 +128,7 @@ void GeometryCache::renderSphere(gpu::Batch& batch, float radius, int slices, in
|
||||||
qCDebug(renderutils) << "renderSphere()... REUSING PREVIOUSLY REGISTERED VERTICES BUFFER";
|
qCDebug(renderutils) << "renderSphere()... REUSING PREVIOUSLY REGISTERED VERTICES BUFFER";
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((registered && (!_registeredSphereIndices.contains(id) || _lastRegisteredSphereIndices[id] != slicesStacksKey))
|
if ((registered && (!_registeredSphereIndices.contains(id) || _lastRegisteredSphereIndices[id] != slicesStacksKey))
|
||||||
|| (!registered && !_sphereIndices.contains(slicesStacksKey))) {
|
|| (!registered && !_sphereIndices.contains(slicesStacksKey))) {
|
||||||
|
|
||||||
|
@ -1321,7 +1321,9 @@ void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec3& topLeft, cons
|
||||||
batch.draw(gpu::TRIANGLE_STRIP, 4, 0);
|
batch.draw(gpu::TRIANGLE_STRIP, 4, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeometryCache::renderDashedLine(gpu::Batch& batch, const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id) {
|
void GeometryCache::renderDashedLine(gpu::Batch& batch, const glm::vec3& start, const glm::vec3& end, const glm::vec4& color,
|
||||||
|
const float dash_length, const float gap_length, int id) {
|
||||||
|
|
||||||
bool registered = (id != UNKNOWN_ID);
|
bool registered = (id != UNKNOWN_ID);
|
||||||
Vec3PairVec2Pair key(Vec3Pair(start, end), Vec2Pair(glm::vec2(color.x, color.y), glm::vec2(color.z, color.w)));
|
Vec3PairVec2Pair key(Vec3Pair(start, end), Vec2Pair(glm::vec2(color.x, color.y), glm::vec2(color.z, color.w)));
|
||||||
BatchItemDetails& details = registered ? _registeredDashedLines[id] : _dashedLines[key];
|
BatchItemDetails& details = registered ? _registeredDashedLines[id] : _dashedLines[key];
|
||||||
|
@ -1345,16 +1347,14 @@ void GeometryCache::renderDashedLine(gpu::Batch& batch, const glm::vec3& start,
|
||||||
((int(color.w * 255.0f) & 0xFF) << 24);
|
((int(color.w * 255.0f) & 0xFF) << 24);
|
||||||
|
|
||||||
// draw each line segment with appropriate gaps
|
// draw each line segment with appropriate gaps
|
||||||
const float DASH_LENGTH = 0.05f;
|
const float SEGMENT_LENGTH = dash_length + gap_length;
|
||||||
const float GAP_LENGTH = 0.025f;
|
|
||||||
const float SEGMENT_LENGTH = DASH_LENGTH + GAP_LENGTH;
|
|
||||||
float length = glm::distance(start, end);
|
float length = glm::distance(start, end);
|
||||||
float segmentCount = length / SEGMENT_LENGTH;
|
float segmentCount = length / SEGMENT_LENGTH;
|
||||||
int segmentCountFloor = (int)glm::floor(segmentCount);
|
int segmentCountFloor = (int)glm::floor(segmentCount);
|
||||||
|
|
||||||
glm::vec3 segmentVector = (end - start) / segmentCount;
|
glm::vec3 segmentVector = (end - start) / segmentCount;
|
||||||
glm::vec3 dashVector = segmentVector / SEGMENT_LENGTH * DASH_LENGTH;
|
glm::vec3 dashVector = segmentVector / SEGMENT_LENGTH * dash_length;
|
||||||
glm::vec3 gapVector = segmentVector / SEGMENT_LENGTH * GAP_LENGTH;
|
glm::vec3 gapVector = segmentVector / SEGMENT_LENGTH * gap_length;
|
||||||
|
|
||||||
const int FLOATS_PER_VERTEX = 3;
|
const int FLOATS_PER_VERTEX = 3;
|
||||||
details.vertices = (segmentCountFloor + 1) * 2;
|
details.vertices = (segmentCountFloor + 1) * 2;
|
||||||
|
@ -1388,7 +1388,7 @@ void GeometryCache::renderDashedLine(gpu::Batch& batch, const glm::vec3& start,
|
||||||
*(vertex++) = point.y;
|
*(vertex++) = point.y;
|
||||||
*(vertex++) = point.z;
|
*(vertex++) = point.z;
|
||||||
*(colorDataAt++) = compactColor;
|
*(colorDataAt++) = compactColor;
|
||||||
|
|
||||||
for (int i = 0; i < segmentCountFloor; i++) {
|
for (int i = 0; i < segmentCountFloor; i++) {
|
||||||
point += dashVector;
|
point += dashVector;
|
||||||
*(vertex++) = point.x;
|
*(vertex++) = point.x;
|
||||||
|
|
|
@ -179,7 +179,8 @@ public:
|
||||||
void renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2,
|
void renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2,
|
||||||
const glm::vec4& color1, const glm::vec4& color2, int id = UNKNOWN_ID);
|
const glm::vec4& color1, const glm::vec4& color2, int id = UNKNOWN_ID);
|
||||||
|
|
||||||
void renderDashedLine(gpu::Batch& batch, const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id = UNKNOWN_ID);
|
void renderDashedLine(gpu::Batch& batch, const glm::vec3& start, const glm::vec3& end, const glm::vec4& color,
|
||||||
|
const float dash_length = 0.05f, const float gap_length = 0.025f, int id = UNKNOWN_ID);
|
||||||
|
|
||||||
void renderLine(gpu::Batch& batch, const glm::vec2& p1, const glm::vec2& p2, const glm::vec3& color, int id = UNKNOWN_ID)
|
void renderLine(gpu::Batch& batch, const glm::vec2& p1, const glm::vec2& p2, const glm::vec3& color, int id = UNKNOWN_ID)
|
||||||
{ renderLine(batch, p1, p2, glm::vec4(color, 1.0f), id); }
|
{ renderLine(batch, p1, p2, glm::vec4(color, 1.0f), id); }
|
||||||
|
@ -189,9 +190,9 @@ public:
|
||||||
|
|
||||||
|
|
||||||
void renderLine(gpu::Batch& batch, const glm::vec2& p1, const glm::vec2& p2,
|
void renderLine(gpu::Batch& batch, const glm::vec2& p1, const glm::vec2& p2,
|
||||||
const glm::vec3& color1, const glm::vec3& color2, int id = UNKNOWN_ID)
|
const glm::vec3& color1, const glm::vec3& color2, int id = UNKNOWN_ID)
|
||||||
{ renderLine(batch, p1, p2, glm::vec4(color1, 1.0f), glm::vec4(color2, 1.0f), id); }
|
{ renderLine(batch, p1, p2, glm::vec4(color1, 1.0f), glm::vec4(color2, 1.0f), id); }
|
||||||
|
|
||||||
void renderLine(gpu::Batch& batch, const glm::vec2& p1, const glm::vec2& p2,
|
void renderLine(gpu::Batch& batch, const glm::vec2& p1, const glm::vec2& p2,
|
||||||
const glm::vec4& color1, const glm::vec4& color2, int id = UNKNOWN_ID);
|
const glm::vec4& color1, const glm::vec4& color2, int id = UNKNOWN_ID);
|
||||||
|
|
||||||
|
@ -216,7 +217,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
GeometryCache();
|
GeometryCache();
|
||||||
virtual ~GeometryCache();
|
virtual ~GeometryCache();
|
||||||
|
|
||||||
typedef QPair<int, int> IntPair;
|
typedef QPair<int, int> IntPair;
|
||||||
typedef QPair<unsigned int, unsigned int> VerticesIndices;
|
typedef QPair<unsigned int, unsigned int> VerticesIndices;
|
||||||
|
|
||||||
|
@ -247,7 +248,7 @@ private:
|
||||||
~BatchItemDetails();
|
~BatchItemDetails();
|
||||||
void clear();
|
void clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
QHash<IntPair, VerticesIndices> _coneVBOs;
|
QHash<IntPair, VerticesIndices> _coneVBOs;
|
||||||
|
|
||||||
int _nextID;
|
int _nextID;
|
||||||
|
|
Loading…
Reference in a new issue