add dashed line drawing to Base3DOverlay and 3d line and rectangle overlays

This commit is contained in:
ZappoMan 2014-10-01 09:45:20 -07:00
parent 7a9be9e5b9
commit 94c2540db0
4 changed files with 50 additions and 13 deletions

View file

@ -110,6 +110,38 @@ void Base3DOverlay::setProperties(const QScriptValue& properties) {
setIsDashedLine(properties.property("isDashedLine").toVariant().toBool());
}
if (properties.property("dashed").isValid()) {
setIsDashedLine(!properties.property("dashed").toVariant().toBool());
setIsDashedLine(properties.property("dashed").toVariant().toBool());
}
}
void Base3DOverlay::drawDashedLine(const glm::vec3& start, const glm::vec3& end) {
glBegin(GL_LINES);
// draw each line segment with appropriate gaps
const float dashLength = 0.05f;
const float gapLength = 0.025f;
const float segmentLength = dashLength + gapLength;
float length = glm::distance(start, end);
float segmentCount = length / segmentLength;
int segmentCountFloor = (int)glm::floor(segmentCount);
glm::vec3 segmentVector = (end - start) / segmentCount;
glm::vec3 dashVector = segmentVector / segmentLength * dashLength;
glm::vec3 gapVector = segmentVector / segmentLength * gapLength;
glm::vec3 point = start;
glVertex3f(point.x, point.y, point.z);
for (int i = 0; i < segmentCountFloor; i++) {
point += dashVector;
glVertex3f(point.x, point.y, point.z);
point += gapVector;
glVertex3f(point.x, point.y, point.z);
}
glVertex3f(end.x, end.y, end.z);
glEnd();
}

View file

@ -43,6 +43,8 @@ public:
virtual void setProperties(const QScriptValue& properties);
protected:
void drawDashedLine(const glm::vec3& start, const glm::vec3& end);
glm::vec3 _position;
float _lineWidth;
glm::quat _rotation;

View file

@ -40,10 +40,14 @@ void Line3DOverlay::render() {
const float MAX_COLOR = 255;
glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
glBegin(GL_LINES);
if (getIsDashedLine()) {
drawDashedLine(_position, _end);
} else {
glBegin(GL_LINES);
glVertex3f(_position.x, _position.y, _position.z);
glVertex3f(_end.x, _end.y, _end.z);
glEnd();
glEnd();
}
glEnable(GL_LIGHTING);
if (glower) {

View file

@ -70,17 +70,17 @@ void Rectangle3DOverlay::render() {
glEnd();
} else {
if (getIsDashedLine()) {
// TODO: change this to be dashed!
glBegin(GL_LINE_STRIP);
glVertex3f(-halfDimensions.x, 0.0f, -halfDimensions.y);
glVertex3f(halfDimensions.x, 0.0f, -halfDimensions.y);
glVertex3f(halfDimensions.x, 0.0f, halfDimensions.y);
glVertex3f(-halfDimensions.x, 0.0f, halfDimensions.y);
glVertex3f(-halfDimensions.x, 0.0f, -halfDimensions.y);
glm::vec3 point1(-halfDimensions.x, 0.0f, -halfDimensions.y);
glm::vec3 point2(halfDimensions.x, 0.0f, -halfDimensions.y);
glm::vec3 point3(halfDimensions.x, 0.0f, halfDimensions.y);
glm::vec3 point4(-halfDimensions.x, 0.0f, halfDimensions.y);
glEnd();
drawDashedLine(point1, point2);
drawDashedLine(point2, point3);
drawDashedLine(point3, point4);
drawDashedLine(point4, point1);
} else {
glBegin(GL_LINE_STRIP);
@ -112,4 +112,3 @@ void Rectangle3DOverlay::setProperties(const QScriptValue &properties) {