git-svn-id: svn://db.shs.com.ru/libs@651 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2019-12-04 17:04:06 +00:00
parent d7797e2278
commit 888f970f44
20 changed files with 224 additions and 329 deletions

View File

@@ -187,7 +187,7 @@ void createGLTexture(QOpenGLExtraFunctions * f, GLuint & tex, const QImage & ima
} }
QMatrix4x4 glMatrixPerspective(float angle, float aspect, float near_, float far_) { QMatrix4x4 glMatrixPerspective(float angle, float aspect, float near_) {
QMatrix4x4 ret; QMatrix4x4 ret;
float t = 1.f / (tanf(angle * deg2rad / 2.f)), e = 2.4e-7f; float t = 1.f / (tanf(angle * deg2rad / 2.f)), e = 2.4e-7f;
if (aspect >= 1.) { if (aspect >= 1.) {

View File

@@ -157,7 +157,7 @@ void glClearFramebuffer(const QColor & color = Qt::black, bool depth = true);
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); 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);
void createGLTexture(QOpenGLExtraFunctions * f, GLuint & tex, int width, int height, const GLenum & format = GL_RGBA, const GLenum & target = GL_TEXTURE_2D); void createGLTexture(QOpenGLExtraFunctions * f, GLuint & tex, int width, int height, const GLenum & format = GL_RGBA, const GLenum & target = GL_TEXTURE_2D);
void createGLTexture(QOpenGLExtraFunctions * f, GLuint & tex, const QImage & image, const GLenum & format = GL_RGBA, const GLenum & target = GL_TEXTURE_2D); void createGLTexture(QOpenGLExtraFunctions * f, GLuint & tex, const QImage & image, const GLenum & format = GL_RGBA, const GLenum & target = GL_TEXTURE_2D);
QMatrix4x4 glMatrixPerspective(float angle, float aspect, float near_, float far_); QMatrix4x4 glMatrixPerspective(float angle, float aspect, float near_);
QImage rotateQImageLeft(const QImage & im); QImage rotateQImageLeft(const QImage & im);
QImage rotateQImageRight(const QImage & im); QImage rotateQImageRight(const QImage & im);
inline QImage rotateQImage180(const QImage & im) {return im.mirrored(true, true);} inline QImage rotateQImage180(const QImage & im) {return im.mirrored(true, true);}

View File

@@ -23,23 +23,12 @@
Camera::Camera() { Camera::Camera() {
type_ = glCamera; type_ = glCamera;
fov_ = 60.; fov_ = 60.;
angle_limit_lower_xy = 0.f;
angle_limit_upper_xy = 360.f;
//setRotationX(90.f); //setRotationX(90.f);
depth_start = 0.1f; depth_start = 0.1f;
depth_end = 1000.f;
mirror_x = mirror_y = false; mirror_x = mirror_y = false;
} }
void Camera::anglesFromPoints() {
//QVector3D dv = aim_ - pos_, tv;
//tv = QVector3D(dv.x(), dv.y(), 0.);
//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);
}
QMatrix4x4 Camera::offsetMatrix() const { QMatrix4x4 Camera::offsetMatrix() const {
QMatrix4x4 ret; QMatrix4x4 ret;
ret.translate(parent_ ? -offset_ : -aim()); ret.translate(parent_ ? -offset_ : -aim());
@@ -65,12 +54,9 @@ void Camera::assign(const Camera & c) {
trans = c.trans; trans = c.trans;
aim_dist = c.aim_dist; aim_dist = c.aim_dist;
fov_ = c.fov_; fov_ = c.fov_;
angle_limit_lower_xy = c.angle_limit_lower_xy;
angle_limit_upper_xy = c.angle_limit_upper_xy;
mirror_x = c.mirror_x; mirror_x = c.mirror_x;
mirror_y = c.mirror_y; mirror_y = c.mirror_y;
depth_start = c.depth_start; depth_start = c.depth_start;
depth_end = c.depth_end;
buildTransform(); buildTransform();
} }
@@ -89,12 +75,9 @@ ObjectBase * Camera::clone(bool withChildren) {
o->trans = trans; o->trans = trans;
o->aim_dist = aim_dist; o->aim_dist = aim_dist;
o->fov_ = fov_; o->fov_ = fov_;
o->angle_limit_lower_xy = angle_limit_lower_xy;
o->angle_limit_upper_xy = angle_limit_upper_xy;
o->mirror_x = mirror_x; o->mirror_x = mirror_x;
o->mirror_y = mirror_y; o->mirror_y = mirror_y;
o->depth_start = depth_start; o->depth_start = depth_start;
o->depth_end = depth_end;
o->meta = meta; o->meta = meta;
return o; return o;
} }
@@ -121,175 +104,5 @@ QMatrix4x4 Camera::viewMatrix() const {
QMatrix4x4 Camera::projectionMatrix(double aspect) const { QMatrix4x4 Camera::projectionMatrix(double aspect) const {
return glMatrixPerspective(fov_, aspect, depth_start, depth_end); return glMatrixPerspective(fov_, aspect, depth_start);
} }
void Camera::panZ(const float & a) {
/*QVector3D dv = aim_ - pos_;
float tl = QVector2D(dv.x(), dv.y()).length();
angles_.setZ(angles_.z() + a);
dv = QVector3D(sinf(angles_.z() * deg2rad) * tl, cosf(angles_.z() * deg2rad) * tl, dv.z());
aim_ = pos_ + dv;
buildTransform();*/
}
void Camera::panXY(const float & a) {
/*QVector3D dv = aim_ - pos_;
float tl = dv.length(), tc;
angles_.setY(angles_.y() + a);
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 float & a) {
/*QVector3D dv = aim_ - pos_;
float tl = QVector2D(dv.x(), dv.y()).length();
angles_.setZ(angles_.z() + a);
dv = QVector3D(sinf(angles_.z() * deg2rad) * tl, cosf(angles_.z() * deg2rad) * tl, dv.z());
aim_ = pos_ + dv;
buildTransform();*/
}
void Camera::rotateXY(const float & a) {
/*QVector3D dv = aim_ - pos_;
float tl = dv.length(), tc;
angles_.setY(angles_.y() + a);
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 float & a) {
//qDebug() << rotation() << Transform::fromDirection(direction());
QVector3D pa = aim();
//trans.rotationRef() *= QQuaternion::fromEulerAngles(0, a, 0);
ObjectBase::rotateZ(-a);
move(pa - aim());
/*QVector3D dv = aim_ - pos_;
float tl = QVector2D(dv.x(), dv.y()).length();
angles_.setZ(angles_.z() + a);
dv = QVector3D(sinf(angles_.z() * deg2rad) * tl, cosf(angles_.z() * deg2rad) * tl, dv.z());
pos_ = aim_ - dv;
buildTransform();*/
}
void Camera::orbitXY(const float & a) {
QVector3D pa = aim();
//trans.rotationRef() *= QQuaternion::fromEulerAngles(a, 0, 0);
ObjectBase::rotateX(-a);
move(pa - aim());
//qDebug() << pos() << aim();
/*QVector3D dv = aim_ - pos_;
float tl = dv.length(), tc;
angles_.setY(angles_.y() + a);
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 float & a) {
/*QVector3D dv = aim_ - pos_;
float tl = QVector2D(dv.x(), dv.y()).length();
angles_.setZ(a);
dv = QVector3D(sinf(angles_.z() * deg2rad) * tl, cosf(angles_.z() * deg2rad) * tl, dv.z());
aim_ = pos_ + dv;
buildTransform();*/
}
void Camera::setAngleXY(const float & a) {
/*QVector3D dv = aim_ - pos_;
float tl = dv.length(), tc;
angles_.setY(a);
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();*/
//anglesFromPoints();
}
void Camera::moveForward(const float & x, bool withZ) {
/*Vector3D dv;// = aim_ - pos_;
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;
aim_ += dv;
buildTransform();*/
}
void Camera::moveLeft(const float & x, bool withZ) {
/*QVector3D dv;// = aim_ - pos_;
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;
aim_ += dv;
buildTransform();*/
}
void Camera::moveUp(const float & x, bool onlyZ) {
/*QVector3D dv;
if (onlyZ)
dv = QVector3D(0., 0., x);
else {
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;
}
pos_ += dv;
aim_ += dv;
buildTransform();*/
}
/*
void Camera::flyCloser(const float & s) {
QVector3D dv = aim_ - pos_;
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 float & s) {
QVector3D dv = aim_ - pos_;
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 float & d) {
QVector3D dv = aim_ - pos_;
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();
}
*/

View File

@@ -33,29 +33,12 @@ class Camera: public AimedObject
public: public:
Camera(); Camera();
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) {rotateX(a);}
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 setFOV(const float & f) {fov_ = f;}
void setAngles(const QVector3D & a) {setRotation(a);} void setAngles(const QVector3D & a) {setRotation(a);}
void setAngleZ(const float & a); void setAngleZ(const float & a) {setRotationZ(a);}
void setAngleXY(const float & a); void setAngleXY(const float & a) {setRotationX(a);}
void setAngleRoll(const float & a) {setRotationX(a);} void setAngleRoll(const float & a) {setRotationY(a);}
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 setDepthStart(const float & d) {depth_start = d;}
void setDepthEnd(const float & d) {depth_end = d;}
void setMirrorX(bool yes) {mirror_x = yes;} void setMirrorX(bool yes) {mirror_x = yes;}
void setMirrorY(bool yes) {mirror_y = yes;} void setMirrorY(bool yes) {mirror_y = yes;}
@@ -63,16 +46,11 @@ public:
float angleZ() const {return rotationZ();} float angleZ() const {return rotationZ();}
float angleXY() const {return rotationY();} float angleXY() const {return rotationY();}
float angleRoll() const {return rotationZ();} float angleRoll() const {return rotationZ();}
float angleLowerLimitXY() const {return angle_limit_lower_xy;}
float angleUpperLimitXY() const {return angle_limit_upper_xy;}
float depthStart() const {return depth_start;} float depthStart() const {return depth_start;}
float depthEnd() const {return depth_end;}
bool isMirrorX() const {return mirror_x;} bool isMirrorX() const {return mirror_x;}
bool isMirrorY() const {return mirror_y;} bool isMirrorY() const {return mirror_y;}
void anglesFromPoints();
void assign(const Camera & c); void assign(const Camera & c);
virtual ObjectBase * clone(bool withChildren = true); virtual ObjectBase * clone(bool withChildren = true);
QMatrix4x4 viewMatrix() const; QMatrix4x4 viewMatrix() const;
QMatrix4x4 projectionMatrix(double aspect) const; QMatrix4x4 projectionMatrix(double aspect) const;
@@ -84,9 +62,6 @@ private:
mutable QVector3D offset_; mutable QVector3D offset_;
GLfloat fov_; GLfloat fov_;
GLfloat depth_start; GLfloat depth_start;
GLfloat depth_end;
GLfloat angle_limit_lower_xy;
GLfloat angle_limit_upper_xy;
bool mirror_x; bool mirror_x;
bool mirror_y; bool mirror_y;

View File

@@ -495,6 +495,41 @@ void AimedObject::flyToDistance(double d) {
} }
void AimedObject::moveForward(const float & x, bool withZ) {
QVector3D dv = itransform_.mapVector(QVector3D(0, 0, -x));
if (!withZ) dv[2] = 0.;
move(dv);
}
void AimedObject::moveLeft(const float & x, bool withZ) {
QVector3D dv = itransform_.mapVector(QVector3D(-x, 0, 0));
if (!withZ) dv[2] = 0.;
move(dv);
}
void AimedObject::moveUp(const float & x, bool onlyZ) {
QVector3D dv = itransform_.mapVector(QVector3D(0, x, 0));
if (onlyZ) dv[0] = dv[1] = 0.;
move(dv);
}
void AimedObject::orbitZ(const float & a) {
QVector3D pa = aim();
rotateZ(-a);
move(pa - aim());
}
void AimedObject::orbitXY(const float & a) {
QVector3D pa = aim();
rotateX(-a);
move(pa - aim());
}
void AimedObject::transformChanged() { void AimedObject::transformChanged() {
} }
@@ -561,23 +596,23 @@ QDataStream & operator <<(QDataStream & s, const ObjectBase * p) {
ChunkStream cs; ChunkStream cs;
//qDebug() << "place" << p->name() << "..."; //qDebug() << "place" << p->name() << "...";
cs.add(1, int(p->type_)).add(2, p->accept_light).add(3, p->accept_fog).add(4, p->visible_) cs.add(1, int(p->type_)).add(2, p->accept_light).add(3, p->accept_fog).add(4, p->visible_)
.add(5, p->cast_shadow).add(6, p->rec_shadow).add(7, p->raw_matrix).add(8, p->line_width) .add(5, p->cast_shadow).add(6, p->rec_shadow).add(7, p->raw_matrix).add(8, p->line_width)
.add(9, int(p->render_mode)).add(14, p->mat_).add(16, p->children_.size()) .add(9, int(p->render_mode)).add(14, p->mat_).add(16, p->children_.size())
.add(17, p->name_).add(18, p->meta).add(19, p->color_).add(20, p->trans); .add(17, p->name_).add(18, p->meta).add(19, p->color_).add(20, p->trans);
//qDebug() << "place self done"; //qDebug() << "place self done";
if (p->type_ == ObjectBase::glLight) { if (p->type_ == ObjectBase::glLight) {
//qDebug() << "place light ..."; //qDebug() << "place light ...";
const Light * l = (const Light*)p; const Light * l = (const Light*)p;
cs.add(100, l->aim()).add(101, l->angle_start).add(102, l->angle_end).add(103, l->intensity) cs.add(101, l->angle_start).add(102, l->angle_end).add(103, l->intensity)
.add(104, l->decay_const).add(105, l->decay_linear).add(106, l->decay_quadratic) .add(104, l->decay_const).add(105, l->decay_linear).add(106, l->decay_quadratic)
.add(107, l->decay_start).add(108, l->decay_end).add(109, int(l->light_type)); .add(107, l->decay_start).add(108, l->decay_end).add(109, int(l->light_type))
.add(111, l->distance());
} }
if (p->type_ == ObjectBase::glCamera) { if (p->type_ == ObjectBase::glCamera) {
//qDebug() << "place camera ..."; //qDebug() << "place camera ...";
const Camera * c = (const Camera*)p; const Camera * c = (const Camera*)p;
cs.add(200, c->aim()).add(201, c->fov_).add(202, c->depth_start).add(203, c->depth_end) cs.add(200, c->aim()).add(201, c->fov_).add(202, c->depth_start)
.add(204, c->angle_limit_lower_xy).add(205, c->angle_limit_upper_xy) .add(206, c->mirror_x).add(207, c->mirror_y).add(208, c->distance());
.add(206, c->mirror_x).add(207, c->mirror_y);
} }
//qDebug() << "place" << p->name() << cs.data().size() << s.device()->size(); //qDebug() << "place" << p->name() << cs.data().size() << s.device()->size();
s << cs.data(); s << cs.data();
@@ -591,7 +626,6 @@ QDataStream & operator >>(QDataStream & s, ObjectBase *& p) {
int ccnt = 0; int ccnt = 0;
Light * l = nullptr; Light * l = nullptr;
Camera * c = nullptr; Camera * c = nullptr;
QVector3D cam_angles;
//qDebug() << "read obj ..."; //qDebug() << "read obj ...";
while (!cs.atEnd()) { while (!cs.atEnd()) {
switch (cs.read()) { switch (cs.read()) {
@@ -613,18 +647,7 @@ QDataStream & operator >>(QDataStream & s, ObjectBase *& p) {
case 7: if (p) p->raw_matrix = cs.getData<bool>(); break; case 7: if (p) p->raw_matrix = cs.getData<bool>(); break;
case 8: if (p) p->line_width = cs.getData<float>(); break; case 8: if (p) p->line_width = cs.getData<float>(); break;
case 9: if (p) p->render_mode = (ObjectBase::RenderMode)cs.getData<int>(); break; case 9: if (p) p->render_mode = (ObjectBase::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;
//case 12:
// if (p) p->angles_ = cs.getData<QVector3D>();
// if (c) {
// c->setAngles(cs.getData<QVector3D>());
// cam_angles = c->angles();
// }
//break;
//case 13: if (p) p->scale_ = cs.getData<QVector3D>(); break;
case 14: if (p) p->mat_ = cs.getData<QMatrix4x4>(); break; case 14: if (p) p->mat_ = cs.getData<QMatrix4x4>(); break;
//case 15: if (p) p->vbo = cs.getData<VBO>(); break;
case 16: if (p) ccnt = cs.getData<int>(); break; case 16: if (p) ccnt = cs.getData<int>(); break;
case 17: if (p) p->name_ = cs.getData<QString>(); break; case 17: if (p) p->name_ = cs.getData<QString>(); break;
case 18: if (p) p->meta = cs.getData<QVariantMap>(); break; case 18: if (p) p->meta = cs.getData<QVariantMap>(); break;
@@ -640,17 +663,15 @@ QDataStream & operator >>(QDataStream & s, ObjectBase *& p) {
case 107: if (l) l->decay_start = 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 108: if (l) l->decay_end = cs.getData<GLfloat>(); break;
case 109: if (l) l->light_type = (Light::Type)cs.getData<int>(); break; case 109: if (l) l->light_type = (Light::Type)cs.getData<int>(); break;
case 111: if (l) l->setDistance(cs.getData<double>()); break;
case 200: if (c) c->setAim(cs.getData<QVector3D>()); break; case 200: if (c) c->setAim(cs.getData<QVector3D>()); break;
case 201: if (c) c->setFOV(cs.getData<GLfloat>()); break; case 201: if (c) c->setFOV(cs.getData<GLfloat>()); break;
case 202: if (c) c->setDepthStart(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 206: if (c) c->mirror_x = cs.getData<bool>(); break;
case 207: if (c) c->mirror_y = cs.getData<bool>(); break; case 207: if (c) c->mirror_y = cs.getData<bool>(); break;
case 208: if (c) c->setDistance(cs.getData<double>()); break;
} }
} }
//if (c) c->setAngles(cam_angles);
//qDebug() << p->name() << ccnt; //qDebug() << p->name() << ccnt;
for (int i = 0; i < ccnt; ++i) { for (int i = 0; i < ccnt; ++i) {
ObjectBase * c = nullptr; ObjectBase * c = nullptr;

View File

@@ -247,11 +247,24 @@ public:
QVector3D worldDirection() const {return (itransform_ * QVector4D(QVector3D(0,0,-1), 0.)).toVector3D().normalized();} QVector3D worldDirection() const {return (itransform_ * QVector4D(QVector3D(0,0,-1), 0.)).toVector3D().normalized();}
void setDirection(const QVector3D & d); void setDirection(const QVector3D & d);
void setDirection(double x, double y, double z) {setDirection(QVector3D(x, y, z));} void setDirection(double x, double y, double z) {setDirection(QVector3D(x, y, z));}
double distance() const {return aim_dist;} double distance() const {return aim_dist;}
void setDistance(double d) {aim_dist = d;} void setDistance(double d) {aim_dist = d;}
void flyCloser(double s); void flyCloser(double s);
void flyFarer(double s); void flyFarer(double s);
void flyToDistance(double d); void flyToDistance(double d);
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 rotateRoll(const float & a) {rotateY(a);}
void orbitZ(const float & a);
void orbitXY(const float & a);
protected: protected:
void transformChanged() override; void transformChanged() override;
double aim_dist; double aim_dist;

View File

@@ -211,7 +211,6 @@ void GLRendererBase::renderShadow(Light * l, QOpenGLShaderProgram * prog, QMatri
cam.setPos(wp); cam.setPos(wp);
cam.setAim(wp + (l->worldTransform() * QVector4D(l->direction())).toVector3D()); cam.setAim(wp + (l->worldTransform() * QVector4D(l->direction())).toVector3D());
cam.setDepthStart(view->camera()->depthStart()); cam.setDepthStart(view->camera()->depthStart());
cam.setDepthEnd(view->camera()->depthEnd());
cam.setFOV(l->angle_end); cam.setFOV(l->angle_end);
//cam.apply(1.); //cam.apply(1.);
/*cam.rotateXY(l->angle_end); /*cam.rotateXY(l->angle_end);

View File

@@ -37,11 +37,6 @@ qreal GLWidget::depthStart() const {
} }
qreal GLWidget::depthEnd() const {
return view_->depthEnd();
}
QColor GLWidget::ambientColor() const { QColor GLWidget::ambientColor() const {
return view_->ambientColor(); return view_->ambientColor();
} }
@@ -153,11 +148,6 @@ void GLWidget::setDepthStart(const qreal & arg) {
} }
void GLWidget::setDepthEnd(const qreal & arg) {
view_->setDepthEnd(arg);
}
void GLWidget::setAmbientColor(const QColor & arg) { void GLWidget::setAmbientColor(const QColor & arg) {
view_->setAmbientColor(arg); view_->setAmbientColor(arg);
} }

View File

@@ -15,7 +15,6 @@ class GLWidget : public QWidget
Q_PROPERTY (qreal lineWidth READ lineWidth WRITE setLineWidth) Q_PROPERTY (qreal lineWidth READ lineWidth WRITE setLineWidth)
Q_PROPERTY (qreal FOV READ FOV WRITE setFOV) Q_PROPERTY (qreal FOV READ FOV WRITE setFOV)
Q_PROPERTY (qreal depthStart READ depthStart WRITE setDepthStart) Q_PROPERTY (qreal depthStart READ depthStart WRITE setDepthStart)
Q_PROPERTY (qreal depthEnd READ depthEnd WRITE setDepthEnd)
Q_PROPERTY (QColor ambientColor READ ambientColor WRITE setAmbientColor) Q_PROPERTY (QColor ambientColor READ ambientColor WRITE setAmbientColor)
Q_PROPERTY (bool grabMouse READ isGrabMouseEnabled WRITE setGrabMouseEnabled) Q_PROPERTY (bool grabMouse READ isGrabMouseEnabled WRITE setGrabMouseEnabled)
Q_PROPERTY (bool mouseRotate READ isMouseRotateEnabled WRITE setMouseRotateEnabled) Q_PROPERTY (bool mouseRotate READ isMouseRotateEnabled WRITE setMouseRotateEnabled)
@@ -35,7 +34,6 @@ public:
qreal lineWidth() const; qreal lineWidth() const;
qreal FOV() const; qreal FOV() const;
qreal depthStart() const; qreal depthStart() const;
qreal depthEnd() const;
QColor ambientColor() const; QColor ambientColor() const;
bool isLightEnabled() const; bool isLightEnabled() const;
bool isGrabMouseEnabled() const; bool isGrabMouseEnabled() const;
@@ -61,7 +59,6 @@ public slots:
void setLineWidth(const qreal & arg); void setLineWidth(const qreal & arg);
void setFOV(const qreal & arg); void setFOV(const qreal & arg);
void setDepthStart(const qreal & arg); void setDepthStart(const qreal & arg);
void setDepthEnd(const qreal & arg);
void setAmbientColor(const QColor & arg); void setAmbientColor(const QColor & arg);
void setLightEnabled(const bool & arg); void setLightEnabled(const bool & arg);
void setGrabMouseEnabled(const bool & arg); void setGrabMouseEnabled(const bool & arg);

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

View File

@@ -199,17 +199,17 @@ void MouseController::mouseMoveEvent(QMouseEvent * e) {
float dy = e->y() - lastPos.y(); float dy = e->y() - lastPos.y();
if (e->buttons().testFlag(Qt::MidButton)) { if (e->buttons().testFlag(Qt::MidButton)) {
if (cameraOrbit_) { if (cameraOrbit_) {
view->camera()->orbitZ(dx / 4.f); view->camera()->orbitZ (dx / 4.f);
view->camera()->orbitXY(dy / 4.f); view->camera()->orbitXY(dy / 4.f);
} else { } else {
view->camera()->rotateZ(dx / 4.f); view->camera()->rotateZ(dx / 4.f);
view->camera()->rotateXY(dy / 4.f); view->camera()->rotateX(dy / 4.f);
} }
emit view->cameraPosChanged(view->camera()->pos()); emit view->cameraPosChanged(view->camera()->pos());
} else if (e->buttons().testFlag(Qt::RightButton)) { } else if (e->buttons().testFlag(Qt::RightButton)) {
float ad = view->camera()->distance(); float ad = view->camera()->distance();
view->camera()->moveLeft(dx / 1000.f * ad); view->camera()->moveLeft(dx / 1000.f * ad);
view->camera()->moveUp(dy / 1000.f * ad); view->camera()->moveUp (dy / 1000.f * ad);
emit view->cameraPosChanged(view->camera()->pos()); emit view->cameraPosChanged(view->camera()->pos());
} }
} }

View File

@@ -47,7 +47,6 @@ class QGLView: public OpenGLWindow
Q_PROPERTY (float lineWidth READ lineWidth WRITE setLineWidth) Q_PROPERTY (float lineWidth READ lineWidth WRITE setLineWidth)
Q_PROPERTY (float FOV READ FOV WRITE setFOV) Q_PROPERTY (float FOV READ FOV WRITE setFOV)
Q_PROPERTY (float depthStart READ depthStart WRITE setDepthStart) 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 ambientColor READ ambientColor WRITE setAmbientColor)
Q_PROPERTY (QColor fogColor READ fogColor WRITE setFogColor) Q_PROPERTY (QColor fogColor READ fogColor WRITE setFogColor)
Q_PROPERTY (bool fogEnabled READ isFogEnabled WRITE setFogEnabled) Q_PROPERTY (bool fogEnabled READ isFogEnabled WRITE setFogEnabled)
@@ -108,7 +107,6 @@ public:
float lineWidth() const {return lineWidth_;} float lineWidth() const {return lineWidth_;}
float FOV() const {return camera()->fov_;} float FOV() const {return camera()->fov_;}
float depthStart() const {return camera()->depth_start;} float depthStart() const {return camera()->depth_start;}
float depthEnd() const {return camera()->depth_end;}
float currentFPS() const {return fps_;} float currentFPS() const {return fps_;}
int maxAnisotropicLevel() const {return max_anisotropic;} int maxAnisotropicLevel() const {return max_anisotropic;}
@@ -228,7 +226,6 @@ public slots:
void setLineWidth(const float & arg) {lineWidth_ = arg;} void setLineWidth(const float & arg) {lineWidth_ = arg;}
void setFOV(const float & arg) {camera()->fov_ = arg;} void setFOV(const float & arg) {camera()->fov_ = arg;}
void setDepthStart(const float & arg) {camera()->depth_start = 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 setAmbientColor(const QColor & arg) {ambientColor_ = arg;}
void setFogColor(const QColor & arg) {fogColor_ = arg;} void setFogColor(const QColor & arg) {fogColor_ = arg;}
void setFogDensity(const float & arg) {fogDensity_ = arg;} void setFogDensity(const float & arg) {fogDensity_ = arg;}

View File

@@ -45,7 +45,6 @@ QGLViewWindow::QGLViewWindow(QWidget * parent): QMainWindow(parent), Ui::QGLView
spinFOV->setValue(view->view()->FOV()); spinFOV->setValue(view->view()->FOV());
spinDepthStart->setValue(view->view()->depthStart()); spinDepthStart->setValue(view->view()->depthStart());
spinDepthEnd->setValue(view->view()->depthEnd());
groupHoverHalo->setChecked(view->view()->isHoverHaloEnabled()); groupHoverHalo->setChecked(view->view()->isHoverHaloEnabled());
groupSelectionHalo->setChecked(view->view()->isSelectionHaloEnabled()); groupSelectionHalo->setChecked(view->view()->isSelectionHaloEnabled());
spinHoverHaloFill->setValue(view->view()->hoverHaloFillAlpha()); spinHoverHaloFill->setValue(view->view()->hoverHaloFillAlpha());

View File

@@ -63,7 +63,6 @@ private:
private slots: private slots:
void on_spinFOV_valueChanged(double val) {view->view()->setFOV(val);} void on_spinFOV_valueChanged(double val) {view->view()->setFOV(val);}
void on_spinDepthStart_valueChanged(double val) {view->view()->setDepthStart(val);} void on_spinDepthStart_valueChanged(double val) {view->view()->setDepthStart(val);}
void on_spinDepthEnd_valueChanged(double val) {view->view()->setDepthEnd(val);}
void on_comboViewRenderMode_currentIndexChanged(int val) {static int modes[] = {GL_POINT, GL_LINE, GL_FILL}; view->view()->setRenderMode((ObjectBase::RenderMode)modes[val]);} void on_comboViewRenderMode_currentIndexChanged(int val) {static int modes[] = {GL_POINT, GL_LINE, GL_FILL}; view->view()->setRenderMode((ObjectBase::RenderMode)modes[val]);}
void on_groupHoverHalo_clicked(bool val) {view->view()->setHoverHaloEnabled(val);} void on_groupHoverHalo_clicked(bool val) {view->view()->setHoverHaloEnabled(val);}
void on_groupSelectionHalo_clicked(bool val) {view->view()->setSelectionHaloEnabled(val);} void on_groupSelectionHalo_clicked(bool val) {view->view()->setSelectionHaloEnabled(val);}

View File

@@ -51,6 +51,7 @@ bool MaterialsEditor::event(QEvent * e) {
ui->buttonAdd ->setIconSize(sz); ui->buttonAdd ->setIconSize(sz);
ui->buttonDelete->setIconSize(sz); ui->buttonDelete->setIconSize(sz);
ui->buttonAssign->setIconSize(sz); ui->buttonAssign->setIconSize(sz);
ui->buttonUnset ->setIconSize(sz);
} }
return QWidget::event(e); return QWidget::event(e);
} }
@@ -175,3 +176,11 @@ void MaterialsEditor::on_buttonAssign_clicked() {
foreach (ObjectBase * o, ol) foreach (ObjectBase * o, ol)
o->setMaterial(m, true); o->setMaterial(m, true);
} }
void MaterialsEditor::on_buttonUnset_clicked() {
if (!view) return;
QList<ObjectBase*> ol = view->selectedObjects();
foreach (ObjectBase * o, ol)
o->setMaterial(0, true);
}

View File

@@ -55,6 +55,7 @@ private slots:
void on_buttonAdd_clicked(); void on_buttonAdd_clicked();
void on_buttonDelete_clicked(); void on_buttonDelete_clicked();
void on_buttonAssign_clicked(); void on_buttonAssign_clicked();
void on_buttonUnset_clicked();
signals: signals:
void changed(); void changed();

View File

@@ -6,11 +6,23 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>542</width> <width>386</width>
<height>492</height> <height>520</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,1">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
@@ -27,63 +39,122 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QToolButton" name="buttonRename"> <widget class="QWidget" name="widget" native="true">
<property name="toolTip"> <layout class="QVBoxLayout" name="verticalLayout_3">
<string>Rename ...</string> <property name="leftMargin">
</property> <number>0</number>
<property name="icon"> </property>
<iconset resource="../qglview.qrc"> <property name="topMargin">
<normaloff>:/icons/edit-rename.png</normaloff>:/icons/edit-rename.png</iconset> <number>0</number>
</property> </property>
</widget> <property name="rightMargin">
</item> <number>0</number>
<item> </property>
<widget class="QToolButton" name="buttonAdd"> <property name="bottomMargin">
<property name="toolTip"> <number>0</number>
<string>Add</string> </property>
</property> <item>
<property name="icon"> <spacer name="verticalSpacer_2">
<iconset resource="widgets.qrc"> <property name="orientation">
<normaloff>:/icons/list-add.png</normaloff>:/icons/list-add.png</iconset> <enum>Qt::Vertical</enum>
</property> </property>
</widget> <property name="sizeHint" stdset="0">
</item> <size>
<item> <width>20</width>
<widget class="QToolButton" name="buttonDelete"> <height>1</height>
<property name="toolTip"> </size>
<string>Delete</string> </property>
</property> </spacer>
<property name="icon"> </item>
<iconset resource="widgets.qrc"> <item>
<normaloff>:/icons/edit-delete.png</normaloff>:/icons/edit-delete.png</iconset> <layout class="QGridLayout" name="gridLayout_2">
</property> <item row="0" column="0">
</widget> <widget class="QToolButton" name="buttonRename">
</item> <property name="toolTip">
<item> <string>Rename ...</string>
<spacer name="horizontalSpacer"> </property>
<property name="orientation"> <property name="icon">
<enum>Qt::Horizontal</enum> <iconset resource="../qglview.qrc">
</property> <normaloff>:/icons/edit-rename.png</normaloff>:/icons/edit-rename.png</iconset>
<property name="sizeType"> </property>
<enum>QSizePolicy::Preferred</enum> </widget>
</property> </item>
<property name="sizeHint" stdset="0"> <item row="0" column="2" rowspan="2">
<size> <spacer name="horizontalSpacer">
<width>20</width> <property name="orientation">
<height>20</height> <enum>Qt::Horizontal</enum>
</size> </property>
</property> <property name="sizeType">
</spacer> <enum>QSizePolicy::Preferred</enum>
</item> </property>
<item> <property name="sizeHint" stdset="0">
<widget class="QToolButton" name="buttonAssign"> <size>
<property name="toolTip"> <width>40</width>
<string>Assign</string> <height>10</height>
</property> </size>
<property name="icon"> </property>
<iconset resource="widgets.qrc"> </spacer>
<normaloff>:/icons/go-jump.png</normaloff>:/icons/go-jump.png</iconset> </item>
</property> <item row="0" column="3">
<widget class="QToolButton" name="buttonUnset">
<property name="toolTip">
<string>Unset</string>
</property>
<property name="icon">
<iconset resource="../../qcd_utils/pult/cdpult.qrc">
<normaloff>:/icons/dialog-cancel.png</normaloff>:/icons/dialog-cancel.png</iconset>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QToolButton" name="buttonAdd">
<property name="toolTip">
<string>Add</string>
</property>
<property name="icon">
<iconset resource="../../qad/utils/qad_utils.qrc">
<normaloff>:/icons/list-add.png</normaloff>:/icons/list-add.png</iconset>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QToolButton" name="buttonDelete">
<property name="toolTip">
<string>Delete</string>
</property>
<property name="icon">
<iconset resource="../../qad/utils/qad_utils.qrc">
<normaloff>:/icons/edit-delete.png</normaloff>:/icons/edit-delete.png</iconset>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QToolButton" name="buttonAssign">
<property name="toolTip">
<string>Assign</string>
</property>
<property name="icon">
<iconset resource="widgets.qrc">
<normaloff>:/icons/go-jump.png</normaloff>:/icons/go-jump.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>1</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget> </widget>
</item> </item>
</layout> </layout>
@@ -104,12 +175,12 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>522</width> <width>386</width>
<height>440</height> <height>434</height>
</rect> </rect>
</property> </property>
<property name="autoFillBackground"> <property name="autoFillBackground">
<bool>false</bool> <bool>true</bool>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin"> <property name="leftMargin">
@@ -160,6 +231,8 @@
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="../../qad/utils/qad_utils.qrc"/>
<include location="../../qcd_utils/pult/cdpult.qrc"/>
<include location="widgets.qrc"/> <include location="widgets.qrc"/>
<include location="../qglview.qrc"/> <include location="../qglview.qrc"/>
</resources> </resources>

View File

@@ -28,6 +28,7 @@ ObjectEditor::ObjectEditor(QWidget * parent): QWidget(parent) {
ui->setupUi(this); ui->setupUi(this);
view = 0; view = 0;
active = true; active = true;
ignore_next = false;
on_comboLightType_currentIndexChanged(0); on_comboLightType_currentIndexChanged(0);
ui->widgetMain->setEnabled(false); ui->widgetMain->setEnabled(false);
ui->labelAimDist->hide(); ui->labelAimDist->hide();
@@ -84,6 +85,10 @@ void ObjectEditor::changeEvent(QEvent * e) {
void ObjectEditor::selectionChanged() { void ObjectEditor::selectionChanged() {
if (ignore_next) {
ignore_next = false;
return;
}
ui->widgetMain->setEnabled(false); ui->widgetMain->setEnabled(false);
if (!view) return; if (!view) return;
QList<ObjectBase*> sol = view->selectedObjects(true); QList<ObjectBase*> sol = view->selectedObjects(true);
@@ -207,6 +212,7 @@ void ObjectEditor::spinChanged(double v) {
if (s == ui->spinScaleY ) o->setScaleY (v); if (s == ui->spinScaleY ) o->setScaleY (v);
if (s == ui->spinScaleZ ) o->setScaleZ (v); if (s == ui->spinScaleZ ) o->setScaleZ (v);
} }
ignore_next = true;
} }
@@ -224,6 +230,7 @@ void ObjectEditor::spinLightChanged(double v) {
if (s == ui->spinAimDist ) o->setDistance(v); if (s == ui->spinAimDist ) o->setDistance(v);
o->apply(); o->apply();
} }
ignore_next = true;
} }
@@ -236,6 +243,7 @@ void ObjectEditor::spinCameraChanged(double v) {
if (s == ui->spinCameraDepthStart) o->setDepthStart(v); if (s == ui->spinCameraDepthStart) o->setDepthStart(v);
if (s == ui->spinAimDist ) o->setDistance(v); if (s == ui->spinAimDist ) o->setDistance(v);
} }
ignore_next = true;
} }

View File

@@ -40,7 +40,7 @@ protected:
Ui::ObjectEditor * ui; Ui::ObjectEditor * ui;
QGLView * view; QGLView * view;
bool active; bool active, ignore_next;
private slots: private slots:
void selectionChanged(); void selectionChanged();

View File

@@ -2,6 +2,7 @@
<qresource prefix="/"> <qresource prefix="/">
<file>../icons/go-jump.png</file> <file>../icons/go-jump.png</file>
<file>../icons/dialog-close.png</file> <file>../icons/dialog-close.png</file>
<file>../icons/dialog-cancel.png</file>
<file>../icons/edit-clear.png</file> <file>../icons/edit-clear.png</file>
<file>../icons/configure.png</file> <file>../icons/configure.png</file>
<file>../icons/document-save.png</file> <file>../icons/document-save.png</file>