Merge pull request #5940 from ericrius1/polyLineFix

Made polyline painting experience smoother- no more flickering
This commit is contained in:
Ryan Huffman 2015-09-29 18:22:01 -07:00
commit b4ca03ac3f
2 changed files with 65 additions and 65 deletions

View file

@ -86,18 +86,18 @@ void RenderablePolyLineEntityItem::updateGeometry() {
int numTailStrips = 5;
int numHeadStrips = 10;
int startHeadIndex = _normals.size() - numHeadStrips;
for (int i = 0; i < _normals.size(); i++) {
int startHeadIndex = _vertices.size() / 2 - numHeadStrips;
for (int i = 0; i < _vertices.size() / 2; i++) {
uCoord = 0.26f;
vCoord = 0.0f;
//tail
if(i < numTailStrips) {
uCoord = float(i)/numTailStrips * tailLength + tailStart;
if (i < numTailStrips) {
uCoord = float(i) / numTailStrips * tailLength + tailStart;
}
//head
if( i > startHeadIndex) {
uCoord = float( (i+ 1) - startHeadIndex)/numHeadStrips * headLength + headStart;
if (i > startHeadIndex) {
uCoord = float((i + 1) - startHeadIndex) / numHeadStrips * headLength + headStart;
}
uv = vec2(uCoord, vCoord);
@ -115,7 +115,7 @@ void RenderablePolyLineEntityItem::updateGeometry() {
_verticesBuffer->append(sizeof(glm::vec2), (const gpu::Byte*)&uv);
vertexIndex++;
_numVertices +=2;
_numVertices += 2;
}
_pointsChanged = false;
@ -124,7 +124,7 @@ void RenderablePolyLineEntityItem::updateGeometry() {
void RenderablePolyLineEntityItem::render(RenderArgs* args) {
QWriteLocker lock(&_quadReadWriteLock);
if (_points.size() < 2 || _vertices.size() != _normals.size() * 2) {
if (_points.size() < 2 || _normals.size () < 2 || _vertices.size() < 2) {
return;
}

View file

@ -27,12 +27,12 @@ const int PolyLineEntityItem::MAX_POINTS_PER_LINE = 70;
EntityItemPointer PolyLineEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) {
EntityItemPointer result { new PolyLineEntityItem(entityID, properties) };
EntityItemPointer result{ new PolyLineEntityItem(entityID, properties) };
return result;
}
PolyLineEntityItem::PolyLineEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
EntityItem(entityItemID) ,
EntityItem(entityItemID),
_lineWidth(DEFAULT_LINE_WIDTH),
_pointsChanged(true),
_points(QVector<glm::vec3>(0.0f)),
@ -93,7 +93,7 @@ bool PolyLineEntityItem::appendPoint(const glm::vec3& point) {
return false;
}
glm::vec3 halfBox = getDimensions() * 0.5f;
if ( (point.x < - halfBox.x || point.x > halfBox.x) || (point.y < -halfBox.y || point.y > halfBox.y) || (point.z < - halfBox.z || point.z > halfBox.z) ) {
if ((point.x < -halfBox.x || point.x > halfBox.x) || (point.y < -halfBox.y || point.y > halfBox.y) || (point.z < -halfBox.z || point.z > halfBox.z)) {
qDebug() << "Point is outside entity's bounding box";
return false;
}
@ -102,14 +102,14 @@ bool PolyLineEntityItem::appendPoint(const glm::vec3& point) {
return true;
}
bool PolyLineEntityItem::setStrokeWidths(const QVector<float>& strokeWidths ) {
bool PolyLineEntityItem::setStrokeWidths(const QVector<float>& strokeWidths) {
_strokeWidths = strokeWidths;
return true;
}
bool PolyLineEntityItem::setNormals(const QVector<glm::vec3>& normals) {
_normals = normals;
if (_points.size () < 2 || _normals.size() < 2) {
if (_points.size() < 2 || _normals.size() < 2) {
return false;
}
@ -124,11 +124,11 @@ bool PolyLineEntityItem::setNormals(const QVector<glm::vec3>& normals) {
_vertices.clear();
glm::vec3 v1, v2, tangent, binormal, point;
for (int i = 0; i < minVectorSize-1; i++) {
for (int i = 0; i < minVectorSize - 1; i++) {
float width = _strokeWidths.at(i);
point = _points.at(i);
tangent = _points.at(i+1) - point;
tangent = _points.at(i + 1) - point;
glm::vec3 normal = normals.at(i);
binormal = glm::normalize(glm::cross(tangent, normal)) * width;
@ -139,7 +139,7 @@ bool PolyLineEntityItem::setNormals(const QVector<glm::vec3>& normals) {
_vertices << v1 << v2;
}
//for last point we can just assume binormals are same since it represents last two vertices of quad
point = _points.at(_points.size() - 1);
point = _points.at(minVectorSize - 1);
v1 = point + binormal;
v2 = point - binormal;
_vertices << v1 << v2;
@ -157,7 +157,7 @@ bool PolyLineEntityItem::setLinePoints(const QVector<glm::vec3>& points) {
//Check to see if points actually changed. If they haven't, return before doing anything else
else if (points.size() == _points.size()) {
//same number of points, so now compare every point
for (int i = 0; i < points.size(); i++ ) {
for (int i = 0; i < points.size(); i++) {
if (points.at(i) != _points.at(i)){
_pointsChanged = true;
break;
@ -171,9 +171,9 @@ bool PolyLineEntityItem::setLinePoints(const QVector<glm::vec3>& points) {
for (int i = 0; i < points.size(); i++) {
glm::vec3 point = points.at(i);
glm::vec3 halfBox = getDimensions() * 0.5f;
if ((point.x < - halfBox.x || point.x > halfBox.x) ||
if ((point.x < -halfBox.x || point.x > halfBox.x) ||
(point.y < -halfBox.y || point.y > halfBox.y) ||
(point.z < - halfBox.z || point.z > halfBox.z)) {
(point.z < -halfBox.z || point.z > halfBox.z)) {
qDebug() << "Point is outside entity's bounding box";
return false;
}