mirror of
https://github.com/overte-org/overte.git
synced 2025-04-22 09:33:36 +02:00
fix quad logic
This commit is contained in:
parent
43b1751db3
commit
ff99f68f89
2 changed files with 36 additions and 20 deletions
|
@ -67,28 +67,33 @@ int generateColor() {
|
|||
}
|
||||
|
||||
void RenderablePolyLineEntityItem::updateGeometry() {
|
||||
QReadLocker lock(&_quadReadWriteLock);
|
||||
int compactColor = generateColor();
|
||||
_numVertices = 0;
|
||||
_verticesBuffer.reset(new gpu::Buffer());
|
||||
int vertexIndex = 0;
|
||||
for (int i = 0; i < _normals.size(); i++) {
|
||||
_verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex));
|
||||
vertexIndex++;
|
||||
_verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i));
|
||||
_verticesBuffer->append(sizeof(int), (gpu::Byte*)&compactColor);
|
||||
_verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex));
|
||||
vertexIndex++;
|
||||
_verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i));
|
||||
_verticesBuffer->append(sizeof(int), (gpu::Byte*)&compactColor);
|
||||
|
||||
_numVertices +=2;
|
||||
if (_pointsChanged) {
|
||||
int compactColor = generateColor();
|
||||
_numVertices = 0;
|
||||
_verticesBuffer.reset(new gpu::Buffer());
|
||||
int vertexIndex = 0;
|
||||
for (int i = 0; i < _normals.size(); i++) {
|
||||
compactColor = generateColor();
|
||||
_verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex));
|
||||
vertexIndex++;
|
||||
_verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i));
|
||||
_verticesBuffer->append(sizeof(int), (gpu::Byte*)&_color);
|
||||
|
||||
_verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_vertices.at(vertexIndex));
|
||||
vertexIndex++;
|
||||
_verticesBuffer->append(sizeof(glm::vec3), (const gpu::Byte*)&_normals.at(i));
|
||||
_verticesBuffer->append(sizeof(int), (gpu::Byte*)_color);
|
||||
|
||||
_numVertices +=2;
|
||||
}
|
||||
_pointsChanged = false;
|
||||
}
|
||||
_pointsChanged = false;
|
||||
|
||||
}
|
||||
|
||||
void RenderablePolyLineEntityItem::render(RenderArgs* args) {
|
||||
QWriteLocker lock(&_quadReadWriteLock);
|
||||
if (_points.size() < 2 || _vertices.size() != _normals.size() * 2) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ _strokeWidths(QVector<float>(0))
|
|||
}
|
||||
|
||||
EntityItemProperties PolyLineEntityItem::getProperties() const {
|
||||
_quadReadWriteLock.lockForWrite();
|
||||
QWriteLocker lock(&_quadReadWriteLock);
|
||||
EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class
|
||||
|
||||
|
||||
|
@ -67,7 +67,7 @@ EntityItemProperties PolyLineEntityItem::getProperties() const {
|
|||
}
|
||||
|
||||
bool PolyLineEntityItem::setProperties(const EntityItemProperties& properties) {
|
||||
_quadReadWriteLock.lockForWrite();
|
||||
QWriteLocker lock(&_quadReadWriteLock);
|
||||
bool somethingChanged = false;
|
||||
somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class
|
||||
|
||||
|
@ -121,7 +121,7 @@ bool PolyLineEntityItem::setNormals(const QVector<glm::vec3>& normals) {
|
|||
}
|
||||
_normals = normals;
|
||||
_vertices.clear();
|
||||
//Go through and create vertices for triangle strip based on normals
|
||||
//Go through and create vertices for triangle strip based on normalsa
|
||||
if (_normals.size() != _points.size()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -130,8 +130,18 @@ bool PolyLineEntityItem::setNormals(const QVector<glm::vec3>& normals) {
|
|||
float width = _strokeWidths.at(i);
|
||||
point = _points.at(i);
|
||||
//Get tangent
|
||||
|
||||
tangent = _points.at(i+1) - point;
|
||||
binormal = glm::normalize(glm::cross(tangent, normals.at(i))) * width;
|
||||
glm::vec3 normal = normals.at(i);
|
||||
// qDebug() << "next point" << _points.at(i+1) << "cur point" << point;
|
||||
binormal = glm::normalize(glm::cross(tangent, normal)) * _lineWidth;
|
||||
// qDebug() << "glm cross" << glm::cross(tangent, normal);
|
||||
// qDebug()<< "binormal" << binormal;
|
||||
// qDebug() <<"dot " << glm::dot(tangent, normals.at(i));
|
||||
|
||||
if(binormal.x != binormal.x) {
|
||||
|
||||
}
|
||||
v1 = point + binormal;
|
||||
v2 = point - binormal;
|
||||
_vertices << v1 << v2;
|
||||
|
@ -219,6 +229,7 @@ void PolyLineEntityItem::appendSubclassData(OctreePacketData* packetData, Encode
|
|||
int& propertyCount,
|
||||
OctreeElement::AppendState& appendState) const {
|
||||
|
||||
QWriteLocker lock(&_quadReadWriteLock);
|
||||
bool successPropertyFits = true;
|
||||
|
||||
APPEND_ENTITY_PROPERTY(PROP_COLOR, getColor());
|
||||
|
|
Loading…
Reference in a new issue