mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-08 21:57:05 +02:00
Merge branch 'batch-overlay' of https://github.com/huffman/hifi into yellow
This commit is contained in:
commit
0653be445a
6 changed files with 496 additions and 305 deletions
|
@ -43,72 +43,88 @@ void BillboardOverlay::render(RenderArgs* args) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnable(GL_ALPHA_TEST);
|
glm::quat rotation;
|
||||||
glAlphaFunc(GL_GREATER, 0.5f);
|
if (_isFacingAvatar) {
|
||||||
|
// rotate about vertical to face the camera
|
||||||
|
rotation = Application::getInstance()->getCamera()->getRotation();
|
||||||
|
rotation *= glm::angleAxis(glm::pi<float>(), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
|
rotation *= getRotation();
|
||||||
|
} else {
|
||||||
|
rotation = getRotation();
|
||||||
|
}
|
||||||
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
float imageWidth = _texture->getWidth();
|
||||||
glDisable(GL_LIGHTING);
|
float imageHeight = _texture->getHeight();
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, _texture->getID());
|
QRect fromImage;
|
||||||
|
if (_fromImage.isNull()) {
|
||||||
|
fromImage.setX(0);
|
||||||
|
fromImage.setY(0);
|
||||||
|
fromImage.setWidth(imageWidth);
|
||||||
|
fromImage.setHeight(imageHeight);
|
||||||
|
} else {
|
||||||
|
float scaleX = imageWidth / _texture->getOriginalWidth();
|
||||||
|
float scaleY = imageHeight / _texture->getOriginalHeight();
|
||||||
|
|
||||||
glPushMatrix(); {
|
fromImage.setX(scaleX * _fromImage.x());
|
||||||
glTranslatef(_position.x, _position.y, _position.z);
|
fromImage.setY(scaleY * _fromImage.y());
|
||||||
glm::quat rotation;
|
fromImage.setWidth(scaleX * _fromImage.width());
|
||||||
if (_isFacingAvatar) {
|
fromImage.setHeight(scaleY * _fromImage.height());
|
||||||
// rotate about vertical to face the camera
|
}
|
||||||
rotation = Application::getInstance()->getCamera()->getRotation();
|
|
||||||
rotation *= glm::angleAxis(glm::pi<float>(), glm::vec3(0.0f, 1.0f, 0.0f));
|
|
||||||
rotation *= getRotation();
|
|
||||||
} else {
|
|
||||||
rotation = getRotation();
|
|
||||||
}
|
|
||||||
glm::vec3 axis = glm::axis(rotation);
|
|
||||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
|
||||||
glScalef(_scale, _scale, _scale);
|
|
||||||
|
|
||||||
const float MAX_COLOR = 255.0f;
|
float maxSize = glm::max(fromImage.width(), fromImage.height());
|
||||||
xColor color = getColor();
|
float x = fromImage.width() / (2.0f * maxSize);
|
||||||
float alpha = getAlpha();
|
float y = -fromImage.height() / (2.0f * maxSize);
|
||||||
|
|
||||||
float imageWidth = _texture->getWidth();
|
glm::vec2 topLeft(-x, -y);
|
||||||
float imageHeight = _texture->getHeight();
|
glm::vec2 bottomRight(x, y);
|
||||||
|
glm::vec2 texCoordTopLeft(fromImage.x() / imageWidth, fromImage.y() / imageHeight);
|
||||||
|
glm::vec2 texCoordBottomRight((fromImage.x() + fromImage.width()) / imageWidth,
|
||||||
|
(fromImage.y() + fromImage.height()) / imageHeight);
|
||||||
|
|
||||||
QRect fromImage;
|
const float MAX_COLOR = 255.0f;
|
||||||
if (_fromImage.isNull()) {
|
xColor color = getColor();
|
||||||
fromImage.setX(0);
|
float alpha = getAlpha();
|
||||||
fromImage.setY(0);
|
|
||||||
fromImage.setWidth(imageWidth);
|
|
||||||
fromImage.setHeight(imageHeight);
|
|
||||||
} else {
|
|
||||||
float scaleX = imageWidth / _texture->getOriginalWidth();
|
|
||||||
float scaleY = imageHeight / _texture->getOriginalHeight();
|
|
||||||
|
|
||||||
fromImage.setX(scaleX * _fromImage.x());
|
auto batch = args->_batch;
|
||||||
fromImage.setY(scaleY * _fromImage.y());
|
|
||||||
fromImage.setWidth(scaleX * _fromImage.width());
|
|
||||||
fromImage.setHeight(scaleY * _fromImage.height());
|
|
||||||
}
|
|
||||||
|
|
||||||
float maxSize = glm::max(fromImage.width(), fromImage.height());
|
if (batch) {
|
||||||
float x = fromImage.width() / (2.0f * maxSize);
|
Transform transform;
|
||||||
float y = -fromImage.height() / (2.0f * maxSize);
|
transform.setTranslation(_position);
|
||||||
|
transform.setRotation(rotation);
|
||||||
|
transform.setScale(_scale);
|
||||||
|
|
||||||
glm::vec2 topLeft(-x, -y);
|
batch->setModelTransform(transform);
|
||||||
glm::vec2 bottomRight(x, y);
|
batch->setUniformTexture(0, _texture->getGPUTexture());
|
||||||
glm::vec2 texCoordTopLeft(fromImage.x() / imageWidth, fromImage.y() / imageHeight);
|
|
||||||
glm::vec2 texCoordBottomRight((fromImage.x() + fromImage.width()) / imageWidth,
|
DependencyManager::get<GeometryCache>()->renderQuad(*batch, topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight,
|
||||||
(fromImage.y() + fromImage.height()) / imageHeight);
|
|
||||||
|
|
||||||
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight,
|
|
||||||
glm::vec4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha));
|
glm::vec4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha));
|
||||||
|
} else {
|
||||||
|
glEnable(GL_ALPHA_TEST);
|
||||||
|
glAlphaFunc(GL_GREATER, 0.5f);
|
||||||
|
|
||||||
} glPopMatrix();
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
|
|
||||||
glDisable(GL_TEXTURE_2D);
|
glBindTexture(GL_TEXTURE_2D, _texture->getID());
|
||||||
glEnable(GL_LIGHTING);
|
|
||||||
glDisable(GL_ALPHA_TEST);
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glPushMatrix(); {
|
||||||
|
glTranslatef(_position.x, _position.y, _position.z);
|
||||||
|
glm::vec3 axis = glm::axis(rotation);
|
||||||
|
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||||
|
glScalef(_scale, _scale, _scale);
|
||||||
|
|
||||||
|
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight,
|
||||||
|
glm::vec4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha));
|
||||||
|
|
||||||
|
} glPopMatrix();
|
||||||
|
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
glEnable(GL_LIGHTING);
|
||||||
|
glDisable(GL_ALPHA_TEST);
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BillboardOverlay::setProperties(const QScriptValue &properties) {
|
void BillboardOverlay::setProperties(const QScriptValue &properties) {
|
||||||
|
|
|
@ -35,13 +35,6 @@ void Cube3DOverlay::render(RenderArgs* args) {
|
||||||
return; // do nothing if we're not visible
|
return; // do nothing if we're not visible
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float glowLevel = getGlowLevel();
|
|
||||||
Glower* glower = NULL;
|
|
||||||
if (glowLevel > 0.0f) {
|
|
||||||
glower = new Glower(glowLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
float alpha = getAlpha();
|
float alpha = getAlpha();
|
||||||
xColor color = getColor();
|
xColor color = getColor();
|
||||||
const float MAX_COLOR = 255.0f;
|
const float MAX_COLOR = 255.0f;
|
||||||
|
@ -49,91 +42,162 @@ void Cube3DOverlay::render(RenderArgs* args) {
|
||||||
|
|
||||||
//glDisable(GL_LIGHTING);
|
//glDisable(GL_LIGHTING);
|
||||||
|
|
||||||
// TODO: handle registration point??
|
// TODO: handle registration point??
|
||||||
glm::vec3 position = getPosition();
|
glm::vec3 position = getPosition();
|
||||||
glm::vec3 center = getCenter();
|
glm::vec3 center = getCenter();
|
||||||
glm::vec3 dimensions = getDimensions();
|
glm::vec3 dimensions = getDimensions();
|
||||||
glm::quat rotation = getRotation();
|
glm::quat rotation = getRotation();
|
||||||
|
|
||||||
glPushMatrix();
|
|
||||||
glTranslatef(position.x, position.y, position.z);
|
|
||||||
glm::vec3 axis = glm::axis(rotation);
|
|
||||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
|
||||||
glPushMatrix();
|
|
||||||
glm::vec3 positionToCenter = center - position;
|
|
||||||
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
|
||||||
if (_isSolid) {
|
|
||||||
if (_borderSize > 0) {
|
|
||||||
// Draw a cube at a larger size behind the main cube, creating
|
|
||||||
// a border effect.
|
|
||||||
// Disable writing to the depth mask so that the "border" cube will not
|
|
||||||
// occlude the main cube. This means the border could be covered by
|
|
||||||
// overlays that are further back and drawn later, but this is good
|
|
||||||
// enough for the use-case.
|
|
||||||
glDepthMask(GL_FALSE);
|
|
||||||
glPushMatrix();
|
|
||||||
glScalef(dimensions.x * _borderSize, dimensions.y * _borderSize, dimensions.z * _borderSize);
|
|
||||||
|
|
||||||
if (_drawOnHUD) {
|
auto batch = args->_batch;
|
||||||
DependencyManager::get<GeometryCache>()->renderSolidCube(1.0f, glm::vec4(1.0f, 1.0f, 1.0f, alpha));
|
|
||||||
} else {
|
|
||||||
DependencyManager::get<GeometryCache>()->renderSolidCube(1.0f, glm::vec4(1.0f, 1.0f, 1.0f, alpha));
|
|
||||||
}
|
|
||||||
|
|
||||||
glPopMatrix();
|
if (batch) {
|
||||||
glDepthMask(GL_TRUE);
|
Transform transform;
|
||||||
}
|
transform.setTranslation(position);
|
||||||
|
transform.setRotation(rotation);
|
||||||
|
if (_isSolid) {
|
||||||
|
// if (_borderSize > 0) {
|
||||||
|
// // Draw a cube at a larger size behind the main cube, creating
|
||||||
|
// // a border effect.
|
||||||
|
// // Disable writing to the depth mask so that the "border" cube will not
|
||||||
|
// // occlude the main cube. This means the border could be covered by
|
||||||
|
// // overlays that are further back and drawn later, but this is good
|
||||||
|
// // enough for the use-case.
|
||||||
|
// transform.setScale(dimensions * _borderSize);
|
||||||
|
// batch->setModelTransform(transform);
|
||||||
|
// DependencyManager::get<GeometryCache>()->renderSolidCube(*batch, 1.0f, glm::vec4(1.0f, 1.0f, 1.0f, alpha));
|
||||||
|
// }
|
||||||
|
|
||||||
|
transform.setScale(dimensions);
|
||||||
|
batch->setModelTransform(transform);
|
||||||
|
|
||||||
|
DependencyManager::get<DeferredLightingEffect>()->renderSolidCube(*batch, 1.0f, cubeColor);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (getIsDashedLine()) {
|
||||||
|
transform.setScale(1.0f);
|
||||||
|
batch->setModelTransform(transform);
|
||||||
|
|
||||||
|
glm::vec3 halfDimensions = dimensions / 2.0f;
|
||||||
|
glm::vec3 bottomLeftNear(-halfDimensions.x, -halfDimensions.y, -halfDimensions.z);
|
||||||
|
glm::vec3 bottomRightNear(halfDimensions.x, -halfDimensions.y, -halfDimensions.z);
|
||||||
|
glm::vec3 topLeftNear(-halfDimensions.x, halfDimensions.y, -halfDimensions.z);
|
||||||
|
glm::vec3 topRightNear(halfDimensions.x, halfDimensions.y, -halfDimensions.z);
|
||||||
|
|
||||||
|
glm::vec3 bottomLeftFar(-halfDimensions.x, -halfDimensions.y, halfDimensions.z);
|
||||||
|
glm::vec3 bottomRightFar(halfDimensions.x, -halfDimensions.y, halfDimensions.z);
|
||||||
|
glm::vec3 topLeftFar(-halfDimensions.x, halfDimensions.y, halfDimensions.z);
|
||||||
|
glm::vec3 topRightFar(halfDimensions.x, halfDimensions.y, halfDimensions.z);
|
||||||
|
|
||||||
|
auto geometryCache = DependencyManager::get<GeometryCache>();
|
||||||
|
|
||||||
|
geometryCache->renderDashedLine(*batch, bottomLeftNear, bottomRightNear, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(*batch, bottomRightNear, bottomRightFar, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(*batch, bottomRightFar, bottomLeftFar, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(*batch, bottomLeftFar, bottomLeftNear, cubeColor);
|
||||||
|
|
||||||
|
geometryCache->renderDashedLine(*batch, topLeftNear, topRightNear, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(*batch, topRightNear, topRightFar, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(*batch, topRightFar, topLeftFar, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(*batch, topLeftFar, topLeftNear, cubeColor);
|
||||||
|
|
||||||
|
geometryCache->renderDashedLine(*batch, bottomLeftNear, topLeftNear, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(*batch, bottomRightNear, topRightNear, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(*batch, bottomLeftFar, topLeftFar, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(*batch, bottomRightFar, topRightFar, cubeColor);
|
||||||
|
|
||||||
glPushMatrix();
|
|
||||||
glScalef(dimensions.x, dimensions.y, dimensions.z);
|
|
||||||
if (_drawOnHUD) {
|
|
||||||
DependencyManager::get<GeometryCache>()->renderSolidCube(1.0f, cubeColor);
|
|
||||||
} else {
|
|
||||||
DependencyManager::get<GeometryCache>()->renderSolidCube(1.0f, cubeColor);
|
|
||||||
}
|
|
||||||
glPopMatrix();
|
|
||||||
} else {
|
} else {
|
||||||
glLineWidth(_lineWidth);
|
transform.setScale(dimensions);
|
||||||
|
batch->setModelTransform(transform);
|
||||||
if (getIsDashedLine()) {
|
DependencyManager::get<DeferredLightingEffect>()->renderWireCube(*batch, 1.0f, cubeColor);
|
||||||
glm::vec3 halfDimensions = dimensions / 2.0f;
|
|
||||||
glm::vec3 bottomLeftNear(-halfDimensions.x, -halfDimensions.y, -halfDimensions.z);
|
|
||||||
glm::vec3 bottomRightNear(halfDimensions.x, -halfDimensions.y, -halfDimensions.z);
|
|
||||||
glm::vec3 topLeftNear(-halfDimensions.x, halfDimensions.y, -halfDimensions.z);
|
|
||||||
glm::vec3 topRightNear(halfDimensions.x, halfDimensions.y, -halfDimensions.z);
|
|
||||||
|
|
||||||
glm::vec3 bottomLeftFar(-halfDimensions.x, -halfDimensions.y, halfDimensions.z);
|
|
||||||
glm::vec3 bottomRightFar(halfDimensions.x, -halfDimensions.y, halfDimensions.z);
|
|
||||||
glm::vec3 topLeftFar(-halfDimensions.x, halfDimensions.y, halfDimensions.z);
|
|
||||||
glm::vec3 topRightFar(halfDimensions.x, halfDimensions.y, halfDimensions.z);
|
|
||||||
|
|
||||||
auto geometryCache = DependencyManager::get<GeometryCache>();
|
|
||||||
|
|
||||||
geometryCache->renderDashedLine(bottomLeftNear, bottomRightNear, cubeColor);
|
|
||||||
geometryCache->renderDashedLine(bottomRightNear, bottomRightFar, cubeColor);
|
|
||||||
geometryCache->renderDashedLine(bottomRightFar, bottomLeftFar, cubeColor);
|
|
||||||
geometryCache->renderDashedLine(bottomLeftFar, bottomLeftNear, cubeColor);
|
|
||||||
|
|
||||||
geometryCache->renderDashedLine(topLeftNear, topRightNear, cubeColor);
|
|
||||||
geometryCache->renderDashedLine(topRightNear, topRightFar, cubeColor);
|
|
||||||
geometryCache->renderDashedLine(topRightFar, topLeftFar, cubeColor);
|
|
||||||
geometryCache->renderDashedLine(topLeftFar, topLeftNear, cubeColor);
|
|
||||||
|
|
||||||
geometryCache->renderDashedLine(bottomLeftNear, topLeftNear, cubeColor);
|
|
||||||
geometryCache->renderDashedLine(bottomRightNear, topRightNear, cubeColor);
|
|
||||||
geometryCache->renderDashedLine(bottomLeftFar, topLeftFar, cubeColor);
|
|
||||||
geometryCache->renderDashedLine(bottomRightFar, topRightFar, cubeColor);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
glScalef(dimensions.x, dimensions.y, dimensions.z);
|
|
||||||
DependencyManager::get<GeometryCache>()->renderWireCube(1.0f, cubeColor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
glPopMatrix();
|
}
|
||||||
glPopMatrix();
|
} else {
|
||||||
|
float glowLevel = getGlowLevel();
|
||||||
|
Glower* glower = NULL;
|
||||||
|
if (glowLevel > 0.0f) {
|
||||||
|
glower = new Glower(glowLevel);
|
||||||
|
}
|
||||||
|
|
||||||
if (glower) {
|
glPushMatrix();
|
||||||
delete glower;
|
glTranslatef(position.x, position.y, position.z);
|
||||||
|
glm::vec3 axis = glm::axis(rotation);
|
||||||
|
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||||
|
glPushMatrix();
|
||||||
|
glm::vec3 positionToCenter = center - position;
|
||||||
|
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
||||||
|
if (_isSolid) {
|
||||||
|
if (_borderSize > 0) {
|
||||||
|
// Draw a cube at a larger size behind the main cube, creating
|
||||||
|
// a border effect.
|
||||||
|
// Disable writing to the depth mask so that the "border" cube will not
|
||||||
|
// occlude the main cube. This means the border could be covered by
|
||||||
|
// overlays that are further back and drawn later, but this is good
|
||||||
|
// enough for the use-case.
|
||||||
|
glDepthMask(GL_FALSE);
|
||||||
|
glPushMatrix();
|
||||||
|
glScalef(dimensions.x * _borderSize, dimensions.y * _borderSize, dimensions.z * _borderSize);
|
||||||
|
|
||||||
|
if (_drawOnHUD) {
|
||||||
|
DependencyManager::get<GeometryCache>()->renderSolidCube(1.0f, glm::vec4(1.0f, 1.0f, 1.0f, alpha));
|
||||||
|
} else {
|
||||||
|
DependencyManager::get<GeometryCache>()->renderSolidCube(1.0f, glm::vec4(1.0f, 1.0f, 1.0f, alpha));
|
||||||
|
}
|
||||||
|
|
||||||
|
glPopMatrix();
|
||||||
|
glDepthMask(GL_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
glPushMatrix();
|
||||||
|
glScalef(dimensions.x, dimensions.y, dimensions.z);
|
||||||
|
if (_drawOnHUD) {
|
||||||
|
DependencyManager::get<GeometryCache>()->renderSolidCube(1.0f, cubeColor);
|
||||||
|
} else {
|
||||||
|
DependencyManager::get<GeometryCache>()->renderSolidCube(1.0f, cubeColor);
|
||||||
|
}
|
||||||
|
glPopMatrix();
|
||||||
|
} else {
|
||||||
|
glLineWidth(_lineWidth);
|
||||||
|
|
||||||
|
if (getIsDashedLine()) {
|
||||||
|
glm::vec3 halfDimensions = dimensions / 2.0f;
|
||||||
|
glm::vec3 bottomLeftNear(-halfDimensions.x, -halfDimensions.y, -halfDimensions.z);
|
||||||
|
glm::vec3 bottomRightNear(halfDimensions.x, -halfDimensions.y, -halfDimensions.z);
|
||||||
|
glm::vec3 topLeftNear(-halfDimensions.x, halfDimensions.y, -halfDimensions.z);
|
||||||
|
glm::vec3 topRightNear(halfDimensions.x, halfDimensions.y, -halfDimensions.z);
|
||||||
|
|
||||||
|
glm::vec3 bottomLeftFar(-halfDimensions.x, -halfDimensions.y, halfDimensions.z);
|
||||||
|
glm::vec3 bottomRightFar(halfDimensions.x, -halfDimensions.y, halfDimensions.z);
|
||||||
|
glm::vec3 topLeftFar(-halfDimensions.x, halfDimensions.y, halfDimensions.z);
|
||||||
|
glm::vec3 topRightFar(halfDimensions.x, halfDimensions.y, halfDimensions.z);
|
||||||
|
|
||||||
|
auto geometryCache = DependencyManager::get<GeometryCache>();
|
||||||
|
|
||||||
|
geometryCache->renderDashedLine(bottomLeftNear, bottomRightNear, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(bottomRightNear, bottomRightFar, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(bottomRightFar, bottomLeftFar, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(bottomLeftFar, bottomLeftNear, cubeColor);
|
||||||
|
|
||||||
|
geometryCache->renderDashedLine(topLeftNear, topRightNear, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(topRightNear, topRightFar, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(topRightFar, topLeftFar, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(topLeftFar, topLeftNear, cubeColor);
|
||||||
|
|
||||||
|
geometryCache->renderDashedLine(bottomLeftNear, topLeftNear, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(bottomRightNear, topRightNear, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(bottomLeftFar, topLeftFar, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(bottomRightFar, topRightFar, cubeColor);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
glScalef(dimensions.x, dimensions.y, dimensions.z);
|
||||||
|
DependencyManager::get<GeometryCache>()->renderWireCube(1.0f, cubeColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
glPopMatrix();
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
|
if (glower) {
|
||||||
|
delete glower;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,87 +36,128 @@ void Grid3DOverlay::render(RenderArgs* args) {
|
||||||
return; // do nothing if we're not visible
|
return; // do nothing if we're not visible
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_gridProgram.isLinked()) {
|
|
||||||
if (!_gridProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/grid.vert")) {
|
|
||||||
qDebug() << "Failed to compile: " + _gridProgram.log();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!_gridProgram.addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/grid.frag")) {
|
|
||||||
qDebug() << "Failed to compile: " + _gridProgram.log();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!_gridProgram.link()) {
|
|
||||||
qDebug() << "Failed to link: " + _gridProgram.log();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render code largely taken from MetavoxelEditor::render()
|
|
||||||
glDisable(GL_LIGHTING);
|
|
||||||
|
|
||||||
glDepthMask(GL_FALSE);
|
|
||||||
|
|
||||||
glPushMatrix();
|
|
||||||
|
|
||||||
glm::quat rotation = getRotation();
|
|
||||||
|
|
||||||
glm::vec3 axis = glm::axis(rotation);
|
|
||||||
|
|
||||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
|
||||||
|
|
||||||
glLineWidth(1.5f);
|
|
||||||
|
|
||||||
// center the grid around the camera position on the plane
|
|
||||||
glm::vec3 rotated = glm::inverse(rotation) * Application::getInstance()->getCamera()->getPosition();
|
|
||||||
float spacing = _minorGridWidth;
|
|
||||||
|
|
||||||
float alpha = getAlpha();
|
|
||||||
xColor color = getColor();
|
|
||||||
glm::vec3 position = getPosition();
|
|
||||||
|
|
||||||
const int MINOR_GRID_DIVISIONS = 200;
|
const int MINOR_GRID_DIVISIONS = 200;
|
||||||
const int MAJOR_GRID_DIVISIONS = 100;
|
const int MAJOR_GRID_DIVISIONS = 100;
|
||||||
const float MAX_COLOR = 255.0f;
|
const float MAX_COLOR = 255.0f;
|
||||||
|
|
||||||
|
// center the grid around the camera position on the plane
|
||||||
|
glm::vec3 rotated = glm::inverse(_rotation) * Application::getInstance()->getCamera()->getPosition();
|
||||||
|
|
||||||
|
float spacing = _minorGridWidth;
|
||||||
|
|
||||||
|
float alpha = getAlpha();
|
||||||
|
xColor color = getColor();
|
||||||
glm::vec4 gridColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
|
glm::vec4 gridColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
|
||||||
|
|
||||||
_gridProgram.bind();
|
auto batch = args->_batch;
|
||||||
|
|
||||||
// Minor grid
|
if (batch) {
|
||||||
glPushMatrix();
|
Transform transform;
|
||||||
{
|
transform.setRotation(_rotation);
|
||||||
glTranslatef(_minorGridWidth * (floorf(rotated.x / spacing) - MINOR_GRID_DIVISIONS / 2),
|
|
||||||
spacing * (floorf(rotated.y / spacing) - MINOR_GRID_DIVISIONS / 2), position.z);
|
|
||||||
|
|
||||||
float scale = MINOR_GRID_DIVISIONS * spacing;
|
|
||||||
glScalef(scale, scale, scale);
|
|
||||||
|
|
||||||
DependencyManager::get<GeometryCache>()->renderGrid(MINOR_GRID_DIVISIONS, MINOR_GRID_DIVISIONS, gridColor);
|
// Minor grid
|
||||||
|
{
|
||||||
|
batch->_glLineWidth(1.0f);
|
||||||
|
auto position = glm::vec3(_minorGridWidth * (floorf(rotated.x / spacing) - MINOR_GRID_DIVISIONS / 2),
|
||||||
|
spacing * (floorf(rotated.y / spacing) - MINOR_GRID_DIVISIONS / 2),
|
||||||
|
_position.z);
|
||||||
|
float scale = MINOR_GRID_DIVISIONS * spacing;
|
||||||
|
|
||||||
|
transform.setTranslation(position);
|
||||||
|
transform.setScale(scale);
|
||||||
|
|
||||||
|
batch->setModelTransform(transform);
|
||||||
|
|
||||||
|
DependencyManager::get<GeometryCache>()->renderGrid(*batch, MINOR_GRID_DIVISIONS, MINOR_GRID_DIVISIONS, gridColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Major grid
|
||||||
|
{
|
||||||
|
batch->_glLineWidth(4.0f);
|
||||||
|
spacing *= _majorGridEvery;
|
||||||
|
auto position = glm::vec3(spacing * (floorf(rotated.x / spacing) - MAJOR_GRID_DIVISIONS / 2),
|
||||||
|
spacing * (floorf(rotated.y / spacing) - MAJOR_GRID_DIVISIONS / 2),
|
||||||
|
_position.z);
|
||||||
|
float scale = MAJOR_GRID_DIVISIONS * spacing;
|
||||||
|
|
||||||
|
transform.setTranslation(position);
|
||||||
|
transform.setScale(scale);
|
||||||
|
|
||||||
|
batch->setModelTransform(transform);
|
||||||
|
|
||||||
|
DependencyManager::get<GeometryCache>()->renderGrid(*batch, MAJOR_GRID_DIVISIONS, MAJOR_GRID_DIVISIONS, gridColor);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!_gridProgram.isLinked()) {
|
||||||
|
if (!_gridProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/grid.vert")) {
|
||||||
|
qDebug() << "Failed to compile: " + _gridProgram.log();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!_gridProgram.addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/grid.frag")) {
|
||||||
|
qDebug() << "Failed to compile: " + _gridProgram.log();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!_gridProgram.link()) {
|
||||||
|
qDebug() << "Failed to link: " + _gridProgram.log();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render code largely taken from MetavoxelEditor::render()
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
|
|
||||||
|
glDepthMask(GL_FALSE);
|
||||||
|
|
||||||
|
glPushMatrix();
|
||||||
|
|
||||||
|
glm::quat rotation = getRotation();
|
||||||
|
|
||||||
|
glm::vec3 axis = glm::axis(rotation);
|
||||||
|
|
||||||
|
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||||
|
|
||||||
|
glLineWidth(1.5f);
|
||||||
|
|
||||||
|
glm::vec3 position = getPosition();
|
||||||
|
|
||||||
|
_gridProgram.bind();
|
||||||
|
|
||||||
|
// Minor grid
|
||||||
|
glPushMatrix();
|
||||||
|
{
|
||||||
|
glTranslatef(_minorGridWidth * (floorf(rotated.x / spacing) - MINOR_GRID_DIVISIONS / 2),
|
||||||
|
spacing * (floorf(rotated.y / spacing) - MINOR_GRID_DIVISIONS / 2), position.z);
|
||||||
|
|
||||||
|
float scale = MINOR_GRID_DIVISIONS * spacing;
|
||||||
|
glScalef(scale, scale, scale);
|
||||||
|
|
||||||
|
DependencyManager::get<GeometryCache>()->renderGrid(MINOR_GRID_DIVISIONS, MINOR_GRID_DIVISIONS, gridColor);
|
||||||
|
}
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
|
// Major grid
|
||||||
|
glPushMatrix();
|
||||||
|
{
|
||||||
|
glLineWidth(4.0f);
|
||||||
|
spacing *= _majorGridEvery;
|
||||||
|
glTranslatef(spacing * (floorf(rotated.x / spacing) - MAJOR_GRID_DIVISIONS / 2),
|
||||||
|
spacing * (floorf(rotated.y / spacing) - MAJOR_GRID_DIVISIONS / 2), position.z);
|
||||||
|
|
||||||
|
float scale = MAJOR_GRID_DIVISIONS * spacing;
|
||||||
|
glScalef(scale, scale, scale);
|
||||||
|
|
||||||
|
DependencyManager::get<GeometryCache>()->renderGrid(MAJOR_GRID_DIVISIONS, MAJOR_GRID_DIVISIONS, gridColor);
|
||||||
|
}
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
|
_gridProgram.release();
|
||||||
|
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
|
glEnable(GL_LIGHTING);
|
||||||
|
glDepthMask(GL_TRUE);
|
||||||
}
|
}
|
||||||
glPopMatrix();
|
|
||||||
|
|
||||||
// Major grid
|
|
||||||
glPushMatrix();
|
|
||||||
{
|
|
||||||
glLineWidth(4.0f);
|
|
||||||
spacing *= _majorGridEvery;
|
|
||||||
glTranslatef(spacing * (floorf(rotated.x / spacing) - MAJOR_GRID_DIVISIONS / 2),
|
|
||||||
spacing * (floorf(rotated.y / spacing) - MAJOR_GRID_DIVISIONS / 2), position.z);
|
|
||||||
|
|
||||||
float scale = MAJOR_GRID_DIVISIONS * spacing;
|
|
||||||
glScalef(scale, scale, scale);
|
|
||||||
|
|
||||||
DependencyManager::get<GeometryCache>()->renderGrid(MAJOR_GRID_DIVISIONS, MAJOR_GRID_DIVISIONS, gridColor);
|
|
||||||
}
|
|
||||||
glPopMatrix();
|
|
||||||
|
|
||||||
_gridProgram.release();
|
|
||||||
|
|
||||||
glPopMatrix();
|
|
||||||
|
|
||||||
glEnable(GL_LIGHTING);
|
|
||||||
glDepthMask(GL_TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Grid3DOverlay::setProperties(const QScriptValue& properties) {
|
void Grid3DOverlay::setProperties(const QScriptValue& properties) {
|
||||||
|
|
|
@ -37,41 +37,57 @@ void Line3DOverlay::render(RenderArgs* args) {
|
||||||
return; // do nothing if we're not visible
|
return; // do nothing if we're not visible
|
||||||
}
|
}
|
||||||
|
|
||||||
float glowLevel = getGlowLevel();
|
|
||||||
Glower* glower = NULL;
|
|
||||||
if (glowLevel > 0.0f) {
|
|
||||||
glower = new Glower(glowLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
glPushMatrix();
|
|
||||||
|
|
||||||
glDisable(GL_LIGHTING);
|
|
||||||
glLineWidth(_lineWidth);
|
|
||||||
|
|
||||||
float alpha = getAlpha();
|
float alpha = getAlpha();
|
||||||
xColor color = getColor();
|
xColor color = getColor();
|
||||||
const float MAX_COLOR = 255.0f;
|
const float MAX_COLOR = 255.0f;
|
||||||
glm::vec4 colorv4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
|
glm::vec4 colorv4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
|
||||||
|
|
||||||
glm::vec3 position = getPosition();
|
auto batch = args->_batch;
|
||||||
glm::quat rotation = getRotation();
|
|
||||||
|
|
||||||
glTranslatef(position.x, position.y, position.z);
|
if (batch) {
|
||||||
glm::vec3 axis = glm::axis(rotation);
|
Transform transform;
|
||||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
transform.setTranslation(_position);
|
||||||
|
transform.setRotation(_rotation);
|
||||||
|
batch->setModelTransform(transform);
|
||||||
|
|
||||||
if (getIsDashedLine()) {
|
if (getIsDashedLine()) {
|
||||||
// TODO: add support for color to renderDashedLine()
|
// TODO: add support for color to renderDashedLine()
|
||||||
DependencyManager::get<GeometryCache>()->renderDashedLine(_position, _end, colorv4, _geometryCacheID);
|
DependencyManager::get<GeometryCache>()->renderDashedLine(*batch, _position, _end, colorv4, _geometryCacheID);
|
||||||
|
} else {
|
||||||
|
DependencyManager::get<GeometryCache>()->renderLine(*batch, _start, _end, colorv4, _geometryCacheID);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
DependencyManager::get<GeometryCache>()->renderLine(_start, _end, colorv4, _geometryCacheID);
|
float glowLevel = getGlowLevel();
|
||||||
}
|
Glower* glower = NULL;
|
||||||
glEnable(GL_LIGHTING);
|
if (glowLevel > 0.0f) {
|
||||||
|
glower = new Glower(glowLevel);
|
||||||
|
}
|
||||||
|
|
||||||
glPopMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
if (glower) {
|
glDisable(GL_LIGHTING);
|
||||||
delete glower;
|
glLineWidth(_lineWidth);
|
||||||
|
|
||||||
|
glm::vec3 position = getPosition();
|
||||||
|
glm::quat rotation = getRotation();
|
||||||
|
|
||||||
|
glTranslatef(position.x, position.y, position.z);
|
||||||
|
glm::vec3 axis = glm::axis(rotation);
|
||||||
|
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||||
|
|
||||||
|
if (getIsDashedLine()) {
|
||||||
|
// TODO: add support for color to renderDashedLine()
|
||||||
|
DependencyManager::get<GeometryCache>()->renderDashedLine(_position, _end, colorv4, _geometryCacheID);
|
||||||
|
} else {
|
||||||
|
DependencyManager::get<GeometryCache>()->renderLine(_start, _end, colorv4, _geometryCacheID);
|
||||||
|
}
|
||||||
|
glEnable(GL_LIGHTING);
|
||||||
|
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
|
if (glower) {
|
||||||
|
delete glower;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,74 +41,116 @@ void Rectangle3DOverlay::render(RenderArgs* args) {
|
||||||
const float MAX_COLOR = 255.0f;
|
const float MAX_COLOR = 255.0f;
|
||||||
glm::vec4 rectangleColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
|
glm::vec4 rectangleColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
|
||||||
|
|
||||||
glDisable(GL_LIGHTING);
|
|
||||||
|
|
||||||
glm::vec3 position = getPosition();
|
glm::vec3 position = getPosition();
|
||||||
glm::vec3 center = getCenter();
|
glm::vec3 center = getCenter();
|
||||||
glm::vec2 dimensions = getDimensions();
|
glm::vec2 dimensions = getDimensions();
|
||||||
glm::vec2 halfDimensions = dimensions * 0.5f;
|
glm::vec2 halfDimensions = dimensions * 0.5f;
|
||||||
glm::quat rotation = getRotation();
|
glm::quat rotation = getRotation();
|
||||||
|
|
||||||
float glowLevel = getGlowLevel();
|
auto batch = args->_batch;
|
||||||
Glower* glower = NULL;
|
|
||||||
if (glowLevel > 0.0f) {
|
|
||||||
glower = new Glower(glowLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
glPushMatrix();
|
if (batch) {
|
||||||
glTranslatef(position.x, position.y, position.z);
|
Transform transform;
|
||||||
glm::vec3 axis = glm::axis(rotation);
|
transform.setTranslation(position);
|
||||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
transform.setRotation(rotation);
|
||||||
glPushMatrix();
|
|
||||||
glm::vec3 positionToCenter = center - position;
|
|
||||||
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
|
||||||
//glScalef(dimensions.x, dimensions.y, 1.0f);
|
|
||||||
|
|
||||||
glLineWidth(_lineWidth);
|
batch->setModelTransform(transform);
|
||||||
|
|
||||||
|
if (getIsSolid()) {
|
||||||
|
glm::vec3 topLeft(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
glm::vec3 bottomRight(halfDimensions.x, halfDimensions.y, 0.0f);
|
||||||
|
DependencyManager::get<GeometryCache>()->renderQuad(*batch, topLeft, bottomRight, rectangleColor);
|
||||||
|
} else {
|
||||||
auto geometryCache = DependencyManager::get<GeometryCache>();
|
auto geometryCache = DependencyManager::get<GeometryCache>();
|
||||||
|
if (getIsDashedLine()) {
|
||||||
|
glm::vec3 point1(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
glm::vec3 point2(halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
glm::vec3 point3(halfDimensions.x, halfDimensions.y, 0.0f);
|
||||||
|
glm::vec3 point4(-halfDimensions.x, halfDimensions.y, 0.0f);
|
||||||
|
|
||||||
// for our overlay, is solid means we draw a solid "filled" rectangle otherwise we just draw a border line...
|
geometryCache->renderDashedLine(*batch, point1, point2, rectangleColor);
|
||||||
if (getIsSolid()) {
|
geometryCache->renderDashedLine(*batch, point2, point3, rectangleColor);
|
||||||
glm::vec3 topLeft(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
geometryCache->renderDashedLine(*batch, point3, point4, rectangleColor);
|
||||||
glm::vec3 bottomRight(halfDimensions.x, halfDimensions.y, 0.0f);
|
geometryCache->renderDashedLine(*batch, point4, point1, rectangleColor);
|
||||||
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, rectangleColor);
|
|
||||||
} else {
|
} else {
|
||||||
if (getIsDashedLine()) {
|
if (halfDimensions != _previousHalfDimensions) {
|
||||||
|
QVector<glm::vec3> border;
|
||||||
|
border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
border << glm::vec3(halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
border << glm::vec3(halfDimensions.x, halfDimensions.y, 0.0f);
|
||||||
|
border << glm::vec3(-halfDimensions.x, halfDimensions.y, 0.0f);
|
||||||
|
border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
geometryCache->updateVertices(_geometryCacheID, border, rectangleColor);
|
||||||
|
|
||||||
glm::vec3 point1(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
_previousHalfDimensions = halfDimensions;
|
||||||
glm::vec3 point2(halfDimensions.x, -halfDimensions.y, 0.0f);
|
|
||||||
glm::vec3 point3(halfDimensions.x, halfDimensions.y, 0.0f);
|
|
||||||
glm::vec3 point4(-halfDimensions.x, halfDimensions.y, 0.0f);
|
|
||||||
|
|
||||||
geometryCache->renderDashedLine(point1, point2, rectangleColor);
|
|
||||||
geometryCache->renderDashedLine(point2, point3, rectangleColor);
|
|
||||||
geometryCache->renderDashedLine(point3, point4, rectangleColor);
|
|
||||||
geometryCache->renderDashedLine(point4, point1, rectangleColor);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if (halfDimensions != _previousHalfDimensions) {
|
|
||||||
QVector<glm::vec3> border;
|
|
||||||
border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
|
||||||
border << glm::vec3(halfDimensions.x, -halfDimensions.y, 0.0f);
|
|
||||||
border << glm::vec3(halfDimensions.x, halfDimensions.y, 0.0f);
|
|
||||||
border << glm::vec3(-halfDimensions.x, halfDimensions.y, 0.0f);
|
|
||||||
border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
|
||||||
geometryCache->updateVertices(_geometryCacheID, border, rectangleColor);
|
|
||||||
|
|
||||||
_previousHalfDimensions = halfDimensions;
|
|
||||||
|
|
||||||
}
|
|
||||||
geometryCache->renderVertices(gpu::LINE_STRIP, _geometryCacheID);
|
|
||||||
}
|
}
|
||||||
|
geometryCache->renderVertices(*batch, gpu::LINE_STRIP, _geometryCacheID);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
|
|
||||||
|
float glowLevel = getGlowLevel();
|
||||||
|
Glower* glower = NULL;
|
||||||
|
if (glowLevel > 0.0f) {
|
||||||
|
glower = new Glower(glowLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
glPushMatrix();
|
||||||
|
glTranslatef(position.x, position.y, position.z);
|
||||||
|
glm::vec3 axis = glm::axis(rotation);
|
||||||
|
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||||
|
glPushMatrix();
|
||||||
|
glm::vec3 positionToCenter = center - position;
|
||||||
|
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
||||||
|
//glScalef(dimensions.x, dimensions.y, 1.0f);
|
||||||
|
|
||||||
|
glLineWidth(_lineWidth);
|
||||||
|
|
||||||
|
auto geometryCache = DependencyManager::get<GeometryCache>();
|
||||||
|
|
||||||
|
// for our overlay, is solid means we draw a solid "filled" rectangle otherwise we just draw a border line...
|
||||||
|
if (getIsSolid()) {
|
||||||
|
glm::vec3 topLeft(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
glm::vec3 bottomRight(halfDimensions.x, halfDimensions.y, 0.0f);
|
||||||
|
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, rectangleColor);
|
||||||
|
} else {
|
||||||
|
if (getIsDashedLine()) {
|
||||||
|
|
||||||
|
glm::vec3 point1(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
glm::vec3 point2(halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
glm::vec3 point3(halfDimensions.x, halfDimensions.y, 0.0f);
|
||||||
|
glm::vec3 point4(-halfDimensions.x, halfDimensions.y, 0.0f);
|
||||||
|
|
||||||
|
geometryCache->renderDashedLine(point1, point2, rectangleColor);
|
||||||
|
geometryCache->renderDashedLine(point2, point3, rectangleColor);
|
||||||
|
geometryCache->renderDashedLine(point3, point4, rectangleColor);
|
||||||
|
geometryCache->renderDashedLine(point4, point1, rectangleColor);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (halfDimensions != _previousHalfDimensions) {
|
||||||
|
QVector<glm::vec3> border;
|
||||||
|
border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
border << glm::vec3(halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
border << glm::vec3(halfDimensions.x, halfDimensions.y, 0.0f);
|
||||||
|
border << glm::vec3(-halfDimensions.x, halfDimensions.y, 0.0f);
|
||||||
|
border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
geometryCache->updateVertices(_geometryCacheID, border, rectangleColor);
|
||||||
|
|
||||||
|
_previousHalfDimensions = halfDimensions;
|
||||||
|
|
||||||
|
}
|
||||||
|
geometryCache->renderVertices(gpu::LINE_STRIP, _geometryCacheID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
glPopMatrix();
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glPopMatrix();
|
|
||||||
|
if (glower) {
|
||||||
if (glower) {
|
delete glower;
|
||||||
delete glower;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,33 +39,45 @@ void Sphere3DOverlay::render(RenderArgs* args) {
|
||||||
const float MAX_COLOR = 255.0f;
|
const float MAX_COLOR = 255.0f;
|
||||||
glm::vec4 sphereColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
|
glm::vec4 sphereColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
|
||||||
|
|
||||||
glDisable(GL_LIGHTING);
|
auto batch = args->_batch;
|
||||||
|
|
||||||
glm::vec3 position = getPosition();
|
|
||||||
glm::vec3 center = getCenter();
|
|
||||||
glm::vec3 dimensions = getDimensions();
|
|
||||||
glm::quat rotation = getRotation();
|
|
||||||
|
|
||||||
float glowLevel = getGlowLevel();
|
if (batch) {
|
||||||
Glower* glower = NULL;
|
Transform transform;
|
||||||
if (glowLevel > 0.0f) {
|
transform.setTranslation(_position);
|
||||||
glower = new Glower(glowLevel);
|
transform.setRotation(_rotation);
|
||||||
}
|
transform.setScale(_dimensions);
|
||||||
|
|
||||||
|
batch->setModelTransform(transform);
|
||||||
|
DependencyManager::get<GeometryCache>()->renderSphere(*batch, 1.0f, SLICES, SLICES, sphereColor, _isSolid);
|
||||||
|
} else {
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
|
|
||||||
|
glm::vec3 position = getPosition();
|
||||||
|
glm::vec3 center = getCenter();
|
||||||
|
glm::vec3 dimensions = getDimensions();
|
||||||
|
glm::quat rotation = getRotation();
|
||||||
|
|
||||||
|
float glowLevel = getGlowLevel();
|
||||||
|
Glower* glower = NULL;
|
||||||
|
if (glowLevel > 0.0f) {
|
||||||
|
glower = new Glower(glowLevel);
|
||||||
|
}
|
||||||
|
|
||||||
glPushMatrix();
|
|
||||||
glTranslatef(position.x, position.y, position.z);
|
|
||||||
glm::vec3 axis = glm::axis(rotation);
|
|
||||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glm::vec3 positionToCenter = center - position;
|
glTranslatef(position.x, position.y, position.z);
|
||||||
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
glm::vec3 axis = glm::axis(rotation);
|
||||||
glScalef(dimensions.x, dimensions.y, dimensions.z);
|
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||||
DependencyManager::get<GeometryCache>()->renderSphere(1.0f, SLICES, SLICES, sphereColor, _isSolid);
|
glPushMatrix();
|
||||||
|
glm::vec3 positionToCenter = center - position;
|
||||||
|
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
||||||
|
glScalef(dimensions.x, dimensions.y, dimensions.z);
|
||||||
|
DependencyManager::get<GeometryCache>()->renderSphere(1.0f, SLICES, SLICES, sphereColor, _isSolid);
|
||||||
|
glPopMatrix();
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glPopMatrix();
|
|
||||||
|
if (glower) {
|
||||||
if (glower) {
|
delete glower;
|
||||||
delete glower;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue