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

This commit is contained in:
2019-12-01 16:52:10 +00:00
parent 09298fadcd
commit 385070f70f
33 changed files with 226 additions and 83 deletions

View File

@@ -465,18 +465,41 @@ QMatrix4x4 ObjectBase::worldMatrix(QMatrix4x4 parent) const {
Light::Light(): ObjectBase(), shadow_map(0, true, GL_R16F) {
AimedObject::AimedObject() {
}
void AimedObject::setAim(const QVector3D & p) {
aim_ = p;
}
QVector3D AimedObject::direction() const {
return (aim_ - pos_).normalized();
}
void AimedObject::setDirection(const QVector3D & d) {
double len = qMax(direction().length(), 0.001f);
aim_ = pos_ + (d.normalized() * len);
}
Light::Light(): AimedObject(), shadow_map(0, true, GL_R16F) {
type_ = glLight;
light_type = Omni;
intensity = 1.;
angle_start = angle_end = 180.;
decay_linear = decay_quadratic = decay_start = 0.;
decay_const = decay_end = 1.;
direction.setZ(1.);
setDirection(0, 0, -1.);
}
Light::Light(const QVector3D & p, const QColor & c, float i): ObjectBase(), shadow_map(0, true, GL_R16F) {
Light::Light(const QVector3D & p, const QColor & c, float i): AimedObject(), shadow_map(0, true, GL_R16F) {
type_ = glLight;
light_type = Omni;
pos_ = p;
@@ -485,7 +508,7 @@ Light::Light(const QVector3D & p, const QColor & c, float i): ObjectBase(), shad
angle_start = angle_end = 180.;
decay_linear = decay_quadratic = decay_start = 0.;
decay_const = decay_end = 1.;
direction.setZ(1.);
setDirection(0, 0, -1.);
}
@@ -502,7 +525,8 @@ ObjectBase * Light::clone(bool withChildren) {
}
o->color_ = color_;
o->light_type = light_type;
o->direction = direction;
o->pos_ = pos_;
o->aim_ = aim_;
o->angle_start = angle_start;
o->angle_end = angle_end;
o->intensity = intensity;
@@ -531,9 +555,9 @@ QDataStream & operator <<(QDataStream & s, const ObjectBase * p) {
if (p->type_ == ObjectBase::glLight) {
//qDebug() << "place light ...";
const Light * l = (const Light*)p;
cs.add(100, l->direction).add(101, l->angle_start).add(102, l->angle_end).add(103, l->intensity)
cs.add(100, l->direction()).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(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(110, l->aim());
}
if (p->type_ == ObjectBase::glCamera) {
//qDebug() << "place camera ...";
@@ -592,7 +616,7 @@ QDataStream & operator >>(QDataStream & s, ObjectBase *& p) {
case 17: if (p) p->name_ = cs.getData<QString>(); break;
case 18: if (p) p->meta = cs.getData<QVariantMap>(); break;
case 19: if (p) p->color_ = cs.getData<QColor>(); break;
case 100: if (l) l->direction = cs.getData<QVector3D>(); break;
case 100: if (l) l->setDirection(cs.getData<QVector3D>());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;
@@ -602,6 +626,7 @@ QDataStream & operator >>(QDataStream & s, ObjectBase *& p) {
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 110: if (l) l->setAim(cs.getData<QVector3D>()); if (l->aim().isNull()) l->setAim(l->direction()); break;
case 200: if (c) c->setAim(cs.getData<QVector3D>()); break;
case 201: if (c) c->setFOV(cs.getData<GLfloat>()); break;
case 202: if (c) c->setDepthStart(cs.getData<GLfloat>()); break;