git-svn-id: svn://db.shs.com.ru/libs@540 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -19,18 +19,15 @@
|
||||
#include "gltypes.h"
|
||||
#include "qglview.h"
|
||||
|
||||
Camera * currentCamera;
|
||||
QMatrix4x4 globCameraMatrix;
|
||||
|
||||
|
||||
Camera::Camera() {
|
||||
type_ = glCamera;
|
||||
fov_ = 60.;
|
||||
angle_limit_lower_xy = 0.;
|
||||
angle_limit_upper_xy = 360.;
|
||||
angles_.setY(270.);
|
||||
depth_start = 0.1;
|
||||
depth_end = 1000.;
|
||||
angle_limit_lower_xy = 0.f;
|
||||
angle_limit_upper_xy = 360.f;
|
||||
angles_.setY(270.f);
|
||||
depth_start = 0.1f;
|
||||
depth_end = 1000.f;
|
||||
mirror_x = mirror_y = false;
|
||||
}
|
||||
|
||||
@@ -38,15 +35,15 @@ Camera::Camera() {
|
||||
void Camera::anglesFromPoints() {
|
||||
QVector3D dv = aim_ - pos_, tv;
|
||||
tv = QVector3D(dv.x(), dv.y(), 0.);
|
||||
angles_.setZ(atan2(tv.x(), tv.y()) * rad2deg);
|
||||
angles_.setY(piClamp<GLdouble>(atan2(tv.length(), dv.z()) * rad2deg, angle_limit_lower_xy, angle_limit_upper_xy) + 180.);
|
||||
angles_.setZ(atan2f(tv.x(), tv.y()) * rad2deg);
|
||||
angles_.setY(piClamp<GLfloat>(atan2f(tv.length(), dv.z()) * rad2deg, angle_limit_lower_xy, angle_limit_upper_xy) + 180.f);
|
||||
}
|
||||
|
||||
|
||||
void Camera::apply(const GLdouble & aspect) {
|
||||
void Camera::apply(const GLfloat & aspect) {
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
if (aspect <= 1.)
|
||||
glScaled(aspect, aspect, 1.);
|
||||
if (aspect <= 1.f)
|
||||
glScalef(aspect, aspect, 1.f);
|
||||
QMatrix4x4 pm = glMatrixPerspective(fov_, aspect, depth_start, depth_end);
|
||||
//pm.perspective(fov_, aspect, depth_start, depth_end);
|
||||
//qDebug() << pm;// << glMatrixPerspective(fov_, aspect, depth_start, depth_end);
|
||||
@@ -60,13 +57,10 @@ void Camera::apply(const GLdouble & aspect) {
|
||||
pm.rotate(angles_.z(), 0., 0., 1.);
|
||||
//pm.translate(-aim_);
|
||||
if (parent_) {
|
||||
//double dist = pm(2, 3);
|
||||
QMatrix4x4 pmat = parent_->worldTransform();//.inverted();
|
||||
//offset_.setZ(offset_.z() - dist);
|
||||
QMatrix4x4 pmat = parent_->worldTransform();
|
||||
offset_ = pmat.column(3).toVector3D();
|
||||
pmat(0, 3) = pmat(1, 3) = pmat(2, 3) = 0.;
|
||||
pmat.translate(aim_);
|
||||
//pm.translate(-aim_);
|
||||
pm *= pmat.inverted();
|
||||
//qDebug() << pmat;
|
||||
}
|
||||
@@ -107,88 +101,88 @@ void Camera::assign(const Camera & c) {
|
||||
}
|
||||
|
||||
|
||||
void Camera::panZ(const double & a) {
|
||||
void Camera::panZ(const float & a) {
|
||||
QVector3D dv = aim_ - pos_;
|
||||
double tl = QVector2D(dv.x(), dv.y()).length();
|
||||
float tl = QVector2D(dv.x(), dv.y()).length();
|
||||
angles_.setZ(angles_.z() + a);
|
||||
dv = QVector3D(sin(angles_.z() * deg2rad) * tl, cos(angles_.z() * deg2rad) * tl, dv.z());
|
||||
dv = QVector3D(sinf(angles_.z() * deg2rad) * tl, cosf(angles_.z() * deg2rad) * tl, dv.z());
|
||||
aim_ = pos_ + dv;
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void Camera::panXY(const double & a) {
|
||||
void Camera::panXY(const float & a) {
|
||||
QVector3D dv = aim_ - pos_;
|
||||
double tl = dv.length(), tc;
|
||||
float tl = dv.length(), tc;
|
||||
angles_.setY(angles_.y() + a);
|
||||
angles_.setY(piClamp<GLdouble>(angles_.y(), angle_limit_lower_xy, angle_limit_upper_xy));
|
||||
tc = -sin(angles_.y() * deg2rad);
|
||||
dv = QVector3D(sin(angles_.z() * deg2rad) * tc, cos(angles_.z() * deg2rad) * tc, -cos(angles_.y() * deg2rad));
|
||||
angles_.setY(piClamp<GLfloat>(angles_.y(), angle_limit_lower_xy, angle_limit_upper_xy));
|
||||
tc = -sinf(angles_.y() * deg2rad);
|
||||
dv = QVector3D(sinf(angles_.z() * deg2rad) * tc, cosf(angles_.z() * deg2rad) * tc, -cosf(angles_.y() * deg2rad));
|
||||
aim_ = pos_ + dv * tl;
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void Camera::rotateZ(const double & a) {
|
||||
void Camera::rotateZ(const float & a) {
|
||||
QVector3D dv = aim_ - pos_;
|
||||
double tl = QVector2D(dv.x(), dv.y()).length();
|
||||
float tl = QVector2D(dv.x(), dv.y()).length();
|
||||
angles_.setZ(angles_.z() + a);
|
||||
dv = QVector3D(sin(angles_.z() * deg2rad) * tl, cos(angles_.z() * deg2rad) * tl, dv.z());
|
||||
dv = QVector3D(sinf(angles_.z() * deg2rad) * tl, cosf(angles_.z() * deg2rad) * tl, dv.z());
|
||||
aim_ = pos_ + dv;
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void Camera::rotateXY(const double & a) {
|
||||
void Camera::rotateXY(const float & a) {
|
||||
QVector3D dv = aim_ - pos_;
|
||||
double tl = dv.length(), tc;
|
||||
float tl = dv.length(), tc;
|
||||
angles_.setY(angles_.y() + a);
|
||||
angles_.setY(piClamp<GLdouble>(angles_.y(), angle_limit_lower_xy, angle_limit_upper_xy));
|
||||
tc = -sin(angles_.y() * deg2rad);
|
||||
dv = QVector3D(sin(angles_.z() * deg2rad) * tc, cos(angles_.z() * deg2rad) * tc, -cos(angles_.y() * deg2rad));
|
||||
angles_.setY(piClamp<GLfloat>(angles_.y(), angle_limit_lower_xy, angle_limit_upper_xy));
|
||||
tc = -sinf(angles_.y() * deg2rad);
|
||||
dv = QVector3D(sinf(angles_.z() * deg2rad) * tc, cosf(angles_.z() * deg2rad) * tc, -cosf(angles_.y() * deg2rad));
|
||||
aim_ = pos_ + dv * tl;
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void Camera::orbitZ(const double & a) {
|
||||
void Camera::orbitZ(const float & a) {
|
||||
QVector3D dv = aim_ - pos_;
|
||||
double tl = QVector2D(dv.x(), dv.y()).length();
|
||||
float tl = QVector2D(dv.x(), dv.y()).length();
|
||||
angles_.setZ(angles_.z() + a);
|
||||
dv = QVector3D(sin(angles_.z() * deg2rad) * tl, cos(angles_.z() * deg2rad) * tl, dv.z());
|
||||
dv = QVector3D(sinf(angles_.z() * deg2rad) * tl, cosf(angles_.z() * deg2rad) * tl, dv.z());
|
||||
pos_ = aim_ - dv;
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void Camera::orbitXY(const double & a) {
|
||||
void Camera::orbitXY(const float & a) {
|
||||
QVector3D dv = aim_ - pos_;
|
||||
double tl = dv.length(), tc;
|
||||
float tl = dv.length(), tc;
|
||||
angles_.setY(angles_.y() + a);
|
||||
angles_.setY(piClamp<GLdouble>(angles_.y(), angle_limit_lower_xy, angle_limit_upper_xy));
|
||||
tc = -sin(angles_.y() * deg2rad);
|
||||
dv = QVector3D(sin(angles_.z() * deg2rad) * tc, cos(angles_.z() * deg2rad) * tc, -cos(angles_.y() * deg2rad));
|
||||
angles_.setY(piClamp<GLfloat>(angles_.y(), angle_limit_lower_xy, angle_limit_upper_xy));
|
||||
tc = -sinf(angles_.y() * deg2rad);
|
||||
dv = QVector3D(sinf(angles_.z() * deg2rad) * tc, cosf(angles_.z() * deg2rad) * tc, -cosf(angles_.y() * deg2rad));
|
||||
pos_ = aim_ - dv * tl;
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void Camera::setAngleZ(const double & a) {
|
||||
void Camera::setAngleZ(const float & a) {
|
||||
QVector3D dv = aim_ - pos_;
|
||||
double tl = QVector2D(dv.x(), dv.y()).length();
|
||||
float tl = QVector2D(dv.x(), dv.y()).length();
|
||||
angles_.setZ(a);
|
||||
dv = QVector3D(sin(angles_.z() * deg2rad) * tl, cos(angles_.z() * deg2rad) * tl, dv.z());
|
||||
dv = QVector3D(sinf(angles_.z() * deg2rad) * tl, cosf(angles_.z() * deg2rad) * tl, dv.z());
|
||||
aim_ = pos_ + dv;
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void Camera::setAngleXY(const double & a) {
|
||||
void Camera::setAngleXY(const float & a) {
|
||||
QVector3D dv = aim_ - pos_;
|
||||
double tl = dv.length(), tc;
|
||||
float tl = dv.length(), tc;
|
||||
angles_.setY(a);
|
||||
tc = -sin(angles_.y() * deg2rad);
|
||||
dv = QVector3D(sin(angles_.z() * deg2rad) * tc, cos(angles_.z() * deg2rad) * tc, -cos(angles_.y() * deg2rad));
|
||||
tc = -sinf(angles_.y() * deg2rad);
|
||||
dv = QVector3D(sinf(angles_.z() * deg2rad) * tc, cosf(angles_.z() * deg2rad) * tc, -cosf(angles_.y() * deg2rad));
|
||||
//pos_ = aim_ - dv;
|
||||
aim_ = pos_ + dv * tl;
|
||||
buildTransform();
|
||||
@@ -196,11 +190,11 @@ void Camera::setAngleXY(const double & a) {
|
||||
}
|
||||
|
||||
|
||||
void Camera::moveForward(const double & x, bool withZ) {
|
||||
void Camera::moveForward(const float & x, bool withZ) {
|
||||
QVector3D dv;// = aim_ - pos_;
|
||||
double tc = -sin(angles_.y() * deg2rad);
|
||||
dv = QVector3D(sin(angles_.z() * deg2rad) * tc, cos(angles_.z() * deg2rad) * tc, 0.);
|
||||
if (withZ) dv.setZ(-cos(angles_.y() * deg2rad));
|
||||
float tc = -sinf(angles_.y() * deg2rad);
|
||||
dv = QVector3D(sinf(angles_.z() * deg2rad) * tc, cosf(angles_.z() * deg2rad) * tc, 0.);
|
||||
if (withZ) dv.setZ(-cosf(angles_.y() * deg2rad));
|
||||
dv.normalize();
|
||||
dv *= x;
|
||||
pos_ += dv;
|
||||
@@ -209,11 +203,11 @@ void Camera::moveForward(const double & x, bool withZ) {
|
||||
}
|
||||
|
||||
|
||||
void Camera::moveLeft(const double & x, bool withZ) {
|
||||
void Camera::moveLeft(const float & x, bool withZ) {
|
||||
QVector3D dv;// = aim_ - pos_;
|
||||
double tc = -sin(angles_.y() * deg2rad);
|
||||
dv = QVector3D(sin(angles_.z() * deg2rad - M_PI_2) * tc, cos(angles_.z() * deg2rad - M_PI_2) * tc, 0.);
|
||||
if (withZ) dv.setZ(-sin(angles_.x() * deg2rad));
|
||||
float tc = -sinf(angles_.y() * deg2rad);
|
||||
dv = QVector3D(sinf(angles_.z() * deg2rad - float(M_PI_2)) * tc, cosf(angles_.z() * deg2rad - float(M_PI_2)) * tc, 0.f);
|
||||
if (withZ) dv.setZ(-sinf(angles_.x() * deg2rad));
|
||||
dv.normalize();
|
||||
dv *= x;
|
||||
pos_ += dv;
|
||||
@@ -222,13 +216,13 @@ void Camera::moveLeft(const double & x, bool withZ) {
|
||||
}
|
||||
|
||||
|
||||
void Camera::moveUp(const double & x, bool onlyZ) {
|
||||
void Camera::moveUp(const float & x, bool onlyZ) {
|
||||
QVector3D dv;
|
||||
if (onlyZ)
|
||||
dv = QVector3D(0., 0., x);
|
||||
else {
|
||||
double tc = cos(angles_.y() * deg2rad);
|
||||
dv = QVector3D(sin(angles_.z() * deg2rad) * tc, cos(angles_.z() * deg2rad) * tc, -sin(angles_.y() * deg2rad));
|
||||
float tc = cosf(angles_.y() * deg2rad);
|
||||
dv = QVector3D(sinf(angles_.z() * deg2rad) * tc, cosf(angles_.z() * deg2rad) * tc, -sinf(angles_.y() * deg2rad));
|
||||
dv.normalize();
|
||||
dv *= x;
|
||||
}
|
||||
@@ -238,37 +232,29 @@ void Camera::moveUp(const double & x, bool onlyZ) {
|
||||
}
|
||||
|
||||
|
||||
void Camera::flyCloser(const double & s) {
|
||||
void Camera::flyCloser(const float & s) {
|
||||
QVector3D dv = aim_ - pos_;
|
||||
double tl = dv.length() / (1. + s), tc = -sin(angles_.y() * deg2rad);
|
||||
dv = QVector3D(sin(angles_.z() * deg2rad) * tc, cos(angles_.z() * deg2rad) * tc, -cos(angles_.y() * deg2rad));
|
||||
float tl = dv.length() / (1.f + s), tc = -sinf(angles_.y() * deg2rad);
|
||||
dv = QVector3D(sinf(angles_.z() * deg2rad) * tc, cosf(angles_.z() * deg2rad) * tc, -cosf(angles_.y() * deg2rad));
|
||||
pos_ = aim_ - dv * tl;
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void Camera::flyFarer(const double & s) {
|
||||
void Camera::flyFarer(const float & s) {
|
||||
QVector3D dv = aim_ - pos_;
|
||||
double tl = dv.length() * (1. + s), tc = -sin(angles_.y() * deg2rad);
|
||||
dv = QVector3D(sin(angles_.z() * deg2rad) * tc, cos(angles_.z() * deg2rad) * tc, -cos(angles_.y() * deg2rad));
|
||||
float tl = dv.length() * (1.f + s), tc = -sinf(angles_.y() * deg2rad);
|
||||
dv = QVector3D(sinf(angles_.z() * deg2rad) * tc, cosf(angles_.z() * deg2rad) * tc, -cosf(angles_.y() * deg2rad));
|
||||
pos_ = aim_ - dv * tl;
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void Camera::flyToDistance(const double & d) {
|
||||
void Camera::flyToDistance(const float & d) {
|
||||
QVector3D dv = aim_ - pos_;
|
||||
double tc = -sin(angles_.y() * deg2rad);
|
||||
dv = QVector3D(sin(angles_.z() * deg2rad) * tc, cos(angles_.z() * deg2rad) * tc, -cos(angles_.y() * deg2rad));
|
||||
float tc = -sinf(angles_.y() * deg2rad);
|
||||
dv = QVector3D(sinf(angles_.z() * deg2rad) * tc, cosf(angles_.z() * deg2rad) * tc, -cosf(angles_.y() * deg2rad));
|
||||
pos_ = aim_ - dv * d;
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
/*
|
||||
QVector3D Camera::pointFromViewport(int x_, int y_, double z_) {
|
||||
GLsizei mx = x_, my = viewport[3] - y_, mz = z_;
|
||||
GLdouble x,y,z;
|
||||
gluUnProject(mx, my, mz, modelview, projection, viewport, &x, &y, &z);
|
||||
return QVector3D(x,y,z);
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -36,74 +36,66 @@ public:
|
||||
Camera();
|
||||
|
||||
void setPos(const QVector3D & p) {pos_ = p; anglesFromPoints(); buildTransform();}
|
||||
/*void setPosX(const double & o) {QVector3D dv = aim_ - pos_; pos_.setX(o); aim_ = pos_ + dv;}
|
||||
void setPosY(const double & o) {QVector3D dv = aim_ - pos_; pos_.setY(o); aim_ = pos_ + dv;}
|
||||
void setPosZ(const double & o) {QVector3D dv = aim_ - pos_; pos_.setZ(o); aim_ = pos_ + dv;}*/
|
||||
void setAim(const QVector3D & p) {aim_ = p; anglesFromPoints(); buildTransform();}
|
||||
void move(const QVector3D & p) {pos_ += p; aim_ += p; buildTransform();}
|
||||
void move(const double & x, const double & y = 0., const double & z = 0.) {pos_ += QVector3D(x, y, z); aim_ += QVector3D(x, y, z); buildTransform();}
|
||||
void moveForward(const double & x, bool withZ = true);
|
||||
void moveBackward(const double & x, bool withZ = true) {moveForward(-x, withZ);}
|
||||
void moveLeft(const double & x, bool withZ = true);
|
||||
void moveRight(const double & x, bool withZ = true) {moveLeft(-x, withZ);}
|
||||
void moveUp(const double & x, bool onlyZ = false);
|
||||
void moveDown(const double & x, bool onlyZ = false) {moveUp(-x, onlyZ);}
|
||||
void rotateZ(const double & a);
|
||||
void rotateXY(const double & a);
|
||||
void rotateRoll(const double & a) {angles_.setX(angles_.x() + a); buildTransform();}
|
||||
void orbitZ(const double & a);
|
||||
void orbitXY(const double & a);
|
||||
void panZ(const double & a);
|
||||
void panXY(const double & a);
|
||||
void setFOV(const double & f) {fov_ = f;}
|
||||
void move(const float & x, const float & y = 0., const float & z = 0.) {pos_ += QVector3D(x, y, z); aim_ += QVector3D(x, y, z); buildTransform();}
|
||||
void moveForward(const float & x, bool withZ = true);
|
||||
void moveBackward(const float & x, bool withZ = true) {moveForward(-x, withZ);}
|
||||
void moveLeft(const float & x, bool withZ = true);
|
||||
void moveRight(const float & x, bool withZ = true) {moveLeft(-x, withZ);}
|
||||
void moveUp(const float & x, bool onlyZ = false);
|
||||
void moveDown(const float & x, bool onlyZ = false) {moveUp(-x, onlyZ);}
|
||||
void rotateZ(const float & a);
|
||||
void rotateXY(const float & a);
|
||||
void rotateRoll(const float & a) {angles_.setX(angles_.x() + a); buildTransform();}
|
||||
void orbitZ(const float & a);
|
||||
void orbitXY(const float & a);
|
||||
void panZ(const float & a);
|
||||
void panXY(const float & a);
|
||||
void setFOV(const float & f) {fov_ = f;}
|
||||
void setAngles(const QVector3D & a) {setRotation(a);}
|
||||
void setAngleZ(const double & a);
|
||||
void setAngleXY(const double & a);
|
||||
void setAngleRoll(const double & a) {angles_.setX(a); buildTransform();}
|
||||
void setAngleLowerLimitXY(const double & a) {angle_limit_lower_xy = a; buildTransform();}
|
||||
void setAngleUpperLimitXY(const double & a) {angle_limit_upper_xy = a; buildTransform();}
|
||||
void setAngleLimitsXY(const double & lower, const double & upper) {angle_limit_lower_xy = lower; angle_limit_upper_xy = upper; buildTransform();}
|
||||
void setDepthStart(const double & d) {depth_start = d;}
|
||||
void setDepthEnd(const double & d) {depth_end = d;}
|
||||
void setAngleZ(const float & a);
|
||||
void setAngleXY(const float & a);
|
||||
void setAngleRoll(const float & a) {angles_.setX(a); buildTransform();}
|
||||
void setAngleLowerLimitXY(const float & a) {angle_limit_lower_xy = a; buildTransform();}
|
||||
void setAngleUpperLimitXY(const float & a) {angle_limit_upper_xy = a; buildTransform();}
|
||||
void setAngleLimitsXY(const float & lower, const float & upper) {angle_limit_lower_xy = lower; angle_limit_upper_xy = upper; buildTransform();}
|
||||
void setDepthStart(const float & d) {depth_start = d;}
|
||||
void setDepthEnd(const float & d) {depth_end = d;}
|
||||
void setMirrorX(bool yes) {mirror_x = yes;}
|
||||
void setMirrorY(bool yes) {mirror_y = yes;}
|
||||
void flyCloser(const double & s);
|
||||
void flyFarer(const double & s);
|
||||
void flyToDistance(const double & d);
|
||||
void flyCloser(const float & s);
|
||||
void flyFarer(const float & s);
|
||||
void flyToDistance(const float & d);
|
||||
|
||||
QVector3D aim() const {return aim_;}
|
||||
QVector3D angles() const {return rotation();}
|
||||
QVector3D direction() const {return (aim_ - pos_).normalized();}
|
||||
QVector3D directionXY() const {QVector3D tv = aim_ - pos_; return QVector3D(tv.x(), tv.y(), 0.).normalized();}
|
||||
double FOV() const {return fov_;}
|
||||
double distance() const {return (pos_ - aim_).length();}
|
||||
double angleZ() const {return angles_.z();}
|
||||
double angleXY() const {return angles_.y();}
|
||||
double angleRoll() const {return angles_.x();}
|
||||
double angleLowerLimitXY() const {return angle_limit_lower_xy;}
|
||||
double angleUpperLimitXY() const {return angle_limit_upper_xy;}
|
||||
double depthStart() const {return depth_start;}
|
||||
double depthEnd() const {return depth_end;}
|
||||
float FOV() const {return fov_;}
|
||||
float distance() const {return (pos_ - aim_).length();}
|
||||
float angleZ() const {return angles_.z();}
|
||||
float angleXY() const {return angles_.y();}
|
||||
float angleRoll() const {return angles_.x();}
|
||||
float angleLowerLimitXY() const {return angle_limit_lower_xy;}
|
||||
float angleUpperLimitXY() const {return angle_limit_upper_xy;}
|
||||
float depthStart() const {return depth_start;}
|
||||
float depthEnd() const {return depth_end;}
|
||||
bool isMirrorX() const {return mirror_x;}
|
||||
bool isMirrorY() const {return mirror_y;}
|
||||
void anglesFromPoints();
|
||||
void apply(const GLdouble & aspect = 1.);
|
||||
void apply(const GLfloat & aspect = 1.);
|
||||
void assign(const Camera & c);
|
||||
//QVector3D pointFromViewport(int x_, int y_, double z_); TODO
|
||||
|
||||
QMatrix4x4 offsetMatrix() const;
|
||||
|
||||
private:
|
||||
//void localTransform(QMatrix4x4 & m);
|
||||
|
||||
QVector3D aim_, offset_;
|
||||
GLdouble fov_;
|
||||
GLdouble depth_start;
|
||||
GLdouble depth_end;
|
||||
GLdouble angle_limit_lower_xy;
|
||||
GLdouble angle_limit_upper_xy;
|
||||
//GLdouble modelview[16], projection[16];
|
||||
//GLint viewport[4];
|
||||
GLfloat fov_;
|
||||
GLfloat depth_start;
|
||||
GLfloat depth_end;
|
||||
GLfloat angle_limit_lower_xy;
|
||||
GLfloat angle_limit_upper_xy;
|
||||
bool mirror_x;
|
||||
bool mirror_y;
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ void GLFramebuffer::setWriteBuffers(int * indeces, int count) {
|
||||
|
||||
void GLFramebuffer::bindColorTextures() {
|
||||
for (int i = colors.size() - 1; i >= 0; --i) {
|
||||
glActiveTextureChannel(i);
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
glBindTexture(GL_TEXTURE_2D, colors[i]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
@@ -140,6 +140,6 @@ void GLFramebuffer::bindColorTextures() {
|
||||
|
||||
|
||||
void GLFramebuffer::bindDepthTexture(int channel) {
|
||||
glActiveTextureChannel(channel);
|
||||
glActiveTexture(GL_TEXTURE0 + channel);
|
||||
glBindTexture(GL_TEXTURE_2D, tex_d);
|
||||
}
|
||||
|
||||
@@ -50,6 +50,9 @@ public:
|
||||
void bindDepthTexture(int channel);
|
||||
|
||||
private:
|
||||
void deleteGLRenderbuffer(GLuint & drbo) {if (drbo != 0) glDeleteRenderbuffers(1, &drbo); drbo = 0;}
|
||||
void deleteGLFramebuffer(GLuint & fbo) {if (fbo != 0) glDeleteFramebuffers(1, &fbo); fbo = 0;}
|
||||
|
||||
bool is_depth, is_changed;
|
||||
QVector<GLuint> colors;
|
||||
GLenum color_format, target_;
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#include "gltypes.h"
|
||||
#include "qglview.h"
|
||||
|
||||
GLTextureManager * currentGLTextureManager;
|
||||
QStringList GLTextureManagerBase::search_pathes(".");
|
||||
|
||||
|
||||
@@ -35,12 +34,12 @@ bool GLCubeTexture::create() {
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
//glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
|
||||
//glClearError();
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, format_, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, format_, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, format_, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, format_, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, format_, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, format_, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, format_, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, format_, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, format_, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, format_, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, format_, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, format_, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||
//qDebug() << glGetError();
|
||||
changed_ = false;
|
||||
return id_ > 0;
|
||||
@@ -83,16 +82,14 @@ void GLCubeTexture::loadPathesFromDirectory(const QString & dir) {
|
||||
|
||||
|
||||
QString GLTextureManagerBase::findFile(const QString & path) {
|
||||
if (!currentGLTextureManager) return QString();
|
||||
return ::findFile(path, currentGLTextureManager->search_pathes);
|
||||
return ::findFile(path, search_pathes);
|
||||
}
|
||||
|
||||
|
||||
GLuint GLTextureManagerBase::loadTexture(const QString & path, bool ownership, bool bump) {
|
||||
if (!currentGLTextureManager) return 0;
|
||||
QString p = findFile(path);
|
||||
if (p.isEmpty()) return 0;
|
||||
int tid = ((GLTextureManagerBase*)currentGLTextureManager)->textureID(p, bump);
|
||||
int tid = textureID(p, bump);
|
||||
if (tid > 0) {
|
||||
//qDebug() << "[TextureManager] Found" << path << "as" << tid;
|
||||
return tid;
|
||||
@@ -110,7 +107,7 @@ GLuint GLTextureManagerBase::loadTexture(const QString & path, bool ownership, b
|
||||
return tid;
|
||||
}
|
||||
qDebug() << "[TextureManager] Loaded" << p << "as" << tid;
|
||||
if (ownership) ((GLTextureManagerBase*)currentGLTextureManager)->tex_ids[bump ? 1 : 0].insert(p, tid);
|
||||
if (ownership) tex_ids[bump ? 1 : 0].insert(p, tid);
|
||||
return tid;
|
||||
}
|
||||
|
||||
@@ -126,13 +123,12 @@ GLuint GLTextureManagerBase::loadTexture(const QImage & im, bool ownership, bool
|
||||
return tid;
|
||||
}
|
||||
//qDebug() << "[TextureManager] Loaded image as" << tid;
|
||||
if (ownership) ((GLTextureManagerBase*)currentGLTextureManager)->tex_ids[bump ? 1 : 0].insert(QString(), tid);
|
||||
if (ownership) tex_ids[bump ? 1 : 0].insert(QString(), tid);
|
||||
return tid;
|
||||
}
|
||||
|
||||
|
||||
void GLTextureManagerBase::reloadTexture(GLuint tid, const QString & path) {
|
||||
if (!currentGLTextureManager) return;
|
||||
QString p = findFile(path);
|
||||
if (p.isEmpty() || (tid == 0)) return;
|
||||
QImage image(p);
|
||||
@@ -146,7 +142,6 @@ void GLTextureManagerBase::reloadTexture(GLuint tid, const QString & path) {
|
||||
|
||||
|
||||
void GLTextureManagerBase::reloadTexture(GLuint tid, const QImage & im) {
|
||||
if (!currentGLTextureManager) return;
|
||||
if (im.isNull() || (tid == 0)) return;
|
||||
QImage image(im);
|
||||
createGLTexture(tid, image);
|
||||
@@ -154,28 +149,31 @@ void GLTextureManagerBase::reloadTexture(GLuint tid, const QImage & im) {
|
||||
}
|
||||
|
||||
|
||||
Vector3d colorVector(QRgb c) {return Vector3d(((uchar*)(&c))[0] / 255., ((uchar*)(&c))[1] / 255., ((uchar*)(&c))[2] / 255.);}
|
||||
Vector3d colorVector(QRgb c) {
|
||||
return Vector3d(((uchar*)(&c))[0] / 255., ((uchar*)(&c))[1] / 255., ((uchar*)(&c))[2] / 255.);
|
||||
}
|
||||
|
||||
|
||||
void GLTextureManagerBase::convertToNormal(QImage & im) {
|
||||
if (im.isNull()) return;
|
||||
QImage sim = im.convertToFormat(QImage::Format_ARGB32);
|
||||
double sum[3] = {0., 0., 0.};
|
||||
float sum[3] = {0., 0., 0.};
|
||||
llong a = 0;
|
||||
const uchar * sd = sim.constBits();
|
||||
for (int i = 0; i < sim.height(); i++) {
|
||||
for (int j = 0; j < sim.width(); j++) {
|
||||
sum[2] += double(sd[a]) / 255. - 0.5; ++a;
|
||||
sum[1] += double(sd[a]) / 255. - 0.5; ++a;
|
||||
sum[0] += double(sd[a]) / 255. - 0.5; ++a;
|
||||
sum[2] += sd[a] / 255.f - 0.5f; ++a;
|
||||
sum[1] += sd[a] / 255.f - 0.5f; ++a;
|
||||
sum[0] += sd[a] / 255.f - 0.5f; ++a;
|
||||
++a;
|
||||
}
|
||||
}
|
||||
double wh = sim.width() * sim.height();
|
||||
float wh = sim.width() * sim.height();
|
||||
sum[0] /= wh;
|
||||
sum[1] /= wh;
|
||||
sum[2] /= wh;
|
||||
qDebug() << sum[0] << sum[1] << sum[2];
|
||||
if ((qAbs(sum[0]) <= 0.05) && (qAbs(sum[1]) <= 0.05) && (sum[2] >= 0.4)) /// already normal
|
||||
if ((qAbs(sum[0]) <= 0.05f) && (qAbs(sum[1]) <= 0.05f) && (sum[2] >= 0.4f)) /// already normal
|
||||
return;
|
||||
qDebug() << "convert to bump";
|
||||
QImage dim = QImage(sim.width(), sim.height(), QImage::Format_ARGB32);
|
||||
@@ -192,14 +190,14 @@ void GLTextureManagerBase::convertToNormal(QImage & im) {
|
||||
p[0] = colorVector(sim.pixel(j, i));
|
||||
p[1] = colorVector(sim.pixel(j, ty));
|
||||
p[2] = colorVector(sim.pixel(tx, i));
|
||||
res.y = piClamp(0.5 + (p[0].length() - p[1].length()) / 2., 0., 1.);
|
||||
res.x = piClamp(0.5 + (p[0].length() - p[2].length()) / 2., 0., 1.);
|
||||
res.y = piClamp(0.5f + (p[0].length() - p[1].length()) / 2.f, 0.f, 1.f);
|
||||
res.x = piClamp(0.5f + (p[0].length() - p[2].length()) / 2.f, 0.f, 1.f);
|
||||
tx = (j + 1) % w;
|
||||
ty = (i + 1) % h;
|
||||
p[1] = colorVector(sim.pixel(j, ty));
|
||||
p[2] = colorVector(sim.pixel(tx, i));
|
||||
res.y = piClamp(0.5 + (p[0].length() - p[1].length()) / 2., 0., 1.);
|
||||
res.x = piClamp(0.5 + (p[0].length() - p[2].length()) / 2., 0., 1.);
|
||||
res.y = piClamp(0.5f + (p[0].length() - p[1].length()) / 2.f, 0.f, 1.f);
|
||||
res.x = piClamp(0.5f + (p[0].length() - p[2].length()) / 2.f, 0.f, 1.f);
|
||||
res.z = 1.;
|
||||
dd[a] = res.z * 255; ++a;
|
||||
dd[a] = res.x * 255; ++a;
|
||||
@@ -247,7 +245,7 @@ void Material::apply(QOpenGLShaderProgram * prog) {
|
||||
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
|
||||
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
|
||||
//qDebug() << (map_specularity.color_amount)*128.;
|
||||
glMaterialf(GL_FRONT, GL_SHININESS, (map_specularity.color_amount)*128.);
|
||||
glMaterialf(GL_FRONT, GL_SHININESS, (map_specularity.color_amount)*128.f);
|
||||
glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_diffuse);
|
||||
}
|
||||
@@ -256,7 +254,6 @@ void Material::apply(QOpenGLShaderProgram * prog) {
|
||||
|
||||
void Material::loadTextures(GLTextureManagerBase * tm) {
|
||||
//qDebug() << "load textures";
|
||||
if (!tm) tm = (GLTextureManagerBase*)currentGLTextureManager;
|
||||
if (!tm) return;
|
||||
if (!map_diffuse.bitmap_path.isEmpty()) map_diffuse.bitmap_id = tm->loadTexture(map_diffuse.bitmap_path);
|
||||
if (!map_normal.bitmap_path.isEmpty()) map_normal.bitmap_id = tm->loadTexture(map_normal.bitmap_path, true, true);
|
||||
|
||||
@@ -76,14 +76,19 @@ class GLTextureManager;
|
||||
|
||||
class GLTextureManagerBase {
|
||||
public:
|
||||
static void addSearchPath(const QString & path) {search_pathes << path;}
|
||||
GLTextureManagerBase() {}
|
||||
virtual ~GLTextureManagerBase() {}
|
||||
void addSearchPath(const QString & path) {search_pathes << path;}
|
||||
static QStringList searchPathes() {return search_pathes;}
|
||||
static QString findFile(const QString & path);
|
||||
static GLuint loadTexture(const QString & path, bool ownership = true, bool bump = false);
|
||||
static GLuint loadTexture(const QImage & image, bool ownership = true, bool bump = false);
|
||||
static void reloadTexture(GLuint tid, const QString & path);
|
||||
static void reloadTexture(GLuint tid, const QImage & image);
|
||||
QString findFile(const QString & path);
|
||||
GLuint loadTexture(const QString & path, bool ownership = true, bool bump = false);
|
||||
GLuint loadTexture(const QImage & image, bool ownership = true, bool bump = false);
|
||||
void reloadTexture(GLuint tid, const QString & path);
|
||||
void reloadTexture(GLuint tid, const QImage & image);
|
||||
int textureID(const QString & path, bool bump = false) {return tex_ids[bump ? 1 : 0][path];}
|
||||
virtual void addTexture(const QString & path) = 0;
|
||||
virtual void addAnimation(const QString & dir, const QString & name) = 0;
|
||||
virtual bool loadTextures() = 0;
|
||||
|
||||
protected:
|
||||
static void convertToNormal(QImage & im);
|
||||
@@ -92,8 +97,6 @@ protected:
|
||||
|
||||
};
|
||||
|
||||
//extern GLTextureManager * currentGLTextureManager;
|
||||
|
||||
struct Map {
|
||||
Map() {bitmap_id = 0; color_amount = 1.f; color_offset = 0.f; animation_frame_rate = -1.f;}
|
||||
QString bitmap_path;
|
||||
@@ -108,7 +111,7 @@ struct Map {
|
||||
struct Material {
|
||||
Material();
|
||||
void apply(QOpenGLShaderProgram * prog);
|
||||
void loadTextures(GLTextureManagerBase * tm = 0);
|
||||
void loadTextures(GLTextureManagerBase * tm);
|
||||
QString name;
|
||||
QColor color_diffuse;
|
||||
QColor color_specular;
|
||||
|
||||
@@ -27,7 +27,7 @@ GLObjectBase::GLObjectBase() {
|
||||
pass_ = Solid;
|
||||
geom_prim = Triangles;
|
||||
scale_ = QVector3D(1., 1., 1.);
|
||||
parent_ = 0;
|
||||
parent_ = nullptr;
|
||||
is_root = is_init = is_tex_loaded = selected_ = false;
|
||||
visible_ = accept_fog = accept_light = cast_shadow = rec_shadow = select_ = true;
|
||||
line_width = -1.;
|
||||
@@ -36,7 +36,7 @@ GLObjectBase::GLObjectBase() {
|
||||
type_ = glMesh;
|
||||
raw_matrix = false;
|
||||
mat_.setToIdentity();
|
||||
view_ = 0;
|
||||
view_ = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ GLObjectBase::~GLObjectBase() {
|
||||
if (parent_) parent_->children_.removeAll(this);
|
||||
if (view_) ((QGLView*)view_)->objectDeleted(this);
|
||||
foreach (GLObjectBase * c, children_) {
|
||||
c->parent_ = 0;
|
||||
c->parent_ = nullptr;
|
||||
delete c;
|
||||
}
|
||||
}
|
||||
@@ -81,7 +81,7 @@ GLObjectBase * GLObjectBase::clone(bool withChildren) {
|
||||
o->vbo.normals_ = vbo.normals_;
|
||||
o->vbo.texcoords_ = vbo.texcoords_;
|
||||
o->vbo.colors_ = vbo.colors_;
|
||||
o->view_ = 0;
|
||||
o->view_ = nullptr;
|
||||
o->children_.clear();
|
||||
if (withChildren) {
|
||||
for (int i = 0; i < children_.size(); ++i)
|
||||
@@ -90,6 +90,17 @@ GLObjectBase * GLObjectBase::clone(bool withChildren) {
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
void GLObjectBase::init() {
|
||||
calculateBoundingBox();
|
||||
vbo.init();
|
||||
vbo.rebuffer();
|
||||
//material_.reflection.create();
|
||||
//qDebug() << "init" << vbo.buffer_;
|
||||
is_init = true;
|
||||
}
|
||||
|
||||
|
||||
void GLObjectBase::draw(QOpenGLShaderProgram * prog, bool simplest) {
|
||||
vbo.draw(geom_prim, prog, simplest);
|
||||
/*if (!d_vertices.isEmpty()) {
|
||||
@@ -134,21 +145,65 @@ void GLObjectBase::addChild(GLObjectBase * o) {
|
||||
}
|
||||
|
||||
|
||||
void GLObjectBase::removeChild(GLObjectBase * o) {
|
||||
if (o == this) return;
|
||||
children_.removeAll(o);
|
||||
o->parent_ = nullptr;
|
||||
o->buildTransform();
|
||||
if (view_ != nullptr) view_->collectLights();
|
||||
}
|
||||
|
||||
|
||||
void GLObjectBase::removeChild(int index) {
|
||||
children_[index]->parent_ = nullptr;
|
||||
children_[index]->buildTransform();
|
||||
children_.removeAt(index);
|
||||
if (view_ != nullptr) view_->collectLights();
|
||||
}
|
||||
|
||||
|
||||
void GLObjectBase::clearChildren(bool deleteAll) {
|
||||
foreach (GLObjectBase * i, children_) {
|
||||
i->view_ = 0;
|
||||
i->parent_ = 0;
|
||||
i->view_ = nullptr;
|
||||
i->parent_ = nullptr;
|
||||
i->clearChildren(deleteAll);
|
||||
if (deleteAll) {
|
||||
delete i;
|
||||
} else {
|
||||
i->buildTransform();
|
||||
}
|
||||
i->buildTransform();
|
||||
}
|
||||
children_.clear();
|
||||
if (view_) view_->collectLights();
|
||||
}
|
||||
|
||||
|
||||
GLObjectBase * GLObjectBase::child(int index) {
|
||||
if (index < 0 || index >= children_.size()) return nullptr;
|
||||
return children_[index];
|
||||
}
|
||||
|
||||
|
||||
GLObjectBase * GLObjectBase::child(const QString & name) {
|
||||
foreach (GLObjectBase * i, children_)
|
||||
if (i->name_ == name) return i;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
const GLObjectBase * GLObjectBase::child(int index) const {
|
||||
if (index < 0 || index >= children_.size()) return nullptr;
|
||||
return children_[index];
|
||||
}
|
||||
|
||||
|
||||
const GLObjectBase * GLObjectBase::child(const QString & name) const {
|
||||
foreach (GLObjectBase * i, children_)
|
||||
if (i->name_ == name) return i;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
QList<GLObjectBase * > GLObjectBase::children(bool all_) {
|
||||
if (!all_) return children_;
|
||||
QList<GLObjectBase * > cl;
|
||||
@@ -157,6 +212,66 @@ QList<GLObjectBase * > GLObjectBase::children(bool all_) {
|
||||
}
|
||||
|
||||
|
||||
void GLObjectBase::rotateX(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
angles_.setX(angles_.x() + a);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void GLObjectBase::rotateY(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
angles_.setY(angles_.y() + a);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void GLObjectBase::rotateZ(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
angles_.setZ(angles_.z() + a);
|
||||
while (angles_.z() < -360.f) angles_.setZ(angles_.z() + 360.f);
|
||||
while (angles_.z() > 360.f) angles_.setZ(angles_.z() - 360.f);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void GLObjectBase::setRotationX(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
angles_.setX(a);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void GLObjectBase::setRotationY(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
angles_.setY(a);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void GLObjectBase::setRotationZ(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
angles_.setZ(a);
|
||||
while (angles_.z() < -360.f) angles_.setZ(angles_.z() + 360.f);
|
||||
while (angles_.z() > 360.f) angles_.setZ(angles_.z() - 360.f);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void GLObjectBase::setRotation(const QVector3D & a) {
|
||||
raw_matrix = false;
|
||||
angles_= a;
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void GLObjectBase::resetRotation() {
|
||||
raw_matrix = false;
|
||||
angles_ = QVector3D(0., 0., 0.);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void GLObjectBase::addChildren(QList<GLObjectBase * > & list, GLObjectBase * where) {
|
||||
foreach (GLObjectBase * i, where->children_) {
|
||||
list << i;
|
||||
@@ -165,6 +280,15 @@ void GLObjectBase::addChildren(QList<GLObjectBase * > & list, GLObjectBase * whe
|
||||
}
|
||||
|
||||
|
||||
void GLObjectBase::loadTextures(bool with_children) {
|
||||
material_.loadTextures(view_->textureManager());
|
||||
if (with_children)
|
||||
foreach (GLObjectBase * i, children_) i->loadTextures();
|
||||
is_tex_loaded = true;
|
||||
checkPass();
|
||||
}
|
||||
|
||||
|
||||
void GLObjectBase::calculateBoundingBox() {
|
||||
bound = vbo.boundingBox();
|
||||
QVector<QVector3D> c = bound.corners(), tc;
|
||||
@@ -218,6 +342,15 @@ void GLObjectBase::select() {
|
||||
}
|
||||
|
||||
|
||||
void GLObjectBase::setMaterial(const Material & m, bool with_children) {
|
||||
material_ = m;
|
||||
if (with_children)
|
||||
foreach (GLObjectBase * i, children_) i->setMaterial(m, true);
|
||||
checkPass();
|
||||
is_tex_loaded = false;
|
||||
}
|
||||
|
||||
|
||||
void GLObjectBase::buildTransform() {
|
||||
itransform_.setToIdentity();
|
||||
GLObjectBase * p = parent_;
|
||||
@@ -235,6 +368,13 @@ void GLObjectBase::buildTransform() {
|
||||
}
|
||||
|
||||
|
||||
void GLObjectBase::initInternal() {
|
||||
init();
|
||||
loadTextures();
|
||||
foreach (GLObjectBase * i, children_) i->initInternal();
|
||||
}
|
||||
|
||||
|
||||
void GLObjectBase::localTransform(QMatrix4x4 & m) {
|
||||
m.translate(pos_);
|
||||
m.rotate(angles_.z(), 0., 0., 1.);
|
||||
@@ -245,7 +385,7 @@ void GLObjectBase::localTransform(QMatrix4x4 & m) {
|
||||
|
||||
|
||||
void GLObjectBase::checkPass() {
|
||||
if (material_.color_diffuse.alphaF() * (1.f - material_.transparency) < 1.f) pass_ = Transparent;
|
||||
if (float(material_.color_diffuse.alphaF()) * (1.f - material_.transparency) < 1.f) pass_ = Transparent;
|
||||
else pass_ = Solid;
|
||||
}
|
||||
|
||||
@@ -256,9 +396,9 @@ QMatrix4x4 GLObjectBase::worldMatrix(QMatrix4x4 parent) const {
|
||||
if (raw_matrix) {
|
||||
mat *= mat_;
|
||||
} else {
|
||||
if (angles_.z() != 0.) mat.rotate(angles_.z(), 0., 0., 1.);
|
||||
if (angles_.y() != 0.) mat.rotate(angles_.y(), 0., 1., 0.);
|
||||
if (angles_.x() != 0.) mat.rotate(angles_.x(), 1., 0., 0.);
|
||||
if (angles_.z() != 0.f) mat.rotate(angles_.z(), 0., 0., 1.);
|
||||
if (angles_.y() != 0.f) mat.rotate(angles_.y(), 0., 1., 0.);
|
||||
if (angles_.x() != 0.f) mat.rotate(angles_.x(), 1., 0., 0.);
|
||||
mat.scale(scale_);
|
||||
}
|
||||
return parent * mat;
|
||||
@@ -269,14 +409,14 @@ void GLObjectBase::render(int * id, QMap<int, GLObjectBase * > * ids, int sh_id_
|
||||
if (!visible_) return;
|
||||
//glPushMatrix();
|
||||
///qglMultMatrix TODO
|
||||
material_.apply(0);
|
||||
if (id != 0) {
|
||||
material_.apply(nullptr);
|
||||
if (id != nullptr) {
|
||||
++(*id);
|
||||
ids->insert(*id, this);
|
||||
//glVertexAttrib1f(sh_id_loc, (*id) / 255.f);
|
||||
//qDebug() << "assign to" << sh_id_loc << (*id) / 255.f;
|
||||
}
|
||||
draw(0);
|
||||
draw(nullptr);
|
||||
foreach (GLObjectBase * i, children_)
|
||||
i->render(id, ids, sh_id_loc);
|
||||
//glPopMatrix();
|
||||
@@ -296,7 +436,7 @@ Light::Light(): GLObjectBase(), shadow_map(0, true, GL_R16F) {
|
||||
}
|
||||
|
||||
|
||||
Light::Light(const QVector3D & p, const QColor & c, GLdouble i): GLObjectBase(), shadow_map(0, true, GL_R16F) {
|
||||
Light::Light(const QVector3D & p, const QColor & c, float i): GLObjectBase(), shadow_map(0, true, GL_R16F) {
|
||||
type_ = glLight;
|
||||
light_type = Omni;
|
||||
pos_ = p;
|
||||
@@ -314,7 +454,7 @@ GLObjectBase * Light::clone(bool withChildren) {
|
||||
//GLObjectBase::clone(withChildren);
|
||||
o->is_init = false;
|
||||
o->name_ = name_ + "_copy";
|
||||
o->view_ = 0;
|
||||
o->view_ = nullptr;
|
||||
o->children_.clear();
|
||||
if (withChildren) {
|
||||
for (int i = 0; i < children_.size(); ++i)
|
||||
@@ -340,7 +480,7 @@ void Light::draw(QOpenGLShaderProgram * prog, bool simplest) {
|
||||
glBegin(GL_POINTS);
|
||||
glVertex3f(0., 0., 0.);
|
||||
glEnd();
|
||||
double s = 10;
|
||||
float s = 10;
|
||||
if (light_type != Omni) {
|
||||
glBegin(GL_LINES);
|
||||
QVector4D dir = QVector4D(direction);
|
||||
@@ -365,14 +505,14 @@ QDataStream & operator <<(QDataStream & s, const GLObjectBase * p) {
|
||||
//qDebug() << "place self done";
|
||||
if (p->type_ == GLObjectBase::glLight) {
|
||||
//qDebug() << "place light ...";
|
||||
Light * l = (Light*)p;
|
||||
const Light * l = (const Light*)p;
|
||||
cs << cs.chunk(100, l->direction) << cs.chunk(101, l->angle_start) << cs.chunk(102, l->angle_end) << cs.chunk(103, l->intensity)
|
||||
<< cs.chunk(104, l->decay_const) << cs.chunk(105, l->decay_linear) << cs.chunk(106, l->decay_quadratic)
|
||||
<< cs.chunk(107, l->decay_start) << cs.chunk(108, l->decay_end) << cs.chunk(109, int(l->light_type));
|
||||
}
|
||||
if (p->type_ == GLObjectBase::glCamera) {
|
||||
//qDebug() << "place camera ...";
|
||||
Camera * c = (Camera*)p;
|
||||
const Camera * c = (const Camera*)p;
|
||||
cs << cs.chunk(200, c->aim_) << cs.chunk(201, c->fov_) << cs.chunk(202, c->depth_start) << cs.chunk(203, c->depth_end)
|
||||
<< cs.chunk(204, c->angle_limit_lower_xy) << cs.chunk(205, c->angle_limit_upper_xy)
|
||||
<< cs.chunk(206, c->mirror_x) << cs.chunk(207, c->mirror_y);
|
||||
@@ -385,10 +525,10 @@ QDataStream & operator <<(QDataStream & s, const GLObjectBase * p) {
|
||||
}
|
||||
QDataStream & operator >>(QDataStream & s, GLObjectBase *& p) {
|
||||
ChunkStream cs(s);
|
||||
p = 0;
|
||||
p = nullptr;
|
||||
int ccnt = 0;
|
||||
Light * l = 0;
|
||||
Camera * c = 0;
|
||||
Light * l = nullptr;
|
||||
Camera * c = nullptr;
|
||||
//qDebug() << "read obj ...";
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
@@ -410,7 +550,7 @@ QDataStream & operator >>(QDataStream & s, GLObjectBase *& p) {
|
||||
case 5: if (p) p->cast_shadow = cs.getData<bool>(); break;
|
||||
case 6: if (p) p->rec_shadow = cs.getData<bool>(); break;
|
||||
case 7: if (p) p->raw_matrix = cs.getData<bool>(); break;
|
||||
case 8: if (p) p->line_width = cs.getData<double>(); break;
|
||||
case 8: if (p) p->line_width = cs.getData<float>(); break;
|
||||
case 9: if (p) p->render_mode = (GLObjectBase::RenderMode)cs.getData<int>(); break;
|
||||
case 10: if (p) p->material_ = cs.getData<Material>(); break;
|
||||
case 11: if (p) p->pos_ = cs.getData<QVector3D>(); break;
|
||||
@@ -422,28 +562,28 @@ QDataStream & operator >>(QDataStream & s, GLObjectBase *& p) {
|
||||
case 17: if (p) p->name_ = cs.getData<QString>(); break;
|
||||
case 18: if (p) p->meta = cs.getData<QVariantMap>(); break;
|
||||
case 100: if (l) l->direction = cs.getData<QVector3D>(); break;
|
||||
case 101: if (l) l->angle_start = cs.getData<GLdouble>(); break;
|
||||
case 102: if (l) l->angle_end = cs.getData<GLdouble>(); break;
|
||||
case 103: if (l) l->intensity = cs.getData<GLdouble>(); break;
|
||||
case 104: if (l) l->decay_const = cs.getData<GLdouble>(); break;
|
||||
case 105: if (l) l->decay_linear = cs.getData<GLdouble>(); break;
|
||||
case 106: if (l) l->decay_quadratic = cs.getData<GLdouble>(); break;
|
||||
case 107: if (l) l->decay_start = cs.getData<GLdouble>(); break;
|
||||
case 108: if (l) l->decay_end = cs.getData<GLdouble>(); break;
|
||||
case 101: if (l) l->angle_start = cs.getData<GLfloat>(); break;
|
||||
case 102: if (l) l->angle_end = cs.getData<GLfloat>(); break;
|
||||
case 103: if (l) l->intensity = cs.getData<GLfloat>(); break;
|
||||
case 104: if (l) l->decay_const = cs.getData<GLfloat>(); break;
|
||||
case 105: if (l) l->decay_linear = cs.getData<GLfloat>(); break;
|
||||
case 106: if (l) l->decay_quadratic = cs.getData<GLfloat>(); break;
|
||||
case 107: if (l) l->decay_start = cs.getData<GLfloat>(); break;
|
||||
case 108: if (l) l->decay_end = cs.getData<GLfloat>(); break;
|
||||
case 109: if (l) l->light_type = (Light::Type)cs.getData<int>(); break;
|
||||
case 200: if (c) c->setAim(cs.getData<QVector3D>()); break;
|
||||
case 201: if (c) c->setFOV(cs.getData<GLdouble>()); break;
|
||||
case 202: if (c) c->setDepthStart(cs.getData<GLdouble>()); break;
|
||||
case 203: if (c) c->setDepthEnd(cs.getData<GLdouble>()); break;
|
||||
case 204: if (c) c->setAngleLowerLimitXY(cs.getData<GLdouble>()); break;
|
||||
case 205: if (c) c->setAngleUpperLimitXY(cs.getData<GLdouble>()); break;
|
||||
case 201: if (c) c->setFOV(cs.getData<GLfloat>()); break;
|
||||
case 202: if (c) c->setDepthStart(cs.getData<GLfloat>()); break;
|
||||
case 203: if (c) c->setDepthEnd(cs.getData<GLfloat>()); break;
|
||||
case 204: if (c) c->setAngleLowerLimitXY(cs.getData<GLfloat>()); break;
|
||||
case 205: if (c) c->setAngleUpperLimitXY(cs.getData<GLfloat>()); break;
|
||||
case 206: if (c) c->mirror_x = cs.getData<bool>(); break;
|
||||
case 207: if (c) c->mirror_y = cs.getData<bool>(); break;
|
||||
}
|
||||
}
|
||||
//qDebug() << p->name() << ccnt;
|
||||
for (int i = 0; i < ccnt; ++i) {
|
||||
GLObjectBase * c = 0;
|
||||
GLObjectBase * c = nullptr;
|
||||
s >> c;
|
||||
if (!c) continue;
|
||||
c->parent_ = p;
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
enum GeomPrimitives {Triangles = GL_TRIANGLES, Quads = GL_QUADS};
|
||||
enum RenderMode {View = 0, Point = GL_POINT, Line = GL_LINE, Fill = GL_FILL};
|
||||
|
||||
GLObjectBase();
|
||||
explicit GLObjectBase();
|
||||
virtual ~GLObjectBase();
|
||||
|
||||
virtual GLObjectBase * clone(bool withChildren = true);
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
QString name() const {return name_;}
|
||||
void setName(const QString & name) {name_ = name;}
|
||||
//virtual GLuint hList() {return list;}
|
||||
virtual void init() {calculateBoundingBox(); vbo.init(); vbo.rebuffer(); /*material_.reflection.create();*/ /*qDebug() << "init" << vbo.buffer_;*/ is_init = true;}
|
||||
virtual void init();
|
||||
virtual void draw(QOpenGLShaderProgram * prog, bool simplest = false);
|
||||
virtual void update() {}
|
||||
bool isInit() const {return is_init;}
|
||||
@@ -57,24 +57,24 @@ public:
|
||||
RenderMode renderMode() const {return render_mode;}
|
||||
void setRenderMode(RenderMode mode) {render_mode = mode;}
|
||||
|
||||
double lineWidth() const {return line_width;}
|
||||
void setLineWidth(const double & width) {line_width = width;}
|
||||
float lineWidth() const {return line_width;}
|
||||
void setLineWidth(const float & width) {line_width = width;}
|
||||
|
||||
GLObjectBase * parent() {return parent_;}
|
||||
void setParent(GLObjectBase * o) {parent_ = o;}
|
||||
bool hasParent() const {return parent_ != 0;}
|
||||
bool hasParent() const {return parent_ != nullptr;}
|
||||
bool hasChildren() const {return children_.size() != 0;}
|
||||
void setView(QGLView * v);
|
||||
|
||||
void addChild(GLObjectBase * o);
|
||||
void removeChild(GLObjectBase * o) {if (o == this) return; children_.removeAll(o); o->parent_ = 0; o->buildTransform(); if (view_ != 0) view_->collectLights();}
|
||||
void removeChild(int index) {children_[index]->parent_ = 0; children_[index]->buildTransform(); children_.removeAt(index); if (view_ != 0) view_->collectLights();}
|
||||
void removeChild(GLObjectBase * o);
|
||||
void removeChild(int index);
|
||||
void clearChildren(bool deleteAll = false);
|
||||
int childCount() const {return children_.size();}
|
||||
GLObjectBase * child(int index) {if (index < 0 || index >= children_.size()) return 0; return children_[index];}
|
||||
GLObjectBase * child(const QString & name) {foreach (GLObjectBase * i, children_) if (i->name_ == name) return i; return 0;}
|
||||
const GLObjectBase * child(int index) const {if (index < 0 || index >= children_.size()) return 0; return children_[index];}
|
||||
const GLObjectBase * child(const QString & name) const {foreach (GLObjectBase * i, children_) if (i->name_ == name) return i; return 0;}
|
||||
GLObjectBase * child(int index);
|
||||
GLObjectBase * child(const QString & name);
|
||||
const GLObjectBase * child(int index) const;
|
||||
const GLObjectBase * child(const QString & name) const;
|
||||
QList<GLObjectBase * > children(bool all_ = false);
|
||||
|
||||
bool isVisible() const {return visible_;}
|
||||
@@ -91,54 +91,54 @@ public:
|
||||
|
||||
void move(const QVector3D & dv) {pos_ += dv; buildTransform();}
|
||||
void moveTo(const QVector3D & dv) {pos_ = dv; buildTransform();}
|
||||
void move(GLdouble dx, GLdouble dy, GLdouble dz = 0.) {move(QVector3D(dx, dy, dz)); buildTransform();}
|
||||
void moveTo(GLdouble dx, GLdouble dy, GLdouble dz = 0.) {moveTo(QVector3D(dx, dy, dz)); buildTransform();}
|
||||
void moveX(GLdouble o) {pos_.setX(pos_.x() + o); buildTransform();}
|
||||
void moveY(GLdouble o) {pos_.setY(pos_.y() + o); buildTransform();}
|
||||
void moveZ(GLdouble o) {pos_.setZ(pos_.z() + o); buildTransform();}
|
||||
void setPosX(GLdouble o) {pos_.setX(o); buildTransform();}
|
||||
void setPosY(GLdouble o) {pos_.setY(o); buildTransform();}
|
||||
void setPosZ(GLdouble o) {pos_.setZ(o); buildTransform();}
|
||||
void setPos(GLdouble x, GLdouble y, GLdouble z) {pos_ = QVector3D(x, y, z); buildTransform();}
|
||||
void move(GLfloat dx, GLfloat dy, GLfloat dz = 0.) {move(QVector3D(dx, dy, dz)); buildTransform();}
|
||||
void moveTo(GLfloat dx, GLfloat dy, GLfloat dz = 0.) {moveTo(QVector3D(dx, dy, dz)); buildTransform();}
|
||||
void moveX(GLfloat o) {pos_.setX(pos_.x() + o); buildTransform();}
|
||||
void moveY(GLfloat o) {pos_.setY(pos_.y() + o); buildTransform();}
|
||||
void moveZ(GLfloat o) {pos_.setZ(pos_.z() + o); buildTransform();}
|
||||
void setPosX(GLfloat o) {pos_.setX(o); buildTransform();}
|
||||
void setPosY(GLfloat o) {pos_.setY(o); buildTransform();}
|
||||
void setPosZ(GLfloat o) {pos_.setZ(o); buildTransform();}
|
||||
void setPos(GLfloat x, GLfloat y, GLfloat z) {pos_ = QVector3D(x, y, z); buildTransform();}
|
||||
void setPos(const QVector3D & p) {pos_ = p; buildTransform();}
|
||||
void resetPos() {pos_ = QVector3D(0., 0., 0.); buildTransform();}
|
||||
|
||||
QVector3D pos() const {return pos_;}
|
||||
double posX() const {return pos_.x();}
|
||||
double posY() const {return pos_.y();}
|
||||
double posZ() const {return pos_.z();}
|
||||
float posX() const {return pos_.x();}
|
||||
float posY() const {return pos_.y();}
|
||||
float posZ() const {return pos_.z();}
|
||||
QVector3D worldPos() const {return (itransform_ * QVector4D(0, 0, 0, 1.)).toVector3D();}
|
||||
QMatrix4x4 worldTransform() const {return itransform_;}
|
||||
|
||||
QVector3D rotation() const {return angles_;}
|
||||
double rotationX() const {return angles_.x();}
|
||||
double rotationY() const {return angles_.y();}
|
||||
double rotationZ() const {return angles_.z();}
|
||||
void rotateX(GLdouble a) {raw_matrix = false; angles_.setX(angles_.x() + a); buildTransform();}
|
||||
void rotateY(GLdouble a) {raw_matrix = false; angles_.setY(angles_.y() + a); buildTransform();}
|
||||
void rotateZ(GLdouble a) {raw_matrix = false; angles_.setZ(angles_.z() + a); while (angles_.z() < -360.) angles_.setZ(angles_.z() + 360.); while (angles_.z() > 360.) angles_.setZ(angles_.z() - 360.); buildTransform();}
|
||||
void setRotationX(GLdouble a) {raw_matrix = false; angles_.setX(a); buildTransform();}
|
||||
void setRotationY(GLdouble a) {raw_matrix = false; angles_.setY(a); buildTransform();}
|
||||
void setRotationZ(GLdouble a) {raw_matrix = false; angles_.setZ(a); while (angles_.z() < -360.) angles_.setZ(angles_.z() + 360.); while (angles_.z() > 360.) angles_.setZ(angles_.z() - 360.); buildTransform();}
|
||||
void setRotation(const QVector3D & a) {raw_matrix = false; angles_= a; buildTransform();}
|
||||
void resetRotation() {raw_matrix = false; angles_ = QVector3D(0., 0., 0.); buildTransform();}
|
||||
float rotationX() const {return angles_.x();}
|
||||
float rotationY() const {return angles_.y();}
|
||||
float rotationZ() const {return angles_.z();}
|
||||
void rotateX(GLfloat a);
|
||||
void rotateY(GLfloat a);
|
||||
void rotateZ(GLfloat a);
|
||||
void setRotationX(GLfloat a);
|
||||
void setRotationY(GLfloat a);
|
||||
void setRotationZ(GLfloat a);
|
||||
void setRotation(const QVector3D & a);
|
||||
void resetRotation();
|
||||
|
||||
QVector3D scale() {return scale_;}
|
||||
double scaleX() {return scale_.x();}
|
||||
double scaleY() {return scale_.y();}
|
||||
double scaleZ() {return scale_.z();}
|
||||
float scaleX() {return scale_.x();}
|
||||
float scaleY() {return scale_.y();}
|
||||
float scaleZ() {return scale_.z();}
|
||||
void scale(const QVector3D & sv) {raw_matrix = false; scale_ *= sv; buildTransform();}
|
||||
void scale(GLdouble sx, GLdouble sy, GLdouble sz) {raw_matrix = false; scale(QVector3D(sx, sy, sz)); buildTransform();}
|
||||
void scale(GLdouble sx, GLdouble sy) {raw_matrix = false; scale(QVector3D(sx, sy, sy)); buildTransform();}
|
||||
void scale(GLdouble sx) {raw_matrix = false; scale(QVector3D(sx, sx, sx)); buildTransform();}
|
||||
void scaleX(GLdouble a) {raw_matrix = false; scale_.setX(scale_.x() + a); buildTransform();}
|
||||
void scaleY(GLdouble a) {raw_matrix = false; scale_.setY(scale_.y() + a); buildTransform();}
|
||||
void scaleZ(GLdouble a) {raw_matrix = false; scale_.setZ(scale_.z() + a); buildTransform();}
|
||||
void scale(GLfloat sx, GLfloat sy, GLfloat sz) {raw_matrix = false; scale(QVector3D(sx, sy, sz)); buildTransform();}
|
||||
void scale(GLfloat sx, GLfloat sy) {raw_matrix = false; scale(QVector3D(sx, sy, sy)); buildTransform();}
|
||||
void scale(GLfloat sx) {raw_matrix = false; scale(QVector3D(sx, sx, sx)); buildTransform();}
|
||||
void scaleX(GLfloat a) {raw_matrix = false; scale_.setX(scale_.x() + a); buildTransform();}
|
||||
void scaleY(GLfloat a) {raw_matrix = false; scale_.setY(scale_.y() + a); buildTransform();}
|
||||
void scaleZ(GLfloat a) {raw_matrix = false; scale_.setZ(scale_.z() + a); buildTransform();}
|
||||
void setScale(const QVector3D & a) {raw_matrix = false; scale_ = a; buildTransform();}
|
||||
void setScale(GLdouble a) {raw_matrix = false; scale_ = QVector3D(a, a, a); buildTransform();}
|
||||
void setScaleX(GLdouble a) {raw_matrix = false; scale_.setX(a); buildTransform();}
|
||||
void setScaleY(GLdouble a) {raw_matrix = false; scale_.setY(a); buildTransform();}
|
||||
void setScaleZ(GLdouble a) {raw_matrix = false; scale_.setZ(a); buildTransform();}
|
||||
void setScale(GLfloat a) {raw_matrix = false; scale_ = QVector3D(a, a, a); buildTransform();}
|
||||
void setScaleX(GLfloat a) {raw_matrix = false; scale_.setX(a); buildTransform();}
|
||||
void setScaleY(GLfloat a) {raw_matrix = false; scale_.setY(a); buildTransform();}
|
||||
void setScaleZ(GLfloat a) {raw_matrix = false; scale_.setZ(a); buildTransform();}
|
||||
void resetScale() {raw_matrix = false; scale_ = QVector3D(1., 1., 1.); buildTransform();}
|
||||
|
||||
QMatrix4x4 transform() {return mat_;}
|
||||
@@ -170,8 +170,8 @@ public:
|
||||
void setSrcAlpha(GLenum mode) {blend_src = mode;}
|
||||
void setDestAlpha(GLenum mode) {blend_dest = mode;}
|
||||
|
||||
void setMaterial(const Material & m, bool with_children = false) {material_ = m; if (with_children) foreach (GLObjectBase * i, children_) i->setMaterial(m, true); checkPass(); is_tex_loaded = false;}
|
||||
Material & material() {/*is_tex_loaded = false;*/ return material_;}
|
||||
void setMaterial(const Material & m, bool with_children = false);
|
||||
Material & material() {return material_;}
|
||||
|
||||
const Box3D & boundingBox(bool withChildren = true) const {return bound;}
|
||||
GLVBO & VBO() {return vbo;}
|
||||
@@ -192,11 +192,11 @@ public:
|
||||
|
||||
protected:
|
||||
void addChildren(QList<GLObjectBase * > & list, GLObjectBase * where);
|
||||
void loadTextures(bool with_children = false) {material_.loadTextures(view_->textureManager()); if (with_children) foreach (GLObjectBase * i, children_) i->loadTextures(); is_tex_loaded = true; checkPass();}
|
||||
void loadTextures(bool with_children = false);
|
||||
//void deleteTextures() {foreach (GLuint i, textures) currentQGLView->deleteTexture(i); textures.clear();}
|
||||
void buildTransform();
|
||||
void initInternal() {init(); loadTextures(); foreach (GLObjectBase * i, children_) i->initInternal();}
|
||||
void render(int * id = 0, QMap<int, GLObjectBase * > * ids = 0, int sh_id_loc = 0);
|
||||
void initInternal();
|
||||
void render(int * id = nullptr, QMap<int, GLObjectBase * > * ids = nullptr, int sh_id_loc = 0);
|
||||
void checkPass();
|
||||
virtual void localTransform(QMatrix4x4 & m);
|
||||
QMatrix4x4 worldMatrix(QMatrix4x4 parent) const;
|
||||
@@ -204,7 +204,7 @@ protected:
|
||||
int pass_; // Pass
|
||||
bool is_init, is_tex_loaded, accept_light, accept_fog, /*write_depth_,*/ visible_, cast_shadow, rec_shadow, select_, selected_, raw_matrix;
|
||||
bool is_root;
|
||||
double line_width;
|
||||
float line_width;
|
||||
Type type_;
|
||||
GeomPrimitives geom_prim;
|
||||
RenderMode render_mode;
|
||||
@@ -233,20 +233,20 @@ public:
|
||||
enum Type {Omni, Directional, Cone};
|
||||
|
||||
Light();
|
||||
Light(const QVector3D & p, const QColor & c = Qt::white, GLdouble i = 1.);
|
||||
Light(const QVector3D & p, const QColor & c = Qt::white, float i = 1.);
|
||||
virtual GLObjectBase * clone(bool withChildren = true);
|
||||
virtual void init() {shadow_map.resize(512, 512); is_init = true;}
|
||||
virtual void draw(QOpenGLShaderProgram * prog, bool simplest = false);
|
||||
|
||||
QVector3D direction, dir0, dir1;
|
||||
GLdouble angle_start;
|
||||
GLdouble angle_end;
|
||||
GLdouble intensity;
|
||||
GLdouble decay_const;
|
||||
GLdouble decay_linear;
|
||||
GLdouble decay_quadratic;
|
||||
GLdouble decay_start;
|
||||
GLdouble decay_end;
|
||||
float angle_start;
|
||||
float angle_end;
|
||||
float intensity;
|
||||
float decay_const;
|
||||
float decay_linear;
|
||||
float decay_quadratic;
|
||||
float decay_start;
|
||||
float decay_end;
|
||||
Type light_type;
|
||||
GLFramebuffer shadow_map;
|
||||
QMatrix4x4 shadow_matrix;
|
||||
|
||||
@@ -110,11 +110,10 @@ void GLParticlesSystem::update() {
|
||||
|
||||
void GLParticlesSystem::draw(QOpenGLShaderProgram * prog, bool) {
|
||||
if (particles.isEmpty()) return;
|
||||
if (view_ == 0) return;
|
||||
QGLCI
|
||||
if (view_ == nullptr) return;
|
||||
pass_ = GLObjectBase::Transparent;
|
||||
Camera & camera(view_->camera());
|
||||
QVector3D apos = camera.pos(), dir = camera.direction();
|
||||
Camera * camera(view_->camera());
|
||||
QVector3D apos = camera->pos(), dir = camera->direction();
|
||||
//qDebug() << dir;
|
||||
//qDebug() << camera.angles();
|
||||
//qDebug() << camera.angle_xy;
|
||||
@@ -124,9 +123,9 @@ void GLParticlesSystem::draw(QOpenGLShaderProgram * prog, bool) {
|
||||
tr_b = material_.color_diffuse.blueF(),
|
||||
tr_a = material_.color_diffuse.alphaF() * (1.f - material_.transparency);
|
||||
//cxys = sin(camera.angle_xy * deg2rad);
|
||||
cxyc = cos(camera.angles_.y() * deg2rad);
|
||||
czs = sin(camera.angles_.z() * deg2rad);
|
||||
czc = cos(camera.angles_.z() * deg2rad);
|
||||
cxyc = cosf(camera->angles_.y() * deg2rad);
|
||||
czs = sinf(camera->angles_.z() * deg2rad);
|
||||
czc = cosf(camera->angles_.z() * deg2rad);
|
||||
|
||||
dx = -czc;
|
||||
dy = czs;
|
||||
@@ -161,7 +160,7 @@ void GLParticlesSystem::draw(QOpenGLShaderProgram * prog, bool) {
|
||||
colors << tr_r << tr_g << tr_b << a;
|
||||
colors << tr_r << tr_g << tr_b << a;
|
||||
if (add_vert_face) {
|
||||
if (cxyc > 0.) {
|
||||
if (cxyc > 0.f) {
|
||||
vertices << i.pos.x() - cdx << i.pos.y() - cdy << i.pos.z();
|
||||
vertices << i.pos.x() + cdx << i.pos.y() - cdy << i.pos.z();
|
||||
vertices << i.pos.x() + cdx << i.pos.y() + cdy << i.pos.z();
|
||||
@@ -187,7 +186,7 @@ void GLParticlesSystem::draw(QOpenGLShaderProgram * prog, bool) {
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
QGLC glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
//glNormal3f(vn.x(), vn.y(), vn.z());
|
||||
glNormal3f(0., 0., 1.);
|
||||
glDepthMask(false);
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "globject.h"
|
||||
#include "glcamera.h"
|
||||
|
||||
class GLParticlesSystem: public QObject, public GLObjectBase
|
||||
class GLParticlesSystem: public QObject, public GLObjectBase, protected QOpenGLFunctions
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(float birthRate READ birthRate WRITE setBirthRate)
|
||||
|
||||
@@ -32,14 +32,14 @@ void GLPrimitivePoint::draw(QOpenGLShaderProgram * prog, bool simplest) {
|
||||
void GLPrimitiveLine::draw(QOpenGLShaderProgram * prog, bool simplest) {
|
||||
glColor3f(material_.color_diffuse.redF(), material_.color_diffuse.greenF(), material_.color_diffuse.blueF());
|
||||
glBegin(GL_LINES);
|
||||
glVertex3d(p0.x(), p0.y(), p0.z());
|
||||
glVertex3d(p1.x(), p1.y(), p1.z());
|
||||
glVertex3f(p0.x(), p0.y(), p0.z());
|
||||
glVertex3f(p1.x(), p1.y(), p1.z());
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
||||
|
||||
GLPrimitiveCube::GLPrimitiveCube(double width, double length, double height, QVector3D pos): GLObjectBase() {
|
||||
GLPrimitiveCube::GLPrimitiveCube(float width, float length, float height, QVector3D pos): GLObjectBase() {
|
||||
geom_prim = Quads;
|
||||
w = width;
|
||||
l = length;
|
||||
@@ -50,7 +50,7 @@ GLPrimitiveCube::GLPrimitiveCube(double width, double length, double height, QVe
|
||||
|
||||
|
||||
void GLPrimitiveCube::init() {
|
||||
double hw = w / 2., hl = l / 2., hh = h / 2.;
|
||||
float hw = w / 2.f, hl = l / 2.f, hh = h / 2.f;
|
||||
//list = glGenLists(1);
|
||||
//glNewList(list, GL_COMPILE);
|
||||
//glColor4d(material_.color_diffuse.redF(), material_.color_diffuse.greenF(), material_.color_diffuse.blueF(), material_.color_diffuse.alphaF());
|
||||
@@ -106,7 +106,7 @@ void GLPrimitiveCube::init() {
|
||||
}
|
||||
|
||||
|
||||
GLPrimitiveEllipsoid::GLPrimitiveEllipsoid(double width, double length, double height, int seg_wl, int seg_h, QVector3D pos) {
|
||||
GLPrimitiveEllipsoid::GLPrimitiveEllipsoid(float width, float length, float height, int seg_wl, int seg_h, QVector3D pos) {
|
||||
geom_prim = GLObjectBase::Triangles;
|
||||
w = width;
|
||||
l = length;
|
||||
@@ -135,21 +135,21 @@ void GLPrimitiveEllipsoid::init() {
|
||||
QVector<QVector3D> points;
|
||||
vbo.clear();
|
||||
vbo.init();
|
||||
uint ret = 0;
|
||||
int ret = 0;
|
||||
int hseg = sh + 1, wlseg = swl + 1;
|
||||
double crw, crl, a, ch, twl;
|
||||
QVector3D cp(0., 0., -h / 2.);
|
||||
float crw, crl, a, ch, twl;
|
||||
QVector3D cp(0., 0., -h / 2.f);
|
||||
points << cp;
|
||||
for (int i = 1; i < hseg; i++) {
|
||||
ch = -cos((double)i / hseg * M_PI);
|
||||
cp.setZ(ch * h / 2.);
|
||||
twl = sqrt(1. - ch * ch) / 2.;
|
||||
ch = -cosf((float)i / hseg * float(M_PI));
|
||||
cp.setZ(ch * h / 2.f);
|
||||
twl = sqrtf(1.f - ch * ch) / 2.f;
|
||||
crw = twl * w;
|
||||
crl = twl * l;
|
||||
for (int j = 0; j < wlseg * 2; j++) {
|
||||
a = (double)j / wlseg * M_PI;
|
||||
cp.setY(crw * sin(a));
|
||||
cp.setX(crl * cos(a));
|
||||
a = (float)j / wlseg * float(M_PI);
|
||||
cp.setY(crw * sinf(a));
|
||||
cp.setX(crl * cosf(a));
|
||||
points << cp;
|
||||
ret = points.size() - 1;
|
||||
if (i == 1)
|
||||
@@ -167,7 +167,7 @@ void GLPrimitiveEllipsoid::init() {
|
||||
putTriangle(points[ret - wlseg * 2 + 1], points[ret - wlseg * 2], points[ret - wlseg * 4 + 1]);
|
||||
}
|
||||
}
|
||||
points << QVector3D(0., 0., h / 2.);
|
||||
points << QVector3D(0., 0., h / 2.f);
|
||||
ret = points.size() - 1;
|
||||
putTriangle(points[ret - 1], points[ret - wlseg * 2], points[ret]);
|
||||
for (int j = 1; j < wlseg * 2; j++)
|
||||
|
||||
@@ -53,10 +53,10 @@ private:
|
||||
class GLPrimitiveCube: public GLObjectBase
|
||||
{
|
||||
public:
|
||||
GLPrimitiveCube(double width = 1., double length = 1., double height = 1., QVector3D pos = QVector3D());
|
||||
GLPrimitiveCube(float width = 1., float length = 1., float height = 1., QVector3D pos = QVector3D());
|
||||
virtual void init();
|
||||
private:
|
||||
double w, l, h;
|
||||
float w, l, h;
|
||||
};
|
||||
|
||||
|
||||
@@ -65,11 +65,11 @@ private:
|
||||
class GLPrimitiveEllipsoid: public GLObjectBase
|
||||
{
|
||||
public:
|
||||
GLPrimitiveEllipsoid(double width = 1., double length = 1., double height = 1., int seg_wl = 10, int seg_h = 10, QVector3D pos = QVector3D());
|
||||
GLPrimitiveEllipsoid(float width = 1., float length = 1., float height = 1., int seg_wl = 10, int seg_h = 10, QVector3D pos = QVector3D());
|
||||
virtual void init();
|
||||
private:
|
||||
void putTriangle(const QVector3D & v0, const QVector3D & v1, const QVector3D & v2);
|
||||
double w, l, h;
|
||||
float w, l, h;
|
||||
int swl, sh;
|
||||
};
|
||||
|
||||
|
||||
@@ -43,9 +43,9 @@ void GLRendererBase::setupLight(const Light & l, int inpass_index, int gl_index)
|
||||
dir[0] = ld.x();
|
||||
dir[1] = ld.y();
|
||||
dir[2] = ld.z();
|
||||
col[0] = l.visible_ ? l.color().redF() * l.intensity : 0.;
|
||||
col[1] = l.visible_ ? l.color().greenF() * l.intensity : 0.;
|
||||
col[2] = l.visible_ ? l.color().blueF() * l.intensity : 0.;
|
||||
col[0] = l.visible_ ? l.color().redF() * l.intensity : 0.f;
|
||||
col[1] = l.visible_ ? l.color().greenF() * l.intensity : 0.f;
|
||||
col[2] = l.visible_ ? l.color().blueF() * l.intensity : 0.f;
|
||||
glEnable(gl_index);
|
||||
//glLightfv(gl_index, GL_AMBIENT, ambient);
|
||||
glLightfv(gl_index, GL_DIFFUSE, col);
|
||||
@@ -56,8 +56,8 @@ void GLRendererBase::setupLight(const Light & l, int inpass_index, int gl_index)
|
||||
glLightf(gl_index, GL_QUADRATIC_ATTENUATION, l.decay_quadratic);
|
||||
if (l.light_type == Light::Cone) {
|
||||
glLightfv(gl_index, GL_SPOT_DIRECTION, dir);
|
||||
glLightf(gl_index, GL_SPOT_CUTOFF, l.angle_end / 2.);
|
||||
glLightf(gl_index, GL_SPOT_EXPONENT, (1. - piClamp<double>((l.angle_end - l.angle_start) / (l.angle_end + 0.001), 0., 1.)) * 128.);
|
||||
glLightf(gl_index, GL_SPOT_CUTOFF, l.angle_end / 2.f);
|
||||
glLightf(gl_index, GL_SPOT_EXPONENT, (1.f - piClamp<float>((l.angle_end - l.angle_start) / (l.angle_end + 0.001f), 0., 1.f)) * 128.f);
|
||||
} else {
|
||||
glLightf(gl_index, GL_SPOT_CUTOFF, 180.);
|
||||
}
|
||||
@@ -88,12 +88,12 @@ void GLRendererBase::setupShadersLights(int lights_count) {
|
||||
|
||||
#define BIND_TEXTURE(ch, map) if (rp.prev_tex[ch] != mat.map.bitmap_id) { \
|
||||
rp.prev_tex[ch] = mat.map.bitmap_id; \
|
||||
glActiveTextureChannel(ch); glBindTexture(GL_TEXTURE_2D, mat.map.bitmap_id); \
|
||||
glActiveTexture(GL_TEXTURE0 + ch); glBindTexture(GL_TEXTURE_2D, mat.map.bitmap_id); \
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, view.feature(QGLView::qglAnisotropicLevel).toInt());}
|
||||
|
||||
void GLRendererBase::setupTextures(GLObjectBase & o, GLRendererBase::RenderingParameters & rp, bool first_object) {
|
||||
if (first_object) {
|
||||
glReleaseTextures();
|
||||
view.glReleaseTextures();
|
||||
return;
|
||||
}
|
||||
setupShadersTextures(o, rp);
|
||||
@@ -107,13 +107,13 @@ void GLRendererBase::setupTextures(GLObjectBase & o, GLRendererBase::RenderingPa
|
||||
else {if (rp.prev_fog) {glSetFogEnabled(false); rp.prev_fog = false;}}
|
||||
}
|
||||
if (rp.textures) {
|
||||
BIND_TEXTURE(0, map_diffuse);
|
||||
BIND_TEXTURE(1, map_normal);
|
||||
BIND_TEXTURE(2, map_relief);
|
||||
BIND_TEXTURE(3, map_self_illumination);
|
||||
BIND_TEXTURE(4, map_specularity);
|
||||
BIND_TEXTURE(5, map_specular);
|
||||
glActiveTextureChannel(0);
|
||||
BIND_TEXTURE(0, map_diffuse)
|
||||
BIND_TEXTURE(1, map_normal)
|
||||
BIND_TEXTURE(2, map_relief)
|
||||
BIND_TEXTURE(3, map_self_illumination)
|
||||
BIND_TEXTURE(4, map_specularity)
|
||||
BIND_TEXTURE(5, map_specular)
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ void GLRendererBase::renderObjects(int pass, int light_pass, void * shaders, boo
|
||||
rpl.prev_view_matrix = rp.prev_view_matrix;
|
||||
rpl.proj_matrix = rp.proj_matrix;
|
||||
rpl.prev_proj_matrix = rp.prev_proj_matrix;
|
||||
rpl.cam_offset_matrix = view.camera().offsetMatrix();
|
||||
rpl.cam_offset_matrix = view.camera()->offsetMatrix();
|
||||
//qDebug() << "view:" << rp.view_matrix;
|
||||
for (int i = 0; i < 32; ++i) rpl.prev_tex[i] = 0;
|
||||
setupTextures(view.objects_, rpl, true);
|
||||
@@ -192,12 +192,12 @@ void GLRendererBase::renderSingleObject(GLObjectBase & o, RenderingParameters &
|
||||
setupTextures(o, rpl, false);
|
||||
mat.apply((QOpenGLShaderProgram*)rpl.shaders);
|
||||
glSetPolygonMode(o.render_mode != GLObjectBase::View ? o.render_mode : (view.rmode != GLObjectBase::View ? view.rmode : GL_FILL));
|
||||
glLineWidth(o.line_width > 0. ? o.line_width : view.lineWidth_);
|
||||
glPointSize(o.line_width > 0. ? o.line_width : view.lineWidth_);
|
||||
glLineWidth(o.line_width > 0.f ? o.line_width : view.lineWidth_);
|
||||
glPointSize(o.line_width > 0.f ? o.line_width : view.lineWidth_);
|
||||
o.update();
|
||||
if (o.pass_ == GLObjectBase::Transparent) {
|
||||
glActiveTextureChannel(3);
|
||||
if (mat.reflectivity > 0.) {
|
||||
glActiveTexture(GL_TEXTURE0 + 3);
|
||||
if (mat.reflectivity > 0.f) {
|
||||
glEnable(GL_TEXTURE_CUBE_MAP);
|
||||
if (!mat.map_reflection.isEmpty()) mat.map_reflection.bind();
|
||||
else glDisable(GL_TEXTURE_CUBE_MAP);
|
||||
@@ -214,7 +214,7 @@ void GLRendererBase::renderSingleObject(GLObjectBase & o, RenderingParameters &
|
||||
///glLoadTransposeMatrixf(gm);
|
||||
glScalef(-1., -1., -1.);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glActiveTextureChannel(0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
if (rpl.shaders) {
|
||||
//qDebug() << o.name() << curview << curview.determinant();
|
||||
@@ -235,8 +235,8 @@ void GLRendererBase::renderShadow(Light * l, QOpenGLShaderProgram * prog, QMatri
|
||||
QVector3D wp = l->worldPos();
|
||||
cam.setPos(wp);
|
||||
cam.setAim(wp + (/*l->worldTransform() */ QVector4D(l->direction)).toVector3D());
|
||||
cam.setDepthStart(view.camera().depthStart());
|
||||
cam.setDepthEnd(view.camera().depthEnd());
|
||||
cam.setDepthStart(view.camera()->depthStart());
|
||||
cam.setDepthEnd(view.camera()->depthEnd());
|
||||
cam.setFOV(l->angle_end);
|
||||
cam.apply(1.);
|
||||
/*cam.rotateXY(l->angle_end);
|
||||
@@ -276,8 +276,8 @@ void GLRendererBase::renderSingleShadow(GLObjectBase & o, RenderingParameters &
|
||||
setGLMatrix(rpl.view_matrix * rpl.cam_offset_matrix * o.itransform_);
|
||||
}
|
||||
glPolygonMode(GL_FRONT_AND_BACK, o.render_mode != GLObjectBase::View ? o.render_mode : (view.rmode != GLObjectBase::View ? view.rmode : GL_FILL));
|
||||
glLineWidth(o.line_width > 0. ? o.line_width : view.lineWidth_);
|
||||
glPointSize(o.line_width > 0. ? o.line_width : view.lineWidth_);
|
||||
glLineWidth(o.line_width > 0.f ? o.line_width : view.lineWidth_);
|
||||
glPointSize(o.line_width > 0.f ? o.line_width : view.lineWidth_);
|
||||
o.draw((QOpenGLShaderProgram*)rpl.shaders, true);
|
||||
foreach (GLObjectBase * i, o.children_)
|
||||
renderSingleShadow(*i, rpl);
|
||||
@@ -287,8 +287,8 @@ void GLRendererBase::renderSingleShadow(GLObjectBase & o, RenderingParameters &
|
||||
|
||||
|
||||
GLRendererBase::RenderingParameters::RenderingParameters() {
|
||||
shaders = 0;
|
||||
cur_shader = 0;
|
||||
shaders = nullptr;
|
||||
cur_shader = nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -180,13 +180,13 @@ void setUniformMap(QOpenGLShaderProgram * prog, QString map_name, const Map & ma
|
||||
void setUniformMaterial(QOpenGLShaderProgram * prog, const Material & mat) {
|
||||
if (!prog) return;
|
||||
if (!prog->isLinked()) return;
|
||||
QGLCI
|
||||
QOpenGLFunctions *glFuncs = QOpenGLContext::currentContext()->functions();
|
||||
GLfloat mat_diffuse[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
mat_diffuse[0] = mat.color_diffuse.redF();
|
||||
mat_diffuse[1] = mat.color_diffuse.greenF();
|
||||
mat_diffuse[2] = mat.color_diffuse.blueF();
|
||||
mat_diffuse[3] = mat.color_diffuse.alphaF() * (1.f - mat.transparency);
|
||||
QGLC glVertexAttrib4f(prog->attributeLocation("qgl_Color"), mat_diffuse[0], mat_diffuse[1], mat_diffuse[2], mat_diffuse[3]);
|
||||
glFuncs->glVertexAttrib4f(prog->attributeLocation("qgl_Color"), mat_diffuse[0], mat_diffuse[1], mat_diffuse[2], mat_diffuse[3]);
|
||||
prog->setUniformValue("qgl_Material.transparency", mat.transparency);
|
||||
prog->setUniformValue("qgl_Material.reflectivity", mat.reflectivity);
|
||||
prog->setUniformValue("qgl_Material.iof", mat.iof);
|
||||
@@ -228,7 +228,7 @@ void setUniformLight(QOpenGLShaderProgram * prog, Light * light, QString ulightn
|
||||
QVector4D pos(0, 0, 0, 1.), dir(light->direction);//, dir0(light->dir0), dir1(light->dir1);
|
||||
pos = m * pos;
|
||||
dir = (mat * dir).normalized();
|
||||
double ang_start = light->angle_start / 2., ang_end = light->angle_end / 2.;
|
||||
float ang_start = light->angle_start / 2.f, ang_end = light->angle_end / 2.f;
|
||||
if (light->light_type == Light::Omni)
|
||||
ang_start = ang_end = 180.;
|
||||
//qDebug() << "light" << light->name() << ulightn << pos;
|
||||
@@ -236,9 +236,9 @@ void setUniformLight(QOpenGLShaderProgram * prog, Light * light, QString ulightn
|
||||
prog->setUniformValue((ulightn + ".direction").toLatin1().constData(), dir);
|
||||
prog->setUniformValue((ulightn + ".intensity").toLatin1().constData(), GLfloat(light->intensity));
|
||||
prog->setUniformValue((ulightn + ".startAngle").toLatin1().constData(), GLfloat(ang_start));
|
||||
prog->setUniformValue((ulightn + ".startAngleCos").toLatin1().constData(), GLfloat(cos(ang_start * deg2rad)));
|
||||
prog->setUniformValue((ulightn + ".startAngleCos").toLatin1().constData(), GLfloat(cosf(ang_start * deg2rad)));
|
||||
prog->setUniformValue((ulightn + ".endAngle").toLatin1().constData(), GLfloat(ang_end));
|
||||
prog->setUniformValue((ulightn + ".endAngleCos").toLatin1().constData(), GLfloat(cos(ang_end * deg2rad)));
|
||||
prog->setUniformValue((ulightn + ".endAngleCos").toLatin1().constData(), GLfloat(cosf(ang_end * deg2rad)));
|
||||
prog->setUniformValue((ulightn + ".color").toLatin1().constData(), light->color());
|
||||
prog->setUniformValue((ulightn + ".constantAttenuation").toLatin1().constData(), GLfloat(light->decay_const));
|
||||
prog->setUniformValue((ulightn + ".linearAttenuation").toLatin1().constData(), GLfloat(light->decay_linear));
|
||||
|
||||
@@ -32,5 +32,4 @@ void setUniformMap(QOpenGLShaderProgram * prog, const Map & map, int channel, in
|
||||
void setUniformMaterial(QOpenGLShaderProgram * prog, const Material & mat);
|
||||
void setUniformLights(QOpenGLShaderProgram * prog, const QVector<Light*> & lights, const QMatrix4x4 & mat, int shadow_start);
|
||||
void setUniformLight(QOpenGLShaderProgram * prog, Light * light, QString ulightn, const QMatrix4x4 & mat = QMatrix4x4(), int shadow = 0);
|
||||
|
||||
#endif // GLSHADERS_H
|
||||
|
||||
@@ -54,7 +54,6 @@ QString findFile(const QString & file, const QStringList & pathes) {
|
||||
|
||||
|
||||
void glDrawQuad(QOpenGLShaderProgram * prog, QVector4D * corner_dirs, GLfloat x, GLfloat y, GLfloat w, GLfloat h) {
|
||||
QGLCI
|
||||
glResetAllTransforms();
|
||||
glSetPolygonMode(GL_FILL);
|
||||
int loc = prog ? prog->attributeLocation("qgl_Color") : 0,
|
||||
@@ -62,18 +61,19 @@ void glDrawQuad(QOpenGLShaderProgram * prog, QVector4D * corner_dirs, GLfloat x,
|
||||
loct = prog ? prog->attributeLocation("qgl_Texture") : 0,
|
||||
locc = prog ? prog->attributeLocation("view_corner") : 0;
|
||||
glBegin(GL_QUADS);
|
||||
if (prog) {QGLC glVertexAttrib3f(loc, 1.f, 1.f, 1.f);} glColor3f(1.f, 1.f, 1.f);
|
||||
if (prog) {if (corner_dirs) prog->setAttributeValue(locc, corner_dirs[0]); QGLC glVertexAttrib2f(loct, 0.f, 0.f); QGLC glVertexAttrib2f(locv, x, y);} glTexCoord2f(0.f, 0.f); glVertex2f(x, y);
|
||||
if (prog) {if (corner_dirs) prog->setAttributeValue(locc, corner_dirs[1]); QGLC glVertexAttrib2f(loct, 1.f, 0.f); QGLC glVertexAttrib2f(locv, x + w, y);} glTexCoord2f(1.f, 0.f); glVertex2f(x + w, y);
|
||||
if (prog) {if (corner_dirs) prog->setAttributeValue(locc, corner_dirs[2]); QGLC glVertexAttrib2f(loct, 1.f, 1.f); QGLC glVertexAttrib2f(locv, x + w, y + h);} glTexCoord2f(1.f, 1.f); glVertex2f(x + w, y + h);
|
||||
if (prog) {if (corner_dirs) prog->setAttributeValue(locc, corner_dirs[3]); QGLC glVertexAttrib2f(loct, 0.f, 1.f); QGLC glVertexAttrib2f(locv, x, y + h);} glTexCoord2f(0.f, 1.f); glVertex2f(x, y + h);
|
||||
QOpenGLFunctions *glFuncs = QOpenGLContext::currentContext()->functions();
|
||||
if (prog) {glFuncs->glVertexAttrib3f(loc, 1.f, 1.f, 1.f);} glColor3f(1.f, 1.f, 1.f);
|
||||
if (prog) {if (corner_dirs) prog->setAttributeValue(locc, corner_dirs[0]); glFuncs->glVertexAttrib2f(loct, 0.f, 0.f); glFuncs->glVertexAttrib2f(locv, x, y);} glTexCoord2f(0.f, 0.f); glVertex2f(x, y);
|
||||
if (prog) {if (corner_dirs) prog->setAttributeValue(locc, corner_dirs[1]); glFuncs->glVertexAttrib2f(loct, 1.f, 0.f); glFuncs->glVertexAttrib2f(locv, x + w, y);} glTexCoord2f(1.f, 0.f); glVertex2f(x + w, y);
|
||||
if (prog) {if (corner_dirs) prog->setAttributeValue(locc, corner_dirs[2]); glFuncs->glVertexAttrib2f(loct, 1.f, 1.f); glFuncs->glVertexAttrib2f(locv, x + w, y + h);} glTexCoord2f(1.f, 1.f); glVertex2f(x + w, y + h);
|
||||
if (prog) {if (corner_dirs) prog->setAttributeValue(locc, corner_dirs[3]); glFuncs->glVertexAttrib2f(loct, 0.f, 1.f); glFuncs->glVertexAttrib2f(locv, x, y + h);} glTexCoord2f(0.f, 1.f); glVertex2f(x, y + h);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
||||
QMatrix4x4 getGLMatrix(GLenum matrix) {
|
||||
GLdouble gm[16];
|
||||
glGetDoublev(matrix, gm);
|
||||
GLfloat gm[16];
|
||||
glGetFloatv(matrix, gm);
|
||||
float qm[16];
|
||||
for (int i = 0; i < 16; ++i)
|
||||
qm[i] = gm[i];
|
||||
@@ -82,22 +82,22 @@ QMatrix4x4 getGLMatrix(GLenum matrix) {
|
||||
|
||||
|
||||
void setGLMatrix(QMatrix4x4 matrix) {
|
||||
GLdouble gm[16];
|
||||
GLfloat gm[16];
|
||||
float qm[16];
|
||||
matrix.transposed().copyDataTo(qm);
|
||||
for (int i = 0; i < 16; ++i)
|
||||
gm[i] = qm[i];
|
||||
glLoadMatrixd(gm);
|
||||
glLoadMatrixf(gm);
|
||||
}
|
||||
|
||||
|
||||
void qglMultMatrix(const QMatrix4x4 & m) {
|
||||
GLdouble gm[16];
|
||||
GLfloat gm[16];
|
||||
float qm[16];
|
||||
m.transposed().copyDataTo(qm);
|
||||
for (int i = 0; i < 16; ++i)
|
||||
gm[i] = qm[i];
|
||||
glMultMatrixd(gm);
|
||||
glMultMatrixf(gm);
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ void createGLTexture(GLuint & tex, int width, int height, const GLenum & format,
|
||||
}
|
||||
//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, 0);
|
||||
glTexImage2D(target, 0, format, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, nullptr);
|
||||
else {
|
||||
int t = GL_UNSIGNED_BYTE;
|
||||
int f = GL_RGBA;
|
||||
@@ -117,7 +117,7 @@ void createGLTexture(GLuint & tex, int width, int height, const GLenum & format,
|
||||
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, 0);
|
||||
glTexImage2D(target, 0, format, width, height, 0, f, t, nullptr);
|
||||
//glGenerateMipmap(target);
|
||||
//qDebug() << "glTexImage2D" << width << height << QString::number(t, 16);
|
||||
}
|
||||
@@ -147,15 +147,15 @@ void createGLTexture(GLuint & tex, const QImage & image, const GLenum & format,
|
||||
}
|
||||
|
||||
|
||||
QMatrix4x4 glMatrixPerspective(double angle, double aspect, double near_, double far_) {
|
||||
QMatrix4x4 glMatrixPerspective(float angle, float aspect, float near_, float far_) {
|
||||
QMatrix4x4 ret;
|
||||
double t = 1. / (tan(angle * deg2rad / 2.)), e = 2.4e-7;
|
||||
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.;//far_ / (far_ - near_) - 1.;
|
||||
ret(2, 3) = (e - 2.) * near_;//2. * far_ * near_ / (far_ - near_);
|
||||
ret(3, 2) = -1.;
|
||||
ret(3, 3) = 0.;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -185,19 +185,19 @@ QImage rotateQImageRight(const QImage & im) {
|
||||
QColor colorFromString(const QString & str) {
|
||||
QString s = str.trimmed();
|
||||
int i = s.indexOf("\t");
|
||||
double r, g, b;
|
||||
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);
|
||||
b = s.toFloat();
|
||||
return QColor(r * 255., g * 255., b * 255.);
|
||||
return QColor(r * 255.f, g * 255.f, b * 255.f);
|
||||
}
|
||||
|
||||
|
||||
QVector3D orthToVector(const QVector3D & v, const double & scale) {
|
||||
QVector3D orthToVector(const QVector3D & v, const float & scale) {
|
||||
if (v.isNull()) return QVector3D();
|
||||
QVector3D rv, fn, sn;
|
||||
if (v.x() != 0) rv.setZ(1.);
|
||||
else if (v.y() != 0) rv.setX(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();
|
||||
@@ -214,18 +214,18 @@ QVector3D rotateVector(const QVector3D & v, const QVector3D & a) {
|
||||
}
|
||||
|
||||
|
||||
void setVectorLength(QVector3D & v, const double & l) {
|
||||
double vl = v.length();
|
||||
if (vl == 0.) return;
|
||||
double c = l / vl;
|
||||
void setVectorLength(QVector3D & v, const float & l) {
|
||||
float vl = v.length();
|
||||
if (vl == 0.f) return;
|
||||
float c = l / vl;
|
||||
v *= c;
|
||||
}
|
||||
|
||||
|
||||
void lengthenVector(QVector3D & v, const double & l) {
|
||||
double vl = v.length();
|
||||
if (l == 0. || vl == 0.) return;
|
||||
double c = 1. + l / vl;
|
||||
void lengthenVector(QVector3D & v, const float & l) {
|
||||
float vl = v.length();
|
||||
if (l == 0.f || vl == 0.f) return;
|
||||
float c = 1.f + l / vl;
|
||||
v *= c;
|
||||
}
|
||||
|
||||
@@ -276,26 +276,32 @@ void glClearFramebuffer(const QColor & color, bool depth) {
|
||||
|
||||
QGLViewBase::QGLViewBase() {
|
||||
camera_ = new Camera();
|
||||
textures_manager = new GLTextureManager();
|
||||
}
|
||||
|
||||
|
||||
Camera & QGLViewBase::camera() {
|
||||
return *camera_;
|
||||
QGLViewBase::~QGLViewBase() {
|
||||
delete textures_manager;
|
||||
}
|
||||
|
||||
|
||||
const Camera & QGLViewBase::camera() const {
|
||||
return *camera_;
|
||||
Camera * QGLViewBase::camera() {
|
||||
return camera_;
|
||||
}
|
||||
|
||||
|
||||
void QGLViewBase::setCamera(const Camera & camera) {
|
||||
*camera_ = camera;
|
||||
const Camera * QGLViewBase::camera() const {
|
||||
return camera_;
|
||||
}
|
||||
|
||||
|
||||
void QGLViewBase::setCamera(Camera * camera) {
|
||||
camera_ = camera;
|
||||
}
|
||||
|
||||
|
||||
GLTextureManagerBase * QGLViewBase::textureManager() {
|
||||
return m_texture_manager;
|
||||
return textures_manager;
|
||||
}
|
||||
|
||||
|
||||
@@ -307,9 +313,9 @@ 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<double>(ix, points[i].x()); ax = qMax<double>(ax, points[i].x());
|
||||
iy = qMin<double>(iy, points[i].y()); ay = qMax<double>(ay, points[i].y());
|
||||
iz = qMin<double>(iz, points[i].z()); az = qMax<double>(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;
|
||||
|
||||
@@ -110,8 +110,8 @@ typedef unsigned long ulong;
|
||||
typedef unsigned long long ullong;
|
||||
typedef long double ldouble;
|
||||
|
||||
const double deg2rad = atan(1.) / 45.;
|
||||
const double rad2deg = 45. / atan(1.);
|
||||
const float deg2rad = atanf(1.f) / 45.f;
|
||||
const float rad2deg = 45.f / atanf(1.f);
|
||||
|
||||
# ifdef WINDOWS
|
||||
inline int random() {return rand();}
|
||||
@@ -121,9 +121,9 @@ inline int random() {return rand();}
|
||||
#endif
|
||||
|
||||
#ifdef CC_VC
|
||||
inline double round(const double & v) {return floor(v + 0.5);}
|
||||
inline float round(const float & v) {return floor(v + 0.5);}
|
||||
#endif
|
||||
inline double randomu() {return double(random()) / RAND_MAX;}
|
||||
inline float randomu() {return float(random()) / RAND_MAX;}
|
||||
|
||||
inline const QSizeF operator *(const QSizeF & f, const QSizeF & s) {return QSizeF(f.width() * s.width(), f.height() * s.height());}
|
||||
#ifndef PIP_VERSION
|
||||
@@ -136,13 +136,13 @@ template<typename Type> inline Type piClamp(const Type & v, const Type & min, co
|
||||
inline ushort letobe_s(ushort v) {return (v << 8) | (v >> 8);}
|
||||
#endif
|
||||
// return [-1, 1]
|
||||
inline double urand(const double & scale = 1.) {return ((double)rand() / RAND_MAX - .5) * (scale + scale);}
|
||||
inline float urand(const float & scale = 1.) {return ((float)rand() / RAND_MAX - .5f) * (scale + scale);}
|
||||
// return [0, 1]
|
||||
inline double uprand(const double & scale = 1.) {return ((double)rand() / RAND_MAX) * scale;}
|
||||
inline float uprand(const float & scale = 1.) {return ((float)rand() / RAND_MAX) * scale;}
|
||||
QString readCharsUntilNull(QDataStream & s);
|
||||
QString findFile(const QString & file, const QStringList & pathes);
|
||||
inline QColor operator *(const QColor & c, double v) {return QColor(c.red() * v, c.green() * v, c.blue() * v, c.alpha() * v);}
|
||||
inline QColor operator /(const QColor & c, double v) {return QColor(c.red() / v, c.green() / v, c.blue() / v, c.alpha() / v);}
|
||||
inline QColor operator *(const QColor & c, float v) {return QColor(c.red() * v, c.green() * v, c.blue() * v, c.alpha() * v);}
|
||||
inline QColor operator /(const QColor & c, float v) {return QColor(c.red() / v, c.green() / v, c.blue() / v, c.alpha() / v);}
|
||||
|
||||
//extern __GLWidget__ * currentQGLView;
|
||||
|
||||
@@ -158,26 +158,26 @@ inline void glSetCapEnabled(GLenum cap, bool on = true) {if (on) glEnable(cap);
|
||||
inline void glSetLightEnabled(bool on) {if (on) glEnable(GL_LIGHTING); else glDisable(GL_LIGHTING);}
|
||||
inline void glSetFogEnabled(bool on) {if (on) glEnable(GL_FOG); else glDisable(GL_FOG);}
|
||||
inline void glSetPolygonMode(GLenum mode) {glPolygonMode(GL_FRONT_AND_BACK, mode);}
|
||||
void glDrawQuad(QOpenGLShaderProgram * prog = 0, QVector4D * corner_dirs = 0, GLfloat x = -1.f, GLfloat y = -1.f, GLfloat w = 2.f, GLfloat h = 2.f);
|
||||
void glDrawQuad(QOpenGLShaderProgram * prog = nullptr, QVector4D * corner_dirs = nullptr, GLfloat x = -1.f, GLfloat y = -1.f, GLfloat w = 2.f, GLfloat h = 2.f);
|
||||
QMatrix4x4 getGLMatrix(GLenum matrix);
|
||||
void setGLMatrix(QMatrix4x4 matrix);
|
||||
inline void deleteGLTexture(GLuint & tex) {if (tex != 0) glDeleteTextures(1, &tex); tex = 0;}
|
||||
# define QGLCI if (!QOpenGLContext::currentContext()) return; QOpenGLExtraFunctions gf(QOpenGLContext::currentContext());
|
||||
# define QGLC gf.
|
||||
inline void glActiveTextureChannel(int channel) {QGLCI gf.glActiveTexture(GL_TEXTURE0 + channel);}
|
||||
inline void glDisableTextures(int channels = 8) {QGLCI for (int i = channels - 1; i >= 0; --i) {glActiveTextureChannel(i); glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_CUBE_MAP);}}
|
||||
inline void glReleaseTextures(int channels = 8) {QGLCI for (int i = channels - 1; i >= 0; --i) {glActiveTextureChannel(i); glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_CUBE_MAP, 0);}}
|
||||
inline void glReleaseFramebuffer() {QGLCI gf.glBindFramebuffer(GL_FRAMEBUFFER, 0);}
|
||||
inline void glReleaseShaders() {QGLCI gf.glUseProgram(0);}
|
||||
inline void deleteGLFramebuffer(GLuint & fbo) {QGLCI if (fbo != 0) gf.glDeleteFramebuffers(1, &fbo); fbo = 0;}
|
||||
inline void deleteGLRenderbuffer(GLuint & drbo) {QGLCI if (drbo != 0) gf.glDeleteRenderbuffers(1, &drbo); drbo = 0;}
|
||||
inline void deleteGLBuffer(GLuint & bo) {QGLCI if (bo != 0) gf.glDeleteBuffers(1, &bo); bo = 0;}
|
||||
inline void deleteGLVertexArray(GLuint & va) {QGLCI if (va != 0) gf.glDeleteVertexArrays(1, &va); va = 0;}
|
||||
//# define QGLCI if (!QOpenGLContext::currentContext()) return; QOpenGLExtraFunctions gf(QOpenGLContext::currentContext());
|
||||
//# define QGLC gf.
|
||||
//inline void glActiveTextureChannel(int channel) {QGLCI gf.glActiveTexture(GL_TEXTURE0 + channel);}
|
||||
//inline void glDisableTextures(int channels = 8) {QGLCI for (int i = channels - 1; i >= 0; --i) {glActiveTextureChannel(i); glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_CUBE_MAP);}}
|
||||
//inline void glReleaseTextures(int channels = 8) {QGLCI for (int i = channels - 1; i >= 0; --i) {glActiveTextureChannel(i); glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_CUBE_MAP, 0);}}
|
||||
//inline void glReleaseFramebuffer() {QGLCI gf.glBindFramebuffer(GL_FRAMEBUFFER, 0);}
|
||||
//inline void glReleaseShaders() {QGLCI gf.glUseProgram(0);}
|
||||
//inline void deleteGLFramebuffer(GLuint & fbo) {QGLCI if (fbo != 0) gf.glDeleteFramebuffers(1, &fbo); fbo = 0;}
|
||||
//inline void deleteGLRenderbuffer(GLuint & drbo) {QGLCI if (drbo != 0) gf.glDeleteRenderbuffers(1, &drbo); drbo = 0;}
|
||||
//inline void deleteGLBuffer(GLuint & bo) {QGLCI if (bo != 0) gf.glDeleteBuffers(1, &bo); bo = 0;}
|
||||
//inline void deleteGLVertexArray(GLuint & va) {QGLCI if (va != 0) gf.glDeleteVertexArrays(1, &va); va = 0;}
|
||||
void createGLTexture(GLuint & tex, int width, int height, const GLenum & format = GL_RGBA8, const GLenum & target = GL_TEXTURE_2D);
|
||||
void createGLTexture(GLuint & tex, const QImage & image, const GLenum & format = GL_RGBA8, const GLenum & target = GL_TEXTURE_2D);
|
||||
inline void qglTranslate(const QVector3D & v) {glTranslated(v.x(), v.y(), v.z());}
|
||||
inline void qglScale(const QVector3D & v) {glScaled(v.x(), v.y(), v.z());}
|
||||
QMatrix4x4 glMatrixPerspective(double angle, double aspect, double near_, double far_);
|
||||
inline void qglTranslate(const QVector3D & v) {glTranslatef(v.x(), v.y(), v.z());}
|
||||
inline void qglScale(const QVector3D & v) {glScalef(v.x(), v.y(), v.z());}
|
||||
QMatrix4x4 glMatrixPerspective(float angle, float aspect, float near_, float far_);
|
||||
QImage rotateQImageLeft(const QImage & im);
|
||||
QImage rotateQImageRight(const QImage & im);
|
||||
inline QImage rotateQImage180(const QImage & im) {return im.mirrored(true, true);}
|
||||
@@ -197,11 +197,11 @@ struct Box3D {
|
||||
Box3D() {x = y = z = width = length = height = angle_z = angle_xy = angle_roll = 0.f;}
|
||||
Box3D(const QVector3D & center, GLfloat hwid, GLfloat hlen, GLfloat hhei) {x = center.x() - hwid; y = center.y() - hlen; z = center.z() - hhei; width = 2 * hwid; length = 2 * hlen; height = 2 * hhei; angle_z = angle_xy = angle_roll = 0.f;}
|
||||
Box3D(const QVector<QVector3D> & points);
|
||||
bool isEmpty() const {return (qAbs(width) < 1E-6) || (qAbs(length) < 1E-6) || (qAbs(height) < 1E-6);}
|
||||
bool isEmpty() const {return (qAbs(width) < 1E-6f) || (qAbs(length) < 1E-6f) || (qAbs(height) < 1E-6f);}
|
||||
QVector3D randomPoint() const {return QVector3D(uprand(length) + x, uprand(width) + y, uprand(height) + z);}
|
||||
QVector3D pos() const {return QVector3D(x, y, z);}
|
||||
QVector3D size() const {return QVector3D(length, width, height);}
|
||||
QVector3D center() const {return QVector3D(length / 2. + x, width / 2. + y, height / 2. + z);}
|
||||
QVector3D center() const {return QVector3D(length / 2.f + x, width / 2.f + y, height / 2.f + z);}
|
||||
QVector3D angles() const {return QVector3D(angle_xy, angle_roll, angle_z);}
|
||||
QVector<QVector3D> corners() const;
|
||||
void setPos(const QVector3D & p) {x = p.x(); y = p.y(); z = p.z();}
|
||||
@@ -228,14 +228,14 @@ struct Vector3d {
|
||||
Vector3d(const QVector3D & v) {x = v.x(); y = v.y(); z = v.z();}
|
||||
Vector3d(const QString & str);
|
||||
inline void clear() {x = y = z = 0.;}
|
||||
inline GLfloat length() const {return sqrt(x*x + y*y + z*z);}
|
||||
inline GLfloat length() const {return sqrtf(x*x + y*y + z*z);}
|
||||
inline GLfloat lengthSquared() const {return x*x + y*y + z*z;}
|
||||
Vector3d & normalize() {
|
||||
GLfloat l = length();
|
||||
if (l == 0.) return *this;
|
||||
if (l == 0.f) return *this;
|
||||
x /= l; y /= l; z /= l;
|
||||
return *this;
|
||||
};
|
||||
}
|
||||
Vector3d normalized() {return Vector3d(*this).normalize();}
|
||||
Vector3d projectTo(Vector3d dir) {dir.normalize(); return dir * dot(dir, *this);}
|
||||
Vector3d operator *(const GLfloat v) {return Vector3d(x*v, y*v, z*v);}
|
||||
@@ -309,19 +309,19 @@ inline QDataStream & operator <<(QDataStream & s, const Vector3i & v) {s << v.p0
|
||||
inline QDataStream & operator >>(QDataStream & s, Vector3i & v) {s >> v.p0 >> v.p1 >> v.p2; return s;}
|
||||
|
||||
QColor colorFromString(const QString & str);
|
||||
inline double cosABV(const QVector3D & v0, const QVector3D & v1) {
|
||||
double l = v0.length() * v1.length();
|
||||
if (l == 0.) return 0.;
|
||||
inline float cosABV(const QVector3D & v0, const QVector3D & v1) {
|
||||
float l = v0.length() * v1.length();
|
||||
if (l == 0.f) return 0.;
|
||||
return (QVector3D::dotProduct(v0, v1)) / l;
|
||||
}
|
||||
inline QVector3D projection(const QVector3D & v, const QVector3D & to) {return to.normalized() * v.length() * cosABV(v, to);}
|
||||
QVector3D orthToVector(const QVector3D & v, const double & scale = 1.);
|
||||
QVector3D orthToVector(const QVector3D & v, const float & scale = 1.);
|
||||
QVector3D rotateVector(const QVector3D & v, const QVector3D & a);
|
||||
void setVectorLength(QVector3D & v, const double & l);
|
||||
void lengthenVector(QVector3D & v, const double & l);
|
||||
inline double squareLength(const QVector3D & from, const QVector3D & to) {return (to.x() - from.x())*(to.x() - from.x()) + (to.y() - from.y())*(to.y() - from.y()) + (to.z() - from.z())*(to.z() - from.z());}
|
||||
void setVectorLength(QVector3D & v, const float & l);
|
||||
void lengthenVector(QVector3D & v, const float & l);
|
||||
inline float squareLength(const QVector3D & from, const QVector3D & to) {return (to.x() - from.x())*(to.x() - from.x()) + (to.y() - from.y())*(to.y() - from.y()) + (to.z() - from.z())*(to.z() - from.z());}
|
||||
inline QVector3D directionFromAngles(const QVector3D & a) {return rotateVector(QVector3D(1., 0., 0.), a);}
|
||||
inline double frac(const double & x, const double & b) {return x - int(x / b) * b;}
|
||||
inline float frac(const float & x, const float & b) {return x - int(x / b) * b;}
|
||||
|
||||
class GLObjectBase;
|
||||
class QGLView;
|
||||
@@ -334,14 +334,15 @@ class QGLViewBase
|
||||
friend class GLObjectBase;
|
||||
public:
|
||||
QGLViewBase();
|
||||
Camera & camera();
|
||||
const Camera & camera() const;
|
||||
void setCamera(const Camera & camera);
|
||||
virtual ~QGLViewBase();
|
||||
Camera * camera();
|
||||
const Camera * camera() const;
|
||||
void setCamera(Camera * camera);
|
||||
GLTextureManagerBase * textureManager();
|
||||
protected:
|
||||
virtual void collectLights() = 0;
|
||||
Camera * camera_;
|
||||
GLTextureManagerBase * m_texture_manager;
|
||||
GLTextureManagerBase * textures_manager;
|
||||
};
|
||||
|
||||
#endif // GLTYPES_H
|
||||
|
||||
@@ -43,8 +43,10 @@ void GLVBO::init() {
|
||||
|
||||
|
||||
void GLVBO::destroy() {
|
||||
deleteGLBuffer(buffer_);
|
||||
//deleteGLVertexArray(va_);
|
||||
if (buffer_ != 0) glDeleteFramebuffers(1, &buffer_);
|
||||
buffer_ = 0;
|
||||
// if (va_ != 0) glDeleteVertexArrays(1, &va_);
|
||||
// va_ = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -13,4 +13,23 @@ GLWidget::GLWidget(QWidget *parent) : QWidget(parent)
|
||||
lay->setContentsMargins(0, 0, 0, 0);
|
||||
lay->setSpacing(0);
|
||||
setMouseTracking(true);
|
||||
connect(view_, &QGLView::doubleClick, this, &GLWidget::viewDoubleClicked);
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::viewDoubleClicked() {
|
||||
// qDebug() << "click widget!!";
|
||||
if (view_->windowState() == Qt::WindowFullScreen) {
|
||||
// view_->hide();
|
||||
container = QWidget::createWindowContainer(view_, this);
|
||||
lay->addWidget(container);
|
||||
container->show();
|
||||
// show();
|
||||
} else {
|
||||
// hide();
|
||||
view_->setParent(nullptr);
|
||||
view_->showFullScreen();
|
||||
lay->removeWidget(container);
|
||||
}
|
||||
// qDebug() << "click widge done!";
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@ public:
|
||||
|
||||
public slots:
|
||||
|
||||
private slots:
|
||||
void viewDoubleClicked();
|
||||
|
||||
private:
|
||||
QWidget * container;
|
||||
QGLView * view_;
|
||||
|
||||
@@ -37,11 +37,11 @@ void Loader3DS::init3DSMesh(GLObjectBase * o, const QVector<uint> & smooth) {
|
||||
v2 = points[cf.p2];
|
||||
fnormals[i] = ((v1 - v0) * (v2 - v0)).normalized();
|
||||
}
|
||||
uint fcnt = faces.size() * 3;
|
||||
int fcnt = faces.size() * 3;
|
||||
vertices.resize(fcnt * 3);
|
||||
normals.resize(vertices.size());
|
||||
if (has_uv) uvs.resize(fcnt * 2);
|
||||
uint ind = 0, induv = 0, ncnt0, ncnt1, ncnt2, csg;
|
||||
int ind = 0, induv = 0, ncnt0, ncnt1, ncnt2, csg;
|
||||
//qDebug() << faces.size();
|
||||
if (smooth.isEmpty()) {
|
||||
for (int i = 0; i < faces.size(); ++i) {
|
||||
@@ -129,18 +129,18 @@ Material Loader3DS::materialByName(const QVector<Material> & materials, const QS
|
||||
}
|
||||
|
||||
|
||||
GLObjectBase * loadFrom3DSFile(const QString & filepath, double scale) {
|
||||
GLObjectBase * loadFrom3DSFile(const QString & filepath, float scale) {
|
||||
QFile f(filepath);
|
||||
if (!f.exists()) {
|
||||
qDebug() << "[Loader 3DS] Error: can`t open \"" + filepath + "\"";
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
f.open(QIODevice::ReadOnly);
|
||||
QDataStream stream(&f);
|
||||
QVector<Material> materials;
|
||||
QVector<uint> smooth;
|
||||
QVector<ushort> face_mats;
|
||||
GLObjectBase * root = new GLObjectBase(), * co = 0;
|
||||
GLObjectBase * root = new GLObjectBase(), * co = nullptr;
|
||||
Material mat;
|
||||
Loader3DS::Chunk cc;
|
||||
Loader3DS::Face face;
|
||||
@@ -159,7 +159,7 @@ GLObjectBase * loadFrom3DSFile(const QString & filepath, double scale) {
|
||||
case LOADER_3DS_CHUNK_MAIN: /*qDebug() << "main" << cc.size;*/ break;
|
||||
case LOADER_3DS_CHUNK_OBJECTS: /*qDebug() << " objects" << cc.size;*/ break;
|
||||
case LOADER_3DS_CHUNK_OBJECT:
|
||||
if (co != 0) {
|
||||
if (co != nullptr) {
|
||||
Loader3DS::init3DSMesh(co, smooth);
|
||||
root->addChild(co);
|
||||
}
|
||||
@@ -257,7 +257,7 @@ GLObjectBase * loadFrom3DSFile(const QString & filepath, double scale) {
|
||||
stream.skipRawData(cc.size - 6);
|
||||
fl = globject_cast<Light * >(co)->decay_end;
|
||||
//fl1 = globject_cast<Light * >(co)->decay_start;
|
||||
globject_cast<Light * >(co)->decay_quadratic = 4. / fl;
|
||||
globject_cast<Light * >(co)->decay_quadratic = 4.f / fl;
|
||||
//qDebug() << "decay" << globject_cast<Light * >(co)->decay_quadratic;
|
||||
break;
|
||||
case LOADER_3DS_CHUNK_COLOR_F:
|
||||
@@ -337,7 +337,7 @@ GLObjectBase * loadFrom3DSFile(const QString & filepath, double scale) {
|
||||
materials << mat;
|
||||
foreach (const Material & m, materials)
|
||||
qDebug() << m.name;
|
||||
if (co != 0) {
|
||||
if (co != nullptr) {
|
||||
Loader3DS::init3DSMesh(co, smooth);
|
||||
root->addChild(co);
|
||||
}
|
||||
|
||||
@@ -72,6 +72,6 @@ namespace Loader3DS {
|
||||
Material materialByName(const QVector<Material> & materials, const QString & name);
|
||||
}
|
||||
|
||||
GLObjectBase * loadFrom3DSFile(const QString & filepath, double scale = 1.0);
|
||||
GLObjectBase * loadFrom3DSFile(const QString & filepath, float scale = 1.0);
|
||||
|
||||
#endif // LOADER_3DS_H
|
||||
|
||||
@@ -27,7 +27,7 @@ void LoaderASE::initASEMesh(GLObjectBase * o) {
|
||||
bool has_uv = !puvws.isEmpty(), has_norms = !fnormals.isEmpty();
|
||||
Vector3i cf;
|
||||
Vector3d v0, v1, v2, cn0, cn1, cn2;
|
||||
uint ni = 0;
|
||||
int ni = 0;
|
||||
for (int i = 0; i < points.size(); ++i)
|
||||
points[i] -= pos;
|
||||
if (!has_norms) {
|
||||
@@ -43,11 +43,11 @@ void LoaderASE::initASEMesh(GLObjectBase * o) {
|
||||
fnormals[ni] = cn0; ++ni;
|
||||
}
|
||||
}
|
||||
uint fcnt = faces.size() * 3;
|
||||
int fcnt = faces.size() * 3;
|
||||
vertices.resize(fcnt * 3);
|
||||
normals.resize(vertices.size());
|
||||
if (has_uv) uvs.resize(fcnt * 2);
|
||||
uint ind = 0, induv = 0;
|
||||
int ind = 0, induv = 0;
|
||||
qDebug() << "init ase" << faces.size() << "faces";
|
||||
ni = 0;
|
||||
for (int i = 0; i < faces.size(); ++i) {
|
||||
@@ -79,15 +79,15 @@ void LoaderASE::initASEMesh(GLObjectBase * o) {
|
||||
}
|
||||
|
||||
|
||||
GLObjectBase * loadFromASEFile(const QString & filepath, double scale) {
|
||||
GLObjectBase * loadFromASEFile(const QString & filepath, float scale) {
|
||||
QFile f(filepath);
|
||||
if (!f.exists()) {
|
||||
qDebug() << "[Loader ASE] Error: can`t open" << filepath;
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
f.open(QIODevice::ReadOnly);
|
||||
//QVector<Material> materials;
|
||||
GLObjectBase * root = new GLObjectBase(), * co = 0;
|
||||
GLObjectBase * root = new GLObjectBase(), * co = nullptr;
|
||||
root->setName(QFileInfo(f).baseName());
|
||||
QTextStream stream(&f);
|
||||
QVector<Material> materials;
|
||||
@@ -95,7 +95,8 @@ GLObjectBase * loadFromASEFile(const QString & filepath, double scale) {
|
||||
QVector<Vector3i> faces, uvws;
|
||||
QVector<Vector3d> normals;
|
||||
Vector3d cv;
|
||||
int mst = -1, pst;//, mat_ind;
|
||||
int mst = -1;//, mat_ind;
|
||||
qint64 pst;
|
||||
QString line, cname;
|
||||
|
||||
|
||||
@@ -121,7 +122,7 @@ GLObjectBase * loadFromASEFile(const QString & filepath, double scale) {
|
||||
if (line.left(17) == "*MATERIAL_DIFFUSE") {materials[i].color_diffuse = colorFromString(line.right(line.length() - 18)); continue;} //qDebug() << "diffuse " << i << " = " << colorFromString(line.right(line.length() - 18));
|
||||
if (line.left(18) == "*MATERIAL_SPECULAR") {materials[i].color_specular = colorFromString(line.right(line.length() - 19)); continue;} //qDebug() << "specular " << i << " = " << colorFromString(line.right(line.length() - 19));
|
||||
if (line.left(23) == "*MATERIAL_SHINESTRENGTH") {materials[i].map_specular.color_amount = line.right(line.length() - 24).toFloat(); continue;}
|
||||
if (line.left(15) == "*MATERIAL_SHINE") {materials[i].map_specularity.color_amount = 2. / exp(line.right(line.length() - 16).toFloat()); continue;}
|
||||
if (line.left(15) == "*MATERIAL_SHINE") {materials[i].map_specularity.color_amount = 2.f / expf(line.right(line.length() - 16).toFloat()); continue;}
|
||||
if (line.left(22) == "*MATERIAL_TRANSPARENCY") {materials[i].transparency = line.right(line.length() - 23).toFloat(); continue;}
|
||||
if (line.left(12) == "*MAP_DIFFUSE") {
|
||||
line = stream.readLine().trimmed();
|
||||
@@ -167,7 +168,7 @@ GLObjectBase * loadFromASEFile(const QString & filepath, double scale) {
|
||||
if (line.indexOf("GEOMOBJECT {") >= 0) cotype = 0;
|
||||
if (line.indexOf("LIGHTOBJECT {") >= 0) cotype = 1;
|
||||
mst = -1;
|
||||
if (co != 0) {
|
||||
if (co != nullptr) {
|
||||
co->points = points;
|
||||
co->faces = faces;
|
||||
co->normals = normals;
|
||||
@@ -367,7 +368,7 @@ GLObjectBase * loadFromASEFile(const QString & filepath, double scale) {
|
||||
mst = -1;
|
||||
}
|
||||
f.close();
|
||||
if (co != 0) {
|
||||
if (co != nullptr) {
|
||||
co->points = points;
|
||||
co->faces = faces;
|
||||
co->normals = normals;
|
||||
|
||||
@@ -28,6 +28,6 @@ namespace LoaderASE {
|
||||
void initASEMesh(GLObjectBase * o);
|
||||
}
|
||||
|
||||
GLObjectBase * loadFromASEFile(const QString & filepath, double scale = 1.0);
|
||||
GLObjectBase * loadFromASEFile(const QString & filepath, float scale = 1.0);
|
||||
|
||||
#endif // LOADER_ASE_H
|
||||
|
||||
@@ -45,8 +45,8 @@ QVector4D readXMLVector(QDomElement n) {
|
||||
QStringList sl(n.firstChild().nodeValue().trimmed().split(" "));
|
||||
sl.removeAll("");
|
||||
sl.removeAll(" ");
|
||||
if (sl.size() == 3) return QVector4D(sl[0].toDouble(), sl[1].toDouble(), sl[2].toDouble(), 0.);
|
||||
if (sl.size() == 4) return QVector4D(sl[0].toDouble(), sl[1].toDouble(), sl[2].toDouble(), sl[3].toDouble());
|
||||
if (sl.size() == 3) return QVector4D(sl[0].toFloat(), sl[1].toFloat(), sl[2].toFloat(), 0.);
|
||||
if (sl.size() == 4) return QVector4D(sl[0].toFloat(), sl[1].toFloat(), sl[2].toFloat(), sl[3].toFloat());
|
||||
return QVector4D();
|
||||
}
|
||||
|
||||
@@ -60,13 +60,13 @@ QMatrix4x4 readXMLMatrix(QDomElement n) {
|
||||
int ind = -1;
|
||||
for (int r = 0; r < 4; ++r)
|
||||
for (int c = 0; c < 4; ++c)
|
||||
m(r, c) = sl[++ind].toDouble();
|
||||
m(r, c) = sl[++ind].toFloat();
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
double readXMLFloat(QDomElement n) {
|
||||
return n.firstChildElement("float").firstChild().nodeValue().toDouble();
|
||||
float readXMLFloat(QDomElement n) {
|
||||
return n.firstChildElement("float").firstChild().nodeValue().toFloat();
|
||||
}
|
||||
|
||||
|
||||
@@ -140,9 +140,9 @@ QVector<Material> LoaderDAE::readMaterials(QDomElement le, QDomElement li, bool
|
||||
if (col.isValid()) mat.color_diffuse = col;
|
||||
col = readXMLColor(pn.firstChildElement("specular"));
|
||||
if (col.isValid()) mat.color_specular = col;
|
||||
mat.map_specularity.color_amount = 2. / exp(readXMLFloat(pn.firstChildElement("shininess")));
|
||||
mat.map_specularity.color_amount = 2.f / expf(readXMLFloat(pn.firstChildElement("shininess")));
|
||||
mat.transparency = readXMLFloat(pn.firstChildElement("transparency"));
|
||||
if (!fbx) mat.transparency = 1. - mat.transparency;
|
||||
if (!fbx) mat.transparency = 1.f - mat.transparency;
|
||||
text = readXMLTexture(pn.firstChildElement("diffuse"), prof, li);
|
||||
if (!text.isEmpty()) mat.map_diffuse.bitmap_path = text;
|
||||
text = readXMLTexture(pn.firstChildElement("diffuse"), prof, li);
|
||||
@@ -221,18 +221,18 @@ void readScene(QDomElement n, QMatrix4x4 cm, QVector<QPair<QPair<QString, QStrin
|
||||
}
|
||||
|
||||
|
||||
GLObjectBase * loadFromDAEFile(const QString & filepath, double scale) {
|
||||
GLObjectBase * loadFromDAEFile(const QString & filepath, float scale) {
|
||||
QFile f(filepath);
|
||||
if (!f.exists()) {
|
||||
qDebug() << "[Loader DAE] Error: can`t open \"" + filepath + "\"";
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
QTime tm;
|
||||
tm.restart();
|
||||
QDomDocument dom(filepath);
|
||||
if (!dom.setContent(&f)) {
|
||||
qDebug() << "[Loader DAE] Error: can`t parse \"" + filepath + "\"";
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
//qDebug() << "parse" << tm.elapsed();
|
||||
tm.restart();
|
||||
@@ -240,7 +240,7 @@ GLObjectBase * loadFromDAEFile(const QString & filepath, double scale) {
|
||||
bool fbx = maine.firstChildElement("asset").firstChildElement("contributor").firstChildElement("authoring_tool").firstChild().nodeValue().startsWith("FBX");
|
||||
QVector<Material> materials = LoaderDAE::readMaterials(maine.firstChildElement("library_effects"),
|
||||
maine.firstChildElement("library_images"), fbx);
|
||||
GLObjectBase * root = new GLObjectBase(), * co = 0;
|
||||
GLObjectBase * root = new GLObjectBase(), * co = nullptr;
|
||||
QMap<QString, QVector<GLObjectBase * > > objects;
|
||||
|
||||
QMap<QString, QString> mat_names;
|
||||
@@ -293,9 +293,9 @@ GLObjectBase * loadFromDAEFile(const QString & filepath, double scale) {
|
||||
sl.removeAll(" ");
|
||||
for (int c = 0; c < sl.size(); c += stride) {
|
||||
Vector3d v;
|
||||
if (stride >= 1) v.x = sl[c].toDouble();
|
||||
if (stride >= 2) v.y = sl[c + 1].toDouble();
|
||||
if (stride >= 3) v.z = sl[c + 2].toDouble();
|
||||
if (stride >= 1) v.x = sl[c].toFloat();
|
||||
if (stride >= 2) v.y = sl[c + 1].toFloat();
|
||||
if (stride >= 3) v.z = sl[c + 2].toFloat();
|
||||
sd << v;
|
||||
}
|
||||
//qDebug() << " found source" << id << "stride =" << stride << ":" << sd;
|
||||
@@ -324,12 +324,12 @@ GLObjectBase * loadFromDAEFile(const QString & filepath, double scale) {
|
||||
QDomElement di = einp.at(k).toElement();
|
||||
QString src = di.attribute("source"), sem = di.attribute("semantic").toLower();
|
||||
int offset = di.attribute("offset").toInt();
|
||||
QVector<GLfloat> * curv = 0;
|
||||
QVector<GLfloat> * curv = nullptr;
|
||||
int pccnt = 0;
|
||||
if (sem == "vertex") {curv = &vertices; pccnt = 3;}
|
||||
if (sem == "normal") {curv = &normals; pccnt = 3;}
|
||||
if (sem == "texcoord") {curv = &uvs; pccnt = 2;}
|
||||
if (curv == 0) continue;
|
||||
if (curv == nullptr) continue;
|
||||
if (src.startsWith("#")) src.remove(0, 1);
|
||||
QVector<Vector3d> & data(source_data[source_names.value(src, src)]);
|
||||
for (int ii = offset; ii < p.size(); ii += pbv) {
|
||||
@@ -363,17 +363,17 @@ GLObjectBase * loadFromDAEFile(const QString & filepath, double scale) {
|
||||
}
|
||||
lo->setColor(readXMLColor(dl));
|
||||
QDomNodeList ml = dn.elementsByTagName("multiplier");
|
||||
if (!ml.isEmpty()) lo->intensity = ml.at(0).firstChild().nodeValue().toDouble();
|
||||
if (!ml.isEmpty()) lo->intensity = ml.at(0).firstChild().nodeValue().toFloat();
|
||||
ml = dn.elementsByTagName("intensity");
|
||||
if (!ml.isEmpty()) lo->intensity = ml.at(0).firstChild().nodeValue().toDouble();
|
||||
if (!ml.isEmpty()) lo->intensity = ml.at(0).firstChild().nodeValue().toFloat();
|
||||
QString sv;
|
||||
sv = dl.firstChildElement("constant_attenuation").firstChild().nodeValue(); if (!sv.isEmpty()) lo->decay_const = sv.toDouble();
|
||||
sv = dl.firstChildElement("linear_attenuation").firstChild().nodeValue(); if (!sv.isEmpty()) lo->decay_linear = sv.toDouble();
|
||||
sv = dl.firstChildElement("quadratic_attenuation").firstChild().nodeValue(); if (!sv.isEmpty()) lo->decay_quadratic = sv.toDouble();
|
||||
sv = dl.firstChildElement("constant_attenuation").firstChild().nodeValue(); if (!sv.isEmpty()) lo->decay_const = sv.toFloat();
|
||||
sv = dl.firstChildElement("linear_attenuation").firstChild().nodeValue(); if (!sv.isEmpty()) lo->decay_linear = sv.toFloat();
|
||||
sv = dl.firstChildElement("quadratic_attenuation").firstChild().nodeValue(); if (!sv.isEmpty()) lo->decay_quadratic = sv.toFloat();
|
||||
///lo->setTransform(matrices.value(name));
|
||||
if (lo->light_type == Light::Cone) {
|
||||
ml = dn.elementsByTagName("decay_falloff"); if (!ml.isEmpty()) lo->angle_end = ml.at(0).firstChild().nodeValue().toDouble();
|
||||
ml = dn.elementsByTagName("hotspot_beam"); if (!ml.isEmpty()) lo->angle_start = ml.at(0).firstChild().nodeValue().toDouble();
|
||||
ml = dn.elementsByTagName("decay_falloff"); if (!ml.isEmpty()) lo->angle_end = ml.at(0).firstChild().nodeValue().toFloat();
|
||||
ml = dn.elementsByTagName("hotspot_beam"); if (!ml.isEmpty()) lo->angle_start = ml.at(0).firstChild().nodeValue().toFloat();
|
||||
}
|
||||
QVector<GLObjectBase*> ol;
|
||||
ol << lo;
|
||||
@@ -423,7 +423,7 @@ GLObjectBase * loadFromDAEFile(const QString & filepath, double scale) {
|
||||
for (int j = 0; j < dol[i].size(); ++j)
|
||||
delete dol[i][j];
|
||||
|
||||
root->setScale(0.001);
|
||||
root->setScale(0.001f);
|
||||
qDebug() << "[Loader DAE] Loaded" << root->childCount() << "objects from" << filepath;
|
||||
return root;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,6 @@ namespace LoaderDAE {
|
||||
QVector<Material> readMaterials(QDomElement le, QDomElement li, bool fbx);
|
||||
}
|
||||
|
||||
GLObjectBase * loadFromDAEFile(const QString & filepath, double scale = 1.0);
|
||||
GLObjectBase * loadFromDAEFile(const QString & filepath, float scale = 1.0);
|
||||
|
||||
#endif // LOADER_DAE_H
|
||||
|
||||
@@ -28,11 +28,11 @@ void LoaderOBJ::initOBJMesh(GLObjectBase * o, const QVector<Vector3d> & src_vert
|
||||
Vector3d v[3], t[3], n[3];
|
||||
//for (int i = 0; i < points.size(); ++i)
|
||||
// points[i] -= pos;
|
||||
uint fcnt = faces.size() * 3;
|
||||
int fcnt = faces.size() * 3;
|
||||
vertices.resize(fcnt * 3);
|
||||
normals.resize(vertices.size());
|
||||
if (has_uv) uvs.resize(fcnt * 2);
|
||||
uint ind = 0, induv = 0;
|
||||
int ind = 0, induv = 0;
|
||||
//qDebug() << "initOBJMesh" << faces.size();
|
||||
for (int i = 0; i < faces.size(); ++i) {
|
||||
cf = faces[i];
|
||||
@@ -74,9 +74,9 @@ Vector3d readVector3d(QString s) {
|
||||
Vector3d ret;
|
||||
QStringList sl(s.trimmed().split(" "));
|
||||
sl.removeAll(""); sl.removeAll(" ");
|
||||
if (sl.size() > 0) ret.x = sl[0].toDouble();
|
||||
if (sl.size() > 1) ret.y = sl[1].toDouble();
|
||||
if (sl.size() > 2) ret.z = sl[2].toDouble();
|
||||
if (sl.size() > 0) ret.x = sl[0].toFloat();
|
||||
if (sl.size() > 1) ret.y = sl[1].toFloat();
|
||||
if (sl.size() > 2) ret.z = sl[2].toFloat();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -85,8 +85,8 @@ Vector2d readVector2d(QString s) {
|
||||
Vector2d ret;
|
||||
QStringList sl(s.trimmed().split(" "));
|
||||
sl.removeAll(""); sl.removeAll(" ");
|
||||
if (sl.size() > 0) ret.x = sl[0].toDouble();
|
||||
if (sl.size() > 1) ret.y = sl[1].toDouble();
|
||||
if (sl.size() > 0) ret.x = sl[0].toFloat();
|
||||
if (sl.size() > 1) ret.y = sl[1].toFloat();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -157,18 +157,18 @@ QVector<Material> readMTL(QString obj_path, QString path) {
|
||||
if (line.startsWith("Ks")) {
|
||||
Vector3d v = readVector3d(line.mid(2).trimmed());
|
||||
mat.map_specular.color_amount = v.length();
|
||||
double mc = qMax(v.x, qMax(v.y, v.z));
|
||||
if (mc > 0.) v /= mc;
|
||||
float mc = qMax(v.x, qMax(v.y, v.z));
|
||||
if (mc > 0.f) v /= mc;
|
||||
mat.color_specular = QColor::fromRgbF(v.x, v.y, v.z);
|
||||
//qDebug() << mat.shine_strength << mat.color_specular;
|
||||
continue;
|
||||
}
|
||||
if (line.startsWith("Ns")) {
|
||||
mat.map_specularity.color_amount = 2. / exp(line.mid(2).trimmed().toDouble());
|
||||
mat.map_specularity.color_amount = 2.f / expf(line.mid(2).trimmed().toFloat());
|
||||
continue;
|
||||
}
|
||||
if (line.startsWith("d")) {
|
||||
mat.transparency = 1. - line.mid(1).trimmed().toDouble();
|
||||
mat.transparency = 1.f - line.mid(1).trimmed().toFloat();
|
||||
continue;
|
||||
}
|
||||
if (line.startsWith("map_Kd")) {
|
||||
@@ -181,7 +181,7 @@ QVector<Material> readMTL(QString obj_path, QString path) {
|
||||
line = line.mid(3).trimmed();
|
||||
QString sv = line.left(line.indexOf(" "));
|
||||
line = line.mid(sv.size()).trimmed();
|
||||
mat.map_normal.color_amount = sv.toDouble();
|
||||
mat.map_normal.color_amount = sv.toFloat();
|
||||
}
|
||||
mat.map_normal.bitmap_path = findFile(line, sp);
|
||||
//qDebug() << "BUMP" << mat.name << mat.bump_scale << mat.bump.bitmap_path;
|
||||
@@ -203,17 +203,17 @@ Material LoaderOBJ::materialByName(const QVector<Material> & materials, const QS
|
||||
}
|
||||
|
||||
|
||||
GLObjectBase * loadFromOBJFile(const QString & filepath, double scale) {
|
||||
GLObjectBase * loadFromOBJFile(const QString & filepath, float scale) {
|
||||
QFile f(filepath);
|
||||
if (!f.exists()) {
|
||||
qDebug() << "[Loader OBJ] Error: can`t open \"" + filepath + "\"";
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
f.open(QIODevice::ReadOnly);
|
||||
QTextStream stream(&f);
|
||||
QVector<Vector3d> vertices, normals, texcoords;
|
||||
QVector<Material> materials;
|
||||
GLObjectBase * root = new GLObjectBase(), * co = 0;
|
||||
GLObjectBase * root = new GLObjectBase(), * co = nullptr;
|
||||
QString name;
|
||||
root->setName(QFileInfo(f).baseName());
|
||||
int cnt = 0;
|
||||
@@ -237,7 +237,7 @@ GLObjectBase * loadFromOBJFile(const QString & filepath, double scale) {
|
||||
}
|
||||
if (line.startsWith("g ")) {
|
||||
name = line.mid(1).trimmed();
|
||||
if (co != 0) {
|
||||
if (co != nullptr) {
|
||||
LoaderOBJ::initOBJMesh(co, vertices, normals, texcoords);
|
||||
root->addChild(co);
|
||||
}
|
||||
@@ -261,7 +261,7 @@ GLObjectBase * loadFromOBJFile(const QString & filepath, double scale) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (co != 0) {
|
||||
if (co != nullptr) {
|
||||
LoaderOBJ::initOBJMesh(co, vertices, normals, texcoords);
|
||||
root->addChild(co);
|
||||
}
|
||||
|
||||
@@ -37,6 +37,6 @@ namespace LoaderOBJ {
|
||||
Material materialByName(const QVector<Material> & materials, const QString & name);
|
||||
}
|
||||
|
||||
GLObjectBase * loadFromOBJFile(const QString & filepath, double scale = 1.0);
|
||||
GLObjectBase * loadFromOBJFile(const QString & filepath, float scale = 1.0);
|
||||
|
||||
#endif // LOADER_3DS_H
|
||||
|
||||
@@ -7,12 +7,26 @@
|
||||
|
||||
OpenGLWindow::OpenGLWindow(QWindow *parent)
|
||||
: QWindow(parent)
|
||||
, m_animating(false)
|
||||
, m_context(nullptr)
|
||||
, m_device(nullptr)
|
||||
{
|
||||
setFlag(Qt::FramelessWindowHint);
|
||||
setSurfaceType(QWindow::OpenGLSurface);
|
||||
QSurfaceFormat format = QSurfaceFormat::defaultFormat();
|
||||
// qDebug() << format;
|
||||
#ifdef QT_OPENGL_ES_2
|
||||
format.setRenderableType(QSurfaceFormat::OpenGLES);
|
||||
#else
|
||||
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
|
||||
format.setVersion(2, 0);
|
||||
format.setProfile(QSurfaceFormat::NoProfile);
|
||||
}
|
||||
#endif
|
||||
format.setDepthBufferSize(24);
|
||||
// format.setSamples(4);
|
||||
// format.setStencilBufferSize(8);
|
||||
setFormat(format);
|
||||
QSurfaceFormat::setDefaultFormat(format);
|
||||
}
|
||||
|
||||
|
||||
@@ -77,13 +91,5 @@ void OpenGLWindow::renderNow() {
|
||||
}
|
||||
render();
|
||||
m_context->swapBuffers(this);
|
||||
if (m_animating)
|
||||
renderLater();
|
||||
}
|
||||
|
||||
|
||||
void OpenGLWindow::setAnimating(bool animating) {
|
||||
m_animating = animating;
|
||||
if (animating) renderLater();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,6 @@ public:
|
||||
|
||||
virtual void initialize();
|
||||
|
||||
void setAnimating(bool animating);
|
||||
|
||||
QOpenGLContext * context() {return m_context;}
|
||||
|
||||
public slots:
|
||||
@@ -32,7 +30,6 @@ protected:
|
||||
void exposeEvent(QExposeEvent *event) override;
|
||||
|
||||
private:
|
||||
bool m_animating;
|
||||
QOpenGLContext *m_context;
|
||||
QOpenGLPaintDevice *m_device;
|
||||
};
|
||||
|
||||
@@ -53,11 +53,10 @@ QGLView::QGLView(): OpenGLWindow(), fbo_selection(3) {
|
||||
fogDensity_ = fogEnd_ = 1.;
|
||||
fogStart_ = 0.;
|
||||
fogMode_ = Exp;
|
||||
hoverHaloFill_ = 0.333;
|
||||
selectionHaloFill_ = 0.5;
|
||||
hoverHaloFill_ = 0.333f;
|
||||
selectionHaloFill_ = 0.5f;
|
||||
//lmode = Simple;
|
||||
shader_select = shader_halo = nullptr;
|
||||
m_texture_manager = new GLTextureManager();
|
||||
setFeature(qglMSAA, false);
|
||||
setFeature(qglFXAA, false);
|
||||
setFeature(qglLinearFiltering, true);
|
||||
@@ -91,11 +90,11 @@ QGLView::QGLView(): OpenGLWindow(), fbo_selection(3) {
|
||||
sel_mode = QGLView::SingleSelection;
|
||||
// sel_pen = QPen(Qt::black, 1, Qt::DashLine);
|
||||
// sel_brush = QBrush(QColor(170, 100, 255, 120));
|
||||
camera().setAim(QVector3D(0,0,5.5));
|
||||
camera().setPos(QVector3D(10, 5, 5.5));
|
||||
camera().setName("Camera");
|
||||
camera()->setAim(QVector3D(0,0,5.5));
|
||||
camera()->setPos(QVector3D(10, 5, 5.5));
|
||||
camera()->setName("Camera");
|
||||
addObject(camera());
|
||||
emit cameraPosChanged(camera().pos());
|
||||
emit cameraPosChanged(camera()->pos());
|
||||
//camera().aim_ = camera().pos_;
|
||||
ktm_.restart();
|
||||
}
|
||||
@@ -105,7 +104,6 @@ QGLView::~QGLView() {
|
||||
stop();
|
||||
if (shader_select) delete shader_select;
|
||||
if (shader_halo) delete shader_halo;
|
||||
delete m_texture_manager;
|
||||
}
|
||||
|
||||
|
||||
@@ -114,8 +112,8 @@ void QGLView::stop() {
|
||||
}
|
||||
|
||||
|
||||
void QGLView::start(double freq) {
|
||||
timer = startTimer(freq <= 0. ? 0 : 1000. / freq);
|
||||
void QGLView::start(float freq) {
|
||||
timer = startTimer(freq <= 0.f ? 0 : int(1000.f / freq));
|
||||
}
|
||||
|
||||
|
||||
@@ -144,6 +142,14 @@ void QGLView::addObject(GLObjectBase * o) {
|
||||
}
|
||||
|
||||
|
||||
int QGLView::objectsCount(bool all) {
|
||||
if (!all) return objects_.childCount();
|
||||
int cnt = 0;
|
||||
objectsCountInternal(&cnt, &objects_);
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::removeObject(GLObjectBase * o, bool inChildren) {
|
||||
o->setView(nullptr);
|
||||
if (inChildren)
|
||||
@@ -154,6 +160,11 @@ void QGLView::removeObject(GLObjectBase * o, bool inChildren) {
|
||||
}
|
||||
|
||||
|
||||
void QGLView::removeObject(GLObjectBase & o, bool inChildren) {
|
||||
removeObject(&o, inChildren);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::clearObjects(bool deleteAll) {
|
||||
removeObject(camera_);
|
||||
objects_.clearChildren(deleteAll);
|
||||
@@ -163,6 +174,58 @@ void QGLView::clearObjects(bool deleteAll) {
|
||||
}
|
||||
|
||||
|
||||
QList<GLObjectBase *> QGLView::objects(bool all) {
|
||||
return objects_.children(all);
|
||||
}
|
||||
|
||||
|
||||
int QGLView::lightsCount() const {
|
||||
return lights_.size();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::removeLight(int index) {
|
||||
removeObject(lights_.at(index));
|
||||
lights_.removeAt(index);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::removeLight(Light * l) {
|
||||
foreach (Light * i, lights_)
|
||||
if (i == l) removeObject(i);
|
||||
lights_.removeAll(l);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::clearLights(bool deleteAll) {
|
||||
if (deleteAll)
|
||||
foreach (Light * i, lights_) delete i;
|
||||
lights_.clear();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::addTexture(const QString & path) {
|
||||
textures_manager->addTexture(path);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::addAnimation(const QString & dir, const QString & name) {
|
||||
textures_manager->addAnimation(dir, name);
|
||||
}
|
||||
|
||||
|
||||
Light * QGLView::light(int index) {
|
||||
return lights_[index];
|
||||
}
|
||||
|
||||
|
||||
Light * QGLView::light(const QString & name) {
|
||||
foreach (Light * i, lights_)
|
||||
if (i->name_ == name) return i;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::selectObject(GLObjectBase * o) {
|
||||
if (o == sel_obj) return;
|
||||
GLObjectBase * pso = sel_obj;
|
||||
@@ -172,7 +235,8 @@ void QGLView::selectObject(GLObjectBase * o) {
|
||||
|
||||
|
||||
void QGLView::resizeEvent(QResizeEvent * e) {
|
||||
resizeGL(width(), height());
|
||||
// if (isExposed())
|
||||
// resizeGL(width(), height());
|
||||
/* QWindow::resizeEvent(e);*/
|
||||
}
|
||||
|
||||
@@ -186,15 +250,16 @@ void QGLView::timerEvent(QTimerEvent *) {
|
||||
|
||||
|
||||
void QGLView::render() {
|
||||
resizeGL(width(), height());
|
||||
QRect g_rect(QPoint(), size());
|
||||
emit glBeforePaint();
|
||||
//qDebug() << "paintGL";
|
||||
//QMutexLocker ml_v(&v_mutex);
|
||||
glEnable(GL_CULL_FACE);
|
||||
//glDisable(GL_CULL_FACE);
|
||||
camera().apply(aspect);
|
||||
camera()->apply(aspect);
|
||||
//objects_.preparePos(camera());
|
||||
start_rp.cam_offset_matrix = camera().offsetMatrix();
|
||||
start_rp.cam_offset_matrix = camera()->offsetMatrix();
|
||||
start_rp.proj_matrix = getGLMatrix(GL_PROJECTION_MATRIX);
|
||||
start_rp.view_matrix = getGLMatrix(GL_MODELVIEW_MATRIX);
|
||||
//objects_.buildTransform();
|
||||
@@ -232,7 +297,7 @@ void QGLView::render() {
|
||||
}
|
||||
} else {
|
||||
glReadPixels(lastPos.x(), height() - lastPos.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, cgid);
|
||||
iid = (cgid[0] << 24) | (cgid[1] << 16) | (cgid[2] << 8) | cgid[3];
|
||||
iid = uint(cgid[0] << 24) | uint(cgid[1] << 16) | uint(cgid[2] << 8) | cgid[3];
|
||||
so = ids.value(iid, nullptr);
|
||||
//qDebug() <<cgid[0]<<cgid[1]<<cgid[2]<<cgid[3]<< iid;
|
||||
if (so != hov_obj) {
|
||||
@@ -256,8 +321,8 @@ void QGLView::render() {
|
||||
glEnableClientState(GL_COLOR_ARRAY);*/
|
||||
}
|
||||
|
||||
camera().apply(aspect);
|
||||
start_rp.cam_offset_matrix = camera().offsetMatrix();
|
||||
camera()->apply(aspect);
|
||||
start_rp.cam_offset_matrix = camera()->offsetMatrix();
|
||||
cur_mvpm = start_rp.proj_matrix * start_rp.view_matrix * start_rp.cam_offset_matrix;
|
||||
//objects_.preparePos(camera());
|
||||
|
||||
@@ -280,9 +345,9 @@ void QGLView::render() {
|
||||
emit glPainting();
|
||||
if (selectionHalo_ || hoverHalo_) {
|
||||
glReleaseTextures();
|
||||
glReleaseShaders();
|
||||
glReleaseFramebuffer();
|
||||
glActiveTextureChannel(0);
|
||||
glUseProgram(0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnable(GL_BLEND);
|
||||
glDisable(GL_TEXTURE_CUBE_MAP);
|
||||
@@ -301,9 +366,9 @@ void QGLView::render() {
|
||||
}
|
||||
}
|
||||
|
||||
glReleaseShaders();
|
||||
glUseProgram(0);
|
||||
glResetAllTransforms();
|
||||
glReleaseFramebuffer();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
emit glEndPaint();
|
||||
|
||||
@@ -350,13 +415,13 @@ void QGLView::render() {
|
||||
|
||||
|
||||
void QGLView::initialize() {
|
||||
initializeOpenGLFunctions();
|
||||
//initializeOpenGLFunctions();
|
||||
glEnable(GL_TEXTURE_MAX_ANISOTROPY_EXT);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glEnableDepth();
|
||||
glEnable(GL_CULL_FACE);
|
||||
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
|
||||
glActiveTextureChannel(3);
|
||||
glActiveTexture(GL_TEXTURE0 + 3);
|
||||
glEnable(GL_TEXTURE_GEN_S);
|
||||
glEnable(GL_TEXTURE_GEN_T);
|
||||
glEnable(GL_TEXTURE_GEN_R);
|
||||
@@ -366,13 +431,13 @@ void QGLView::initialize() {
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
glActiveTextureChannel(0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glCullFace(GL_BACK);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glColorMaterial(GL_FRONT, GL_DIFFUSE);
|
||||
|
||||
textures_manager.loadTextures();
|
||||
textures_manager->loadTextures();
|
||||
objects_.initInternal();
|
||||
checkCaps();
|
||||
|
||||
@@ -380,23 +445,23 @@ void QGLView::initialize() {
|
||||
shader_halo = new QOpenGLShaderProgram(context());
|
||||
reloadThisShaders();
|
||||
is_init = true;
|
||||
resizeGL(width(), height());
|
||||
//resizeGL(width(), height());
|
||||
need_init_ = false;
|
||||
emit glInitializeDone();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::renderHalo(const GLObjectBase * obj, const uint iid, const QColor & color, const double & fill) {
|
||||
void QGLView::renderHalo(const GLObjectBase * obj, const uint iid, const QColor & color, const float & fill) {
|
||||
if (!shaders_supported) return;
|
||||
if (!shader_halo) return;
|
||||
if (!shader_halo->isLinked()) return;
|
||||
if (obj) {
|
||||
shader_halo->bind();
|
||||
shader_halo->setUniformValue("qgl_ModelViewProjectionMatrix", QMatrix4x4());
|
||||
glActiveTextureChannel(0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_selection.colorTexture());
|
||||
shader_halo->setUniformValue("t0", 0);
|
||||
shader_halo->setUniformValue("dt", QVector2D(1. / width(), 1. / height()));
|
||||
shader_halo->setUniformValue("dt", QVector2D(1.f / width(), 1.f / height()));
|
||||
shader_halo->setUniformValue("selected", QVector4D(float((iid >> 24) & 0xFF) / 255.f,
|
||||
float((iid >> 16) & 0xFF) / 255.f,
|
||||
float((iid >> 8) & 0xFF) / 255.f,
|
||||
@@ -493,6 +558,13 @@ void QGLView::collectObjectLights(GLObjectBase * o) {
|
||||
}
|
||||
|
||||
|
||||
void QGLView::objectsCountInternal(int * cnt, GLObjectBase * where) {
|
||||
++(*cnt);
|
||||
foreach (GLObjectBase * i, where->children_)
|
||||
objectsCountInternal(cnt, i);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::removeObjectInternal(GLObjectBase * o, GLObjectBase * where) {
|
||||
foreach (GLObjectBase * i, where->children_) {
|
||||
if (o == i)
|
||||
@@ -520,6 +592,14 @@ void QGLView::reloadThisShaders() {
|
||||
//loadShaders(shader_rope, "rope", "shaders");
|
||||
}
|
||||
|
||||
void QGLView::glReleaseTextures(int channels) {
|
||||
for (int i = channels - 1; i >= 0; --i) {
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QGLView::applyFog() {
|
||||
GLfloat fog_col[4] = {float(fogColor_.redF()), float(fogColor_.greenF()), float(fogColor_.blueF()), .0f};
|
||||
@@ -540,12 +620,12 @@ void QGLView::applyFog() {
|
||||
void QGLView::resizeGL(int width, int height) {
|
||||
if (!is_init) return;
|
||||
if (width <= 0 || height <= 0) return;
|
||||
aspect = double(width) / double(height);
|
||||
aspect = float(width) / float(height);
|
||||
if (renderer_) renderer_->resize(width, height);
|
||||
//qDebug() << "resize" << width << height;
|
||||
fbo_selection.resize(width, height);
|
||||
mouse_first = true;
|
||||
iaspect = (aspect == 0.) ? 0. : 1 / aspect;
|
||||
iaspect = (aspect == 0.f) ? 0. : 1 / aspect;
|
||||
glViewport(0, 0, width, height);
|
||||
emit glResize(width, height);
|
||||
}
|
||||
@@ -592,26 +672,26 @@ void QGLView::mouseMoveEvent(QMouseEvent * e) {
|
||||
///qDebug() << e->x() << e->y();
|
||||
QRect g_rect(QPoint(), size());
|
||||
if (mouseRotate_) {
|
||||
double dx = e->x() - lastPos.x();
|
||||
double dy = e->y() - lastPos.y();
|
||||
float dx = e->x() - lastPos.x();
|
||||
float dy = e->y() - lastPos.y();
|
||||
if (e->buttons() & Qt::LeftButton) {
|
||||
//camera().angle_z += dx / 4.;
|
||||
//camera().angle_xy += dy / 4.;
|
||||
if (cameraOrbit_) {
|
||||
camera().orbitZ(dx / 4.);
|
||||
camera().orbitXY(dy / 4.);
|
||||
camera()->orbitZ(dx / 4.f);
|
||||
camera()->orbitXY(dy / 4.f);
|
||||
} else {
|
||||
camera().rotateZ(dx / 4.);
|
||||
camera().rotateXY(dy / 4.);
|
||||
camera()->rotateZ(dx / 4.f);
|
||||
camera()->rotateXY(dy / 4.f);
|
||||
}
|
||||
emit cameraPosChanged(camera().pos());
|
||||
emit cameraPosChanged(camera()->pos());
|
||||
} else if (e->buttons() & Qt::RightButton) {
|
||||
double ad = camera().distance();
|
||||
camera().moveLeft(dx / 1000. * ad);
|
||||
camera().moveUp(dy / 1000. * ad);
|
||||
float ad = camera()->distance();
|
||||
camera()->moveLeft(dx / 1000.f * ad);
|
||||
camera()->moveUp(dy / 1000.f * ad);
|
||||
//camera().pos.setX(camera().pos.x() + camera().pos.z() * dx / 500.);
|
||||
//camera().pos.setY(camera().pos.y() - camera().pos.z() * dy / 500.);
|
||||
emit cameraPosChanged(camera().pos());
|
||||
emit cameraPosChanged(camera()->pos());
|
||||
}
|
||||
//lights[0]->pos_ = camera().pos();
|
||||
}
|
||||
@@ -643,9 +723,9 @@ void QGLView::mouseMoveEvent(QMouseEvent * e) {
|
||||
|
||||
void QGLView::wheelEvent(QWheelEvent * e) {
|
||||
if (mouseRotate_) {
|
||||
if (e->delta() > 0) camera().flyCloser(0.1); //camera().pos.setZ(camera().pos.z() - 0.1 * camera().pos.z());
|
||||
if (e->delta() < 0) camera().flyFarer(0.1); //camera().pos.setZ(camera().pos.z() + 0.1 * camera().pos.z());
|
||||
emit cameraPosChanged(camera().pos());
|
||||
if (e->delta() > 0) camera()->flyCloser(0.1f); //camera().pos.setZ(camera().pos.z() - 0.1 * camera().pos.z());
|
||||
if (e->delta() < 0) camera()->flyFarer(0.1f); //camera().pos.setZ(camera().pos.z() + 0.1 * camera().pos.z());
|
||||
emit cameraPosChanged(camera()->pos());
|
||||
}
|
||||
emit glWheelEvent(e);
|
||||
}
|
||||
@@ -660,6 +740,9 @@ void QGLView::leaveEvent(QEvent * ) {
|
||||
void QGLView::keyPressEvent(QKeyEvent * e) {
|
||||
emit glKeyPressEvent(e);
|
||||
if (e->key() > 0) keys_.insert(e->key());
|
||||
if (e->key() == Qt::Key_F11) {
|
||||
emit doubleClick();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -669,7 +752,12 @@ void QGLView::keyReleaseEvent(QKeyEvent * e) {
|
||||
}
|
||||
|
||||
|
||||
void QGLView::focusOutEvent(QFocusEvent *)
|
||||
{keys_.clear();
|
||||
void QGLView::focusOutEvent(QFocusEvent *) {
|
||||
keys_.clear();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::mouseDoubleClickEvent(QMouseEvent * e) {
|
||||
if (e->buttons().testFlag(Qt::MidButton))
|
||||
emit doubleClick();
|
||||
}
|
||||
|
||||
@@ -33,15 +33,15 @@ class QGLView: public OpenGLWindow, public QGLViewBase
|
||||
friend class GLObjectBase;
|
||||
Q_OBJECT
|
||||
Q_PROPERTY (QColor backColor READ backColor WRITE setBackColor)
|
||||
Q_PROPERTY (double lineWidth READ lineWidth WRITE setLineWidth)
|
||||
Q_PROPERTY (double FOV READ FOV WRITE setFOV)
|
||||
Q_PROPERTY (double depthStart READ depthStart WRITE setDepthStart)
|
||||
Q_PROPERTY (double depthEnd READ depthEnd WRITE setDepthEnd)
|
||||
Q_PROPERTY (float lineWidth READ lineWidth WRITE setLineWidth)
|
||||
Q_PROPERTY (float FOV READ FOV WRITE setFOV)
|
||||
Q_PROPERTY (float depthStart READ depthStart WRITE setDepthStart)
|
||||
Q_PROPERTY (float depthEnd READ depthEnd WRITE setDepthEnd)
|
||||
Q_PROPERTY (QColor ambientColor READ ambientColor WRITE setAmbientColor)
|
||||
Q_PROPERTY (QColor fogColor READ fogColor WRITE setFogColor)
|
||||
Q_PROPERTY (double fogDensity READ fogDensity WRITE setFogDensity)
|
||||
Q_PROPERTY (double fogStart READ fogStart WRITE setFogStart)
|
||||
Q_PROPERTY (double fogEnd READ fogEnd WRITE setFogEnd)
|
||||
Q_PROPERTY (float fogDensity READ fogDensity WRITE setFogDensity)
|
||||
Q_PROPERTY (float fogStart READ fogStart WRITE setFogStart)
|
||||
Q_PROPERTY (float fogEnd READ fogEnd WRITE setFogEnd)
|
||||
Q_PROPERTY (FogMode fogMode READ fogMode WRITE setFogMode)
|
||||
Q_PROPERTY (bool fogEnabled READ isFogEnabled WRITE setFogEnabled)
|
||||
Q_PROPERTY (int renderMode READ renderMode WRITE setRenderMode)
|
||||
@@ -51,10 +51,10 @@ class QGLView: public OpenGLWindow, public QGLViewBase
|
||||
Q_PROPERTY (bool cameraOrbit READ isCameraOrbit WRITE setCameraOrbit)
|
||||
Q_PROPERTY (bool hoverHalo READ isHoverHaloEnabled WRITE setHoverHaloEnabled)
|
||||
Q_PROPERTY (QColor hoverHaloColor READ hoverHaloColor WRITE setHoverHaloColor)
|
||||
Q_PROPERTY (double hoverHaloFillAlpha READ hoverHaloFillAlpha WRITE setHoverHaloFillAlpha)
|
||||
Q_PROPERTY (float hoverHaloFillAlpha READ hoverHaloFillAlpha WRITE setHoverHaloFillAlpha)
|
||||
Q_PROPERTY (bool selectionHalo READ isSelectionHaloEnabled WRITE setSelectionHaloEnabled)
|
||||
Q_PROPERTY (QColor selectionHaloColor READ selectionHaloColor WRITE setSelectionHaloColor)
|
||||
Q_PROPERTY (double selectionHaloFillAlpha READ selectionHaloFillAlpha WRITE setSelectionHaloFillAlpha)
|
||||
Q_PROPERTY (float selectionHaloFillAlpha READ selectionHaloFillAlpha WRITE setSelectionHaloFillAlpha)
|
||||
Q_PROPERTY (Qt::MouseButton selectionButton READ selectionButton WRITE setSelectionButton)
|
||||
Q_PROPERTY (Qt::KeyboardModifier selectionModifier READ selectionModifier WRITE setSelectionModifier)
|
||||
Q_PROPERTY (SelectionMode selectionMode READ selectionMode WRITE setSelectionMode)
|
||||
@@ -99,24 +99,24 @@ public:
|
||||
Q_ENUMS (SelectionMode)
|
||||
|
||||
void stop();
|
||||
void start(double freq = 40.);
|
||||
void start(float freq = 40.);
|
||||
|
||||
GLRendererBase * renderer();
|
||||
void setRenderer(GLRendererBase * r, GLRendererBase ** prev = nullptr);
|
||||
|
||||
QColor backColor() const {return backColor_;}
|
||||
double lineWidth() const {return lineWidth_;}
|
||||
double FOV() const {return camera().fov_;}
|
||||
double depthStart() const {return camera().depth_start;}
|
||||
double depthEnd() const {return camera().depth_end;}
|
||||
double currentFPS() const {return fps_;}
|
||||
float lineWidth() const {return lineWidth_;}
|
||||
float FOV() const {return camera()->fov_;}
|
||||
float depthStart() const {return camera()->depth_start;}
|
||||
float depthEnd() const {return camera()->depth_end;}
|
||||
float currentFPS() const {return fps_;}
|
||||
int maxAnisotropicLevel() const {return max_anisotropic;}
|
||||
|
||||
QColor ambientColor() const {return ambientColor_;}
|
||||
QColor fogColor() const {return fogColor_;}
|
||||
double fogDensity() const {return fogDensity_;}
|
||||
double fogStart() const {return fogStart_;}
|
||||
double fogEnd() const {return fogEnd_;}
|
||||
float fogDensity() const {return fogDensity_;}
|
||||
float fogStart() const {return fogStart_;}
|
||||
float fogEnd() const {return fogEnd_;}
|
||||
FogMode fogMode() const {return fogMode_;}
|
||||
bool isFogEnabled() const {return fogEnabled_;}
|
||||
bool isLightEnabled() const {return lightEnabled_;}
|
||||
@@ -126,10 +126,10 @@ public:
|
||||
bool isCameraOrbit() const {return cameraOrbit_;}
|
||||
bool isHoverHaloEnabled() const {return hoverHalo_;}
|
||||
QColor hoverHaloColor() const {return hoverHaloColor_;}
|
||||
double hoverHaloFillAlpha() const {return hoverHaloFill_;}
|
||||
float hoverHaloFillAlpha() const {return hoverHaloFill_;}
|
||||
bool isSelectionHaloEnabled() const {return selectionHalo_;}
|
||||
QColor selectionHaloColor() const {return selectionHaloColor_;}
|
||||
double selectionHaloFillAlpha() const {return selectionHaloFill_;}
|
||||
float selectionHaloFillAlpha() const {return selectionHaloFill_;}
|
||||
|
||||
QVariant feature(Feature f) const {return features_.value(int(f));}
|
||||
QVariant setFeature(Feature f, const QVariant & value) {QVariant ret = features_.value(int(f)); features_[int(f)] = value; return ret;}
|
||||
@@ -138,30 +138,28 @@ public:
|
||||
int renderMode() const {return (int)rmode;}
|
||||
void setRenderMode(int mode) {rmode = (GLObjectBase::RenderMode)mode;}
|
||||
|
||||
void addObject(QWidget * o, Qt::WindowFlags f = Qt::Widget);
|
||||
void addObject(GLObjectBase * o);
|
||||
void addObject(GLObjectBase & o) {addObject(&o);}
|
||||
int objectsCount(bool all = false) {if (!all) return objects_.childCount(); int cnt = 0; objectsCountInternal(&cnt, &objects_); return cnt;}
|
||||
// void addObject(GLObjectBase & o) {addObject(&o);}
|
||||
int objectsCount(bool all = false);
|
||||
void removeObject(GLObjectBase * o, bool inChildren = true);
|
||||
void removeObject(GLObjectBase & o, bool inChildren = true) {removeObject(&o, inChildren);}
|
||||
void removeObject(GLObjectBase & o, bool inChildren = true);
|
||||
void clearObjects(bool deleteAll = false);
|
||||
QList<GLObjectBase * > objects(bool all = false) {return objects_.children(all);}
|
||||
QList<GLObjectBase * > objects(bool all = false);
|
||||
|
||||
int lightsCount() const {return lights_.size();}
|
||||
void removeLight(int index) {removeObject(lights_.at(index)); lights_.removeAt(index);}
|
||||
void removeLight(Light * l) {foreach (Light * i, lights_) removeObject(i); lights_.removeAll(l);}
|
||||
void clearLights(bool deleteAll = false) {if (deleteAll) foreach (Light * i, lights_) delete i; lights_.clear();}
|
||||
int lightsCount() const;
|
||||
void removeLight(int index);
|
||||
void removeLight(Light * l);
|
||||
void clearLights(bool deleteAll = false);
|
||||
QList<Light * > lights() {return lights_;}
|
||||
|
||||
GLTextureManager * textureManager() {return &textures_manager;}
|
||||
void addTexture(const QString & path) {textures_manager.addTexture(path);}
|
||||
void addAnimation(const QString & dir, const QString & name) {textures_manager.addAnimation(dir, name);}
|
||||
void addTexture(const QString & path);
|
||||
void addAnimation(const QString & dir, const QString & name);
|
||||
|
||||
const GLObjectBase & rootObject() {return objects_;}
|
||||
GLObjectBase * object(int index) {return objects_.child(index);}
|
||||
GLObjectBase * object(const QString & name) {return objects_.child(name);}
|
||||
Light * light(int index) {return lights_[index];}
|
||||
Light * light(const QString & name) {foreach (Light * i, lights_) if (i->name_ == name) return i; return 0;}
|
||||
Light * light(int index);
|
||||
Light * light(const QString & name);
|
||||
|
||||
SelectionMode selectionMode() const {return sel_mode;}
|
||||
Qt::MouseButton selectionButton() const {return sel_button;}
|
||||
@@ -173,7 +171,9 @@ public:
|
||||
void selectObject(GLObjectBase * o);
|
||||
GLObjectBase * selectedObject() const {return sel_obj;}
|
||||
|
||||
GLdouble aspect, iaspect;
|
||||
void glReleaseTextures(int channels = 8);
|
||||
|
||||
GLfloat aspect, iaspect;
|
||||
QMatrix4x4 cur_mvpm;
|
||||
|
||||
protected:
|
||||
@@ -188,6 +188,7 @@ protected:
|
||||
void mouseReleaseEvent(QMouseEvent * e);
|
||||
void wheelEvent(QWheelEvent * e);
|
||||
void leaveEvent(QEvent * );
|
||||
void mouseDoubleClickEvent(QMouseEvent * e);
|
||||
|
||||
void keyPressEvent(QKeyEvent * e);
|
||||
void keyReleaseEvent(QKeyEvent * e);
|
||||
@@ -202,17 +203,16 @@ protected:
|
||||
private:
|
||||
void objectDeleted(GLObjectBase * o);
|
||||
void collectObjectLights(GLObjectBase * o);
|
||||
void objectsCountInternal(int * cnt, GLObjectBase * where) {++(*cnt); foreach (GLObjectBase * i, where->children_) objectsCountInternal(cnt, i);}
|
||||
void objectsCountInternal(int * cnt, GLObjectBase * where);
|
||||
void removeObjectInternal(GLObjectBase * o, GLObjectBase * where);
|
||||
void renderSingleSelection(GLObjectBase & o);
|
||||
//void renderSingleShadow(GLObjectBase & o);
|
||||
void renderHalo(const GLObjectBase * obj, const uint iid, const QColor & color, const double & fill);
|
||||
void renderHalo(const GLObjectBase * obj, const uint iid, const QColor & color, const float & fill);
|
||||
void reloadThisShaders();
|
||||
void processKeys();
|
||||
bool setupViewport();
|
||||
|
||||
QPoint lastPos, downPos;
|
||||
GLTextureManager textures_manager;
|
||||
GLObjectBase objects_;
|
||||
QList<Light * > lights_;
|
||||
// uint cid;
|
||||
@@ -232,8 +232,8 @@ private:
|
||||
Qt::KeyboardModifier sel_mod;
|
||||
GLRendererBase::RenderingParameters start_rp;
|
||||
QHash<int, QVariant> features_;
|
||||
double lineWidth_;
|
||||
double fogDensity_, fogStart_, fogEnd_, fps_, fps_tm, hoverHaloFill_, selectionHaloFill_, m_motionBlurFactor;
|
||||
float lineWidth_;
|
||||
float fogDensity_, fogStart_, fogEnd_, fps_, fps_tm, hoverHaloFill_, selectionHaloFill_, m_motionBlurFactor;
|
||||
int timer, fps_cnt, sh_id_loc;
|
||||
bool is_first_draw, is_init, fogEnabled_, lightEnabled_, grabMouse_, mouse_first, mouseRotate_, mouseSelect_, customMouseMove_;
|
||||
bool shaders_supported, changed_, cameraOrbit_, need_init_;
|
||||
@@ -241,15 +241,15 @@ private:
|
||||
|
||||
public slots:
|
||||
void setBackColor(const QColor & arg) {backColor_ = arg;}
|
||||
void setLineWidth(const double & arg) {lineWidth_ = arg;}
|
||||
void setFOV(const double & arg) {camera().fov_ = arg;}
|
||||
void setDepthStart(const double & arg) {camera().depth_start = arg;}
|
||||
void setDepthEnd(const double & arg) {camera().depth_end = arg;}
|
||||
void setLineWidth(const float & arg) {lineWidth_ = arg;}
|
||||
void setFOV(const float & arg) {camera()->fov_ = arg;}
|
||||
void setDepthStart(const float & arg) {camera()->depth_start = arg;}
|
||||
void setDepthEnd(const float & arg) {camera()->depth_end = arg;}
|
||||
void setAmbientColor(const QColor & arg) {ambientColor_ = arg;}
|
||||
void setFogColor(const QColor & arg) {fogColor_ = arg;}
|
||||
void setFogDensity(const double & arg) {fogDensity_ = arg;}
|
||||
void setFogStart(const double & arg) {fogStart_ = arg;}
|
||||
void setFogEnd(const double & arg) {fogEnd_ = arg;}
|
||||
void setFogDensity(const float & arg) {fogDensity_ = arg;}
|
||||
void setFogStart(const float & arg) {fogStart_ = arg;}
|
||||
void setFogEnd(const float & arg) {fogEnd_ = arg;}
|
||||
void setFogMode(const FogMode & arg) {fogMode_ = arg;}
|
||||
void setFogEnabled(const bool & arg) {fogEnabled_ = arg;}
|
||||
void setLightEnabled(const bool & arg) {lightEnabled_ = arg;}
|
||||
@@ -260,13 +260,13 @@ public slots:
|
||||
void setCameraOrbit(const bool & arg) {cameraOrbit_ = arg;}
|
||||
void setHoverHaloEnabled(const bool & arg) {hoverHalo_ = arg;}
|
||||
void setHoverHaloColor(const QColor & arg) {hoverHaloColor_ = arg;}
|
||||
void setHoverHaloFillAlpha(const double & arg) {hoverHaloFill_ = arg;}
|
||||
void setHoverHaloFillAlpha(const float & arg) {hoverHaloFill_ = arg;}
|
||||
void setSelectionHaloEnabled(const bool & arg) {selectionHalo_ = arg;}
|
||||
void setSelectionHaloColor(const QColor & arg) {selectionHaloColor_ = arg;}
|
||||
void setSelectionHaloFillAlpha(const double & arg) {selectionHaloFill_ = arg;}
|
||||
void setSelectionHaloFillAlpha(const float & arg) {selectionHaloFill_ = arg;}
|
||||
|
||||
void reloadShaders() {if (renderer_ != 0) renderer_->reloadShaders(); reloadThisShaders();}
|
||||
void deselect() {sel_obj = 0;}
|
||||
void reloadShaders() {if (renderer_ != nullptr) renderer_->reloadShaders(); reloadThisShaders();}
|
||||
void deselect() {sel_obj = nullptr;}
|
||||
|
||||
signals:
|
||||
void glBeforePaint();
|
||||
@@ -288,6 +288,7 @@ signals:
|
||||
void hoverChanged(GLObjectBase * cur, GLObjectBase * prev);
|
||||
void selectionChanged(GLObjectBase * cur, GLObjectBase * prev);
|
||||
void objectAdded(GLObjectBase * );
|
||||
void doubleClick();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -35,9 +35,9 @@ QGLViewWindow::QGLViewWindow(QWidget * parent): QMainWindow(parent), Ui::QGLView
|
||||
icon_camera = QIcon(":/icons/type-camera.png");
|
||||
icon_light = QIcon(":/icons/type-light.png");
|
||||
|
||||
sel_obj = 0;
|
||||
view->view()->camera().setAim(QVector3D());
|
||||
view->view()->camera().setPos(QVector3D(2, 2, 2));
|
||||
sel_obj = nullptr;
|
||||
view->view()->camera()->setAim(QVector3D());
|
||||
view->view()->camera()->setPos(QVector3D(2, 2, 2));
|
||||
// view->setFrameShape(QFrame::NoFrame);
|
||||
view->view()->setRenderer(new RendererSimple(view->view()));
|
||||
view->view()->setMouseRotateEnabled(true);
|
||||
@@ -105,7 +105,7 @@ QGLViewWindow::QGLViewWindow(QWidget * parent): QMainWindow(parent), Ui::QGLView
|
||||
cam_light = new Light();
|
||||
cam_light->intensity = 0.5;
|
||||
cam_light->setName("Camera_Light");
|
||||
view->view()->camera().addChild(cam_light);
|
||||
view->view()->camera()->addChild(cam_light);
|
||||
view->view()->start(-1);
|
||||
startTimer(1000/60);
|
||||
|
||||
@@ -153,7 +153,7 @@ void QGLViewWindow::loadFile(const QString & path) {
|
||||
void QGLViewWindow::importFile(const QString & path) {
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
QFileInfo fi(path);
|
||||
GLObjectBase * o = 0;
|
||||
GLObjectBase * o = nullptr;
|
||||
if (fi.suffix().toLower() == "qgl") o = loadFromQGLFile(path);
|
||||
if (fi.suffix().toLower() == "ase") o = loadFromASEFile(path);
|
||||
if (fi.suffix().toLower() == "3ds") o = loadFrom3DSFile(path);
|
||||
@@ -188,10 +188,10 @@ void QGLViewWindow::makeObjetTree(const GLObjectBase * o, QTreeWidgetItem * ti)
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::selectionChanged(GLObjectBase * cur, GLObjectBase * prev) {
|
||||
void QGLViewWindow::selectionChanged(GLObjectBase * cur, GLObjectBase *) {
|
||||
sel_obj = cur;
|
||||
//qDebug() << "selected" << (cur != 0 ? cur->name() : "0");
|
||||
labelName->setText(cur != 0 ? cur->name() : "");
|
||||
labelName->setText(cur != nullptr ? cur->name() : "");
|
||||
/**if (cur == 0) box->hide();
|
||||
else {
|
||||
box->setScale(cur->boundingBox().size());
|
||||
@@ -203,26 +203,26 @@ void QGLViewWindow::selectionChanged(GLObjectBase * cur, GLObjectBase * prev) {
|
||||
box->show();
|
||||
}*/
|
||||
objectEditor->setObject(sel_obj);
|
||||
if (sel_obj == 0) return;
|
||||
if (sel_obj == nullptr) return;
|
||||
matEditor->setMaterial(sel_obj->material());
|
||||
//qDebug() << sel_obj->boundingBox();
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::materialChanged() {
|
||||
if (sel_obj == 0) return;
|
||||
if (sel_obj == nullptr) return;
|
||||
sel_obj->setMaterial(matEditor->material());
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::on_comboRenderer_currentIndexChanged(int val) {
|
||||
GLRendererBase * pr = 0;
|
||||
GLRendererBase * pr = nullptr;
|
||||
switch (val) {
|
||||
case 0: view->view()->setRenderer(new RendererSimple(view->view()), &pr); break;
|
||||
case 1: view->view()->setRenderer(new RendererDeferredShading(view->view()), &pr); break;
|
||||
//case 2: view->view()->setRenderer(new RendererRT(view), &pr); break;
|
||||
}
|
||||
if (pr != 0) delete pr;
|
||||
if (pr != nullptr) delete pr;
|
||||
}
|
||||
|
||||
|
||||
@@ -294,20 +294,20 @@ void QGLViewWindow::view_keyEvent(Qt::Key k, Qt::KeyboardModifiers m) {
|
||||
if (m.testFlag(Qt::ShiftModifier))
|
||||
spd = 0.5;
|
||||
switch (k) {
|
||||
case Qt::Key_W: view->view()->camera().moveForward(spd); break;
|
||||
case Qt::Key_S: view->view()->camera().moveBackward(spd); break;
|
||||
case Qt::Key_A: view->view()->camera().moveLeft(spd); break;
|
||||
case Qt::Key_D: view->view()->camera().moveRight(spd); break;
|
||||
case Qt::Key_W: view->view()->camera()->moveForward(spd); break;
|
||||
case Qt::Key_S: view->view()->camera()->moveBackward(spd); break;
|
||||
case Qt::Key_A: view->view()->camera()->moveLeft(spd); break;
|
||||
case Qt::Key_D: view->view()->camera()->moveRight(spd); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::on_treeObjects_itemClicked(QTreeWidgetItem * ti, int col) {
|
||||
void QGLViewWindow::on_treeObjects_itemClicked(QTreeWidgetItem * ti, int) {
|
||||
((GLObjectBase*)(ti->data(0, Qt::UserRole).toULongLong()))->select();
|
||||
//qDebug() << ((GLObjectBase*)(ti->data(0, Qt::UserRole).toULongLong()))->type();
|
||||
if (sel_obj->type() == GLObjectBase::glCamera)
|
||||
view->view()->setCamera(*(Camera*)sel_obj);
|
||||
view->view()->setCamera((Camera*)sel_obj);
|
||||
}
|
||||
|
||||
|
||||
@@ -322,8 +322,8 @@ void QGLViewWindow::on_pushButton_clicked() {
|
||||
//view->view()->removeLight(view->view()->lightsCount() - 1);
|
||||
//setWindowTitle(QString::number(view->view()->lightsCount()));
|
||||
QVector3D wp = view->view()->light(0)->worldPos();
|
||||
view->view()->camera().setPos(wp);
|
||||
view->view()->camera().setAim(wp + (view->view()->light(0)->worldTransform() * QVector4D(view->view()->light(0)->direction)).toVector3D()*100);
|
||||
view->view()->camera()->setPos(wp);
|
||||
view->view()->camera()->setAim(wp + (view->view()->light(0)->worldTransform() * QVector4D(view->view()->light(0)->direction)).toVector3D()*100);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -121,11 +121,11 @@ private slots:
|
||||
|
||||
void view_keyEvent(Qt::Key k, Qt::KeyboardModifiers m);
|
||||
|
||||
void on_treeObjects_itemClicked(QTreeWidgetItem * ti, int col);
|
||||
void on_treeObjects_itemClicked(QTreeWidgetItem * ti, int);
|
||||
|
||||
void objectsTreeChanged();
|
||||
void materialChanged();
|
||||
void selectionChanged(GLObjectBase * cur, GLObjectBase * prev);
|
||||
void selectionChanged(GLObjectBase * cur, GLObjectBase *);
|
||||
|
||||
void on_pushButton_clicked();
|
||||
void on_pushButton_2_clicked() {view->view()->reloadShaders();}
|
||||
|
||||
@@ -39,7 +39,7 @@ fbo_g(5, true, GL_RGBA16F), fbo_out(3, false, GL_RGBA16F), fbo_hsmall(1, false,
|
||||
<< ShaderPair("ssao_merge", &shader_ssao_merge)
|
||||
<< ShaderPair("dof", &shader_dof);
|
||||
for (int i = 0; i < shaders.size(); ++i)
|
||||
*(shaders[i].second) = 0;
|
||||
*(shaders[i].second) = nullptr;
|
||||
lights_per_pass = 8;
|
||||
tnoise = 0;
|
||||
exposure_ = 1.;
|
||||
@@ -73,12 +73,12 @@ void RendererDeferredShading::renderScene() {
|
||||
QMatrix4x4 mview = rp.view_matrix;
|
||||
QMatrix4x4 mviewi = rp.view_matrix_i;
|
||||
QMatrix4x4 mviewproji = (mproj * mview).inverted();
|
||||
QMatrix4x4 moffset = view.camera().offsetMatrix();
|
||||
QMatrix4x4 moffset = view.camera()->offsetMatrix();
|
||||
QMatrix4x4 moffseti = moffset.inverted();
|
||||
rp.prev_proj_matrix = prev_proj;
|
||||
rp.prev_view_matrix = prev_view;
|
||||
QMatrix4x4 vc_proji;
|
||||
vc_proji.perspective(90., 1., view.camera().depthStart(), view.camera().depthEnd());
|
||||
vc_proji.perspective(90., 1., view.camera()->depthStart(), view.camera()->depthEnd());
|
||||
vc_proji = vc_proji.inverted();
|
||||
corner_dirs[0] = (mproji * QVector4D( 1, 1, 0, 1));
|
||||
corner_dirs[1] = (mproji * QVector4D(-1, 1, 0, 1));
|
||||
@@ -89,30 +89,30 @@ void RendererDeferredShading::renderScene() {
|
||||
int buffs[] = {0, 1, 2, 3, 4};
|
||||
fbo_g.setWriteBuffers(buffs, 5);
|
||||
if (white_image_id == 0) {
|
||||
glActiveTextureChannel(6);
|
||||
glActiveTexture(GL_TEXTURE0 + 6);
|
||||
white_image_id = view.textureManager()->loadTexture(white_image, false);
|
||||
glBindTexture(GL_TEXTURE_2D, white_image_id);
|
||||
glActiveTextureChannel(0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
if (violent_image_id == 0) {
|
||||
glActiveTextureChannel(7);
|
||||
glActiveTexture(GL_TEXTURE0 + 7);
|
||||
violent_image_id = view.textureManager()->loadTexture(violent_image, false);
|
||||
glBindTexture(GL_TEXTURE_2D, violent_image_id);
|
||||
glActiveTextureChannel(0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
glClearFramebuffer(QColor(0, 0, 0, 0));
|
||||
glDisable(GL_RESCALE_NORMAL);
|
||||
glEnableDepth();
|
||||
shader_ds_0->bind();
|
||||
rp.setUniform(shader_ds_0);
|
||||
shader_ds_0->setUniformValue("z_far", GLfloat(view.depthEnd()));
|
||||
shader_ds_0->setUniformValue("z_near", GLfloat(view.depthStart()));
|
||||
shader_ds_0->setUniformValue("z_far", view.depthEnd());
|
||||
shader_ds_0->setUniformValue("z_near", view.depthStart());
|
||||
shader_ds_0->setUniformValue("t0", 0);
|
||||
shader_ds_0->setUniformValue("t1", 1);
|
||||
shader_ds_0->setUniformValue("t2", 2);
|
||||
shader_ds_0->setUniformValue("t3", 3);
|
||||
shader_ds_0->setUniformValue("t4", 4);
|
||||
shader_ds_0->setUniformValue("dt", QVector2D(1. / view.width(), 1. / view.height()));
|
||||
shader_ds_0->setUniformValue("dt", QVector2D(1.f / view.width(), 1.f / view.height()));
|
||||
//qDebug() << rp.view_matrix << prev_view;
|
||||
//shader_ds_0->setUniformValue("qgl_ModelViewMatrix", rp.view_matrix);
|
||||
renderObjects(GLObjectBase::Solid, 0, shader_ds_0, true, false, false);
|
||||
@@ -156,8 +156,8 @@ void RendererDeferredShading::renderScene() {
|
||||
rp.prepare();
|
||||
//qDebug() << rp.view_matrix;
|
||||
shader_ds_1->bind();
|
||||
shader_ds_1->setUniformValue("z_far", GLfloat(view.depthEnd()));
|
||||
shader_ds_1->setUniformValue("z_near", GLfloat(view.depthStart()));
|
||||
shader_ds_1->setUniformValue("z_far", view.depthEnd());
|
||||
shader_ds_1->setUniformValue("z_near", view.depthStart());
|
||||
shader_ds_1->setUniformValue("t0", 0);
|
||||
shader_ds_1->setUniformValue("t1", 1);
|
||||
shader_ds_1->setUniformValue("t2", 2);
|
||||
@@ -170,7 +170,7 @@ void RendererDeferredShading::renderScene() {
|
||||
shader_ds_1->setUniformValue("mat_viewi", mviewi);
|
||||
shader_ds_1->setUniformValue("mat_viewproji", mviewproji);
|
||||
shader_ds_1->setUniformValue("shadow_on", view.isFeatureEnabled(QGLView::qglShadowsEnabled) ? 1 : 0);
|
||||
shader_ds_1->setUniformValue("dt", QVector2D(1. / view.width(), 1. / view.height()));
|
||||
shader_ds_1->setUniformValue("dt", QVector2D(1.f / view.width(), 1.f / view.height()));
|
||||
rp.setUniform(shader_ds_1);
|
||||
fbo_g.bindColorTextures();
|
||||
fbo_g.bindDepthTexture(5);
|
||||
@@ -188,7 +188,7 @@ void RendererDeferredShading::renderScene() {
|
||||
wi = 1 - l % 2;
|
||||
ri = l % 2;
|
||||
//qDebug() << " pass" << l << "read from" << ri << "write to" << wi;
|
||||
glActiveTextureChannel(6);
|
||||
glActiveTexture(GL_TEXTURE0 + 6);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(ri));
|
||||
fbo_out.setWriteBuffer(wi);
|
||||
setupDSLights(l, mview * moffset);
|
||||
@@ -198,25 +198,25 @@ void RendererDeferredShading::renderScene() {
|
||||
//fbo_out.release();
|
||||
wi = 1 - passes % 2;
|
||||
ri = passes % 2;
|
||||
glActiveTextureChannel(0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(ri));
|
||||
|
||||
if (view.isFeatureEnabled(QGLView::qglSSAOEnabled)) {
|
||||
fbo_out.setWriteBuffer(2);
|
||||
fbo_out.setReadBuffer(ri);
|
||||
glBlitFramebuffer(0, 0, fbo_out.width(), fbo_out.height(), 0, 0, fbo_out.width(), fbo_out.height(), GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
glActiveTextureChannel(1);
|
||||
glActiveTexture(GL_TEXTURE0 + 1);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(2));
|
||||
glActiveTextureChannel(2);
|
||||
glActiveTexture(GL_TEXTURE0 + 2);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_g.colorTexture(1));
|
||||
glActiveTextureChannel(0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
//glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(ri));
|
||||
//glActiveTextureChannel(1);
|
||||
//glBindTexture(GL_TEXTURE_2D, fbo_g.colorTexture(0));
|
||||
int lri = ri, lwi = wi;//, lms = ri;
|
||||
shader_ssao_blur->bind();
|
||||
shader_ssao_blur->setUniformValue("qgl_ModelViewProjectionMatrix", QMatrix4x4());
|
||||
shader_ssao_blur->setUniformValue("dt", QVector2D(1. / fbo_out.width(), 1. / fbo_out.height()));
|
||||
shader_ssao_blur->setUniformValue("dt", QVector2D(1.f / fbo_out.width(), 1.f / fbo_out.height()));
|
||||
shader_ssao_blur->setUniformValue("t0", 0);
|
||||
shader_ssao_blur->setUniformValue("ts", 1);
|
||||
shader_ssao_blur->setUniformValue("tg1", 2);
|
||||
@@ -249,18 +249,18 @@ void RendererDeferredShading::renderScene() {
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(lri));
|
||||
glActiveTextureChannel(1);
|
||||
glActiveTexture(GL_TEXTURE0 + 1);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(2));
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glActiveTextureChannel(2);
|
||||
glActiveTexture(GL_TEXTURE0 + 2);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_g.colorTexture(1));
|
||||
glActiveTextureChannel(3);
|
||||
glActiveTexture(GL_TEXTURE0 + 3);
|
||||
glBindTexture(GL_TEXTURE_1D, tnoise);
|
||||
shader_ssao_merge->bind();
|
||||
shader_ssao_merge->setUniformValue("qgl_ModelViewProjectionMatrix", QMatrix4x4());
|
||||
shader_ssao_merge->setUniformValue("z_far", GLfloat(view.depthEnd()));
|
||||
shader_ssao_merge->setUniformValue("z_near", GLfloat(view.depthStart()));
|
||||
shader_ssao_merge->setUniformValue("z_far", view.depthEnd());
|
||||
shader_ssao_merge->setUniformValue("z_near", view.depthStart());
|
||||
shader_ssao_merge->setUniformValue("mat_proj", mproj);
|
||||
shader_ssao_merge->setUniformValue("n0", 3);
|
||||
shader_ssao_merge->setUniformValue("t0", 0);
|
||||
@@ -273,27 +273,27 @@ void RendererDeferredShading::renderScene() {
|
||||
ri = lwi;
|
||||
//piSwap<int>(wi, ri);
|
||||
|
||||
glActiveTextureChannel(0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(ri));
|
||||
//piSwap<int>(wi, ri);
|
||||
}
|
||||
|
||||
if (view.isFeatureEnabled(QGLView::qglReflectionsEnabled)) {
|
||||
fbo_out.setWriteBuffer(2);
|
||||
glActiveTextureChannel(0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(ri));
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);//_MIPMAP_LINEAR);
|
||||
//glGenerateMipmap(GL_TEXTURE_2D);
|
||||
glActiveTextureChannel(1);
|
||||
glActiveTexture(GL_TEXTURE0 + 1);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_g.colorTexture(0));
|
||||
glActiveTextureChannel(2);
|
||||
glActiveTexture(GL_TEXTURE0 + 2);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_g.colorTexture(1));
|
||||
fbo_g.bindDepthTexture(7);
|
||||
shader_ssr->bind();
|
||||
shader_ssr->setUniformValue("qgl_ModelViewProjectionMatrix", QMatrix4x4());
|
||||
shader_ssr->setUniformValue("z_far", GLfloat(view.depthEnd()));
|
||||
shader_ssr->setUniformValue("z_near", GLfloat(view.depthStart()));
|
||||
shader_ssr->setUniformValue("z_far", view.depthEnd());
|
||||
shader_ssr->setUniformValue("z_near", view.depthStart());
|
||||
shader_ssr->setUniformValue("mat_proj", mproj);
|
||||
shader_ssr->setUniformValue("t0", 1);
|
||||
shader_ssr->setUniformValue("t1", 2);
|
||||
@@ -301,12 +301,12 @@ void RendererDeferredShading::renderScene() {
|
||||
shader_ssr->setUniformValue("td", 7);
|
||||
glDrawQuad(shader_ssr, corner_dirs);
|
||||
|
||||
glActiveTextureChannel(0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
int lri = 2, lwi = wi, lms = ri;
|
||||
if (view.isFeatureEnabled(QGLView::qglReflectionsBlur)) {
|
||||
shader_ssr_blur->bind();
|
||||
shader_ssr_blur->setUniformValue("qgl_ModelViewProjectionMatrix", QMatrix4x4());
|
||||
shader_ssr_blur->setUniformValue("dt", QVector2D(1. / fbo_out.width(), 1. / fbo_out.height()));
|
||||
shader_ssr_blur->setUniformValue("dt", QVector2D(1.f / fbo_out.width(), 1.f / fbo_out.height()));
|
||||
shader_ssr_blur->setUniformValue("t0", 0);
|
||||
int passes = 5;
|
||||
int crad = 1;
|
||||
@@ -326,9 +326,9 @@ void RendererDeferredShading::renderScene() {
|
||||
ri = 1 - lms;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(wi));
|
||||
glActiveTextureChannel(1);
|
||||
glActiveTexture(GL_TEXTURE0 + 1);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_g.colorTexture(1));
|
||||
glActiveTextureChannel(2);
|
||||
glActiveTexture(GL_TEXTURE0 + 2);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(lms));
|
||||
shader_ssr_merge->bind();
|
||||
shader_ssr_merge->setUniformValue("qgl_ModelViewProjectionMatrix", QMatrix4x4());
|
||||
@@ -341,7 +341,7 @@ void RendererDeferredShading::renderScene() {
|
||||
ri = 1 - ri;
|
||||
//piSwap<int>(wi, ri);
|
||||
|
||||
glActiveTextureChannel(0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(wi));
|
||||
piSwap<int>(wi, ri);
|
||||
}
|
||||
@@ -353,43 +353,43 @@ void RendererDeferredShading::renderScene() {
|
||||
fbo_g.bind();
|
||||
glReadPixels(fbo_out.width() / 2, fbo_out.height() / 2, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &cw);
|
||||
fbo_out.bind();
|
||||
const double _pe = 2.4e-7;
|
||||
double cz = cw + cw - 1;
|
||||
cz = ((_pe - 2.) * view.depthStart()) / (cz + _pe - 1.); // infinite depth
|
||||
double z = view.feature(QGLView::qglDepthOfFieldFocus).toDouble(),
|
||||
s = view.feature(QGLView::qglDepthOfFieldAutoFocusSpeed).toDouble();
|
||||
z = z * (1. - s) + cz * s;
|
||||
const float _pe = 2.4e-7f;
|
||||
float cz = cw + cw - 1;
|
||||
cz = ((_pe - 2.f) * view.depthStart()) / (cz + _pe - 1.f); // infinite depth
|
||||
float z = view.feature(QGLView::qglDepthOfFieldFocus).toFloat(),
|
||||
s = view.feature(QGLView::qglDepthOfFieldAutoFocusSpeed).toFloat();
|
||||
z = z * (1.f - s) + cz * s;
|
||||
view.setFeature(QGLView::qglDepthOfFieldFocus, z);
|
||||
}
|
||||
shader_dof->bind();
|
||||
shader_dof->setUniformValue("qgl_ModelViewProjectionMatrix", QMatrix4x4());
|
||||
shader_dof->setUniformValue("z_far", GLfloat(view.depthEnd()));
|
||||
shader_dof->setUniformValue("z_near", GLfloat(view.depthStart()));
|
||||
shader_dof->setUniformValue("focus", GLfloat(view.feature(QGLView::qglDepthOfFieldFocus).toDouble()));
|
||||
shader_dof->setUniformValue("diaphragm", GLfloat(view.feature(QGLView::qglDepthOfFieldDiaphragm).toDouble()));
|
||||
shader_dof->setUniformValue("z_far", view.depthEnd());
|
||||
shader_dof->setUniformValue("z_near", view.depthStart());
|
||||
shader_dof->setUniformValue("focus", view.feature(QGLView::qglDepthOfFieldFocus).toFloat());
|
||||
shader_dof->setUniformValue("diaphragm", view.feature(QGLView::qglDepthOfFieldDiaphragm).toFloat());
|
||||
shader_dof->setUniformValue("t0", 0);
|
||||
shader_dof->setUniformValue("td", 7);
|
||||
fbo_g.bindDepthTexture(7);
|
||||
glActiveTextureChannel(0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
int passes = 3;
|
||||
float crad = 1.;
|
||||
for (int p = 0; p < passes; ++p) {
|
||||
shader_dof->setUniformValue("radius", GLfloat(crad));
|
||||
shader_dof->setUniformValue("radius", crad);
|
||||
fbo_out.setWriteBuffer(wi);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(ri));
|
||||
shader_dof->setUniformValue("dt", QVector2D(1. / fbo_out.width(), 0.));
|
||||
shader_dof->setUniformValue("dt", QVector2D(1.f / fbo_out.width(), 0.f));
|
||||
glDrawQuad(shader_dof);
|
||||
piSwap<int>(wi, ri);
|
||||
fbo_out.setWriteBuffer(wi);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(ri));
|
||||
shader_dof->setUniformValue("dt", QVector2D(0., 1. / fbo_out.height()));
|
||||
shader_dof->setUniformValue("dt", QVector2D(0.f, 1.f / fbo_out.height()));
|
||||
glDrawQuad(shader_dof);
|
||||
piSwap<int>(wi, ri);
|
||||
crad *= 2.;
|
||||
crad *= 2.f;
|
||||
}
|
||||
|
||||
glActiveTextureChannel(0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(ri));
|
||||
}
|
||||
|
||||
@@ -411,11 +411,11 @@ void RendererDeferredShading::renderScene() {
|
||||
//if (min[2] > hcontent[i].z) min[2] = hcontent[i].z;
|
||||
if (max[2] < hcontent[i].z) max[2] = hcontent[i].z;
|
||||
}
|
||||
GLfloat mluma = (0.299 * max[0]) + (0.587 * max[1]) + (0.114 * max[2]);
|
||||
double nexp = mluma / 16., dexp = nexp - exposure_, mestep = exposure_ * view.feature(QGLView::qglEyeAccomodationMaxSpeed).toDouble();
|
||||
dexp /= view.feature(QGLView::qglEyeAccomodationTime).toDouble();
|
||||
if (dexp > 0. && dexp > mestep/4) dexp = mestep/4;
|
||||
if (dexp < 0. && dexp < -mestep) dexp = -mestep;
|
||||
GLfloat mluma = (0.299f * max[0]) + (0.587f * max[1]) + (0.114f * max[2]);
|
||||
float nexp = mluma / 16.f, dexp = nexp - exposure_, mestep = exposure_ * view.feature(QGLView::qglEyeAccomodationMaxSpeed).toFloat();
|
||||
dexp /= view.feature(QGLView::qglEyeAccomodationTime).toFloat();
|
||||
if (dexp > 0.f && dexp > mestep/4) dexp = mestep/4;
|
||||
if (dexp < 0.f && dexp < -mestep) dexp = -mestep;
|
||||
exposure_ += dexp;
|
||||
label_exp->setText(QString("exposure: %1").arg(exposure_));
|
||||
label_exp_step->setText(QString("d_exposure: %1").arg(dexp));
|
||||
@@ -428,7 +428,7 @@ void RendererDeferredShading::renderScene() {
|
||||
shader_hdr->bind();
|
||||
shader_hdr->setUniformValue("qgl_ModelViewProjectionMatrix", QMatrix4x4());
|
||||
shader_hdr->setUniformValue("t0", 0);
|
||||
shader_hdr->setUniformValue("exposure", GLfloat(1./exposure_));
|
||||
shader_hdr->setUniformValue("exposure", GLfloat(1.f/exposure_));
|
||||
glDrawQuad(shader_hdr);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(wi));
|
||||
piSwap<int>(wi, ri);
|
||||
@@ -436,17 +436,17 @@ void RendererDeferredShading::renderScene() {
|
||||
|
||||
if (view.isFeatureEnabled(QGLView::qglMotionBlurEnabled)) {
|
||||
fbo_out.setWriteBuffer(wi);
|
||||
glActiveTextureChannel(1);
|
||||
glActiveTexture(GL_TEXTURE0 + 1);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_g.colorTexture(4));
|
||||
shader_motion_blur->bind();
|
||||
shader_motion_blur->setUniformValue("qgl_ModelViewProjectionMatrix", QMatrix4x4());
|
||||
shader_motion_blur->setUniformValue("dt", QVector2D(1. / fbo_out.width(), 1. / fbo_out.height()));
|
||||
shader_motion_blur->setUniformValue("dt", QVector2D(1.f / fbo_out.width(), 1.f / fbo_out.height()));
|
||||
shader_motion_blur->setUniformValue("t0", 0);
|
||||
shader_motion_blur->setUniformValue("ts", 1);
|
||||
shader_motion_blur->setUniformValue("factor", GLfloat(view.feature(QGLView::qglMotionBlurFactor).toDouble()));
|
||||
shader_motion_blur->setUniformValue("factor", view.feature(QGLView::qglMotionBlurFactor).toFloat());
|
||||
shader_motion_blur->setUniformValue("steps", view.feature(QGLView::qglMotionBlurSteps).toInt());
|
||||
glDrawQuad(shader_motion_blur);
|
||||
glActiveTextureChannel(0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(wi));
|
||||
piSwap<int>(wi, ri);
|
||||
}
|
||||
@@ -460,16 +460,16 @@ void RendererDeferredShading::renderScene() {
|
||||
fbo_out.setWriteBuffer(wi);
|
||||
shader_bloom_0->bind();
|
||||
shader_bloom_0->setUniformValue("qgl_ModelViewProjectionMatrix", QMatrix4x4());
|
||||
shader_bloom_0->setUniformValue("factor", GLfloat(view.feature(QGLView::qglBloomFactor).toDouble()));
|
||||
shader_bloom_0->setUniformValue("threshold", GLfloat(view.feature(QGLView::qglBloomThreshold).toDouble()));
|
||||
shader_bloom_0->setUniformValue("factor", view.feature(QGLView::qglBloomFactor).toFloat());
|
||||
shader_bloom_0->setUniformValue("threshold", view.feature(QGLView::qglBloomThreshold).toFloat());
|
||||
shader_bloom_0->setUniformValue("t0", 0);
|
||||
glDrawQuad(shader_bloom_0);
|
||||
glActiveTextureChannel(0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
piSwap<int>(wi, ri);
|
||||
|
||||
shader_bloom_1->bind();
|
||||
shader_bloom_1->setUniformValue("qgl_ModelViewProjectionMatrix", QMatrix4x4());
|
||||
shader_bloom_1->setUniformValue("dt", QVector2D(1. / fbo_out.width(), 1. / fbo_out.height()));
|
||||
shader_bloom_1->setUniformValue("dt", QVector2D(1.f / fbo_out.width(), 1.f / fbo_out.height()));
|
||||
shader_bloom_1->setUniformValue("t0", 0);
|
||||
int radius = view.feature(QGLView::qglBloomRadius).toInt();
|
||||
int passes = qMax<int>(int(ceil(log2(radius))), 1);
|
||||
@@ -486,28 +486,28 @@ void RendererDeferredShading::renderScene() {
|
||||
}
|
||||
//qDebug() << tm.elapsed();
|
||||
fbo_out.setWriteBuffer(wi);
|
||||
glActiveTextureChannel(0);
|
||||
// glActiveTextureChannel(0);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(ri));
|
||||
glActiveTextureChannel(1);
|
||||
glActiveTexture(GL_TEXTURE0 + 1);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(2));
|
||||
shader_fbo_add->bind();
|
||||
shader_fbo_add->setUniformValue("qgl_ModelViewProjectionMatrix", QMatrix4x4());
|
||||
shader_fbo_add->setUniformValue("t0", 0);
|
||||
shader_fbo_add->setUniformValue("t1", 1);
|
||||
glDrawQuad(shader_fbo_add);
|
||||
glActiveTextureChannel(0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(wi));
|
||||
piSwap<int>(wi, ri);
|
||||
}
|
||||
|
||||
glReleaseShaders();
|
||||
glUseProgram(0);
|
||||
fbo_out.release();
|
||||
|
||||
if (view.isFeatureEnabled(QGLView::qglFXAA)) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
shader_fxaa->bind();
|
||||
shader_fxaa->setUniformValue("dt", QVector2D(1. / view.width(), 1. / view.height()));
|
||||
shader_fxaa->setUniformValue("dt", QVector2D(1.f / view.width(), 1.f / view.height()));
|
||||
} else {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
@@ -546,9 +546,9 @@ void RendererDeferredShading::reloadShaders() {
|
||||
|
||||
|
||||
void RendererDeferredShading::setupShadersTextures(GLObjectBase & object, GLRendererBase::RenderingParameters & rp) {
|
||||
glActiveTextureChannel(6);
|
||||
glActiveTexture(GL_TEXTURE0 + 6);
|
||||
glBindTexture(GL_TEXTURE_2D, white_image_id);
|
||||
glActiveTextureChannel(7);
|
||||
glActiveTexture(GL_TEXTURE0 + 7);
|
||||
glBindTexture(GL_TEXTURE_2D, violent_image_id);
|
||||
}
|
||||
|
||||
@@ -566,7 +566,7 @@ void RendererDeferredShading::setupDSLights(int pass, const QMatrix4x4 & view_ma
|
||||
QVector<Light*> lv;
|
||||
for (int i = light_start; i < light_end; ++i) {
|
||||
lv << view.lights()[i];
|
||||
glActiveTextureChannel(shadow_start + i - light_start);
|
||||
glActiveTexture(GL_TEXTURE0 + shadow_start + i - light_start);
|
||||
glBindTexture(GL_TEXTURE_2D, lv.back()->shadow_map.depthTexture());
|
||||
if (view.isFeatureEnabled(QGLView::qglShadowsSoftEnabled)) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
@@ -43,7 +43,7 @@ private:
|
||||
typedef QPair<QString, QOpenGLShaderProgram **> ShaderPair;
|
||||
|
||||
int cplc, lights_per_pass;
|
||||
double exposure_;
|
||||
float exposure_;
|
||||
GLFramebuffer fbo_g, fbo_out, fbo_hsmall;
|
||||
QOpenGLShaderProgram * shader_fxaa, * shader_ds_0, * shader_ds_1, * shader_hdr, * shader_small;
|
||||
QOpenGLShaderProgram * shader_bloom_0, * shader_bloom_1, * shader_motion_blur, * shader_fbo_add;
|
||||
|
||||
@@ -72,7 +72,7 @@ void RendererSimple::renderScene() {
|
||||
glDepthFunc(GL_EQUAL);
|
||||
}
|
||||
//view.camera().apply(view.aspect);
|
||||
rp.cam_offset_matrix = view.camera().offsetMatrix();
|
||||
rp.cam_offset_matrix = view.camera()->offsetMatrix();
|
||||
rp.prepare();
|
||||
setupLights(l, 8);
|
||||
|
||||
@@ -90,16 +90,16 @@ void RendererSimple::renderScene() {
|
||||
}
|
||||
fbo_c.release();*/
|
||||
//qDebug() << rp.viewproj_matrix << (getGLMatrix(GL_PROJECTION_MATRIX)*getGLMatrix(GL_MODELVIEW_MATRIX));
|
||||
renderObjects(GLObjectBase::Solid, l, 0, true, view.isLightEnabled(), view.isFogEnabled());
|
||||
renderObjects(GLObjectBase::Solid, l, nullptr, true, view.isLightEnabled(), view.isFogEnabled());
|
||||
|
||||
|
||||
//renderObjects(GLObjectBase::Solid, l, 0, true, true, view.isFogEnabled());
|
||||
renderObjects(GLObjectBase::Transparent, l, 0, true, true, view.isFogEnabled());
|
||||
renderObjects(GLObjectBase::Transparent, l, nullptr, true, true, view.isFogEnabled());
|
||||
if (passes > 1) {
|
||||
glSetLightEnabled(false);
|
||||
glSetCapEnabled(GL_BLEND);
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
glReleaseTextures();
|
||||
view.glReleaseTextures();
|
||||
glBindTexture(GL_TEXTURE_2D, fbo.colorTexture(1));
|
||||
glDisableDepth();
|
||||
fbo.setWriteBuffer(0);
|
||||
@@ -109,7 +109,7 @@ void RendererSimple::renderScene() {
|
||||
if (view.isFeatureEnabled(QGLView::qglFXAA) || passes > 1) {
|
||||
fbo.release();
|
||||
//glClearFramebuffer();
|
||||
glActiveTextureChannel(0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo.colorTexture());
|
||||
glSetLightEnabled(false);
|
||||
glSetCapEnabled(GL_BLEND, false);
|
||||
@@ -118,7 +118,7 @@ void RendererSimple::renderScene() {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
shader_fxaa->bind();
|
||||
shader_fxaa->setUniformValue("dt", QVector2D(1. / view.width(), 1. / view.height()));
|
||||
shader_fxaa->setUniformValue("dt", QVector2D(1.f / view.width(), 1.f / view.height()));
|
||||
glDrawQuad();
|
||||
shader_fxaa->release();
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user