Refactored Matrix4 and CameraDefinition

This commit is contained in:
Michaël Lemaire 2013-11-14 18:47:03 +01:00 committed by Michael Lemaire
parent 67105775b6
commit 2df3c90ffd
61 changed files with 1081 additions and 1327 deletions

View file

@ -0,0 +1,48 @@
#include "BoundingBox.h"
#include "Vector3.h"
BoundingBox::BoundingBox()
{
reset();
}
void BoundingBox::reset()
{
empty = 1;
xmin = 10000000000.0;
xmax = -10000000000.0;
ymin = 10000000000.0;
ymax = -10000000000.0;
zmin = 10000000000.0;
zmax = -10000000000.0;
}
void BoundingBox::pushPoint(const Vector3 &point)
{
empty = 0;
if (point.x < xmin)
{
xmin = point.x;
}
if (point.x > xmax)
{
xmax = point.x;
}
if (point.y < ymin)
{
ymin = point.y;
}
if (point.y > ymax)
{
ymax = point.y;
}
if (point.z < zmin)
{
zmin = point.z;
}
if (point.z > zmax)
{
zmax = point.z;
}
}

30
src/basics/BoundingBox.h Normal file
View file

@ -0,0 +1,30 @@
#ifndef BOUNDINGBOX_H
#define BOUNDINGBOX_H
#include "basics_global.h"
namespace paysages {
namespace basics {
class BASICSSHARED_EXPORT BoundingBox
{
public:
BoundingBox();
void reset();
void pushPoint(const Vector3 &point);
public:
int empty;
double xmin;
double xmax;
double ymin;
double ymax;
double zmin;
double zmax;
};
}
}
#endif // BOUNDINGBOX_H

302
src/basics/Matrix4.cpp Normal file
View file

@ -0,0 +1,302 @@
#include "Matrix4.h"
#include <cmath>
#include "PackStream.h"
Matrix4::Matrix4(bool identity)
{
b = c = d = e = g = h = 0.0;
i = j = l = m = n = o = 0.0;
a = f = k = p = (identity ? 1.0 : 0.0);
}
void Matrix4::save(PackStream* stream) const
{
stream->write(&a);
stream->write(&b);
stream->write(&c);
stream->write(&d);
stream->write(&e);
stream->write(&f);
stream->write(&g);
stream->write(&h);
stream->write(&i);
stream->write(&j);
stream->write(&k);
stream->write(&l);
stream->write(&m);
stream->write(&n);
stream->write(&o);
stream->write(&p);
}
void Matrix4::load(PackStream* stream)
{
stream->read(&a);
stream->read(&b);
stream->read(&c);
stream->read(&d);
stream->read(&e);
stream->read(&f);
stream->read(&g);
stream->read(&h);
stream->read(&i);
stream->read(&j);
stream->read(&k);
stream->read(&l);
stream->read(&m);
stream->read(&n);
stream->read(&o);
stream->read(&p);
}
Matrix4 Matrix4::mult(const Matrix4 &other) const
{
Matrix4 result;
result.a = a * other.a + b * other.e + c * other.i + d * other.m;
result.b = a * other.b + b * other.f + c * other.j + d * other.n;
result.c = a * other.c + b * other.g + c * other.k + d * other.o;
result.d = a * other.d + b * other.h + c * other.l + d * other.p;
result.e = e * other.a + f * other.e + g * other.i + h * other.m;
result.f = e * other.b + f * other.f + g * other.j + h * other.n;
result.g = e * other.c + f * other.g + g * other.k + h * other.o;
result.h = e * other.d + f * other.h + g * other.l + h * other.p;
result.i = i * other.a + j * other.e + k * other.i + l * other.m;
result.j = i * other.b + j * other.f + k * other.j + l * other.n;
result.k = i * other.c + j * other.g + k * other.k + l * other.o;
result.l = i * other.d + j * other.h + k * other.l + l * other.p;
result.m = m * other.a + n * other.e + o * other.i + p * other.m;
result.n = m * other.b + n * other.f + o * other.j + p * other.n;
result.o = m * other.c + n * other.g + o * other.k + p * other.o;
result.p = m * other.d + n * other.h + o * other.l + p * other.p;
return result;
}
Vector3 Matrix4::multPoint(const Vector3 &v) const
{
Vector3 result;
result.x = a * v.x + b * v.y + c * v.z + d;
result.y = e * v.x + f * v.y + g * v.z + h;
result.z = i * v.x + j * v.y + k * v.z + l;
return result;
}
Vector3 Matrix4::transform(const Vector3 &v) const
{
Vector3 result;
double w;
result.x = a * v.x + b * v.y + c * v.z + d;
result.y = e * v.x + f * v.y + g * v.z + h;
result.z = i * v.x + j * v.y + k * v.z + l;
w = m * v.x + n * v.y + o * v.z + p;
if (w != 0.0)
{
result.x /= w;
result.y /= w;
result.z /= w;
}
return result;
}
Matrix4 Matrix4::transposed() const
{
Matrix4 result;
result.a = a;
result.e = b;
result.i = c;
result.m = d;
result.b = e;
result.f = f;
result.j = g;
result.n = h;
result.c = i;
result.g = j;
result.k = k;
result.o = l;
result.d = m;
result.h = n;
result.l = o;
result.p = p;
return result;
}
Matrix4 Matrix4::newScale(double x, double y, double z)
{
Matrix4 result;
result.a = x;
result.f = y;
result.k = z;
return result;
}
Matrix4 Matrix4::newTranslate(double x, double y, double z)
{
Matrix4 result;
result.d = x;
result.h = y;
result.l = z;
return result;
}
Matrix4 Matrix4::newRotateX(double angle)
{
Matrix4 result;
double si = sin(angle);
double co = cos(angle);
result.f = result.k = co;
result.g = -si;
result.j = si;
return result;
}
Matrix4 Matrix4::newRotateY(double angle)
{
Matrix4 result;
double si = sin(angle);
double co = cos(angle);
result.a = result.k = co;
result.c = si;
result.i = -si;
return result;
}
Matrix4 Matrix4::newRotateZ(double angle)
{
Matrix4 result;
double si = sin(angle);
double co = cos(angle);
result.a = result.f = co;
result.b = -si;
result.e = si;
return result;
}
Matrix4 Matrix4::newRotateAxis(double angle, const Vector3 &_axis)
{
Matrix4 result;
double si = sin(angle);
double co = cos(angle);
double c1 = 1.0 - co;
Vector3 axis = _axis.normalize();
result.a = axis.x * axis.x * c1 + co;
result.b = axis.x * axis.y * c1 - axis.z * si;
result.c = axis.x * axis.z * c1 + axis.y * si;
result.e = axis.y * axis.x * c1 + axis.z * si;
result.f = axis.y * axis.y * c1 + co;
result.g = axis.y * axis.z * c1 - axis.x * si;
result.i = axis.x * axis.z * c1 - axis.y * si;
result.j = axis.y * axis.z * c1 + axis.x * si;
result.k = axis.z * axis.z * c1 + co;
return result;
}
Matrix4 Matrix4::newRotateEuler(double heading, double attitude, double bank)
{
Matrix4 result;
double ch = cos(heading);
double sh = sin(heading);
double ca = cos(attitude);
double sa = sin(attitude);
double cb = cos(bank);
double sb = sin(bank);
result.a = ch * ca;
result.b = sh * sb - ch * sa * cb;
result.c = ch * sa * sb + sh * cb;
result.e = sa;
result.f = ca * cb;
result.g = -ca * sb;
result.i = -sh * ca;
result.j = sh * sa * cb + ch * sb;
result.k = -sh * sa * sb + ch * cb;
return result;
}
Matrix4 Matrix4::newRotateTripleAxis(const Vector3 &x, const Vector3 &y, const Vector3 &z)
{
Matrix4 result;
result.a = x.x;
result.b = y.x;
result.c = z.x;
result.e = x.y;
result.f = y.y;
result.g = z.y;
result.i = x.z;
result.j = y.z;
result.k = z.z;
return result;
}
Matrix4 Matrix4::newLookAt(const Vector3 &eye, const Vector3 &at, const Vector3 &up)
{
Vector3 z = v3Normalize(v3Sub(at, eye));
Vector3 x = v3Normalize(v3Cross(up, z));
Vector3 y = v3Cross(z, x);
Matrix4 result = Matrix4::newRotateTripleAxis(x, y, z);
result.d = eye.x;
result.h = eye.y;
result.l = eye.z;
return result.inversed();
}
Matrix4 Matrix4::newPerspective(double fov_y, double aspect, double near, double far)
{
Matrix4 result;
double fo = 1 / tan(fov_y / 2.0);
result.a = fo / aspect;
result.f = fo;
result.k = (far + near) / (near - far);
result.l = 2.0 * far * near / (near - far);
result.o = -1.0;
result.p = 0.0;
return result;
}
double Matrix4::getDeterminant() const
{
return ((a * f - e * b)
* (k * p - o * l)
- (a * j - i * b)
* (g * p - o * h)
+ (a * n - m * b)
* (g * l - k * h)
+ (e * j - i * f)
* (c * p - o * d)
- (e * n - m * f)
* (c * l - k * d)
+ (i * n - m * j)
* (c * h - g * d));
}
Matrix4 Matrix4::inversed() const
{
Matrix4 result;
double det = getDeterminant();
if (fabs(det) >= 0.00001)
{
det = 1.0 / det;
result.a = det * (f * (k * p - o * l) + j * (o * h - g * p) + n * (g * l - k * h));
result.e = det * (g * (i * p - m * l) + k * (m * h - e * p) + o * (e * l - i * h));
result.i = det * (h * (i * n - m * j) + l * (m * f - e * n) + p * (e * j - i * f));
result.m = det * (e * (n * k - j * o) + i * (f * o - n * g) + m * (j * g - f * k));
result.b = det * (j * (c * p - o * d) + n * (k * d - c * l) + b * (o * l - k * p));
result.f = det * (k * (a * p - m * d) + o * (i * d - a * l) + c * (m * l - i * p));
result.j = det * (l * (a * n - m * b) + p * (i * b - a * j) + d * (m * j - i * n));
result.n = det * (i * (n * c - b * o) + m * (b * k - j * c) + a * (j * o - n * k));
result.c = det * (n * (c * h - g * d) + b * (g * p - o * h) + f * (o * d - c * p));
result.g = det * (o * (a * h - e * d) + c * (e * p - m * h) + g * (m * d - a * p));
result.k = det * (p * (a * f - e * b) + d * (e * n - m * f) + h * (m * b - a * n));
result.o = det * (m * (f * c - b * g) + a * (n * g - f * o) + e * (b * o - n * c));
result.d = det * (b * (k * h - g * l) + f * (c * l - k * d) + j * (g * d - c * h));
result.h = det * (c * (i * h - e * l) + g * (a * l - i * d) + k * (e * d - a * h));
result.l = det * (d * (i * f - e * j) + h * (a * j - i * b) + l * (e * b - a * f));
result.p = det * (a * (f * k - j * g) + e * (j * c - b * k) + i * (b * g - f * c));
}
return result;
}

60
src/basics/Matrix4.h Normal file
View file

@ -0,0 +1,60 @@
#ifndef MATRIX4_H
#define MATRIX4_H
#include "basics_global.h"
#include "Vector3.h"
namespace paysages {
namespace basics {
class BASICSSHARED_EXPORT Matrix4
{
public:
Matrix4(bool identity=true);
void save(PackStream* stream) const;
void load(PackStream* stream);
Matrix4 mult(const Matrix4 &other) const;
Vector3 multPoint(const Vector3 &v) const;
Vector3 transform(const Vector3 &v) const;
Matrix4 transposed() const;
Matrix4 inversed() const;
static Matrix4 newScale(double x, double y, double z);
static Matrix4 newTranslate(double x, double y, double z);
static Matrix4 newRotateX(double angle);
static Matrix4 newRotateY(double angle);
static Matrix4 newRotateZ(double angle);
static Matrix4 newRotateAxis(double angle, const Vector3 &axis);
static Matrix4 newRotateEuler(double heading, double attitude, double bank);
static Matrix4 newRotateTripleAxis(const Vector3 &x, const Vector3 &y, const Vector3 &z);
static Matrix4 newLookAt(const Vector3 &eye, const Vector3 &at, const Vector3 &up);
static Matrix4 newPerspective(double fov_y, double aspect, double near, double far);
double getDeterminant() const;
private:
double a;
double b;
double c;
double d;
double e;
double f;
double g;
double h;
double i;
double j;
double k;
double l;
double m;
double n;
double o;
double p;
};
}
}
#endif // MATRIX4_H

View file

@ -24,7 +24,9 @@ SOURCES += \
SpaceSegment.cpp \
Color.cpp \
Color.inline.cpp \
ColorHSL.cpp
ColorHSL.cpp \
BoundingBox.cpp \
Matrix4.cpp
HEADERS +=\
basics_global.h \
@ -36,7 +38,9 @@ HEADERS +=\
Vector3.h \
SpaceSegment.h \
Color.h \
ColorHSL.h
ColorHSL.h \
BoundingBox.h \
Matrix4.h
unix:!symbian {
maemo5 {

View file

@ -13,6 +13,8 @@
namespace paysages {
namespace basics {
class Vector3;
class Matrix4;
class BoundingBox;
class SpaceSegment;
class Color;
class NoiseGenerator;

View file

@ -1,42 +0,0 @@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
TARGET = paysages-cli
INCLUDEPATH += $$PWD/..
include(../common.pri)
SOURCES += \
main.cpp
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../rendering/release/ -lpaysages_rendering
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../rendering/debug/ -lpaysages_rendering
else:unix: LIBS += -L$$OUT_PWD/../rendering/ -lpaysages_rendering
INCLUDEPATH += $$PWD/../rendering
DEPENDPATH += $$PWD/../rendering
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../system/release/ -lpaysages_system
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../system/debug/ -lpaysages_system
else:unix: LIBS += -L$$OUT_PWD/../system/ -lpaysages_system
INCLUDEPATH += $$PWD/../system
DEPENDPATH += $$PWD/../system
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../basics/release/ -lpaysages_basics
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../basics/debug/ -lpaysages_basics
else:unix: LIBS += -L$$OUT_PWD/../basics/ -lpaysages_basics
INCLUDEPATH += $$PWD/../basics
DEPENDPATH += $$PWD/../basics
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../definition/release/ -lpaysages_definition
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../definition/debug/ -lpaysages_definition
else:unix: LIBS += -L$$OUT_PWD/../definition/ -lpaysages_definition
INCLUDEPATH += $$PWD/../definition
DEPENDPATH += $$PWD/../definition
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../render/software/release/ -lpaysages_render_software
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../render/software/debug/ -lpaysages_render_software
else:unix: LIBS += -L$$OUT_PWD/../render/software/ -lpaysages_render_software
INCLUDEPATH += $$PWD/../render/software
DEPENDPATH += $$PWD/../render/software

View file

@ -0,0 +1,292 @@
#include "CameraDefinition.h"
#include <cmath>
#include "PackStream.h"
#include "BoundingBox.h"
CameraDefinition::CameraDefinition():
BaseDefinition(NULL)
{
location.x = 0.0;
location.y = 0.0;
location.z = 0.0;
direction.phi = 0.0;
direction.theta = 0.0;
direction.r = 1.0;
roll = 0.0;
width = 1.0;
height = 1.0;
perspective.yfov = 1.57;
perspective.xratio = 1.0;
perspective.znear = 1.0;
perspective.zfar = 1000.0;
validate();
}
void CameraDefinition::save(PackStream* stream) const
{
location.save(stream);
stream->write(&direction.r);
stream->write(&direction.phi);
stream->write(&direction.theta);
stream->write(&roll);
}
void CameraDefinition::load(PackStream* stream)
{
location.load(stream);
stream->read(&direction.r);
stream->read(&direction.phi);
stream->read(&direction.theta);
stream->read(&roll);
validate();
}
void CameraDefinition::copy(BaseDefinition* _destination) const
{
CameraDefinition* destination = (CameraDefinition*)_destination;
destination->location = location;
destination->direction = direction;
destination->roll = roll;
destination->validate();
}
void CameraDefinition::validate()
{
Matrix4 rotation;
if (location.y > 300.0)
{
location.y = 300.0;
}
forward.x = 1.0;
forward.y = 0.0;
forward.z = 0.0;
right.x = 0.0;
right.y = 0.0;
right.z = 1.0;
up.x = 0.0;
up.y = 1.0;
up.z = 0.0;
rotation = Matrix4::newRotateEuler(direction.phi, direction.theta, roll);
forward = rotation.multPoint(forward);
right = rotation.multPoint(right);
up = rotation.multPoint(up);
target = location.add(direction);
projector = Matrix4::newPerspective(perspective.yfov, perspective.xratio, perspective.znear, perspective.zfar).mult(Matrix4::newLookAt(location, target, up));
unprojector = projector.inversed();
}
double CameraDefinition::getRealDepth(const Vector3 &projected) const
{
/* TODO Optimize this */
Matrix4 m = Matrix4::newPerspective(perspective.yfov, perspective.xratio, perspective.znear, perspective.zfar);
Vector3 v(projected.x / (0.5 * width) - 1.0, -(projected.y / (0.5 * height) - 1.0), projected.z);
return m.inversed().transform(v).z;
}
void CameraDefinition::setLocation(const Vector3 &location)
{
this->location = location;
validate();
}
void CameraDefinition::setLocationCoords(double x, double y, double z)
{
location = Vector3(x, y, z);
validate();
}
void CameraDefinition::setTarget(const Vector3 &target)
{
Vector3 forward;
forward = target.sub(location);
if (forward.getNorm() < 0.0000001)
{
return;
}
direction = forward.toSpherical();
validate();
}
void CameraDefinition::setTargetCoords(double x, double y, double z)
{
setTarget(Vector3(x, y, z));
}
void CameraDefinition::setRoll(double angle)
{
roll = angle;
validate();
}
void CameraDefinition::setZoomToTarget(double zoom)
{
direction.r = zoom;
location = target.add(Vector3(direction).scale(-1.0));
validate();
}
void CameraDefinition::strafeForward(double value)
{
location = location.add(forward.scale(value));
validate();
}
void CameraDefinition::strafeRight(double value)
{
location = location.add(right.scale(value));
validate();
}
void CameraDefinition::strafeUp(double value)
{
location = location.add(up.scale(value));
validate();
}
void CameraDefinition::rotateYaw(double value)
{
direction.phi += value;
validate();
}
void CameraDefinition::rotatePitch(double value)
{
direction.theta += value;
validate();
}
void CameraDefinition::rotateRoll(double value)
{
roll += value;
validate();
}
void CameraDefinition::setRenderSize(int width, int height)
{
this->width = (double)width;
this->height = (double)height;
perspective.xratio = this->width / this->height;
validate();
}
Vector3 CameraDefinition::project(const Vector3 &point) const
{
Vector3 tpoint = projector.transform(point);
if (tpoint.z < 1.0)
{
tpoint.x = -tpoint.x;
tpoint.y = -tpoint.y;
}
tpoint.x = (tpoint.x + 1.0) * 0.5 * width;
tpoint.y = (-tpoint.y + 1.0) * 0.5 * height;
return tpoint;
}
Vector3 CameraDefinition::unproject(const Vector3 &point) const
{
Vector3 tpoint(point.x / (0.5 * width) - 1.0, -(point.y / (0.5 * height) - 1.0), point.z);
if (tpoint.z < 1.0)
{
tpoint.x = -tpoint.x;
tpoint.y = -tpoint.y;
}
return unprojector.transform(tpoint);
}
bool CameraDefinition::isBoxInView(const Vector3 &center, double xsize, double ysize, double zsize) const
{
BoundingBox box;
box.pushPoint(v3Add(center, v3(-xsize, -ysize, -zsize)));
box.pushPoint(v3Add(center, v3(xsize, ysize, zsize)));
return isUnprojectedBoxInView(box);
}
bool CameraDefinition::isUnprojectedBoxInView(const BoundingBox &box) const
{
BoundingBox projected;
projected.pushPoint(project(Vector3(box.xmin, box.ymin, box.zmin)));
projected.pushPoint(project(Vector3(box.xmax, box.ymin, box.zmin)));
projected.pushPoint(project(Vector3(box.xmin, box.ymax, box.zmin)));
projected.pushPoint(project(Vector3(box.xmax, box.ymax, box.zmin)));
projected.pushPoint(project(Vector3(box.xmin, box.ymin, box.zmax)));
projected.pushPoint(project(Vector3(box.xmax, box.ymin, box.zmax)));
projected.pushPoint(project(Vector3(box.xmin, box.ymax, box.zmax)));
projected.pushPoint(project(Vector3(box.xmax, box.ymax, box.zmax)));
return isProjectedBoxInView(projected);
}
bool CameraDefinition::isProjectedBoxInView(const BoundingBox &box) const
{
if (box.xmin <= width && box.xmax >= 0.0 && box.ymin <= height && box.ymax >= 0.0 && box.zmax >= perspective.znear)
{
double dx = box.xmax - box.xmin;
double dy = box.ymax - box.ymin;
return (int)ceil(dx) * (int)ceil(dy) > 0;
}
else
{
return false;
}
}
bool CameraDefinition::transitionToAnother(const CameraDefinition *wanted, double factor)
{
double dx, dy, dz, dr, dphi, dtheta, droll;
dx = wanted->location.x - location.x;
dy = wanted->location.y - location.y;
dz = wanted->location.z - location.z;
dr = wanted->direction.r - direction.r;
dphi = wanted->direction.phi - direction.phi;
dtheta = wanted->direction.theta - direction.theta;
droll = wanted->roll - roll;
if (fabs(dx) < 0.000001 && fabs(dy) < 0.000001 && fabs(dz) < 0.000001 && fabs(dr) < 0.000001 && fabs(dphi) < 0.000001 && fabs(dtheta) < 0.000001 && fabs(droll) < 0.000001)
{
return false;
}
else
{
location.x += dx * factor;
location.y += dy * factor;
location.z += dz * factor;
direction.r += dr * factor;
direction.phi += dphi * factor;
direction.theta += dtheta * factor;
roll += droll * factor;
validate();
return true;
}
}

View file

@ -0,0 +1,90 @@
#ifndef CAMERADEFINITION_H
#define CAMERADEFINITION_H
#include "definition_global.h"
#include "BaseDefinition.h"
#include "Vector3.h"
#include "Matrix4.h"
namespace paysages {
namespace definition {
typedef struct
{
double yfov;
double xratio;
double znear;
double zfar;
} CameraPerspective;
class BASICSSHARED_EXPORT CameraDefinition: public BaseDefinition
{
public:
CameraDefinition();
virtual void save(PackStream* pack) const override;
virtual void load(PackStream* pack) override;
virtual void copy(BaseDefinition* destination) const override;
virtual void validate() override;
inline Vector3 getLocation() const {return location;}
inline Vector3 getTarget() const {return target;}
inline Vector3 getUpVector() const {return up;}
inline double getRoll() const {return roll;}
inline Vector3 getDirection() const {return Vector3(direction);}
inline Vector3 getDirectionNormalized() const {return forward;}
inline VectorSpherical getDirectionSpherical() const {return direction;}
inline CameraPerspective getPerspective() const {return perspective;}
double getRealDepth(const Vector3 &projected) const;
void setLocation(const Vector3 &location);
void setLocationCoords(double x, double y, double z);
void setTarget(const Vector3 &target);
void setTargetCoords(double x, double y, double z);
void setRoll(double angle);
void setZoomToTarget(double zoom);
void strafeForward(double value);
void strafeRight(double value);
void strafeUp(double value);
void rotateYaw(double value);
void rotatePitch(double value);
void rotateRoll(double value);
void setRenderSize(int width, int height);
Vector3 project(const Vector3 &point) const;
Vector3 unproject(const Vector3 &point) const;
bool isBoxInView(const Vector3 &center, double xsize, double ysize, double zsize) const;
bool isUnprojectedBoxInView(const BoundingBox &box) const;
bool isProjectedBoxInView(const BoundingBox &box) const;
bool transitionToAnother(const CameraDefinition *wanted, double factor);
private:
/* Definition */
Vector3 location;
VectorSpherical direction;
double roll;
/* Projection info */
double width;
double height;
CameraPerspective perspective;
/* Auto updated */
Vector3 target;
Vector3 forward;
Vector3 right;
Vector3 up;
Matrix4 projector;
Matrix4 unprojector;
};
}
}
#endif // CAMERADEFINITION_H

View file

@ -18,7 +18,8 @@ SOURCES += \
Layers.cpp \
LegacyLayer.cpp \
WaterDefinition.cpp \
SurfaceMaterial.cpp
SurfaceMaterial.cpp \
CameraDefinition.cpp
HEADERS +=\
definition_global.h \
@ -26,7 +27,8 @@ HEADERS +=\
Layers.h \
LegacyLayer.h \
WaterDefinition.h \
SurfaceMaterial.h
SurfaceMaterial.h \
CameraDefinition.h
unix:!symbian {
maemo5 {

View file

@ -13,6 +13,7 @@
namespace paysages {
namespace definition {
class BaseDefinition;
class CameraDefinition;
class SurfaceMaterial;
class WaterDefinition;
}

View file

@ -15,7 +15,7 @@
#include "Scenery.h"
#include "BasePreview.h"
#include "SoftwareRenderer.h"
#include "camera.h"
#include "CameraDefinition.h"
#include "tools.h"
Q_DECLARE_METATYPE(double*)
@ -236,14 +236,12 @@ void FreeFormHelper::processExploreClicked()
emit needAlterRenderer(&renderer);
CameraDefinition* camera = cameraCreateDefinition();
Scenery::getCurrent()->getCamera(camera);
CameraDefinition camera;
Scenery::getCurrent()->getCamera(&camera);
DialogExplorer* dialog = new DialogExplorer(_form_widget, camera, false, &renderer);
DialogExplorer* dialog = new DialogExplorer(_form_widget, &camera, false, &renderer);
dialog->exec();
delete dialog;
cameraDeleteDefinition(camera);
}
void FreeFormHelper::processRenderClicked()

View file

@ -15,6 +15,7 @@
#include "BasePreview.h"
#include "PreviewOsd.h"
#include "PreviewOsdItem.h"
#include "CameraDefinition.h"
#include "formclouds.h"
#include "formatmosphere.h"
#include "formwater.h"
@ -258,10 +259,9 @@ void MainWindow::showLastRender()
void MainWindow::explore3D()
{
CameraDefinition* camera;
CameraDefinition* camera = new CameraDefinition;
int result;
camera = cameraCreateDefinition();
Scenery::getCurrent()->getCamera(camera);
DialogExplorer* dialog = new DialogExplorer(this, camera, true);
@ -275,7 +275,7 @@ void MainWindow::explore3D()
refreshAll();
}
cameraDeleteDefinition(camera);
delete camera;
}
void MainWindow::guiSaveCallback(PackStream* stream, void* data)

View file

@ -5,7 +5,7 @@
#include <QVBoxLayout>
#include <QLabel>
#include "WidgetExplorer.h"
#include "camera.h"
#include "CameraDefinition.h"
#include "renderer.h"
DialogExplorer::DialogExplorer(QWidget* parent, CameraDefinition* camera, bool camera_validable, Renderer* renderer) : QDialog(parent)

View file

@ -5,7 +5,6 @@
#include <QDialog>
class CameraDefinition;
class Renderer;
class DialogExplorer : public QDialog

View file

@ -14,6 +14,7 @@
#include "PackStream.h"
#include "SoftwareRenderer.h"
#include "BasePreview.h"
#include "CameraDefinition.h"
/**************** Previews ****************/
class PreviewRenderLandscape : public BasePreview
@ -114,7 +115,7 @@ BaseForm(parent, true)
_params.width = 800;
_params.height = 600;
_params.antialias = 1;
_camera = cameraCreateDefinition();
_camera = new CameraDefinition;
_renderer_inited = false;
@ -139,7 +140,7 @@ BaseForm(parent, true)
FormRender::~FormRender()
{
cameraDeleteDefinition(_camera);
delete _camera;
if (_renderer_inited)
{
rendererDelete(_renderer);
@ -182,7 +183,7 @@ void FormRender::applyConfig()
void FormRender::configChangeEvent()
{
cameraValidateDefinition(_camera, 1);
_camera->validate();
BaseForm::configChangeEvent();
}

View file

@ -2,7 +2,6 @@
#define _PAYSAGES_QT_FORMRENDER_H_
#include "baseform.h"
#include "camera.h"
#include "renderer.h"
#include "render.h"

View file

@ -4,7 +4,7 @@
#include "BasePreview.h"
#include "renderer.h"
#include "tools.h"
#include "camera.h"
#include "CameraDefinition.h"
/**************** Previews ****************/
class PreviewTexturesCoverage : public BasePreview
@ -67,8 +67,7 @@ public:
_renderer = rendererCreate();
_renderer->render_quality = 3;
Vector3 camera_location = {0.0, 20.0, 0.0};
cameraSetLocation(_renderer->render_camera, camera_location);
_renderer->render_camera->setLocation(Vector3(0.0, 20.0, 0.0));
configScaling(0.01, 1.0, 0.01, 0.1);
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);

View file

@ -13,7 +13,7 @@
#include "tools.h"
#include "Scenery.h"
#include "BasePreview.h"
#include "camera.h"
#include "CameraDefinition.h"
#include "WaterDefinition.h"
static WaterDefinition* _definition;
@ -117,8 +117,7 @@ protected:
void cameraEvent()
{
Vector3 camera_location = {0.0, scaling, -10.0 * scaling};
cameraSetLocation(_renderer->render_camera, camera_location);
_renderer->render_camera->setLocation(Vector3(0.0, scaling, -10.0 * scaling));
}
static double _getWaterHeight(Renderer*)

View file

@ -1,11 +1,11 @@
#ifndef _PAYSAGES_QT_INPUTCAMERA_H_
#define _PAYSAGES_QT_INPUTCAMERA_H_
#include "editing_global.h"
#include <QWidget>
#include "baseinput.h"
#include "camera.h"
class InputCamera:public BaseInput
{
Q_OBJECT

View file

@ -8,7 +8,7 @@
#include "tools/lighting.h"
#include "tools/color.h"
#include "camera.h"
#include "CameraDefinition.h"
/***** Shared renderer *****/
MaterialPreviewRenderer::MaterialPreviewRenderer(SurfaceMaterial* material)
@ -25,8 +25,7 @@ MaterialPreviewRenderer::MaterialPreviewRenderer(SurfaceMaterial* material)
_material = material;
Vector3 camera_location = {0.0, 0.0, 10.0};
cameraSetLocation(render_camera, camera_location);
render_camera->setLocation(Vector3(0.0, 0.0, 10.0));
_color_profile = colorProfileCreate();
colorProfileSetToneMapping(_color_profile, TONE_MAPPING_UNCHARTED, 1.0);

View file

@ -44,16 +44,15 @@ QGLWidget(parent)
_last_update_x = 0;
_last_update_z = 0;
_current_camera = cameraCreateDefinition();
_top_camera = cameraCreateDefinition();
_temp_camera = cameraCreateDefinition();
_current_camera = new CameraDefinition;
_top_camera = new CameraDefinition;
_temp_camera = new CameraDefinition;
_zoom = 35.0;
Vector3 camera_location = {0.0, 80.0, 10.0};
cameraSetLocation(_current_camera, camera_location);
cameraSetTarget(_current_camera, VECTOR_ZERO);
cameraSetZoomToTarget(_top_camera, _zoom);
cameraCopyDefinition(_current_camera, _top_camera);
_current_camera->setLocation(Vector3(0.0, 80.0, 10.0));
_current_camera->setTarget(VECTOR_ZERO);
_top_camera->setZoomToTarget(_zoom);
_current_camera->copy(_top_camera);
_brush = NULL;
_brush_x = 0.0;
@ -62,9 +61,9 @@ QGLWidget(parent)
WidgetHeightMap::~WidgetHeightMap()
{
cameraDeleteDefinition(_current_camera);
cameraDeleteDefinition(_top_camera);
cameraDeleteDefinition(_temp_camera);
delete _current_camera;
delete _top_camera;
delete _temp_camera;
rendererDelete(_renderer);
delete[] _vertices;
}
@ -216,10 +215,10 @@ void WidgetHeightMap::timerEvent(QTimerEvent*)
// Update top camera
Vector3 target = {_target_x, terrainGetInterpolatedHeight(_terrain, _target_x, _target_z, 1, 1), _target_z};
cameraSetLocationCoords(_top_camera, target.x, target.y + 1.0, target.z + 0.1);
cameraSetTarget(_top_camera, target);
cameraSetZoomToTarget(_top_camera, _zoom);
if (cameraTransitionToAnother(_current_camera, _top_camera, 0.8))
_top_camera->setLocationCoords(target.x, target.y + 1.0, target.z + 0.1);
_top_camera->setTarget(target);
_top_camera->setZoomToTarget(_zoom);
if (_current_camera->transitionToAnother(_top_camera, 0.8))
{
int update_x = (int) (floor(_target_x));
int update_z = (int) (floor(_target_z));
@ -372,9 +371,9 @@ void WidgetHeightMap::paintGL()
// Place camera
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Vector3 camera_location = cameraGetLocation(_current_camera);
Vector3 camera_target = cameraGetTarget(_current_camera);
Vector3 camera_up = cameraGetUpVector(_current_camera);
Vector3 camera_location = _current_camera->getLocation();
Vector3 camera_target = _current_camera->getTarget();
Vector3 camera_up = _current_camera->getUpVector();
gluLookAt(camera_location.x, camera_location.y, camera_location.z, camera_target.x, camera_target.y, camera_target.z, camera_up.x, camera_up.y, camera_up.z);
// Place lights

View file

@ -4,7 +4,7 @@
#include <QGLWidget>
#include <QDateTime>
#include "terrain/paintingbrush.h"
#include "camera.h"
#include "CameraDefinition.h"
#include "tools/euclid.h"
#include "renderer.h"
#include "terrain/public.h"

View file

@ -0,0 +1,40 @@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
TARGET = paysages-cli
include(../../common.pri)
SOURCES += \
main.cpp
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../system/release/ -lpaysages_system
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../system/debug/ -lpaysages_system
else:unix: LIBS += -L$$OUT_PWD/../../system/ -lpaysages_system
INCLUDEPATH += $$PWD/../../system
DEPENDPATH += $$PWD/../../system
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../basics/release/ -lpaysages_basics
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../basics/debug/ -lpaysages_basics
else:unix: LIBS += -L$$OUT_PWD/../../basics/ -lpaysages_basics
INCLUDEPATH += $$PWD/../../basics
DEPENDPATH += $$PWD/../../basics
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../definition/release/ -lpaysages_definition
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../definition/debug/ -lpaysages_definition
else:unix: LIBS += -L$$OUT_PWD/../../definition/ -lpaysages_definition
INCLUDEPATH += $$PWD/../../definition
DEPENDPATH += $$PWD/../../definition
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../rendering/release/ -lpaysages_rendering
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../rendering/debug/ -lpaysages_rendering
else:unix: LIBS += -L$$OUT_PWD/../../rendering/ -lpaysages_rendering
INCLUDEPATH += $$PWD/../../rendering
DEPENDPATH += $$PWD/../../rendering
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../render/software/release/ -lpaysages_render_software
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../render/software/debug/ -lpaysages_render_software
else:unix: LIBS += -L$$OUT_PWD/../../render/software/ -lpaysages_render_software
INCLUDEPATH += $$PWD/../../render/software
DEPENDPATH += $$PWD/../../render/software

View file

@ -3,11 +3,11 @@
#include <cstring>
#include <cmath>
#include "rendering/main.h"
#include "rendering/render.h"
#include "rendering/renderer.h"
#include "rendering/atmosphere/public.h"
#include "rendering/camera.h"
#include "main.h"
#include "render.h"
#include "renderer.h"
#include "atmosphere/public.h"
#include "CameraDefinition.h"
#include "SoftwareRenderer.h"
#include "Scenery.h"
@ -174,7 +174,7 @@ int main(int argc, char** argv)
CameraDefinition* camera = Scenery::getCurrent()->getCamera();
Vector3 step = {conf_camera_step_x, conf_camera_step_y, conf_camera_step_z};
cameraSetLocation(camera, v3Add(cameraGetLocation(camera), step));
camera->setLocation(camera->getLocation().add(step));
renderer = new SoftwareRenderer(Scenery::getCurrent());
rendererSetPreviewCallbacks(renderer, NULL, NULL, _previewUpdate);

View file

@ -9,7 +9,7 @@ SUBDIRS = \
render/software \
render/preview \
render/opengl \
interface/commandline \
editing \
controlling \
tests/googletest \
tests

View file

@ -2,14 +2,14 @@
#define BASEEXPLORERCHUNK_H
#include "opengl_global.h"
#include <QMutex>
#include "rendering/tools/color.h"
#include "tools/color.h"
class QImage;
class QGLWidget;
class Renderer;
class ColorProfile;
class CameraDefinition;
namespace paysages {
namespace opengl {

View file

@ -2,9 +2,9 @@
#include <cmath>
#include <GL/gl.h>
#include "rendering/renderer.h"
#include "rendering/camera.h"
#include "rendering/atmosphere/public.h"
#include "renderer.h"
#include "CameraDefinition.h"
#include "atmosphere/public.h"
ExplorerChunkSky::ExplorerChunkSky(Renderer* renderer, double size, SkyboxOrientation orientation) : BaseExplorerChunk(renderer)
{
@ -18,7 +18,7 @@ ExplorerChunkSky::ExplorerChunkSky(Renderer* renderer, double size, SkyboxOrient
void ExplorerChunkSky::onCameraEvent(CameraDefinition* camera)
{
_center = cameraGetLocation(camera);
_center = camera->getLocation();
}
void ExplorerChunkSky::onRenderEvent(QGLWidget*)

View file

@ -2,8 +2,10 @@
#define EXPLORERCHUNKSKY_H
#include "opengl_global.h"
#include "BaseExplorerChunk.h"
#include "rendering/tools/euclid.h"
#include "Vector3.h"
namespace paysages {
namespace opengl {
@ -18,7 +20,7 @@ enum SkyboxOrientation
SKYBOX_BOTTOM
};
class ExplorerChunkSky:public BaseExplorerChunk
class OPENGLSHARED_EXPORT ExplorerChunkSky:public BaseExplorerChunk
{
public:
ExplorerChunkSky(Renderer* renderer, double size, SkyboxOrientation orientation);

View file

@ -2,9 +2,9 @@
#include <cmath>
#include <GL/gl.h>
#include "rendering/camera.h"
#include "rendering/renderer.h"
#include "rendering/terrain/public.h"
#include "CameraDefinition.h"
#include "renderer.h"
#include "terrain/public.h"
ExplorerChunkTerrain::ExplorerChunkTerrain(Renderer* renderer, double x, double z, double size, int nbchunks, double water_height) : BaseExplorerChunk(renderer)
{
@ -86,7 +86,7 @@ bool ExplorerChunkTerrain::onMaintainEvent()
void ExplorerChunkTerrain::onCameraEvent(CameraDefinition* camera)
{
Vector3 camera_location = cameraGetLocation(camera);
Vector3 camera_location = camera->getLocation();
// Handle position
_lock_data.lock();
@ -155,7 +155,7 @@ double ExplorerChunkTerrain::getDisplayedSizeHint(CameraDefinition* camera)
center = getCenter();
if (cameraIsBoxInView(camera, center, _size, 40.0, _size))
if (camera->isBoxInView(center, _size, 40.0, _size))
{
distance = _distance_to_camera;
distance = distance < 0.1 ? 0.1 : distance;

View file

@ -2,12 +2,13 @@
#define EXPLORERCHUNKTERRAIN_H
#include "BaseExplorerChunk.h"
#include "rendering/tools/euclid.h"
#include "Vector3.h"
namespace paysages {
namespace opengl {
class ExplorerChunkTerrain:public BaseExplorerChunk
class OPENGLSHARED_EXPORT ExplorerChunkTerrain:public BaseExplorerChunk
{
public:
ExplorerChunkTerrain(Renderer* renderer, double x, double z, double size, int nbchunks, double water_height);

View file

@ -6,7 +6,7 @@
#include "Scenery.h"
#include "SoftwareRenderer.h"
#include "renderer.h"
#include "rendering/camera.h"
#include "CameraDefinition.h"
OpenGLRenderer::OpenGLRenderer(Scenery* scenery):
scenery(scenery)
@ -51,7 +51,7 @@ void OpenGLRenderer::resize(int width, int height)
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
perspective = cameraGetPerspective(renderer->render_camera);
perspective = renderer->render_camera->getPerspective();
gluPerspective(perspective.yfov * 180.0 / M_PI, perspective.xratio, perspective.znear, perspective.zfar);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

View file

@ -11,12 +11,12 @@
#include "OpenGLRenderer.h"
#include "WaterDefinition.h"
#include "SurfaceMaterial.h"
#include "rendering/tools/euclid.h"
#include "rendering/renderer.h"
#include "rendering/camera.h"
#include "rendering/atmosphere/public.h"
#include "rendering/water/public.h"
#include "rendering/terrain/public.h"
#include "tools/euclid.h"
#include "renderer.h"
#include "CameraDefinition.h"
#include "atmosphere/public.h"
#include "water/public.h"
#include "terrain/public.h"
#include "ExplorerChunkSky.h"
#include "ExplorerChunkTerrain.h"
@ -60,7 +60,7 @@ static QVector<ChunkMaintenanceThread*> _threads;
static Vector3 _getCameraLocation(Renderer* renderer, Vector3)
{
return cameraGetLocation((CameraDefinition*) renderer->customData[2]);
return ((CameraDefinition*)renderer->customData[2])->getLocation();
}
static AtmosphereResult _applyAerialPerspective(Renderer*, Vector3, Color base)
@ -79,9 +79,9 @@ QGLWidget(parent)
setMinimumSize(400, 300);
setFocusPolicy(Qt::StrongFocus);
_current_camera = cameraCreateDefinition();
_current_camera = new CameraDefinition;
_base_camera = camera;
cameraCopyDefinition(camera, _current_camera);
camera->copy(_current_camera);
if (renderer)
{
@ -120,7 +120,7 @@ WidgetExplorer::~WidgetExplorer()
{
delete _chunks[i];
}
cameraDeleteDefinition(_current_camera);
delete _current_camera;
if (_renderer_created)
{
@ -226,13 +226,13 @@ void WidgetExplorer::performChunksMaintenance()
void WidgetExplorer::resetCamera()
{
cameraCopyDefinition(_base_camera, _current_camera);
_base_camera->copy(_current_camera);
updateGL();
}
void WidgetExplorer::validateCamera()
{
cameraCopyDefinition(_current_camera, _base_camera);
_current_camera->copy(_base_camera);
}
void WidgetExplorer::keyPressEvent(QKeyEvent* event)
@ -255,32 +255,32 @@ void WidgetExplorer::keyPressEvent(QKeyEvent* event)
if (event->key() == Qt::Key_Up)
{
cameraStrafeForward(_current_camera, 0.1 * factor);
_current_camera->strafeForward(0.1 * factor);
updateGL();
}
else if (event->key() == Qt::Key_Down)
{
cameraStrafeForward(_current_camera, -0.1 * factor);
_current_camera->strafeForward(-0.1 * factor);
updateGL();
}
else if (event->key() == Qt::Key_Right)
{
cameraStrafeRight(_current_camera, 0.1 * factor);
_current_camera->strafeRight(0.1 * factor);
updateGL();
}
else if (event->key() == Qt::Key_Left)
{
cameraStrafeRight(_current_camera, -0.1 * factor);
_current_camera->strafeRight(-0.1 * factor);
updateGL();
}
else if (event->key() == Qt::Key_PageUp)
{
cameraStrafeUp(_current_camera, 0.1 * factor);
_current_camera->strafeUp(0.1 * factor);
updateGL();
}
else if (event->key() == Qt::Key_PageDown)
{
cameraStrafeUp(_current_camera, -0.1 * factor);
_current_camera->strafeUp(-0.1 * factor);
updateGL();
}
else
@ -317,15 +317,15 @@ void WidgetExplorer::mouseMoveEvent(QMouseEvent* event)
if (event->buttons() & Qt::LeftButton)
{
cameraRotateYaw(_current_camera, (double) (event->x() - _last_mouse_x) * factor * 0.1);
cameraRotatePitch(_current_camera, (double) (event->y() - _last_mouse_y) * factor * 0.1);
_current_camera->rotateYaw((double) (event->x() - _last_mouse_x) * factor * 0.1);
_current_camera->rotatePitch((double) (event->y() - _last_mouse_y) * factor * 0.1);
updateGL();
event->accept();
}
else if (event->buttons() & Qt::RightButton)
{
cameraStrafeRight(_current_camera, (double) (_last_mouse_x - event->x()) * factor);
cameraStrafeUp(_current_camera, (double) (event->y() - _last_mouse_y) * factor);
_current_camera->strafeRight((double) (_last_mouse_x - event->x()) * factor);
_current_camera->strafeUp((double) (event->y() - _last_mouse_y) * factor);
updateGL();
event->accept();
}
@ -358,7 +358,7 @@ void WidgetExplorer::wheelEvent(QWheelEvent* event)
if (event->orientation() == Qt::Vertical)
{
cameraStrafeForward(_current_camera, (double) event->delta() * factor);
_current_camera->strafeForward((double) event->delta() * factor);
updateGL();
}
event->accept();
@ -394,7 +394,7 @@ void WidgetExplorer::initializeGL()
void WidgetExplorer::resizeGL(int w, int h)
{
cameraSetRenderSize(_current_camera, w, h);
_current_camera->setRenderSize(w, h);
_opengl_renderer->resize(w, h);
}
@ -405,16 +405,16 @@ void WidgetExplorer::paintGL()
double frame_time;
WaterDefinition* water = _renderer->water->definition;
cameraCopyDefinition(_current_camera, _renderer->render_camera);
cameraValidateDefinition(_current_camera, 1);
_current_camera->copy(_renderer->render_camera);
// TODO Keep camera above ground
start_time = QTime::currentTime();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Vector3 camera_location = cameraGetLocation(_current_camera);
Vector3 camera_target = cameraGetTarget(_current_camera);
Vector3 camera_up = cameraGetUpVector(_current_camera);
Vector3 camera_location = _current_camera->getLocation();
Vector3 camera_target = _current_camera->getTarget();
Vector3 camera_up = _current_camera->getUpVector();
gluLookAt(camera_location.x, camera_location.y, camera_location.z, camera_target.x, camera_target.y, camera_target.z, camera_up.x, camera_up.y, camera_up.z);
// Background

View file

@ -5,7 +5,6 @@
#include <QGLWidget>
#include <QMutex>
class CameraDefinition;
class Renderer;
namespace paysages {
@ -14,7 +13,7 @@ namespace opengl {
class OpenGLRenderer;
class BaseExplorerChunk;
class WidgetExplorer : public QGLWidget
class OPENGLSHARED_EXPORT WidgetExplorer : public QGLWidget
{
Q_OBJECT
public:

View file

@ -37,9 +37,6 @@ unix:!symbian {
INSTALLS += target
}
# TEMP
INCLUDEPATH += $$PWD/../..
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../system/release/ -lpaysages_system
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../system/debug/ -lpaysages_system
else:unix: LIBS += -L$$OUT_PWD/../../system/ -lpaysages_system

View file

@ -2,7 +2,7 @@
#include "SoftwareRenderer.h"
#include "AtmosphereRenderer.h"
#include "camera.h"
#include "CameraDefinition.h"
#include "tools/lighting.h"
#include "SurfaceMaterial.h"
@ -148,7 +148,7 @@ static inline int _checkHit(Vector3 eye, Vector3 direction, Vector3* hit, Vector
AtmosphereColorPreviewRenderer::AtmosphereColorPreviewRenderer(double heading):
heading(heading)
{
cameraSetLocation(render_camera, Vector3(0.0, 7.0, 0.0));
render_camera->setLocation(Vector3(0.0, 7.0, 0.0));
}
Color AtmosphereColorPreviewRenderer::getColor2D(double x, double y, double)
@ -158,21 +158,21 @@ Color AtmosphereColorPreviewRenderer::getColor2D(double x, double y, double)
Vector3 hit, normal;
Matrix4 rotation;
rotation = m4NewRotateY(heading);
rotation = Matrix4::newRotateY(heading);
if (_checkHit(eye, direction, &hit, &normal))
{
Color color;
normal = m4Transform(rotation, normal);
hit = m4Transform(rotation, hit);
normal = rotation.transform(normal);
hit = rotation.transform(hit);
color = this->applyLightingToSurface(this, hit, normal, &MOUNT_MATERIAL);
return this->atmosphere->applyAerialPerspective(this, hit, color).final;
}
else
{
direction = m4Transform(rotation, direction);
direction = rotation.transform(direction);
return this->atmosphere->getSkyColor(this, direction).final;
}

View file

@ -2,7 +2,7 @@
#include <QPainter>
#include "Vector3.h"
#include "camera.h"
#include "CameraDefinition.h"
PreviewOsdItem::PreviewOsdItem(int width, int height) : QImage(width, height, QImage::Format_ARGB32)
{
@ -19,8 +19,8 @@ void PreviewOsdItem::setLocation(double x, double y)
void PreviewOsdItem::drawCamera(CameraDefinition* camera)
{
Vector3 camera_location = cameraGetLocation(camera);
VectorSpherical camera_direction = cameraGetDirectionSpherical(camera);
Vector3 camera_location = camera->getLocation();
VectorSpherical camera_direction = camera->getDirectionSpherical();
int w2 = width() / 2;
int h2 = height() / 2;

View file

@ -5,8 +5,6 @@
#include <QImage>
class CameraDefinition;
namespace paysages {
namespace preview {

View file

@ -1,6 +1,6 @@
#include "SoftwareRenderer.h"
#include "camera.h"
#include "CameraDefinition.h"
#include "Scenery.h"
#include "FluidMediumManager.h"
#include "AtmosphereRenderer.h"

View file

@ -9,7 +9,7 @@
# define SOFTWARESHARED_EXPORT Q_DECL_IMPORT
#endif
#include "basics_global.h"
#include "definition_global.h"
namespace paysages {
namespace software {

View file

@ -5,7 +5,7 @@
#include "NoiseGenerator.h"
#include "PackStream.h"
#include "atmosphere/public.h"
#include "camera.h"
#include "CameraDefinition.h"
#include "clouds/public.h"
#include "terrain/public.h"
#include "textures/public.h"
@ -20,12 +20,13 @@ Scenery::Scenery():
BaseDefinition(NULL)
{
atmosphere = (AtmosphereDefinition*)AtmosphereDefinitionClass.create();
camera = cameraCreateDefinition();
camera = new CameraDefinition;
clouds = (CloudsDefinition*)CloudsDefinitionClass.create();
terrain = (TerrainDefinition*)TerrainDefinitionClass.create();
textures = (TexturesDefinition*)TexturesDefinitionClass.create();
water = new WaterDefinition(this);
addChild(camera);
addChild(water);
_custom_load = NULL;
@ -35,14 +36,10 @@ Scenery::Scenery():
Scenery::~Scenery()
{
removeChild(water);
AtmosphereDefinitionClass.destroy(atmosphere);
cameraDeleteDefinition(camera);
CloudsDefinitionClass.destroy(clouds);
TerrainDefinitionClass.destroy(terrain);
TexturesDefinitionClass.destroy(textures);
delete water;
}
Scenery* Scenery::getCurrent()
@ -64,7 +61,6 @@ void Scenery::save(PackStream* stream) const
noiseSave(stream);
AtmosphereDefinitionClass.save(stream, atmosphere);
cameraSave(stream, camera);
CloudsDefinitionClass.save(stream, clouds);
TerrainDefinitionClass.save(stream, terrain);
TexturesDefinitionClass.save(stream, textures);
@ -82,7 +78,6 @@ void Scenery::load(PackStream* stream)
noiseLoad(stream);
AtmosphereDefinitionClass.load(stream, atmosphere);
cameraLoad(stream, camera);
CloudsDefinitionClass.load(stream, clouds);
TerrainDefinitionClass.load(stream, terrain);
TexturesDefinitionClass.load(stream, textures);
@ -91,6 +86,13 @@ void Scenery::load(PackStream* stream)
{
_custom_load(stream, _custom_data);
}
validate();
}
void Scenery::validate()
{
// TODO Ensure camera is above ground and water
}
void Scenery::autoPreset(int seed)
@ -107,9 +109,10 @@ void Scenery::autoPreset(int seed)
water->applyPreset(WATER_PRESET_LAKE);
cloudsAutoPreset(clouds, CLOUDS_PRESET_PARTLY_CLOUDY);
cameraSetLocation(camera, VECTOR_ZERO);
cameraSetTarget(camera, VECTOR_NORTH);
cameraValidateDefinition(camera, 1);
camera->setLocation(VECTOR_ZERO);
camera->setTarget(VECTOR_NORTH);
validate();
}
void Scenery::setAtmosphere(AtmosphereDefinition* atmosphere)
@ -124,12 +127,12 @@ void Scenery::getAtmosphere(AtmosphereDefinition* atmosphere)
void Scenery::setCamera(CameraDefinition* camera)
{
cameraCopyDefinition(camera, this->camera);
camera->copy(this->camera);
}
void Scenery::getCamera(CameraDefinition* camera)
{
cameraCopyDefinition(this->camera, camera);
this->camera->copy(camera);
}
void Scenery::setClouds(CloudsDefinition* clouds)
@ -194,11 +197,11 @@ static double _getPrecision(Renderer* renderer, Vector3 location)
{
Vector3 projected;
projected = cameraProject(renderer->render_camera, location);
projected = renderer->render_camera->project(location);
projected.x += 1.0;
//projected.y += 1.0;
return v3Norm(v3Sub(cameraUnproject(renderer->render_camera, projected), location)); // / (double)render_quality;
return v3Norm(v3Sub(renderer->render_camera->unproject(projected), location)); // / (double)render_quality;
}
void Scenery::bindToRenderer(Renderer* renderer)
@ -207,7 +210,7 @@ void Scenery::bindToRenderer(Renderer* renderer)
renderer->rayWalking = _rayWalking;
renderer->getPrecision = _getPrecision;
cameraCopyDefinition(camera, renderer->render_camera);
camera->copy(renderer->render_camera);
AtmosphereRendererClass.bind(renderer, atmosphere);
TerrainRendererClass.bind(renderer, terrain);
TexturesRendererClass.bind(renderer, textures);

View file

@ -6,7 +6,6 @@
#include "BaseDefinition.h"
class AtmosphereDefinition;
class CameraDefinition;
class CloudsDefinition;
class TerrainDefinition;
class TexturesDefinition;
@ -32,6 +31,8 @@ public:
virtual void save(PackStream* stream) const override;
virtual void load(PackStream* stream) override;
virtual void validate() override;
void autoPreset(int seed);
void setAtmosphere(AtmosphereDefinition* atmosphere);

View file

@ -1,442 +0,0 @@
#include "camera.h"
#include <cstdlib>
#include <cmath>
#include "render.h"
#include "Scenery.h"
#include "PackStream.h"
#include "tools.h"
#include "tools/boundingbox.h"
#include "renderer.h"
#include "terrain/public.h"
#include "water/public.h"
class CameraDefinition
{
public:
/* Definition */
Vector3 location;
VectorSpherical direction;
double roll;
/* Projection info */
double width;
double height;
CameraPerspective perspective;
/* Auto updated */
Vector3 target;
Vector3 forward;
Vector3 right;
Vector3 up;
Matrix4 project;
Matrix4 unproject;
};
void cameraSave(PackStream* stream, CameraDefinition* camera)
{
v3Save(stream, &camera->location);
stream->write(&camera->direction.r);
stream->write(&camera->direction.phi);
stream->write(&camera->direction.theta);
stream->write(&camera->roll);
}
void cameraLoad(PackStream* stream, CameraDefinition* camera)
{
v3Load(stream, &camera->location);
stream->read(&camera->direction.r);
stream->read(&camera->direction.phi);
stream->read(&camera->direction.theta);
stream->read(&camera->roll);
cameraValidateDefinition(camera, 0);
}
CameraDefinition* cameraCreateDefinition()
{
CameraDefinition* definition;
definition = new CameraDefinition;
definition->location.x = 0.0;
definition->location.y = 0.0;
definition->location.z = 0.0;
definition->direction.phi = 0.0;
definition->direction.theta = 0.0;
definition->direction.r = 1.0;
definition->roll = 0.0;
definition->width = 1.0;
definition->height = 1.0;
definition->perspective.yfov = 1.57;
definition->perspective.xratio = 1.0;
definition->perspective.znear = 1.0;
definition->perspective.zfar = 1000.0;
cameraValidateDefinition(definition, 0);
return definition;
}
void cameraDeleteDefinition(CameraDefinition* definition)
{
delete definition;
}
void cameraCopyDefinition(CameraDefinition* source, CameraDefinition* destination)
{
*destination = *source;
cameraValidateDefinition(destination, 0);
}
void cameraValidateDefinition(CameraDefinition* definition, int check_above)
{
double water_height, terrain_height, diff;
Vector3 move;
Matrix4 rotation;
if (check_above)
{
TerrainDefinition* terrain = Scenery::getCurrent()->getTerrain();
terrain_height = terrainGetInterpolatedHeight(terrain, definition->location.x, definition->location.z, 1, 1) + 0.5;
water_height = terrainGetWaterHeight(terrain) + 0.5;
if (definition->location.y < water_height || definition->location.y < terrain_height)
{
if (water_height > terrain_height)
{
diff = water_height - definition->location.y;
}
else
{
diff = terrain_height - definition->location.y;
}
move.x = move.z = 0.0;
move.y = diff;
definition->location = v3Add(definition->location, move);
}
}
if (definition->location.y > 300.0)
{
definition->location.y = 300.0;
}
definition->forward.x = 1.0;
definition->forward.y = 0.0;
definition->forward.z = 0.0;
definition->right.x = 0.0;
definition->right.y = 0.0;
definition->right.z = 1.0;
definition->up.x = 0.0;
definition->up.y = 1.0;
definition->up.z = 0.0;
rotation = m4NewRotateEuler(definition->direction.phi, definition->direction.theta, definition->roll);
definition->forward = m4MultPoint(rotation, definition->forward);
definition->right = m4MultPoint(rotation, definition->right);
definition->up = m4MultPoint(rotation, definition->up);
definition->target = v3Add(definition->location, v3FromSpherical(definition->direction));
definition->project = m4Mult(m4NewPerspective(definition->perspective.yfov, definition->perspective.xratio, definition->perspective.znear, definition->perspective.zfar), m4NewLookAt(definition->location, definition->target, definition->up));
definition->unproject = m4Inverse(definition->project);
}
Vector3 cameraGetLocation(CameraDefinition* camera)
{
return camera->location;
}
Vector3 cameraGetTarget(CameraDefinition* camera)
{
return camera->target;
}
Vector3 cameraGetUpVector(CameraDefinition* camera)
{
return camera->up;
}
double cameraGetRoll(CameraDefinition* camera)
{
return camera->roll;
}
Vector3 cameraGetDirection(CameraDefinition* camera)
{
return v3FromSpherical(camera->direction);
}
Vector3 cameraGetDirectionNormalized(CameraDefinition* camera)
{
return camera->forward;
}
VectorSpherical cameraGetDirectionSpherical(CameraDefinition* camera)
{
return camera->direction;
}
CameraPerspective cameraGetPerspective(CameraDefinition* camera)
{
return camera->perspective;
}
double cameraGetRealDepth(CameraDefinition* camera, Vector3 projected)
{
/* TODO Optimize this */
Matrix4 m = m4NewPerspective(camera->perspective.yfov, camera->perspective.xratio, camera->perspective.znear, camera->perspective.zfar);
projected.x = (projected.x / (0.5 * camera->width) - 1.0);
projected.y = -(projected.y / (0.5 * camera->height) - 1.0);
return m4Transform(m4Inverse(m), projected).z;
}
void cameraSetLocation(CameraDefinition* camera, Vector3 location)
{
camera->location = location;
cameraValidateDefinition(camera, 0);
}
void cameraSetLocationCoords(CameraDefinition* camera, double x, double y, double z)
{
Vector3 v(x, y, z);
cameraSetLocation(camera, v);
}
void cameraSetTarget(CameraDefinition* camera, Vector3 target)
{
Vector3 forward;
forward = v3Sub(target, camera->location);
if (v3Norm(forward) < 0.0000001)
{
return;
}
camera->direction = v3ToSpherical(forward);
cameraValidateDefinition(camera, 0);
}
void cameraSetTargetCoords(CameraDefinition* camera, double x, double y, double z)
{
Vector3 v(x, y, z);
cameraSetTarget(camera, v);
}
void cameraSetRoll(CameraDefinition* camera, double angle)
{
camera->roll = angle;
cameraValidateDefinition(camera, 0);
}
void cameraSetZoomToTarget(CameraDefinition* camera, double zoom)
{
camera->direction.r = zoom;
camera->location = v3Add(camera->target, v3Scale(v3FromSpherical(camera->direction), -1.0));
cameraValidateDefinition(camera, 0);
}
void cameraStrafeForward(CameraDefinition* camera, double value)
{
camera->location = v3Add(camera->location, v3Scale(camera->forward, value));
cameraValidateDefinition(camera, 0);
}
void cameraStrafeRight(CameraDefinition* camera, double value)
{
camera->location = v3Add(camera->location, v3Scale(camera->right, value));
cameraValidateDefinition(camera, 0);
}
void cameraStrafeUp(CameraDefinition* camera, double value)
{
camera->location = v3Add(camera->location, v3Scale(camera->up, value));
cameraValidateDefinition(camera, 0);
}
void cameraRotateYaw(CameraDefinition* camera, double value)
{
camera->direction.phi += value;
cameraValidateDefinition(camera, 0);
}
void cameraRotatePitch(CameraDefinition* camera, double value)
{
camera->direction.theta += value;
cameraValidateDefinition(camera, 0);
}
void cameraRotateRoll(CameraDefinition* camera, double value)
{
camera->roll += value;
cameraValidateDefinition(camera, 0);
}
void cameraSetRenderSize(CameraDefinition* camera, int width, int height)
{
camera->width = (double)width;
camera->height = (double)height;
camera->perspective.xratio = camera->width / camera->height;
cameraValidateDefinition(camera, 0);
}
Vector3 cameraProject(CameraDefinition* camera, Vector3 point)
{
point = m4Transform(camera->project, point);
if (point.z < 1.0)
{
point.x = -point.x;
point.y = -point.y;
}
point.x = (point.x + 1.0) * 0.5 * camera->width;
point.y = (-point.y + 1.0) * 0.5 * camera->height;
return point;
}
Vector3 cameraUnproject(CameraDefinition* camera, Vector3 point)
{
point.x = (point.x / (0.5 * camera->width) - 1.0);
point.y = -(point.y / (0.5 * camera->height) - 1.0);
if (point.z < 1.0)
{
point.x = -point.x;
point.y = -point.y;
}
return m4Transform(camera->unproject, point);
}
/**
* Render a quad that will fill the view in front of the camera.
* This quad can be used for post-processing.
*
* @param col Color of the polygon.
* @param callback Post-processing callback.
*/
/*void cameraPushOverlay(CameraDefinition* camera, Color col, f_RenderFragmentCallback callback)
{
Vertex v1, v2, v3, v4;
Vector3 v;
v.x = 0.0;
v.y = 0.0;
v.z = 10.0;
v1.location = cameraUnproject(camera, v);
v1.color = col;
v1.callback = callback;
v.x = 0.0;
v.y = (double)render_height;
v.z = 10.0;
v2.location = cameraUnproject(camera, v);
v2.color = col;
v2.callback = callback;
v.x = (double)render_width;
v.y = (double)render_height;
v.z = 10.0;
v3.location = cameraUnproject(camera, v);
v3.color = col;
v3.callback = callback;
v.x = (double)render_width;
v.y = 0.0;
v.z = 10.0;
v4.location = cameraUnproject(camera, v);
v4.color = col;
v4.callback = callback;
renderPushQuad(&v1, &v2, &v3, &v4);
}*/
int cameraIsBoxInView(CameraDefinition* camera, Vector3 center, double xsize, double ysize, double zsize)
{
BoundingBox box;
boundingBoxReset(&box);
boundingBoxPushPoint(&box, v3Add(center, v3(-xsize, -ysize, -zsize)));
boundingBoxPushPoint(&box, v3Add(center, v3(xsize, ysize, zsize)));
return cameraIsUnprojectedBoxInView(camera, &box);
}
int cameraIsUnprojectedBoxInView(CameraDefinition* camera, BoundingBox* box)
{
BoundingBox projected;
boundingBoxReset(&projected);
boundingBoxPushPoint(&projected, cameraProject(camera, v3(box->xmin, box->ymin, box->zmin)));
boundingBoxPushPoint(&projected, cameraProject(camera, v3(box->xmax, box->ymin, box->zmin)));
boundingBoxPushPoint(&projected, cameraProject(camera, v3(box->xmin, box->ymax, box->zmin)));
boundingBoxPushPoint(&projected, cameraProject(camera, v3(box->xmax, box->ymax, box->zmin)));
boundingBoxPushPoint(&projected, cameraProject(camera, v3(box->xmin, box->ymin, box->zmax)));
boundingBoxPushPoint(&projected, cameraProject(camera, v3(box->xmax, box->ymin, box->zmax)));
boundingBoxPushPoint(&projected, cameraProject(camera, v3(box->xmin, box->ymax, box->zmax)));
boundingBoxPushPoint(&projected, cameraProject(camera, v3(box->xmax, box->ymax, box->zmax)));
return cameraIsProjectedBoxInView(camera, &projected);
}
int cameraIsProjectedBoxInView(CameraDefinition* camera, BoundingBox* box)
{
if (box->xmin <= camera->width && box->xmax >= 0.0 && box->ymin <= camera->height && box->ymax >= 0.0 && box->zmax >= camera->perspective.znear)
{
double dx = box->xmax - box->xmin;
double dy = box->ymax - box->ymin;
return (int)ceil(dx) * (int)ceil(dy);
}
else
{
return 0;
}
}
int cameraTransitionToAnother(CameraDefinition* current, CameraDefinition* wanted, double factor)
{
double dx, dy, dz, dr, dphi, dtheta, droll;
dx = wanted->location.x - current->location.x;
dy = wanted->location.y - current->location.y;
dz = wanted->location.z - current->location.z;
dr = wanted->direction.r - current->direction.r;
dphi = wanted->direction.phi - current->direction.phi;
dtheta = wanted->direction.theta - current->direction.theta;
droll = wanted->roll - current->roll;
if (fabs(dx) < 0.000001 && fabs(dy) < 0.000001 && fabs(dz) < 0.000001 && fabs(dr) < 0.000001 && fabs(dphi) < 0.000001 && fabs(dtheta) < 0.000001 && fabs(droll) < 0.000001)
{
return 0;
}
else
{
current->location.x += dx * factor;
current->location.y += dy * factor;
current->location.z += dz * factor;
current->direction.r += dr * factor;
current->direction.phi += dphi * factor;
current->direction.theta += dtheta * factor;
current->roll += droll * factor;
cameraValidateDefinition(current, 0);
return 1;
}
}

View file

@ -1,65 +0,0 @@
#ifndef _PAYSAGES_CAMERA_H_
#define _PAYSAGES_CAMERA_H_
#include "rendering_global.h"
#include "tools/euclid.h"
#include "tools/boundingbox.h"
namespace paysages {
namespace system {class PackStream;}
}
class CameraDefinition;
typedef struct
{
double yfov;
double xratio;
double znear;
double zfar;
} CameraPerspective;
RENDERINGSHARED_EXPORT void cameraSave(PackStream* stream, CameraDefinition* camera);
RENDERINGSHARED_EXPORT void cameraLoad(PackStream* stream, CameraDefinition* camera);
RENDERINGSHARED_EXPORT CameraDefinition* cameraCreateDefinition();
RENDERINGSHARED_EXPORT void cameraDeleteDefinition(CameraDefinition* definition);
RENDERINGSHARED_EXPORT void cameraCopyDefinition(CameraDefinition* source, CameraDefinition* destination);
RENDERINGSHARED_EXPORT void cameraValidateDefinition(CameraDefinition* definition, int check_above);
RENDERINGSHARED_EXPORT Vector3 cameraGetLocation(CameraDefinition* camera);
RENDERINGSHARED_EXPORT Vector3 cameraGetTarget(CameraDefinition* camera);
RENDERINGSHARED_EXPORT Vector3 cameraGetUpVector(CameraDefinition* camera);
RENDERINGSHARED_EXPORT double cameraGetRoll(CameraDefinition* camera);
RENDERINGSHARED_EXPORT Vector3 cameraGetDirection(CameraDefinition* camera);
RENDERINGSHARED_EXPORT Vector3 cameraGetDirectionNormalized(CameraDefinition* camera);
RENDERINGSHARED_EXPORT VectorSpherical cameraGetDirectionSpherical(CameraDefinition* camera);
RENDERINGSHARED_EXPORT CameraPerspective cameraGetPerspective(CameraDefinition* camera);
RENDERINGSHARED_EXPORT double cameraGetRealDepth(CameraDefinition* camera, Vector3 projected);
RENDERINGSHARED_EXPORT void cameraSetLocation(CameraDefinition* camera, Vector3 location);
RENDERINGSHARED_EXPORT void cameraSetLocationCoords(CameraDefinition* camera, double x, double y, double z);
RENDERINGSHARED_EXPORT void cameraSetTarget(CameraDefinition* camera, Vector3 target);
RENDERINGSHARED_EXPORT void cameraSetTargetCoords(CameraDefinition* camera, double x, double y, double z);
RENDERINGSHARED_EXPORT void cameraSetRoll(CameraDefinition* camera, double angle);
RENDERINGSHARED_EXPORT void cameraSetZoomToTarget(CameraDefinition* camera, double zoom);
RENDERINGSHARED_EXPORT void cameraStrafeForward(CameraDefinition* camera, double value);
RENDERINGSHARED_EXPORT void cameraStrafeRight(CameraDefinition* camera, double value);
RENDERINGSHARED_EXPORT void cameraStrafeUp(CameraDefinition* camera, double value);
RENDERINGSHARED_EXPORT void cameraRotateYaw(CameraDefinition* camera, double value);
RENDERINGSHARED_EXPORT void cameraRotatePitch(CameraDefinition* camera, double value);
RENDERINGSHARED_EXPORT void cameraRotateRoll(CameraDefinition* camera, double value);
RENDERINGSHARED_EXPORT void cameraSetRenderSize(CameraDefinition* camera, int width, int height);
RENDERINGSHARED_EXPORT Vector3 cameraProject(CameraDefinition* camera, Vector3 point);
RENDERINGSHARED_EXPORT Vector3 cameraUnproject(CameraDefinition* camera, Vector3 point);
/*void cameraPushOverlay(CameraDefinition* camera, Color col, f_RenderFragmentCallback callback);*/
RENDERINGSHARED_EXPORT int cameraIsBoxInView(CameraDefinition* camera, Vector3 center, double xsize, double ysize, double zsize);
RENDERINGSHARED_EXPORT int cameraIsUnprojectedBoxInView(CameraDefinition* camera, BoundingBox* box);
RENDERINGSHARED_EXPORT int cameraIsProjectedBoxInView(CameraDefinition* camera, BoundingBox* box);
RENDERINGSHARED_EXPORT int cameraTransitionToAnother(CameraDefinition* current, CameraDefinition* wanted, double factor);
#endif

View file

@ -5,7 +5,7 @@
#include <math.h>
#include "renderer.h"
#include "camera.h"
#include "CameraDefinition.h"
#include "PictureFile.h"
#include "Thread.h"
#include "Mutex.h"
@ -370,8 +370,8 @@ static void _scanGetDiff(ScanPoint* v1, ScanPoint* v2, ScanPoint* result)
static void _scanInterpolate(CameraDefinition* camera, ScanPoint* v1, ScanPoint* diff, double value, ScanPoint* result)
{
double v1depth = cameraGetRealDepth(camera, v1->pixel);
double v2depth = cameraGetRealDepth(camera, v3Add(v1->pixel, diff->pixel));
double v1depth = camera->getRealDepth(v1->pixel);
double v2depth = camera->getRealDepth(v1->pixel.add(diff->pixel));
double factor = ((1.0 - value) / v1depth + value / v2depth);
result->pixel.x = v1->pixel.x + diff->pixel.x * value;

View file

@ -6,7 +6,7 @@
#include "render.h"
#include "Scenery.h"
#include "tools.h"
#include "camera.h"
#include "CameraDefinition.h"
#include "atmosphere/public.h"
#include "clouds/public.h"
#include "terrain/public.h"
@ -34,7 +34,7 @@ static Vector3 _getCameraLocation(Renderer* renderer, Vector3 target)
{
UNUSED(renderer);
UNUSED(target);
return cameraGetLocation(renderer->render_camera);
return renderer->render_camera->getLocation();
}
static Vector3 _getCameraDirection(Renderer* renderer, Vector3 target)
@ -42,7 +42,7 @@ static Vector3 _getCameraDirection(Renderer* renderer, Vector3 target)
UNUSED(renderer);
UNUSED(target);
return cameraGetDirectionNormalized(renderer->render_camera);
return renderer->render_camera->getDirectionNormalized();
}
static double _getPrecision(Renderer* renderer, Vector3 location)
@ -54,12 +54,12 @@ static double _getPrecision(Renderer* renderer, Vector3 location)
static Vector3 _projectPoint(Renderer* renderer, Vector3 point)
{
return cameraProject(renderer->render_camera, point);
return renderer->render_camera->project(point);
}
static Vector3 _unprojectPoint(Renderer* renderer, Vector3 point)
{
return cameraUnproject(renderer->render_camera, point);
return renderer->render_camera->unproject(point);
}
static void _pushTriangle(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, f_RenderFragmentCallback callback, void* callback_data)
@ -132,7 +132,7 @@ Renderer::Renderer()
render_interrupt = 0;
render_progress = 0.0;
is_rendering = 0;
render_camera = cameraCreateDefinition();
render_camera = new CameraDefinition;
render_area = renderCreateArea(this);
renderSetParams(render_area, params);
@ -163,7 +163,7 @@ Renderer::Renderer()
Renderer::~Renderer()
{
cameraDeleteDefinition(render_camera);
delete render_camera;
lightingManagerDelete(lighting);
AtmosphereRendererClass.destroy(atmosphere);
@ -223,7 +223,7 @@ void rendererStart(Renderer* renderer, RenderParams params)
renderer->render_interrupt = 0;
renderer->render_progress = 0.0;
cameraSetRenderSize(renderer->render_camera, renderer->render_width, renderer->render_height);
renderer->render_camera->setRenderSize(renderer->render_width, renderer->render_height);
renderSetBackgroundColor(renderer->render_area, COLOR_BLACK);
renderSetParams(renderer->render_area, params);

View file

@ -5,7 +5,6 @@
#include "shared/types.h"
#include "render.h"
class CameraDefinition;
class LightingManager;
class AtmosphereRenderer;
class TerrainRenderer;

View file

@ -14,7 +14,6 @@ SOURCES += main.cpp \
render.cpp \
opencl.cpp \
geoarea.cpp \
camera.cpp \
atmosphere/atm_render.cpp \
atmosphere/atm_raster.cpp \
atmosphere/atm_presets.cpp \
@ -47,8 +46,6 @@ SOURCES += main.cpp \
tools/curve.cpp \
tools/color.cpp \
tools/cache.cpp \
tools/boundingbox.cpp \
tools/array.cpp \
water/wat_render.cpp \
water/wat_raster.cpp \
water/wat_preview.cpp \
@ -62,7 +59,6 @@ HEADERS += \
opencl.h \
main.h \
geoarea.h \
camera.h \
atmosphere/public.h \
atmosphere/private.h \
clouds/public.h \
@ -87,8 +83,6 @@ HEADERS += \
tools/curve.h \
tools/color.h \
tools/cache.h \
tools/boundingbox.h \
tools/array.h \
water/public.h \
water/private.h \
rendering_global.h \

View file

@ -10,7 +10,6 @@
#include <math.h>
#include "../tools/memory.h"
#include "../tools.h"
#include "../tools/array.h"
#include "PackStream.h"
#include "NoiseGenerator.h"

View file

@ -5,12 +5,12 @@
#include <stdlib.h>
#include <math.h>
#include "../tools.h"
#include "../tools/boundingbox.h"
#include "BoundingBox.h"
#include "../tools/parallel.h"
#include "../renderer.h"
#include "water/public.h"
#include "textures/public.h"
#include "camera.h"
#include "CameraDefinition.h"
/*
* Terrain rasterization.
@ -109,27 +109,26 @@ static void _getChunk(Renderer* renderer, TerrainChunkInfo* chunk, double x, dou
}
BoundingBox box;
boundingBoxReset(&box);
if (displacement_power > 0.0)
{
boundingBoxPushPoint(&box, v3Add(chunk->point_nw, v3(-displacement_power, displacement_power, -displacement_power)));
boundingBoxPushPoint(&box, v3Add(chunk->point_nw, v3(-displacement_power, -displacement_power, -displacement_power)));
boundingBoxPushPoint(&box, v3Add(chunk->point_sw, v3(-displacement_power, displacement_power, displacement_power)));
boundingBoxPushPoint(&box, v3Add(chunk->point_sw, v3(-displacement_power, -displacement_power, displacement_power)));
boundingBoxPushPoint(&box, v3Add(chunk->point_se, v3(displacement_power, displacement_power, displacement_power)));
boundingBoxPushPoint(&box, v3Add(chunk->point_se, v3(displacement_power, -displacement_power, displacement_power)));
boundingBoxPushPoint(&box, v3Add(chunk->point_ne, v3(displacement_power, displacement_power, -displacement_power)));
boundingBoxPushPoint(&box, v3Add(chunk->point_ne, v3(displacement_power, -displacement_power, -displacement_power)));
box.pushPoint(v3Add(chunk->point_nw, v3(-displacement_power, displacement_power, -displacement_power)));
box.pushPoint(v3Add(chunk->point_nw, v3(-displacement_power, -displacement_power, -displacement_power)));
box.pushPoint(v3Add(chunk->point_sw, v3(-displacement_power, displacement_power, displacement_power)));
box.pushPoint(v3Add(chunk->point_sw, v3(-displacement_power, -displacement_power, displacement_power)));
box.pushPoint(v3Add(chunk->point_se, v3(displacement_power, displacement_power, displacement_power)));
box.pushPoint(v3Add(chunk->point_se, v3(displacement_power, -displacement_power, displacement_power)));
box.pushPoint(v3Add(chunk->point_ne, v3(displacement_power, displacement_power, -displacement_power)));
box.pushPoint(v3Add(chunk->point_ne, v3(displacement_power, -displacement_power, -displacement_power)));
}
else
{
boundingBoxPushPoint(&box, chunk->point_nw);
boundingBoxPushPoint(&box, chunk->point_sw);
boundingBoxPushPoint(&box, chunk->point_se);
boundingBoxPushPoint(&box, chunk->point_ne);
box.pushPoint(chunk->point_nw);
box.pushPoint(chunk->point_sw);
box.pushPoint(chunk->point_se);
box.pushPoint(chunk->point_ne);
}
int coverage = cameraIsUnprojectedBoxInView(renderer->render_camera, &box);
int coverage = renderer->render_camera->isUnprojectedBoxInView(box);
if (coverage > 0)
{
chunk->detail_hint = (int)ceil(sqrt((double)coverage) / (double)(25 - 2 * renderer->render_quality));

View file

@ -1,123 +0,0 @@
#include "array.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
void* naiveArrayInsert(void** array, size_t item_size, int item_count, int location)
{
char** barray = (char**)array;
assert(location >= 0);
assert(location <= item_count);
*barray = (char*)realloc(*barray, item_size * (item_count + 1));
if (location < item_count)
{
memmove(*barray + item_size * (location + 1), *barray + item_size * location, item_size * (item_count - location));
}
return *barray + item_size * location;
}
void arrayCreate(Array* array, int item_size)
{
array->length = 0;
array->alloc_length = 1;
array->item_size = item_size;
array->dirty = 1;
array->data = malloc((size_t)item_size * array->alloc_length);
}
void arrayDelete(Array* array)
{
free(array->data);
array->data = NULL;
}
void* arrayAppend(Array* array, void* item)
{
char* dest;
size_t item_size = (size_t)array->item_size;
if (array->length >= array->alloc_length)
{
array->alloc_length += 1;
array->data = realloc(array->data, item_size * array->alloc_length);
}
dest = ((char*)array->data) + item_size * array->length;
memcpy(dest, item, item_size);
array->length++;
array->dirty = 1;
return dest;
}
void arrayInsert(Array* array, void* item, int position)
{
size_t item_size;
char* dest;
if (position >= array->length)
{
arrayAppend(array, item);
}
else if (position >= 0)
{
item_size = (size_t)array->item_size;
if (array->length >= array->alloc_length)
{
array->alloc_length += 10;
array->data = realloc(array->data, item_size * array->alloc_length);
}
dest = ((char*)array->data) + item_size * position;
memmove(dest + item_size, dest, array->length - position);
memcpy(((char*)array->data) + item_size * position, item, item_size);
array->length++;
array->dirty = 1;
}
}
void arrayReplace(Array* array, void* item, int position)
{
size_t item_size;
if (position >= 0 && position < array->length)
{
item_size = (size_t)array->item_size;
memcpy(((char*)array->data) + item_size * position, item, item_size);
array->dirty = 1;
}
}
void arrayLStrip(Array* array, int count)
{
size_t item_size;
if (count >= array->length)
{
arrayClear(array);
}
else if (count >= 0)
{
item_size = (size_t)array->item_size;
memmove(array->data, ((char*)array->data) + item_size * count, item_size * (array->length - count));
array->length -= count;
array->dirty = 1;
}
}
void arrayClear(Array* array)
{
free(array->data);
array->length = 0;
array->alloc_length = 1;
array->data = malloc((size_t)array->item_size * array->alloc_length);
array->dirty = 1;
}

View file

@ -1,34 +0,0 @@
#ifndef _PAYSAGES_TOOLS_ARRAY_H_
#define _PAYSAGES_TOOLS_ARRAY_H_
#include "../rendering_global.h"
#include "../shared/types.h"
#include <stdlib.h>
/**************** Naive methods (basic C arrays) ****************/
/*
* Insert an item at a given position, rallocating the array, moving data and returning a pointer to the inserted element.
*/
RENDERINGSHARED_EXPORT void* naiveArrayInsert(void** array, size_t item_size, int item_count, int location);
/**************** Array object ****************/
typedef struct
{
int length;
int alloc_length;
int item_size;
int dirty;
void* data;
} Array;
RENDERINGSHARED_EXPORT void arrayCreate(Array* array, int item_size);
RENDERINGSHARED_EXPORT void arrayDelete(Array* array);
RENDERINGSHARED_EXPORT void* arrayAppend(Array* array, void* item);
RENDERINGSHARED_EXPORT void arrayInsert(Array* array, void* item, int position);
RENDERINGSHARED_EXPORT void arrayReplace(Array* array, void* item, int position);
RENDERINGSHARED_EXPORT void arrayLStrip(Array* array, int count);
RENDERINGSHARED_EXPORT void arrayClear(Array* array);
#endif

View file

@ -1,41 +0,0 @@
#include "boundingbox.h"
void boundingBoxReset(BoundingBox* box)
{
box->empty = 1;
box->xmin = 10000000000.0;
box->xmax = -10000000000.0;
box->ymin = 10000000000.0;
box->ymax = -10000000000.0;
box->zmin = 10000000000.0;
box->zmax = -10000000000.0;
}
void boundingBoxPushPoint(BoundingBox* box, Vector3 point)
{
box->empty = 0;
if (point.x < box->xmin)
{
box->xmin = point.x;
}
if (point.x > box->xmax)
{
box->xmax = point.x;
}
if (point.y < box->ymin)
{
box->ymin = point.y;
}
if (point.y > box->ymax)
{
box->ymax = point.y;
}
if (point.z < box->zmin)
{
box->zmin = point.z;
}
if (point.z > box->zmax)
{
box->zmax = point.z;
}
}

View file

@ -1,21 +0,0 @@
#ifndef _RENDERING_TOOLS_BOUNDINGBOX_H_
#define _RENDERING_TOOLS_BOUNDINGBOX_H_
#include "../rendering_global.h"
#include "euclid.h"
typedef struct
{
int empty;
double xmin;
double xmax;
double ymin;
double ymax;
double zmin;
double zmax;
} BoundingBox;
RENDERINGSHARED_EXPORT void boundingBoxReset(BoundingBox* box);
RENDERINGSHARED_EXPORT void boundingBoxPushPoint(BoundingBox* box, Vector3 point);
#endif

View file

@ -3,309 +3,6 @@
#include <math.h>
#include "PackStream.h"
void m4Save(PackStream* stream, Matrix4* m)
{
stream->write(&m->a);
stream->write(&m->b);
stream->write(&m->c);
stream->write(&m->d);
stream->write(&m->e);
stream->write(&m->f);
stream->write(&m->g);
stream->write(&m->h);
stream->write(&m->i);
stream->write(&m->j);
stream->write(&m->k);
stream->write(&m->l);
stream->write(&m->m);
stream->write(&m->n);
stream->write(&m->o);
stream->write(&m->p);
}
void m4Load(PackStream* stream, Matrix4* m)
{
stream->read(&m->a);
stream->read(&m->b);
stream->read(&m->c);
stream->read(&m->d);
stream->read(&m->e);
stream->read(&m->f);
stream->read(&m->g);
stream->read(&m->h);
stream->read(&m->i);
stream->read(&m->j);
stream->read(&m->k);
stream->read(&m->l);
stream->read(&m->m);
stream->read(&m->n);
stream->read(&m->o);
stream->read(&m->p);
}
Matrix4 m4NewIdentity()
{
Matrix4 result;
result.a = result.f = result.k = result.p = 1.0;
result.b = result.c = result.d = result.e = result.g = result.h = 0.0;
result.i = result.j = result.l = result.m = result.n = result.o = 0.0;
return result;
}
Matrix4 m4Mult(Matrix4 m1, Matrix4 m2)
{
Matrix4 result;
result.a = m1.a * m2.a + m1.b * m2.e + m1.c * m2.i + m1.d * m2.m;
result.b = m1.a * m2.b + m1.b * m2.f + m1.c * m2.j + m1.d * m2.n;
result.c = m1.a * m2.c + m1.b * m2.g + m1.c * m2.k + m1.d * m2.o;
result.d = m1.a * m2.d + m1.b * m2.h + m1.c * m2.l + m1.d * m2.p;
result.e = m1.e * m2.a + m1.f * m2.e + m1.g * m2.i + m1.h * m2.m;
result.f = m1.e * m2.b + m1.f * m2.f + m1.g * m2.j + m1.h * m2.n;
result.g = m1.e * m2.c + m1.f * m2.g + m1.g * m2.k + m1.h * m2.o;
result.h = m1.e * m2.d + m1.f * m2.h + m1.g * m2.l + m1.h * m2.p;
result.i = m1.i * m2.a + m1.j * m2.e + m1.k * m2.i + m1.l * m2.m;
result.j = m1.i * m2.b + m1.j * m2.f + m1.k * m2.j + m1.l * m2.n;
result.k = m1.i * m2.c + m1.j * m2.g + m1.k * m2.k + m1.l * m2.o;
result.l = m1.i * m2.d + m1.j * m2.h + m1.k * m2.l + m1.l * m2.p;
result.m = m1.m * m2.a + m1.n * m2.e + m1.o * m2.i + m1.p * m2.m;
result.n = m1.m * m2.b + m1.n * m2.f + m1.o * m2.j + m1.p * m2.n;
result.o = m1.m * m2.c + m1.n * m2.g + m1.o * m2.k + m1.p * m2.o;
result.p = m1.m * m2.d + m1.n * m2.h + m1.o * m2.l + m1.p * m2.p;
return result;
}
Vector3 m4MultPoint(Matrix4 m, Vector3 v)
{
Vector3 result;
result.x = m.a * v.x + m.b * v.y + m.c * v.z + m.d;
result.y = m.e * v.x + m.f * v.y + m.g * v.z + m.h;
result.z = m.i * v.x + m.j * v.y + m.k * v.z + m.l;
return result;
}
Vector3 m4Transform(Matrix4 m, Vector3 v)
{
Vector3 result;
double w;
result.x = m.a * v.x + m.b * v.y + m.c * v.z + m.d;
result.y = m.e * v.x + m.f * v.y + m.g * v.z + m.h;
result.z = m.i * v.x + m.j * v.y + m.k * v.z + m.l;
w = m.m * v.x + m.n * v.y + m.o * v.z + m.p;
if (w != 0.0)
{
result.x /= w;
result.y /= w;
result.z /= w;
}
return result;
}
Matrix4 m4Transpose(Matrix4 m)
{
Matrix4 result;
result.a = m.a;
result.e = m.b;
result.i = m.c;
result.m = m.d;
result.b = m.e;
result.f = m.f;
result.j = m.g;
result.n = m.h;
result.c = m.i;
result.g = m.j;
result.k = m.k;
result.o = m.l;
result.d = m.m;
result.h = m.n;
result.l = m.o;
result.p = m.p;
return result;
}
Matrix4 m4NewScale(double x, double y, double z)
{
Matrix4 result = m4NewIdentity();
result.a = x;
result.f = y;
result.k = z;
return result;
}
Matrix4 m4NewTranslate(double x, double y, double z)
{
Matrix4 result = m4NewIdentity();
result.d = x;
result.h = y;
result.l = z;
return result;
}
Matrix4 m4NewRotateX(double angle)
{
Matrix4 result = m4NewIdentity();
double s = sin(angle);
double c = cos(angle);
result.f = result.k = c;
result.g = -s;
result.j = s;
return result;
}
Matrix4 m4NewRotateY(double angle)
{
Matrix4 result = m4NewIdentity();
double s = sin(angle);
double c = cos(angle);
result.a = result.k = c;
result.c = s;
result.i = -s;
return result;
}
Matrix4 m4NewRotateZ(double angle)
{
Matrix4 result = m4NewIdentity();
double s = sin(angle);
double c = cos(angle);
result.a = result.f = c;
result.b = -s;
result.e = s;
return result;
}
Matrix4 m4NewRotateAxis(double angle, Vector3 axis)
{
Matrix4 result = m4NewIdentity();
double s = sin(angle);
double c = cos(angle);
double c1 = 1.0 - c;
axis = v3Normalize(axis);
result.a = axis.x * axis.x * c1 + c;
result.b = axis.x * axis.y * c1 - axis.z * s;
result.c = axis.x * axis.z * c1 + axis.y * s;
result.e = axis.y * axis.x * c1 + axis.z * s;
result.f = axis.y * axis.y * c1 + c;
result.g = axis.y * axis.z * c1 - axis.x * s;
result.i = axis.x * axis.z * c1 - axis.y * s;
result.j = axis.y * axis.z * c1 + axis.x * s;
result.k = axis.z * axis.z * c1 + c;
return result;
}
Matrix4 m4NewRotateEuler(double heading, double attitude, double bank)
{
Matrix4 result = m4NewIdentity();
double ch = cos(heading);
double sh = sin(heading);
double ca = cos(attitude);
double sa = sin(attitude);
double cb = cos(bank);
double sb = sin(bank);
result.a = ch * ca;
result.b = sh * sb - ch * sa * cb;
result.c = ch * sa * sb + sh * cb;
result.e = sa;
result.f = ca * cb;
result.g = -ca * sb;
result.i = -sh * ca;
result.j = sh * sa * cb + ch * sb;
result.k = -sh * sa * sb + ch * cb;
return result;
}
Matrix4 m4NewRotateTripleAxis(Vector3 x, Vector3 y, Vector3 z)
{
Matrix4 result = m4NewIdentity();
result.a = x.x;
result.b = y.x;
result.c = z.x;
result.e = x.y;
result.f = y.y;
result.g = z.y;
result.i = x.z;
result.j = y.z;
result.k = z.z;
return result;
}
Matrix4 m4NewLookAt(Vector3 eye, Vector3 at, Vector3 up)
{
Vector3 z = v3Normalize(v3Sub(at, eye));
Vector3 x = v3Normalize(v3Cross(up, z));
Vector3 y = v3Cross(z, x);
Matrix4 result = m4NewRotateTripleAxis(x, y, z);
result.d = eye.x;
result.h = eye.y;
result.l = eye.z;
return m4Inverse(result);
}
Matrix4 m4NewPerspective(double fov_y, double aspect, double near, double far)
{
Matrix4 result = m4NewIdentity();
double f = 1 / tan(fov_y / 2.0);
result.a = f / aspect;
result.f = f;
result.k = (far + near) / (near - far);
result.l = 2.0 * far * near / (near - far);
result.o = -1.0;
result.p = 0.0;
return result;
}
double m4Determinant(Matrix4 m)
{
return ((m.a * m.f - m.e * m.b)
* (m.k * m.p - m.o * m.l)
- (m.a * m.j - m.i * m.b)
* (m.g * m.p - m.o * m.h)
+ (m.a * m.n - m.m * m.b)
* (m.g * m.l - m.k * m.h)
+ (m.e * m.j - m.i * m.f)
* (m.c * m.p - m.o * m.d)
- (m.e * m.n - m.m * m.f)
* (m.c * m.l - m.k * m.d)
+ (m.i * m.n - m.m * m.j)
* (m.c * m.h - m.g * m.d));
}
Matrix4 m4Inverse(Matrix4 m)
{
Matrix4 result;
double d = m4Determinant(m);
if (fabs(d) < 0.00001)
{
return m4NewIdentity();
}
else
{
d = 1.0 / d;
result.a = d * (m.f * (m.k * m.p - m.o * m.l) + m.j * (m.o * m.h - m.g * m.p) + m.n * (m.g * m.l - m.k * m.h));
result.e = d * (m.g * (m.i * m.p - m.m * m.l) + m.k * (m.m * m.h - m.e * m.p) + m.o * (m.e * m.l - m.i * m.h));
result.i = d * (m.h * (m.i * m.n - m.m * m.j) + m.l * (m.m * m.f - m.e * m.n) + m.p * (m.e * m.j - m.i * m.f));
result.m = d * (m.e * (m.n * m.k - m.j * m.o) + m.i * (m.f * m.o - m.n * m.g) + m.m * (m.j * m.g - m.f * m.k));
result.b = d * (m.j * (m.c * m.p - m.o * m.d) + m.n * (m.k * m.d - m.c * m.l) + m.b * (m.o * m.l - m.k * m.p));
result.f = d * (m.k * (m.a * m.p - m.m * m.d) + m.o * (m.i * m.d - m.a * m.l) + m.c * (m.m * m.l - m.i * m.p));
result.j = d * (m.l * (m.a * m.n - m.m * m.b) + m.p * (m.i * m.b - m.a * m.j) + m.d * (m.m * m.j - m.i * m.n));
result.n = d * (m.i * (m.n * m.c - m.b * m.o) + m.m * (m.b * m.k - m.j * m.c) + m.a * (m.j * m.o - m.n * m.k));
result.c = d * (m.n * (m.c * m.h - m.g * m.d) + m.b * (m.g * m.p - m.o * m.h) + m.f * (m.o * m.d - m.c * m.p));
result.g = d * (m.o * (m.a * m.h - m.e * m.d) + m.c * (m.e * m.p - m.m * m.h) + m.g * (m.m * m.d - m.a * m.p));
result.k = d * (m.p * (m.a * m.f - m.e * m.b) + m.d * (m.e * m.n - m.m * m.f) + m.h * (m.m * m.b - m.a * m.n));
result.o = d * (m.m * (m.f * m.c - m.b * m.g) + m.a * (m.n * m.g - m.f * m.o) + m.e * (m.b * m.o - m.n * m.c));
result.d = d * (m.b * (m.k * m.h - m.g * m.l) + m.f * (m.c * m.l - m.k * m.d) + m.j * (m.g * m.d - m.c * m.h));
result.h = d * (m.c * (m.i * m.h - m.e * m.l) + m.g * (m.a * m.l - m.i * m.d) + m.k * (m.e * m.d - m.a * m.h));
result.l = d * (m.d * (m.i * m.f - m.e * m.j) + m.h * (m.a * m.j - m.i * m.b) + m.l * (m.e * m.b - m.a * m.f));
result.p = d * (m.a * (m.f * m.k - m.j * m.g) + m.e * (m.j * m.c - m.b * m.k) + m.i * (m.b * m.g - m.f * m.c));
return result;
}
}
double euclidGet2DAngle(double x, double y)
{
double nx, ny, d, ret;

View file

@ -10,46 +10,6 @@ namespace paysages {
namespace system {class PackStream;}
}
typedef struct
{
double a;
double b;
double c;
double d;
double e;
double f;
double g;
double h;
double i;
double j;
double k;
double l;
double m;
double n;
double o;
double p;
} Matrix4;
RENDERINGSHARED_EXPORT void m4Save(PackStream* stream, Matrix4* m);
RENDERINGSHARED_EXPORT void m4Load(PackStream* stream, Matrix4* m);
RENDERINGSHARED_EXPORT Matrix4 m4NewIdentity();
RENDERINGSHARED_EXPORT Matrix4 m4Mult(Matrix4 m1, Matrix4 m2);
RENDERINGSHARED_EXPORT Vector3 m4MultPoint(Matrix4 m, Vector3 v);
RENDERINGSHARED_EXPORT Vector3 m4Transform(Matrix4 m, Vector3 v);
RENDERINGSHARED_EXPORT Matrix4 m4Transpose(Matrix4 m);
RENDERINGSHARED_EXPORT Matrix4 m4NewScale(double x, double y, double z);
RENDERINGSHARED_EXPORT Matrix4 m4NewTranslate(double x, double y, double z);
RENDERINGSHARED_EXPORT Matrix4 m4NewRotateX(double angle);
RENDERINGSHARED_EXPORT Matrix4 m4NewRotateY(double angle);
RENDERINGSHARED_EXPORT Matrix4 m4NewRotateZ(double angle);
RENDERINGSHARED_EXPORT Matrix4 m4NewRotateAxis(double angle, Vector3 axis);
RENDERINGSHARED_EXPORT Matrix4 m4NewRotateEuler(double heading, double attitude, double bank);
RENDERINGSHARED_EXPORT Matrix4 m4NewRotateTripleAxis(Vector3 x, Vector3 y, Vector3 z);
RENDERINGSHARED_EXPORT Matrix4 m4NewLookAt(Vector3 eye, Vector3 at, Vector3 up);
RENDERINGSHARED_EXPORT Matrix4 m4NewPerspective(double fov_y, double aspect, double near, double far);
RENDERINGSHARED_EXPORT double m4Determinant(Matrix4 m);
RENDERINGSHARED_EXPORT Matrix4 m4Inverse(Matrix4 m);
RENDERINGSHARED_EXPORT double euclidGet2DAngle(double x, double y);
RENDERINGSHARED_EXPORT Vector3 euclidGetNormalFromTriangle(Vector3 center, Vector3 bottom, Vector3 right);
RENDERINGSHARED_EXPORT double euclidGetDistance2D(double x1, double y1, double x2, double y2);

View file

@ -1,7 +1,24 @@
#include "memory.h"
#include <stdlib.h>
#include <string.h>
#include <cstdlib>
#include <cstring>
#include <cassert>
void* naiveArrayInsert(void** array, size_t item_size, int item_count, int location)
{
char** barray = (char**)array;
assert(location >= 0);
assert(location <= item_count);
*barray = (char*)realloc(*barray, item_size * (item_count + 1));
if (location < item_count)
{
memmove(*barray + item_size * (location + 1), *barray + item_size * location, item_size * (item_count - location));
}
return *barray + item_size * location;
}
char* memory2dRealloc(char* data, int datasize, int oldxsize, int oldysize, int newxsize, int newysize, int xoffset, int yoffset)
{

View file

@ -8,5 +8,6 @@
#include "../rendering_global.h"
RENDERINGSHARED_EXPORT char* memory2dRealloc(char* data, int datasize, int oldxsize, int oldysize, int newxsize, int newysize, int xoffset, int yoffset);
RENDERINGSHARED_EXPORT void* naiveArrayInsert(void** array, size_t item_size, int item_count, int location);
#endif

View file

@ -1,7 +1,7 @@
#include "BaseTestCase.h"
#include "tools/color.h"
#include "camera.h"
#include "CameraDefinition.h"
#include "SoftwareRenderer.h"
#include "atmosphere/public.h"
#include "Scenery.h"
@ -22,9 +22,9 @@ TEST(Bruneton, AerialPerspective1)
renderer.render_height = 600;
renderer.render_quality = 1;
cameraSetLocation(renderer.render_camera, VECTOR_ZERO);
cameraSetTarget(renderer.render_camera, VECTOR_EAST);
cameraSetRenderSize(renderer.render_camera, renderer.render_width, renderer.render_height);
renderer.render_camera->setLocation(VECTOR_ZERO);
renderer.render_camera->setTarget(VECTOR_EAST);
renderer.render_camera->setRenderSize(renderer.render_width, renderer.render_height);
RenderParams params = {renderer.render_width, renderer.render_height, 1, 1};
renderSetParams(renderer.render_area, params);
@ -53,9 +53,9 @@ TEST(Bruneton, AerialPerspective2)
renderer.render_height = 600;
renderer.render_quality = 1;
cameraSetLocation(renderer.render_camera, VECTOR_ZERO);
cameraSetTarget(renderer.render_camera, VECTOR_EAST);
cameraSetRenderSize(renderer.render_camera, renderer.render_width, renderer.render_height);
renderer.render_camera->setLocation(VECTOR_ZERO);
renderer.render_camera->setTarget(VECTOR_EAST);
renderer.render_camera->setRenderSize(renderer.render_width, renderer.render_height);
RenderParams params = {renderer.render_width, renderer.render_height, 1, 1};
renderSetParams(renderer.render_area, params);

View file

@ -1,55 +1,46 @@
#include "BaseTestCase.h"
#include "camera.h"
#include "CameraDefinition.h"
TEST(Camera, Definition)
{
CameraDefinition* cam;
cam = cameraCreateDefinition();
CameraDefinition cam;
cameraSetLocationCoords(cam, 0.0, 1.0, 1.0);
cameraSetTargetCoords(cam, 0.0, 0.0, 0.0);
cam.setLocationCoords(0.0, 1.0, 1.0);
cam.setTargetCoords(0.0, 0.0, 0.0);
EXPECT_VECTOR3_COORDS(cameraGetLocation(cam), 0.0, 1.0, 1.0);
EXPECT_VECTOR3_COORDS(cameraGetTarget(cam), 0.0, 0.0, 0.0);
cameraDeleteDefinition(cam);
EXPECT_VECTOR3_COORDS(cam.getLocation(), 0.0, 1.0, 1.0);
EXPECT_VECTOR3_COORDS(cam.getTarget(), 0.0, 0.0, 0.0);
}
TEST(Camera, Projection)
{
CameraDefinition* cam;
cam = cameraCreateDefinition();
CameraDefinition cam;
cameraSetLocationCoords(cam, 0.0, 1.0, 1.0);
cameraSetTargetCoords(cam, 0.0, 0.0, 0.0);
cam.setLocationCoords(0.0, 1.0, 1.0);
cam.setTargetCoords(0.0, 0.0, 0.0);
/* Test the reversibility of projection */
Vector3 point = cameraProject(cam, v3(12.0, 5.2, -6.3));
point = cameraUnproject(cam, point);
Vector3 point = cam.project(Vector3(12.0, 5.2, -6.3));
point = cam.unproject(point);
EXPECT_VECTOR3_COORDS(point, 12.0, 5.2, -6.3);
point = cameraProject(cam, v3(-25.1, 8.3, 1.3));
point = cameraUnproject(cam, point);
point = cam.project(Vector3(-25.1, 8.3, 1.3));
point = cam.unproject(point);
EXPECT_VECTOR3_COORDS(point, -25.1, 8.3, 1.3);
cameraDeleteDefinition(cam);
}
TEST(Camera, Depth)
{
CameraDefinition* cam;
cam = cameraCreateDefinition();
CameraDefinition cam;
cameraSetLocationCoords(cam, 0.0, 0.0, 0.0);
cameraSetTargetCoords(cam, 1.0, 0.0, 0.0);
cam.setLocationCoords(0.0, 0.0, 0.0);
cam.setTargetCoords(1.0, 0.0, 0.0);
/* Test the real depth getter */
Vector3 point = cameraProject(cam, v3(12.5, 0.0, 0.0));
ASSERT_DOUBLE_EQ(cameraGetRealDepth(cam, point), 12.5);
point = cameraProject(cam, v3(12.5, 8.0, -3.0));
ASSERT_DOUBLE_EQ(cameraGetRealDepth(cam, point), 12.5);
point = cameraProject(cam, v3(12.5, 12.0, 58.0));
ASSERT_DOUBLE_EQ(cameraGetRealDepth(cam, point), 12.5);
cameraDeleteDefinition(cam);
Vector3 point = cam.project(Vector3(12.5, 0.0, 0.0));
ASSERT_DOUBLE_EQ(cam.getRealDepth(point), 12.5);
point = cam.project(Vector3(12.5, 8.0, -3.0));
ASSERT_DOUBLE_EQ(cam.getRealDepth(point), 12.5);
point = cam.project(Vector3(12.5, 12.0, 58.0));
ASSERT_DOUBLE_EQ(cam.getRealDepth(point), 12.5);
}

View file

@ -2,7 +2,7 @@
#include <cmath>
#include "renderer.h"
#include "camera.h"
#include "CameraDefinition.h"
#include "System.h"
static Color _postProcessFragment(Renderer*, Vector3 location, void*)
@ -38,9 +38,9 @@ TEST(Render, quad)
renderer->render_quality = 1;
renderSetToneMapping(renderer->render_area, TONE_MAPPING_CLAMP, 0.0);
cameraSetLocationCoords(renderer->render_camera, 0.0, 0.5, 2.0);
cameraSetTargetCoords(renderer->render_camera, 0.0, 0.5, 0.0);
cameraSetRenderSize(renderer->render_camera, renderer->render_width, renderer->render_height);
renderer->render_camera->setLocationCoords(0.0, 0.5, 2.0);
renderer->render_camera->setTargetCoords(0.0, 0.5, 0.0);
renderer->render_camera->setRenderSize(renderer->render_width, renderer->render_height);
RenderParams params = {renderer->render_width, renderer->render_height, 1, 1};
renderSetParams(renderer->render_area, params);