code format
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
#include <QPainter>
|
||||
|
||||
//__GLWidget__ * currentQGLView;
|
||||
//QMutex globMutex;
|
||||
// QMutex globMutex;
|
||||
|
||||
|
||||
QString readCharsUntilNull(QDataStream & s) {
|
||||
@@ -39,15 +39,14 @@ QString readCharsUntilNull(QDataStream & s) {
|
||||
|
||||
QString findFile(const QString & file, const QStringList & pathes) {
|
||||
QFileInfo fi(QString(file).replace("\\", "/"));
|
||||
//qDebug() << "search" << file << "in" << pathes;
|
||||
// qDebug() << "search" << file << "in" << pathes;
|
||||
if (fi.exists()) return fi.absoluteFilePath();
|
||||
QString fn = fi.fileName();
|
||||
if (fn.contains("/")) fn = fn.mid(fn.lastIndexOf("/"));
|
||||
foreach (QString p, pathes) {
|
||||
foreach(QString p, pathes) {
|
||||
QFileInfoList fil = QDir(p).entryInfoList(QStringList(fn), QDir::Files | QDir::NoDotAndDotDot);
|
||||
//qDebug() << "findFile" << fn << "in" << p << "->" << fil.size();
|
||||
if (!fil.isEmpty())
|
||||
return fil[0].absoluteFilePath();
|
||||
// qDebug() << "findFile" << fn << "in" << p << "->" << fil.size();
|
||||
if (!fil.isEmpty()) return fil[0].absoluteFilePath();
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
@@ -58,22 +57,28 @@ void glDrawQuad(QOpenGLShaderProgram * prog, QVector4D * corner_dirs, GLfloat x,
|
||||
glSetPolygonMode(GL_FILL);
|
||||
glDisable(GL_LIGHTING);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
int loc = prog ? prog->attributeLocation("qgl_Color") : -1,
|
||||
locv = prog ? prog->attributeLocation("qgl_Vertex") : -1,
|
||||
loct = prog ? prog->attributeLocation("qgl_Texture") : -1,
|
||||
locc = prog ? prog->attributeLocation("view_corner") : -1;
|
||||
//if (prog) {qDebug() << locv << loct << locc;}
|
||||
int loc = prog ? prog->attributeLocation("qgl_Color") : -1, locv = prog ? prog->attributeLocation("qgl_Vertex") : -1,
|
||||
loct = prog ? prog->attributeLocation("qgl_Texture") : -1, locc = prog ? prog->attributeLocation("view_corner") : -1;
|
||||
// if (prog) {qDebug() << locv << loct << locc;}
|
||||
QOpenGLFunctions * glFuncs = QOpenGLContext::currentContext()->functions();
|
||||
if (prog) {
|
||||
static const GLfloat cols [] = {1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f};
|
||||
static const GLfloat verts[] = {x, y, x+w, y, x, y+h, x+w, y+h};
|
||||
static const GLfloat texs [] = {0.f, 0.f, 1.f, 0.f, 0.f, 1.f, 1.f, 1.f};
|
||||
GLfloat vcs[] = {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
|
||||
static const GLfloat cols[] = {1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f};
|
||||
static const GLfloat verts[] = {x, y, x + w, y, x, y + h, x + w, y + h};
|
||||
static const GLfloat texs[] = {0.f, 0.f, 1.f, 0.f, 0.f, 1.f, 1.f, 1.f};
|
||||
GLfloat vcs[] = {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
|
||||
if (corner_dirs) {
|
||||
vcs[0] = corner_dirs[0].x(); vcs[1] = corner_dirs[0].y(); vcs[2] = corner_dirs[0].z();
|
||||
vcs[3] = corner_dirs[1].x(); vcs[4] = corner_dirs[1].y(); vcs[5] = corner_dirs[1].z();
|
||||
vcs[6] = corner_dirs[2].x(); vcs[7] = corner_dirs[2].y(); vcs[8] = corner_dirs[2].z();
|
||||
vcs[9] = corner_dirs[3].x(); vcs[10] = corner_dirs[3].y(); vcs[11] = corner_dirs[3].z();
|
||||
vcs[0] = corner_dirs[0].x();
|
||||
vcs[1] = corner_dirs[0].y();
|
||||
vcs[2] = corner_dirs[0].z();
|
||||
vcs[3] = corner_dirs[1].x();
|
||||
vcs[4] = corner_dirs[1].y();
|
||||
vcs[5] = corner_dirs[1].z();
|
||||
vcs[6] = corner_dirs[2].x();
|
||||
vcs[7] = corner_dirs[2].y();
|
||||
vcs[8] = corner_dirs[2].z();
|
||||
vcs[9] = corner_dirs[3].x();
|
||||
vcs[10] = corner_dirs[3].y();
|
||||
vcs[11] = corner_dirs[3].z();
|
||||
}
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_NORMAL_ARRAY);
|
||||
@@ -96,10 +101,14 @@ void glDrawQuad(QOpenGLShaderProgram * prog, QVector4D * corner_dirs, GLfloat x,
|
||||
} else {
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
glColor4f(1.f, 1.f, 1.f, 1.f);
|
||||
glTexCoord2f(0.f, 0.f); glVertex2f(x, y);
|
||||
glTexCoord2f(1.f, 0.f); glVertex2f(x+w, y);
|
||||
glTexCoord2f(0.f, 1.f); glVertex2f(x, y+h);
|
||||
glTexCoord2f(1.f, 1.f); glVertex2f(x+w, y+h);
|
||||
glTexCoord2f(0.f, 0.f);
|
||||
glVertex2f(x, y);
|
||||
glTexCoord2f(1.f, 0.f);
|
||||
glVertex2f(x + w, y);
|
||||
glTexCoord2f(0.f, 1.f);
|
||||
glVertex2f(x, y + h);
|
||||
glTexCoord2f(1.f, 1.f);
|
||||
glVertex2f(x + w, y + h);
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
@@ -141,21 +150,19 @@ void createGLTexture(GLuint & tex, int width, int height, const GLenum & format,
|
||||
glGenTextures(1, &tex);
|
||||
glBindTexture(target, tex);
|
||||
}
|
||||
//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
// glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
if (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_COMPONENT16 || format == GL_DEPTH_COMPONENT24 || format == GL_DEPTH_COMPONENT32)
|
||||
glTexImage2D(target, 0, format, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, nullptr);
|
||||
else {
|
||||
int t = GL_UNSIGNED_BYTE;
|
||||
int f = GL_RGBA;
|
||||
if (format == GL_RGB32F || format == GL_RGB16F || format == GL_RGBA32F || format == GL_RGBA16F)
|
||||
t = GL_FLOAT;
|
||||
if (format == GL_RGB32F || format == GL_RGB16F || format == GL_RGB8 || format == GL_RGB)
|
||||
f = GL_RGB;
|
||||
if (format == GL_RGB32F || format == GL_RGB16F || format == GL_RGBA32F || format == GL_RGBA16F) t = GL_FLOAT;
|
||||
if (format == GL_RGB32F || format == GL_RGB16F || format == GL_RGB8 || format == GL_RGB) f = GL_RGB;
|
||||
glTexImage2D(target, 0, format, width, height, 0, f, t, nullptr);
|
||||
//glGenerateMipmap(target);
|
||||
//qDebug() << "glTexImage2D" << width << height << QString::number(t, 16);
|
||||
// glGenerateMipmap(target);
|
||||
// qDebug() << "glTexImage2D" << width << height << QString::number(t, 16);
|
||||
}
|
||||
//qDebug() << QString::number(glGetError(), 16);
|
||||
// qDebug() << QString::number(glGetError(), 16);
|
||||
}
|
||||
|
||||
|
||||
@@ -165,9 +172,9 @@ void createGLTexture(GLuint & tex, const QImage & image, const GLenum & format,
|
||||
}
|
||||
glBindTexture(target, tex);
|
||||
QImage im = image.mirrored(false, true).convertToFormat(QImage::Format_ARGB32, Qt::ColorOnly);
|
||||
//const QImage & cim(im);
|
||||
//glClearError();
|
||||
//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
// const QImage & cim(im);
|
||||
// glClearError();
|
||||
// glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
if (target == GL_TEXTURE_1D || target == GL_TEXTURE_2D || target == GL_TEXTURE_3D) {
|
||||
glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
@@ -177,7 +184,7 @@ void createGLTexture(GLuint & tex, const QImage & image, const GLenum & format,
|
||||
glTexParameteri(target, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
|
||||
}
|
||||
glTexImage2D(target, 0, format, im.width(), im.height(), 0, GL_BGRA, GL_UNSIGNED_BYTE, im.bits());
|
||||
//qDebug() << tex << im.width() << im.height() << im.bits() << glGetError();
|
||||
// qDebug() << tex << im.width() << im.height() << im.bits() << glGetError();
|
||||
}
|
||||
|
||||
|
||||
@@ -186,8 +193,8 @@ QMatrix4x4 glMatrixPerspective(float angle, float aspect, float near_, float far
|
||||
float t = 1.f / (tanf(angle * deg2rad / 2.f)), e = 2.4e-7f;
|
||||
ret(0, 0) = t / aspect;
|
||||
ret(1, 1) = t;
|
||||
ret(2, 2) = e - 1.f;//far_ / (far_ - near_) - 1.;
|
||||
ret(2, 3) = (e - 2.f) * near_;//2. * far_ * near_ / (far_ - near_);
|
||||
ret(2, 2) = e - 1.f; // far_ / (far_ - near_) - 1.;
|
||||
ret(2, 3) = (e - 2.f) * near_; // 2. * far_ * near_ / (far_ - near_);
|
||||
ret(3, 2) = -1.f;
|
||||
ret(3, 3) = 0.f;
|
||||
return ret;
|
||||
@@ -214,14 +221,15 @@ QImage rotateQImageRight(const QImage & im) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QColor colorFromString(const QString & str) {
|
||||
QString s = str.trimmed();
|
||||
int i = s.indexOf("\t");
|
||||
int i = s.indexOf("\t");
|
||||
float r, g, b;
|
||||
r = s.left(i).toFloat(); s = s.right(s.length() - i - 1); i = s.indexOf("\t");
|
||||
g = s.left(i).toFloat(); s = s.right(s.length() - i - 1);
|
||||
r = s.left(i).toFloat();
|
||||
s = s.right(s.length() - i - 1);
|
||||
i = s.indexOf("\t");
|
||||
g = s.left(i).toFloat();
|
||||
s = s.right(s.length() - i - 1);
|
||||
b = s.toFloat();
|
||||
return QColor(r * 255.f, g * 255.f, b * 255.f);
|
||||
}
|
||||
@@ -230,9 +238,12 @@ QColor colorFromString(const QString & str) {
|
||||
QVector3D orthToVector(const QVector3D & v, const float & scale) {
|
||||
if (v.isNull()) return QVector3D();
|
||||
QVector3D rv, fn, sn;
|
||||
if (v.x() != 0.f) rv.setZ(1.);
|
||||
else if (v.y() != 0.f) rv.setX(1.);
|
||||
else rv.setY(1.);
|
||||
if (v.x() != 0.f)
|
||||
rv.setZ(1.);
|
||||
else if (v.y() != 0.f)
|
||||
rv.setX(1.);
|
||||
else
|
||||
rv.setY(1.);
|
||||
fn = QVector3D::crossProduct(v, rv).normalized();
|
||||
sn = QVector3D::crossProduct(v, fn).normalized();
|
||||
return fn * urand(scale) + sn * urand(scale);
|
||||
@@ -266,25 +277,31 @@ void lengthenVector(QVector3D & v, const float & l) {
|
||||
|
||||
Vector3d::Vector3d(const QString & str) {
|
||||
QString s = str.trimmed();
|
||||
int i = s.indexOf("\t");
|
||||
x = s.left(i).toFloat(); s = s.right(s.length() - i - 1); i = s.indexOf("\t");
|
||||
y = s.left(i).toFloat(); s = s.right(s.length() - i - 1);
|
||||
z = s.toFloat();
|
||||
int i = s.indexOf("\t");
|
||||
x = s.left(i).toFloat();
|
||||
s = s.right(s.length() - i - 1);
|
||||
i = s.indexOf("\t");
|
||||
y = s.left(i).toFloat();
|
||||
s = s.right(s.length() - i - 1);
|
||||
z = s.toFloat();
|
||||
}
|
||||
|
||||
|
||||
Vector3i::Vector3i(const QString & str) {
|
||||
QString s = str.trimmed();
|
||||
int i = s.indexOf("\t");
|
||||
p0 = s.left(i).toInt(); s = s.right(s.length() - i - 1); i = s.indexOf("\t");
|
||||
p1 = s.left(i).toInt(); s = s.right(s.length() - i - 1);
|
||||
p2 = s.toInt();
|
||||
int i = s.indexOf("\t");
|
||||
p0 = s.left(i).toInt();
|
||||
s = s.right(s.length() - i - 1);
|
||||
i = s.indexOf("\t");
|
||||
p1 = s.left(i).toInt();
|
||||
s = s.right(s.length() - i - 1);
|
||||
p2 = s.toInt();
|
||||
}
|
||||
|
||||
|
||||
void glEnableDepth() {
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
//glDepthFunc(GL_GREATER);
|
||||
// glDepthFunc(GL_GREATER);
|
||||
glDepthFunc(GL_LESS);
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
@@ -298,7 +315,7 @@ void glDisableDepth() {
|
||||
|
||||
void glClearFramebuffer(const QColor & color, bool depth) {
|
||||
glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF());
|
||||
//glClearDepth(0.);
|
||||
// glClearDepth(0.);
|
||||
if (depth)
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
else
|
||||
@@ -306,10 +323,8 @@ void glClearFramebuffer(const QColor & color, bool depth) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QGLViewBase::QGLViewBase() {
|
||||
camera_ = new Camera();
|
||||
camera_ = new Camera();
|
||||
textures_manager = new GLTextureManager();
|
||||
}
|
||||
|
||||
@@ -347,13 +362,16 @@ Box3D::Box3D(const QVector<QVector3D> & points) {
|
||||
iy = ay = points[0].y();
|
||||
iz = az = points[0].z();
|
||||
for (int i = 1; i < points.size(); ++i) {
|
||||
ix = qMin<float>(ix, points[i].x()); ax = qMax<float>(ax, points[i].x());
|
||||
iy = qMin<float>(iy, points[i].y()); ay = qMax<float>(ay, points[i].y());
|
||||
iz = qMin<float>(iz, points[i].z()); az = qMax<float>(az, points[i].z());
|
||||
ix = qMin<float>(ix, points[i].x());
|
||||
ax = qMax<float>(ax, points[i].x());
|
||||
iy = qMin<float>(iy, points[i].y());
|
||||
ay = qMax<float>(ay, points[i].y());
|
||||
iz = qMin<float>(iz, points[i].z());
|
||||
az = qMax<float>(az, points[i].z());
|
||||
}
|
||||
x = ix;
|
||||
y = iy;
|
||||
z = iz;
|
||||
x = ix;
|
||||
y = iy;
|
||||
z = iz;
|
||||
length = ax - ix;
|
||||
width = ay - iy;
|
||||
height = az - iz;
|
||||
@@ -363,20 +381,27 @@ Box3D::Box3D(const QVector<QVector3D> & points) {
|
||||
QVector<QVector3D> Box3D::corners() const {
|
||||
QVector<QVector3D> ret;
|
||||
ret << QVector3D(x, y, z) << QVector3D(x, y + width, z) << QVector3D(x, y, z + height) << QVector3D(x, y + width, z + height)
|
||||
<< QVector3D(x + length, y, z) << QVector3D(x + length, y + width, z)
|
||||
<< QVector3D(x + length, y, z + height) << QVector3D(x + length, y + width, z + height);
|
||||
<< QVector3D(x + length, y, z) << QVector3D(x + length, y + width, z) << QVector3D(x + length, y, z + height)
|
||||
<< QVector3D(x + length, y + width, z + height);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Box3D & Box3D::operator |=(const Box3D & o) {
|
||||
if (isEmpty()) *this = o;
|
||||
Box3D & Box3D::operator|=(const Box3D & o) {
|
||||
if (isEmpty())
|
||||
*this = o;
|
||||
else {
|
||||
GLfloat mx = x + length, my = y + width, mz = z + height;
|
||||
GLfloat omx = o.x + o.length, omy = o.y + o.width, omz = o.z + o.height;
|
||||
x = qMin(x, o.x); y = qMin(y, o.y); z = qMin(z, o.z);
|
||||
mx = qMax(mx, omx); my = qMax(my, omy); mz = qMax(mz, omz);
|
||||
length = mx - x; width = my - y; height = mz - z;
|
||||
x = qMin(x, o.x);
|
||||
y = qMin(y, o.y);
|
||||
z = qMin(z, o.z);
|
||||
mx = qMax(mx, omx);
|
||||
my = qMax(my, omy);
|
||||
mz = qMax(mz, omz);
|
||||
length = mx - x;
|
||||
width = my - y;
|
||||
height = mz - z;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user