git-svn-id: svn://db.shs.com.ru/libs@638 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -25,7 +25,7 @@ Camera::Camera() {
|
||||
fov_ = 60.;
|
||||
angle_limit_lower_xy = 0.f;
|
||||
angle_limit_upper_xy = 360.f;
|
||||
angles_.setY(270.f);
|
||||
//setRotationX(90.f);
|
||||
depth_start = 0.1f;
|
||||
depth_end = 1000.f;
|
||||
mirror_x = mirror_y = false;
|
||||
@@ -33,45 +33,16 @@ Camera::Camera() {
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
void Camera::apply(const GLfloat & aspect) {
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
if (aspect <= 1.f)
|
||||
glScalef(aspect, aspect, 1.f);
|
||||
QMatrix4x4 pm = glMatrixPerspective(fov_, aspect, depth_start, depth_end);
|
||||
//pm.perspective(fov_, aspect, depth_start, depth_end);
|
||||
//qDebug() << pm;// << glMatrixPerspective(fov_, aspect, depth_start, depth_end);
|
||||
//qDebug() << pm;
|
||||
//setGLMatrix(pm);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
pm.setToIdentity();
|
||||
pm.translate(0., 0., -distance());
|
||||
pm.rotate(angles_.y(), 1., 0., 0.);
|
||||
pm.rotate(angles_.x(), 0., 1., 0.);
|
||||
pm.rotate(angles_.z(), 0., 0., 1.);
|
||||
//pm.translate(-aim_);
|
||||
if (parent_) {
|
||||
QMatrix4x4 pmat = parent_->worldTransform();
|
||||
offset_ = pmat.column(3).toVector3D();
|
||||
pmat(0, 3) = pmat(1, 3) = pmat(2, 3) = 0.;
|
||||
pmat.translate(aim_);
|
||||
pm *= pmat.inverted();
|
||||
//qDebug() << pmat;
|
||||
}
|
||||
//setGLMatrix(pm);
|
||||
//qDebug() << angles_;
|
||||
//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 ret;
|
||||
ret.translate(parent_ ? -offset_ : -aim_);
|
||||
ret.translate(parent_ ? -offset_ : -aim());
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -91,10 +62,9 @@ void Camera::localTransform(QMatrix4x4 & m) {
|
||||
*/
|
||||
|
||||
void Camera::assign(const Camera & c) {
|
||||
pos_ = c.pos_;
|
||||
aim_ = c.aim_;
|
||||
trans = c.trans;
|
||||
aim_dist = c.aim_dist;
|
||||
fov_ = c.fov_;
|
||||
angles_ = c.angles_;
|
||||
angle_limit_lower_xy = c.angle_limit_lower_xy;
|
||||
angle_limit_upper_xy = c.angle_limit_upper_xy;
|
||||
mirror_x = c.mirror_x;
|
||||
@@ -116,10 +86,9 @@ ObjectBase * Camera::clone(bool withChildren) {
|
||||
for (int i = 0; i < children_.size(); ++i)
|
||||
o->addChild(children_[i]->clone(withChildren));
|
||||
}
|
||||
o->pos_ = pos_;
|
||||
o->aim_ = aim_;
|
||||
o->trans = trans;
|
||||
o->aim_dist = aim_dist;
|
||||
o->fov_ = fov_;
|
||||
o->angles_ = angles_;
|
||||
o->angle_limit_lower_xy = angle_limit_lower_xy;
|
||||
o->angle_limit_upper_xy = angle_limit_upper_xy;
|
||||
o->mirror_x = mirror_x;
|
||||
@@ -133,16 +102,18 @@ ObjectBase * Camera::clone(bool withChildren) {
|
||||
|
||||
QMatrix4x4 Camera::viewMatrix() const {
|
||||
QMatrix4x4 ret;
|
||||
//qDebug() << pos() << aim();
|
||||
ret.translate(0., 0., -distance());
|
||||
ret.rotate(angles_.y(), 1., 0., 0.);
|
||||
ret.rotate(angles_.x(), 0., 1., 0.);
|
||||
ret.rotate(angles_.z(), 0., 0., 1.);
|
||||
ret *= trans.matrixRotateScale().inverted();
|
||||
//ret.rotate(angles_.y(), 1., 0., 0.);
|
||||
//ret.rotate(angles_.x(), 0., 1., 0.);
|
||||
//ret.rotate(angles_.z(), 0., 0., 1.);
|
||||
//pm.translate(-aim_);
|
||||
if (parent_) {
|
||||
QMatrix4x4 pmat = parent_->worldTransform();
|
||||
offset_ = pmat.column(3).toVector3D();
|
||||
pmat(0, 3) = pmat(1, 3) = pmat(2, 3) = 0.;
|
||||
pmat.translate(aim_);
|
||||
pmat.translate(aim());
|
||||
ret *= pmat.inverted();
|
||||
}
|
||||
return ret;
|
||||
@@ -155,96 +126,106 @@ QMatrix4x4 Camera::projectionMatrix(double aspect) const {
|
||||
|
||||
|
||||
void Camera::panZ(const float & a) {
|
||||
QVector3D dv = aim_ - pos_;
|
||||
/*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();
|
||||
buildTransform();*/
|
||||
}
|
||||
|
||||
|
||||
void Camera::panXY(const float & a) {
|
||||
QVector3D dv = aim_ - pos_;
|
||||
/*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();
|
||||
buildTransform();*/
|
||||
}
|
||||
|
||||
|
||||
void Camera::rotateZ(const float & a) {
|
||||
QVector3D dv = aim_ - pos_;
|
||||
/*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();
|
||||
buildTransform();*/
|
||||
}
|
||||
|
||||
|
||||
void Camera::rotateXY(const float & a) {
|
||||
QVector3D dv = aim_ - pos_;
|
||||
/*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();
|
||||
buildTransform();*/
|
||||
}
|
||||
|
||||
|
||||
void Camera::orbitZ(const float & a) {
|
||||
QVector3D dv = aim_ - pos_;
|
||||
//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();
|
||||
buildTransform();*/
|
||||
}
|
||||
|
||||
|
||||
void Camera::orbitXY(const float & a) {
|
||||
QVector3D dv = aim_ - pos_;
|
||||
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();
|
||||
buildTransform();*/
|
||||
}
|
||||
|
||||
|
||||
void Camera::setAngleZ(const float & a) {
|
||||
QVector3D dv = aim_ - pos_;
|
||||
/*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();
|
||||
buildTransform();*/
|
||||
}
|
||||
|
||||
|
||||
void Camera::setAngleXY(const float & a) {
|
||||
QVector3D dv = aim_ - pos_;
|
||||
/*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();
|
||||
buildTransform();*/
|
||||
//anglesFromPoints();
|
||||
}
|
||||
|
||||
|
||||
void Camera::moveForward(const float & x, bool withZ) {
|
||||
QVector3D dv;// = aim_ - pos_;
|
||||
/*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));
|
||||
@@ -252,12 +233,12 @@ void Camera::moveForward(const float & x, bool withZ) {
|
||||
dv *= x;
|
||||
pos_ += dv;
|
||||
aim_ += dv;
|
||||
buildTransform();
|
||||
buildTransform();*/
|
||||
}
|
||||
|
||||
|
||||
void Camera::moveLeft(const float & x, bool withZ) {
|
||||
QVector3D dv;// = aim_ - pos_;
|
||||
/*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));
|
||||
@@ -265,12 +246,12 @@ void Camera::moveLeft(const float & x, bool withZ) {
|
||||
dv *= x;
|
||||
pos_ += dv;
|
||||
aim_ += dv;
|
||||
buildTransform();
|
||||
buildTransform();*/
|
||||
}
|
||||
|
||||
|
||||
void Camera::moveUp(const float & x, bool onlyZ) {
|
||||
QVector3D dv;
|
||||
/*QVector3D dv;
|
||||
if (onlyZ)
|
||||
dv = QVector3D(0., 0., x);
|
||||
else {
|
||||
@@ -281,10 +262,10 @@ void Camera::moveUp(const float & x, bool onlyZ) {
|
||||
}
|
||||
pos_ += dv;
|
||||
aim_ += dv;
|
||||
buildTransform();
|
||||
buildTransform();*/
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
void Camera::flyCloser(const float & s) {
|
||||
QVector3D dv = aim_ - pos_;
|
||||
float tl = dv.length() / (1.f + s), tc = -sinf(angles_.y() * deg2rad);
|
||||
@@ -310,4 +291,4 @@ void Camera::flyToDistance(const float & d) {
|
||||
pos_ = aim_ - dv * d;
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user