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

This commit is contained in:
2019-12-23 14:24:46 +00:00
parent 056eea2407
commit 7c1dd9bf0a
7 changed files with 68 additions and 26 deletions

View File

@@ -23,6 +23,7 @@
Camera::Camera() { Camera::Camera() {
type_ = glCamera; type_ = glCamera;
fov_ = 60.; fov_ = 60.;
roll_ = 0.;
//setRotationX(90.f); //setRotationX(90.f);
depth_start = 0.1f; depth_start = 0.1f;
mirror_x = mirror_y = false; mirror_x = mirror_y = false;
@@ -75,6 +76,7 @@ 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->roll_ = roll_;
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;
@@ -87,10 +89,10 @@ QMatrix4x4 Camera::viewMatrix() const {
QMatrix4x4 ret; QMatrix4x4 ret;
//qDebug() << pos() << aim(); //qDebug() << pos() << aim();
ret.translate(0., 0., -distance()); ret.translate(0., 0., -distance());
ret.rotate(-roll_, 0., 0., 1.);
ret *= trans.matrixRotateScale().inverted(); ret *= trans.matrixRotateScale().inverted();
//ret.rotate(angles_.y(), 1., 0., 0.); //ret.rotate(angles_.y(), 1., 0., 0.);
//ret.rotate(angles_.x(), 0., 1., 0.); //ret.rotate(angles_.x(), 0., 1., 0.);
//ret.rotate(angles_.z(), 0., 0., 1.);
//pm.translate(-aim_); //pm.translate(-aim_);
if (parent_) { if (parent_) {
QMatrix4x4 pmat = parent_->worldTransform(); QMatrix4x4 pmat = parent_->worldTransform();

View File

@@ -37,15 +37,15 @@ public:
void setAngles(const QVector3D & a) {setRotation(a);} void setAngles(const QVector3D & a) {setRotation(a);}
void setAngleZ(const float & a) {setRotationZ(a);} void setAngleZ(const float & a) {setRotationZ(a);}
void setAngleXY(const float & a) {setRotationX(a);} void setAngleXY(const float & a) {setRotationX(a);}
void setAngleRoll(const float & a) {setRotationY(a);} void setAngleRoll(const float & a) {roll_ = a;}
void setDepthStart(const float & d) {depth_start = d;} void setDepthStart(const float & d) {depth_start = 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;}
float FOV() const {return fov_;} float FOV() const {return fov_;}
float angleZ() const {return rotationZ();} float angleZ() const {return rotationZ();}
float angleXY() const {return rotationY();} float angleXY() const {return rotationX();}
float angleRoll() const {return rotationZ();} float angleRoll() const {return roll_;}
float depthStart() const {return depth_start;} float depthStart() const {return depth_start;}
bool isMirrorX() const {return mirror_x;} bool isMirrorX() const {return mirror_x;}
bool isMirrorY() const {return mirror_y;} bool isMirrorY() const {return mirror_y;}
@@ -60,7 +60,7 @@ public:
private: private:
mutable QVector3D offset_; mutable QVector3D offset_;
GLfloat fov_; GLfloat fov_, roll_;
GLfloat depth_start; GLfloat depth_start;
bool mirror_x; bool mirror_x;
bool mirror_y; bool mirror_y;

View File

@@ -642,7 +642,8 @@ QDataStream & operator <<(QDataStream & s, const ObjectBase * p) {
//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) cs.add(200, c->aim()).add(201, c->fov_).add(202, c->depth_start)
.add(206, c->mirror_x).add(207, c->mirror_y).add(208, c->distance()); .add(206, c->mirror_x).add(207, c->mirror_y).add(208, c->distance())
.add(209, c->roll_);
} }
//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();
@@ -700,6 +701,7 @@ QDataStream & operator >>(QDataStream & s, ObjectBase *& p) {
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; case 208: if (c) c->setDistance(cs.getData<double>()); break;
case 209: if (c) c->roll_ = cs.getData<GLfloat>(); break;
} }
} }
//qDebug() << p->name() << ccnt; //qDebug() << p->name() << ccnt;

View File

@@ -88,7 +88,8 @@ RendererService::RendererService(Renderer * r_): r(r_) {
m->transformPoints(mat); m->transformPoints(mat);
camera_mesh_f->append(m); camera_mesh_f->append(m);
line_mesh_f = Primitive::lineFrame(QVector3D(), QVector3D(0, 0, -1)); line_spot_f = Primitive::lineFrame(QVector3D(), QVector3D(0, 0, -1));
line_camera_f = Primitive::lineFrame(QVector3D(), QVector3D(0, 0, -1));
handle_move_mesh = Primitive::arrow(12, 0.06); handle_move_mesh = Primitive::arrow(12, 0.06);
handle_ms_2_mesh = Primitive::torus(8, 12, 0.5, 0.02, 90); handle_ms_2_mesh = Primitive::torus(8, 12, 0.5, 0.02, 90);
@@ -128,7 +129,8 @@ RendererService::~RendererService() {
delete cone_mesh_f; delete cone_mesh_f;
delete camera_mesh; delete camera_mesh;
delete camera_mesh_f; delete camera_mesh_f;
delete line_mesh_f; delete line_spot_f;
delete line_camera_f;
delete axis_camera; delete axis_camera;
delete axis_mesh; delete axis_mesh;
delete handle_move_mesh; delete handle_move_mesh;
@@ -202,14 +204,14 @@ void RendererService::fillOmniObjects() {
} }
void RendererService::fillAimedObjects(const ObjectBaseList & objects) { void RendererService::fillAimedObjects(const ObjectBaseList & objects, Mesh * line_mesh) {
Object o; Object o;
cur_objects.clear(); cur_objects.clear();
cur_aims.clear(); cur_aims.clear();
QVector<QVector3D> & lv (line_mesh_f->vertices ()); QVector<QVector3D> & lv (line_mesh->vertices ());
QVector<QVector3D> & ln (line_mesh_f->normals ()); QVector<QVector3D> & ln (line_mesh->normals ());
QVector<QVector2D> & lt (line_mesh_f->texcoords ()); QVector<QVector2D> & lt (line_mesh->texcoords ());
QVector< Vector2i> & lind(line_mesh_f->indicesLines()); QVector< Vector2i> & lind(line_mesh->indicesLines());
lv.clear(); lv.clear();
foreach (ObjectBase * go, objects) { foreach (ObjectBase * go, objects) {
AimedObject * ao = (AimedObject *)go; AimedObject * ao = (AimedObject *)go;
@@ -333,7 +335,7 @@ void RendererService::drawLights() {
omni_mesh->draw(v, cur_objects.size()); omni_mesh->draw(v, cur_objects.size());
ObjectBaseList ll = lights2objectList(r->view->scene()->lights_used.value(Light::Cone)); ObjectBaseList ll = lights2objectList(r->view->scene()->lights_used.value(Light::Cone));
fillAimedObjects(ll); fillAimedObjects(ll, line_spot_f);
cone_mesh->loadObjects(v, cur_objects); cone_mesh->loadObjects(v, cur_objects);
r->fillSelectionsBuffer(rs.cur_selections_, ll); r->fillSelectionsBuffer(rs.cur_selections_, ll);
cone_mesh->loadSelections(v, rs.cur_selections_); cone_mesh->loadSelections(v, rs.cur_selections_);
@@ -357,7 +359,7 @@ void RendererService::drawLightsFrame(QColor color) {
omni_mesh_f->draw(v, cur_objects.size()); omni_mesh_f->draw(v, cur_objects.size());
ObjectBaseList ll = lights2objectList(r->view->scene()->lights_used.value(Light::Cone)); ObjectBaseList ll = lights2objectList(r->view->scene()->lights_used.value(Light::Cone));
fillAimedObjects(ll); fillAimedObjects(ll, line_spot_f);
setObjectsColor(cur_objects, color); setObjectsColor(cur_objects, color);
cone_mesh_f->loadObjects(v, cur_objects); cone_mesh_f->loadObjects(v, cur_objects);
r->fillSelectionsBuffer(rs.cur_selections_, ll); r->fillSelectionsBuffer(rs.cur_selections_, ll);
@@ -378,7 +380,7 @@ void RendererService::drawCameras() {
ObjectBaseList cl = cameras2objectList(r->view->scene()->cameras_used); ObjectBaseList cl = cameras2objectList(r->view->scene()->cameras_used);
cl.removeOne(r->view->camera()); cl.removeOne(r->view->camera());
fillAimedObjects(cl); fillAimedObjects(cl, line_camera_f);
camera_mesh->loadObjects(v, cur_objects); camera_mesh->loadObjects(v, cur_objects);
r->fillSelectionsBuffer(rs.cur_selections_, cl); r->fillSelectionsBuffer(rs.cur_selections_, cl);
camera_mesh->loadSelections(v, rs.cur_selections_); camera_mesh->loadSelections(v, rs.cur_selections_);
@@ -396,7 +398,7 @@ void RendererService::drawCamerasFrame(QColor color) {
ObjectBaseList cl = cameras2objectList(r->view->scene()->cameras_used); ObjectBaseList cl = cameras2objectList(r->view->scene()->cameras_used);
cl.removeOne(r->view->camera()); cl.removeOne(r->view->camera());
fillAimedObjects(cl); fillAimedObjects(cl, line_camera_f);
setObjectsColor(cur_objects, color); setObjectsColor(cur_objects, color);
camera_mesh_f->loadObjects(v, cur_objects); camera_mesh_f->loadObjects(v, cur_objects);
r->fillSelectionsBuffer(rs.cur_selections_, cl); r->fillSelectionsBuffer(rs.cur_selections_, cl);
@@ -447,8 +449,10 @@ void RendererService::renderService() {
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
r->setUniformCamera(prog, r->view->camera()); r->setUniformCamera(prog, r->view->camera());
line_object.color = QColor2QVector(Qt::white); line_object.color = QColor2QVector(Qt::white);
line_mesh_f->loadObject(f, line_object); line_spot_f ->loadObject(f, line_object);
line_mesh_f->draw(f, 1); line_camera_f->loadObject(f, line_object);
line_spot_f ->draw(f, 1);
line_camera_f->draw(f, 1);
//glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); //glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
} }
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);

View File

@@ -69,7 +69,7 @@ public:
QMatrix4x4 parentRotationMatrix(ObjectBase * o, bool self_rotation = true); QMatrix4x4 parentRotationMatrix(ObjectBase * o, bool self_rotation = true);
void fillXYZObjects(); void fillXYZObjects();
void fillOmniObjects(); void fillOmniObjects();
void fillAimedObjects(const ObjectBaseList & objects); void fillAimedObjects(const ObjectBaseList & objects, Mesh * line_mesh);
void fillHandleObjects(QVector3D center, HandleMesh ids[], const QVector<QMatrix4x4> & mats, const QVector<QVector4D> & colors, QMatrix4x4 add_mat, int count = 3); void fillHandleObjects(QVector3D center, HandleMesh ids[], const QVector<QMatrix4x4> & mats, const QVector<QVector4D> & colors, QMatrix4x4 add_mat, int count = 3);
bool calculateCenter(); bool calculateCenter();
void drawCurrentHandleObjects(); void drawCurrentHandleObjects();
@@ -89,7 +89,7 @@ private:
Mesh * handle_ms_2_mesh, * handle_scale_3_mesh; Mesh * handle_ms_2_mesh, * handle_scale_3_mesh;
Mesh * box_mesh_f, * omni_mesh_f, * cone_mesh_f, * camera_mesh_f; Mesh * box_mesh_f, * omni_mesh_f, * cone_mesh_f, * camera_mesh_f;
Mesh * box_mesh, * omni_mesh, * cone_mesh, * camera_mesh; Mesh * box_mesh, * omni_mesh, * cone_mesh, * camera_mesh;
Mesh * line_mesh_f; Mesh * line_spot_f, * line_camera_f;
QMatrix4x4 v_mat, axis_mat; QMatrix4x4 v_mat, axis_mat;
QVector3D selection_center; QVector3D selection_center;
QVector<QMatrix4x4> mat_xyz, mat_ms2; QVector<QMatrix4x4> mat_xyz, mat_ms2;

View File

@@ -49,7 +49,7 @@ ObjectEditor::ObjectEditor(QWidget * parent): QWidget(parent) {
connect(o, SIGNAL(valueChanged(double)), this, SLOT(spinLightChanged(double))); connect(o, SIGNAL(valueChanged(double)), this, SLOT(spinLightChanged(double)));
ol.clear(); ol.clear();
ol << ui->spinCameraFOV << ui->spinCameraDepthStart << ui->spinAimDist; ol << ui->spinCameraFOV << ui->spinCameraDepthStart << ui->spinCameraRoll << ui->spinAimDist;
foreach (QObject * o, ol) foreach (QObject * o, ol)
connect(o, SIGNAL(valueChanged(double)), this, SLOT(spinCameraChanged(double))); connect(o, SIGNAL(valueChanged(double)), this, SLOT(spinCameraChanged(double)));
@@ -152,6 +152,7 @@ void ObjectEditor::setObject(ObjectBase * o) {
ui->checkCameraMirrorX->setChecked(c->isMirrorX()); ui->checkCameraMirrorX->setChecked(c->isMirrorX());
ui->checkCameraMirrorY->setChecked(c->isMirrorY()); ui->checkCameraMirrorY->setChecked(c->isMirrorY());
ui->spinCameraFOV->setValue(c->FOV()); ui->spinCameraFOV->setValue(c->FOV());
ui->spinCameraRoll->setValue(c->angleRoll());
ui->spinCameraDepthStart->setValue(c->depthStart()); ui->spinCameraDepthStart->setValue(c->depthStart());
ui->spinAimDist->setValue(c->distance()); ui->spinAimDist->setValue(c->distance());
} }
@@ -240,6 +241,7 @@ void ObjectEditor::spinCameraChanged(double v) {
QObject * s = sender(); QObject * s = sender();
foreach (Camera * o, scl) { foreach (Camera * o, scl) {
if (s == ui->spinCameraFOV ) o->setFOV (v); if (s == ui->spinCameraFOV ) o->setFOV (v);
if (s == ui->spinCameraRoll ) o->setAngleRoll (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);
} }

View File

@@ -650,14 +650,14 @@
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label_46"> <widget class="QLabel" name="label_46">
<property name="text"> <property name="text">
<string>Depth start</string> <string>Depth start:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_45"> <widget class="QLabel" name="label_45">
<property name="text"> <property name="text">
<string>FOV</string> <string>FOV:</string>
</property> </property>
</widget> </widget>
</item> </item>
@@ -686,7 +686,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QCheckBox" name="checkCameraMirrorY"> <widget class="QCheckBox" name="checkCameraMirrorY">
@@ -717,6 +717,38 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1">
<widget class="SpinSlider" name="spinCameraRoll">
<property name="minimum">
<double>-180.000000000000000</double>
</property>
<property name="maximum">
<double>180.000000000000000</double>
</property>
<property name="value">
<double>0.000000000000000</double>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="singleStep">
<double>5.000000000000000</double>
</property>
<property name="pageStep">
<double>30.000000000000000</double>
</property>
<property name="suffix">
<string>°</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_47">
<property name="text">
<string>Roll:</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>