git-svn-id: svn://db.shs.com.ru/libs@65 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -18,10 +18,11 @@
|
||||
|
||||
#include "globject.h"
|
||||
#include "glcamera.h"
|
||||
#include "qglview.h"
|
||||
|
||||
|
||||
GLObjectBase::GLObjectBase() {
|
||||
type_ = Mesh;
|
||||
type_ = glMesh;
|
||||
render_mode = View;
|
||||
pass_ = Solid;
|
||||
geom_prim = Triangles;
|
||||
@@ -32,7 +33,7 @@ GLObjectBase::GLObjectBase() {
|
||||
line_width = -1.;
|
||||
blend_src = GL_SRC_ALPHA;
|
||||
blend_dest = GL_ONE_MINUS_SRC_ALPHA;
|
||||
type_ = Mesh;
|
||||
type_ = glMesh;
|
||||
raw_matrix = false;
|
||||
mat_.setToIdentity();
|
||||
view_ = 0;
|
||||
@@ -96,6 +97,13 @@ void GLObjectBase::draw(QGLShaderProgram * prog, bool simplest) {
|
||||
}
|
||||
|
||||
|
||||
void GLObjectBase::setView(QGLView * v) {
|
||||
view_ = v;
|
||||
foreach (GLObjectBase * c, children_)
|
||||
c->setView(v);
|
||||
}
|
||||
|
||||
|
||||
QList<GLObjectBase * > GLObjectBase::children(bool all_) {
|
||||
if (!all_) return children_;
|
||||
QList<GLObjectBase * > cl;
|
||||
@@ -144,6 +152,14 @@ void GLObjectBase::setTransform(const QMatrix4x4 & t) {
|
||||
}
|
||||
|
||||
|
||||
void GLObjectBase::select() {
|
||||
//qDebug() << "select" << name() << view_;
|
||||
selected_ = true;
|
||||
if (view_)
|
||||
((QGLView*)view_)->selectObject(this);
|
||||
}
|
||||
|
||||
|
||||
void GLObjectBase::buildTransform() {
|
||||
itransform_.setToIdentity();
|
||||
GLObjectBase * p = parent_;
|
||||
@@ -212,7 +228,7 @@ void GLObjectBase::render(int * id, QMap<int, GLObjectBase * > * ids, int sh_id_
|
||||
|
||||
|
||||
Light::Light(): GLObjectBase(), shadow_map(0, true, GL_R16F) {
|
||||
type_ = GLObjectBase::Light;
|
||||
type_ = glLight;
|
||||
light_type = Omni;
|
||||
intensity = 1.;
|
||||
angle_start = angle_end = 180.;
|
||||
@@ -223,7 +239,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) {
|
||||
type_ = GLObjectBase::Light;
|
||||
type_ = glLight;
|
||||
light_type = Omni;
|
||||
pos_ = p;
|
||||
intensity = i;
|
||||
@@ -279,3 +295,87 @@ void Light::draw(QGLShaderProgram * prog, bool simplest) {
|
||||
if (l) glEnable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
|
||||
QDataStream & operator <<(QDataStream & s, const GLObjectBase * p) {
|
||||
ChunkStream cs;
|
||||
cs << cs.chunk(1, int(p->type_)) << cs.chunk(2, p->accept_light) << cs.chunk(3, p->accept_fog) << cs.chunk(4, p->visible_)
|
||||
<< cs.chunk(5, p->cast_shadow) << cs.chunk(6, p->rec_shadow) << cs.chunk(7, p->raw_matrix) << cs.chunk(8, p->line_width)
|
||||
<< cs.chunk(9, int(p->render_mode)) << cs.chunk(10, p->material_) << cs.chunk(11, p->pos_) << cs.chunk(12, p->angles_)
|
||||
<< cs.chunk(13, p->scale_) << cs.chunk(14, p->mat_) << cs.chunk(15, p->vbo) << cs.chunk(16, p->children_)
|
||||
<< cs.chunk(17, p->name_);
|
||||
if (p->type_ == GLObjectBase::glLight) {
|
||||
Light * l = (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) {
|
||||
Camera * c = (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);
|
||||
}
|
||||
s << cs.data(); return s;
|
||||
}
|
||||
QDataStream & operator >>(QDataStream & s, GLObjectBase *& p) {
|
||||
ChunkStream cs(s);
|
||||
p = 0;
|
||||
Light * l = 0;
|
||||
Camera * c = 0;
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
case 1:
|
||||
{
|
||||
GLObjectBase::Type type = (GLObjectBase::Type)cs.getData<int>();
|
||||
switch (type) {
|
||||
case GLObjectBase::glMesh: p = new GLObjectBase(); break;
|
||||
case GLObjectBase::glLight: p = new Light(); l = (Light*)p; break;
|
||||
case GLObjectBase::glCamera: p = new Camera(); c = (Camera*)p; break;
|
||||
default : break;
|
||||
}
|
||||
if (p) p->type_ = type;
|
||||
}
|
||||
break;
|
||||
case 2: if (p) p->accept_light = cs.getData<bool>(); break;
|
||||
case 3: if (p) p->accept_fog = cs.getData<bool>(); break;
|
||||
case 4: if (p) p->visible_ = cs.getData<bool>(); break;
|
||||
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 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;
|
||||
case 12: if (p) p->angles_ = cs.getData<QVector3D>(); break;
|
||||
case 13: if (p) p->scale_ = cs.getData<QVector3D>(); break;
|
||||
case 14: if (p) p->mat_ = cs.getData<QMatrix4x4>(); break;
|
||||
case 15: if (p) p->vbo = cs.getData<GLVBO>(); break;
|
||||
case 16: if (p) {
|
||||
p->children_ = cs.getData<QList<GLObjectBase * > >();
|
||||
foreach (GLObjectBase * c_, p->children_)
|
||||
c_->parent_ = p;
|
||||
}
|
||||
break;
|
||||
case 17: if (p) p->name_ = cs.getData<QString>(); 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 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 206: if (c) c->mirror_x = cs.getData<bool>(); break;
|
||||
case 207: if (c) c->mirror_y = cs.getData<bool>(); break;
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user