git-svn-id: svn://db.shs.com.ru/libs@626 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
177
qglengine/widgets/object_editor.cpp
Normal file
177
qglengine/widgets/object_editor.cpp
Normal file
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
QGLView
|
||||
Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "object_editor.h"
|
||||
#include "ui_object_editor.h"
|
||||
#include "glcamera.h"
|
||||
|
||||
|
||||
ObjectEditor::ObjectEditor(QWidget * parent): QWidget(parent) {
|
||||
ui = new Ui::ObjectEditor();
|
||||
ui->setupUi(this);
|
||||
active = true;
|
||||
object = 0;
|
||||
rmodes << ObjectBase::View << ObjectBase::Point << ObjectBase::Line << ObjectBase::Fill;
|
||||
ui->groupLight->setEnabled(false);
|
||||
ui->groupLight->setVisible(false);
|
||||
ui->groupCamera->setEnabled(false);
|
||||
ui->groupCamera->setVisible(false);
|
||||
}
|
||||
|
||||
|
||||
void ObjectEditor::changeEvent(QEvent * e) {
|
||||
QWidget::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
ui->retranslateUi(this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ObjectEditor::setObject(ObjectBase * o) {
|
||||
object = o;
|
||||
if (object == 0) {
|
||||
ui->groupLight->setEnabled(false);
|
||||
ui->groupLight->setVisible(false);
|
||||
ui->groupCamera->setEnabled(false);
|
||||
ui->groupCamera->setVisible(false);
|
||||
return;
|
||||
}
|
||||
ui->buttonDiscardRawMatrix->setEnabled(o->isRawMatrix());
|
||||
active = false;
|
||||
ui->spinPosX->setValue(object->posX());
|
||||
ui->spinPosY->setValue(object->posY());
|
||||
ui->spinPosZ->setValue(object->posZ());
|
||||
ui->spinRotationX->setValue(object->rotationX());
|
||||
ui->spinRotationY->setValue(object->rotationY());
|
||||
ui->spinRotationZ->setValue(object->rotationZ());
|
||||
ui->spinScaleX->setValue(object->scaleX());
|
||||
ui->spinScaleY->setValue(object->scaleY());
|
||||
ui->spinScaleZ->setValue(object->scaleZ());
|
||||
ui->spinLineWidth->setValue(object->lineWidth());
|
||||
ui->checkVisible->setChecked(object->isVisible());
|
||||
ui->checkAcceptLight->setChecked(object->isAcceptLight());
|
||||
ui->checkAcceptFog->setChecked(object->isAcceptFog());
|
||||
ui->checkCastShadows->setChecked(object->isCastShadows());
|
||||
ui->checkReceiveShadows->setChecked(object->isReceiveShadows());
|
||||
ui->comboRenderMode->setCurrentIndex(rmodes.indexOf(object->renderMode()));
|
||||
ui->groupLight->setEnabled(object->type() == ObjectBase::glLight);
|
||||
ui->groupLight->setVisible(object->type() == ObjectBase::glLight);
|
||||
ui->buttonColor->setColor(object->color());
|
||||
if (object->type() == ObjectBase::glLight) {
|
||||
Light * l = globject_cast<Light * >(object);
|
||||
//bool is_dir = l->light_type == Light::Directional, is_cone = l->light_type == Light::Cone;
|
||||
ui->comboLightType->setCurrentIndex(l->light_type);
|
||||
ui->spinLightIntensity->setValue(l->intensity);
|
||||
ui->spinLightDecayConst->setValue(l->decay_const);
|
||||
ui->spinLightDecayLinear->setValue(l->decay_linear);
|
||||
ui->spinLightDecayQuadratic->setValue(l->decay_quadratic);
|
||||
ui->spinLightAngleStart->setValue(l->angle_start);
|
||||
ui->spinLightAngleEnd->setValue(l->angle_end);
|
||||
ui->spinLightDirectionX->setValue(l->direction.x());
|
||||
ui->spinLightDirectionY->setValue(l->direction.y());
|
||||
ui->spinLightDirectionZ->setValue(l->direction.z());
|
||||
}
|
||||
ui->groupCamera->setEnabled(object->type() == ObjectBase::glCamera);
|
||||
ui->groupCamera->setVisible(object->type() == ObjectBase::glCamera);
|
||||
if (object->type() == ObjectBase::glCamera) {
|
||||
Camera * c = globject_cast<Camera * >(object);
|
||||
ui->checkCameraMirrorX->setChecked(c->isMirrorX());
|
||||
ui->checkCameraMirrorY->setChecked(c->isMirrorY());
|
||||
ui->spinCameraFOV->setValue(c->FOV());
|
||||
ui->spinCameraDepthStart->setValue(c->depthStart());
|
||||
ui->spinCameraDepthEnd->setValue(c->depthEnd());
|
||||
}
|
||||
active = true;
|
||||
}
|
||||
|
||||
|
||||
void ObjectEditor::objectChanged() {
|
||||
if (!active || object == 0) return;
|
||||
if (!object->isRawMatrix()) {
|
||||
object->setPosX(ui->spinPosX->value());
|
||||
object->setPosY(ui->spinPosY->value());
|
||||
object->setPosZ(ui->spinPosZ->value());
|
||||
object->setRotationX(ui->spinRotationX->value());
|
||||
object->setRotationY(ui->spinRotationY->value());
|
||||
object->setRotationZ(ui->spinRotationZ->value());
|
||||
object->setScaleX(ui->spinScaleX->value());
|
||||
object->setScaleY(ui->spinScaleY->value());
|
||||
object->setScaleZ(ui->spinScaleZ->value());
|
||||
}
|
||||
/*object->setLineWidth(ui->spinLineWidth->value());
|
||||
object->setVisible(ui->checkVisible->isChecked());
|
||||
object->setAcceptLight(ui->checkAcceptLight->isChecked());
|
||||
object->setAcceptFog(ui->checkAcceptFog->isChecked());
|
||||
object->setCastShadows(ui->checkCastShadows->isChecked());
|
||||
object->setReceiveShadows(ui->checkReceiveShadows->isChecked());
|
||||
object->setRenderMode((ObjectBase::RenderMode)rmodes[ui->comboRenderMode->currentIndex()]);*/
|
||||
object->setColor(ui->buttonColor->color());
|
||||
if (object->type() == ObjectBase::glLight) {
|
||||
Light * l = globject_cast<Light * >(object);
|
||||
//bool is_dir = l->light_type == Light::Directional, is_cone = l->light_type == Light::Cone;
|
||||
l->light_type = (Light::Type)ui->comboLightType->currentIndex();
|
||||
l->intensity = ui->spinLightIntensity->value();
|
||||
l->decay_const = ui->spinLightDecayConst->value();
|
||||
l->decay_linear = ui->spinLightDecayLinear->value();
|
||||
l->decay_quadratic = ui->spinLightDecayQuadratic->value();
|
||||
l->angle_start = ui->spinLightAngleStart->value();
|
||||
l->angle_end = ui->spinLightAngleEnd->value();
|
||||
l->direction = QVector3D(ui->spinLightDirectionX->value(), ui->spinLightDirectionY->value(), ui->spinLightDirectionZ->value()).normalized();
|
||||
l->apply();
|
||||
}
|
||||
if (object->type() == ObjectBase::glCamera) {
|
||||
Camera * c = globject_cast<Camera * >(object);
|
||||
c->setMirrorX(ui->checkCameraMirrorX->isChecked());
|
||||
c->setMirrorY(ui->checkCameraMirrorY->isChecked());
|
||||
c->setFOV(ui->spinCameraFOV->value());
|
||||
c->setDepthStart(ui->spinCameraDepthStart->value());
|
||||
c->setDepthEnd(ui->spinCameraDepthEnd->value());
|
||||
}
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
void ObjectEditor::on_spinLightAngleStart_valueChanged(double v) {
|
||||
if (ui->spinLightAngleEnd->value() < v)
|
||||
ui->spinLightAngleEnd->setValue(v);
|
||||
}
|
||||
|
||||
|
||||
void ObjectEditor::on_spinLightAngleEnd_valueChanged(double v) {
|
||||
if (ui->spinLightAngleStart->value() > v)
|
||||
ui->spinLightAngleStart->setValue(v);
|
||||
}
|
||||
|
||||
|
||||
void ObjectEditor::on_buttonDiscardRawMatrix_clicked() {
|
||||
if (!active || !object) return;
|
||||
object->setPosX(ui->spinPosX->value());
|
||||
object->setPosY(ui->spinPosY->value());
|
||||
object->setPosZ(ui->spinPosZ->value());
|
||||
object->setRotationX(ui->spinRotationX->value());
|
||||
object->setRotationY(ui->spinRotationY->value());
|
||||
object->setRotationZ(ui->spinRotationZ->value());
|
||||
object->setScaleX(ui->spinScaleX->value());
|
||||
object->setScaleY(ui->spinScaleY->value());
|
||||
object->setScaleZ(ui->spinScaleZ->value());
|
||||
ui->buttonDiscardRawMatrix->setEnabled(false);
|
||||
}
|
||||
Reference in New Issue
Block a user