Small source code improvements
This commit is contained in:
parent
aecd3dcdf3
commit
c5d73f96a2
8 changed files with 38 additions and 19 deletions
|
@ -9,6 +9,9 @@ InfiniteCylinder::InfiniteCylinder(const InfiniteRay &axis, double radius) : axi
|
||||||
validate();
|
validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InfiniteCylinder::~InfiniteCylinder() {
|
||||||
|
}
|
||||||
|
|
||||||
int InfiniteCylinder::findRayIntersection(const InfiniteRay &ray, Vector3 *first_intersection,
|
int InfiniteCylinder::findRayIntersection(const InfiniteRay &ray, Vector3 *first_intersection,
|
||||||
Vector3 *second_intersection) const {
|
Vector3 *second_intersection) const {
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -15,6 +15,7 @@ class BASICSSHARED_EXPORT InfiniteCylinder {
|
||||||
public:
|
public:
|
||||||
InfiniteCylinder() = default;
|
InfiniteCylinder() = default;
|
||||||
InfiniteCylinder(const InfiniteRay &axis, double radius);
|
InfiniteCylinder(const InfiniteRay &axis, double radius);
|
||||||
|
virtual ~InfiniteCylinder();
|
||||||
|
|
||||||
inline const InfiniteRay &getAxis() const {
|
inline const InfiniteRay &getAxis() const {
|
||||||
return axis;
|
return axis;
|
||||||
|
|
|
@ -25,7 +25,6 @@ class OpenGLVegetationLayer;
|
||||||
class OpenGLVegetationInstance;
|
class OpenGLVegetationInstance;
|
||||||
class OpenGLVegetationImpostor;
|
class OpenGLVegetationImpostor;
|
||||||
class OpenGLTerrainChunk;
|
class OpenGLTerrainChunk;
|
||||||
template <typename Vertex> class VertexArray;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
using namespace paysages::opengl;
|
using namespace paysages::opengl;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "GodRaysSampler.h"
|
#include "GodRaysSampler.h"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <algorithm>
|
||||||
#include "GodRaysDefinition.h"
|
#include "GodRaysDefinition.h"
|
||||||
#include "AtmosphereDefinition.h"
|
#include "AtmosphereDefinition.h"
|
||||||
#include "SoftwareRenderer.h"
|
#include "SoftwareRenderer.h"
|
||||||
|
@ -13,7 +15,6 @@
|
||||||
#include "TerrainDefinition.h"
|
#include "TerrainDefinition.h"
|
||||||
#include "CloudsRenderer.h"
|
#include "CloudsRenderer.h"
|
||||||
#include "Interpolation.h"
|
#include "Interpolation.h"
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
GodRaysSampler::GodRaysSampler() {
|
GodRaysSampler::GodRaysSampler() {
|
||||||
enabled = true;
|
enabled = true;
|
||||||
|
@ -48,16 +49,14 @@ void GodRaysSampler::prepare(SoftwareRenderer *renderer) {
|
||||||
void GodRaysSampler::reset() {
|
void GodRaysSampler::reset() {
|
||||||
*bounds = SpaceSegment(Vector3(camera_location->x - max_length, low_altitude, camera_location->z - max_length),
|
*bounds = SpaceSegment(Vector3(camera_location->x - max_length, low_altitude, camera_location->z - max_length),
|
||||||
Vector3(camera_location->x + max_length, high_altitude, camera_location->z + max_length));
|
Vector3(camera_location->x + max_length, high_altitude, camera_location->z + max_length));
|
||||||
samples_x = round(bounds->getXDiff() / sampling_step) + 1;
|
samples_x = round_to_int(bounds->getXDiff() / sampling_step) + 1;
|
||||||
samples_y = round(bounds->getYDiff() / sampling_step) + 1;
|
samples_y = round_to_int(bounds->getYDiff() / sampling_step) + 1;
|
||||||
samples_z = round(bounds->getZDiff() / sampling_step) + 1;
|
samples_z = round_to_int(bounds->getZDiff() / sampling_step) + 1;
|
||||||
|
|
||||||
long n = samples_x * samples_y * samples_z;
|
auto n = to_size(samples_x * samples_y * samples_z);
|
||||||
delete[] data;
|
delete[] data;
|
||||||
data = new double[n];
|
data = new double[n];
|
||||||
for (long i = 0; i < n; i++) {
|
fill_n(data, n, -1.0);
|
||||||
data[i] = -1.0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GodRaysSampler::setEnabled(bool enabled) {
|
void GodRaysSampler::setEnabled(bool enabled) {
|
||||||
|
@ -110,9 +109,9 @@ double GodRaysSampler::getCachedLight(const Vector3 &location) {
|
||||||
double y = location.y - bounds->getStart().y;
|
double y = location.y - bounds->getStart().y;
|
||||||
double z = location.z - bounds->getStart().z;
|
double z = location.z - bounds->getStart().z;
|
||||||
|
|
||||||
int ix = (int)floor(x / sampling_step);
|
int ix = floor_to_int(x / sampling_step);
|
||||||
int iy = (int)floor(y / sampling_step);
|
int iy = floor_to_int(y / sampling_step);
|
||||||
int iz = (int)floor(z / sampling_step);
|
int iz = floor_to_int(z / sampling_step);
|
||||||
|
|
||||||
// Check cache limits
|
// Check cache limits
|
||||||
if (ix < 0 || ix >= samples_x - 1 || iy < 0 || iy >= samples_y - 1 || iz < 0 || iz >= samples_z - 1) {
|
if (ix < 0 || ix >= samples_x - 1 || iy < 0 || iy >= samples_y - 1 || iz < 0 || iz >= samples_z - 1) {
|
||||||
|
@ -171,8 +170,8 @@ inline double GodRaysSampler::getCache(int x, int y, int z) {
|
||||||
double *cache = data + z * samples_x * samples_y + y * samples_x + x;
|
double *cache = data + z * samples_x * samples_y + y * samples_x + x;
|
||||||
if (*cache < 0.0) {
|
if (*cache < 0.0) {
|
||||||
Vector3 location =
|
Vector3 location =
|
||||||
Vector3(bounds->getStart().x + sampling_step * (double)x, bounds->getStart().y + sampling_step * (double)y,
|
Vector3(bounds->getStart().x + sampling_step * to_double(x), bounds->getStart().y + sampling_step * to_double(y),
|
||||||
bounds->getStart().z + sampling_step * (double)z);
|
bounds->getStart().z + sampling_step * to_double(z));
|
||||||
double unfiltered_power = getRawLight(location, false).getPower();
|
double unfiltered_power = getRawLight(location, false).getPower();
|
||||||
if (unfiltered_power == 0.0) {
|
if (unfiltered_power == 0.0) {
|
||||||
*cache = 1.0;
|
*cache = 1.0;
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
#define MUTEX_H
|
#define MUTEX_H
|
||||||
|
|
||||||
#include "system_global.h"
|
#include "system_global.h"
|
||||||
#include <QMutex>
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
namespace paysages {
|
namespace paysages {
|
||||||
namespace system {
|
namespace system {
|
||||||
|
@ -10,7 +11,7 @@ namespace system {
|
||||||
/*!
|
/*!
|
||||||
* \brief System mutex
|
* \brief System mutex
|
||||||
*/
|
*/
|
||||||
class SYSTEMSHARED_EXPORT Mutex : private QMutex {
|
class SYSTEMSHARED_EXPORT Mutex : private mutex {
|
||||||
public:
|
public:
|
||||||
/*!
|
/*!
|
||||||
* \brief Create a new mutex
|
* \brief Create a new mutex
|
||||||
|
@ -18,10 +19,10 @@ class SYSTEMSHARED_EXPORT Mutex : private QMutex {
|
||||||
Mutex();
|
Mutex();
|
||||||
|
|
||||||
inline void acquire() {
|
inline void acquire() {
|
||||||
QMutex::lock();
|
mutex::lock();
|
||||||
}
|
}
|
||||||
inline void release() {
|
inline void release() {
|
||||||
QMutex::unlock();
|
mutex::unlock();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
|
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
|
|
||||||
|
PictureWriter::PictureWriter() {
|
||||||
|
}
|
||||||
|
|
||||||
|
PictureWriter::~PictureWriter() {
|
||||||
|
}
|
||||||
|
|
||||||
bool PictureWriter::save(const string &filepath, int width, int height) {
|
bool PictureWriter::save(const string &filepath, int width, int height) {
|
||||||
QImage result(width, height, QImage::Format_ARGB32);
|
QImage result(width, height, QImage::Format_ARGB32);
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,9 @@ namespace system {
|
||||||
|
|
||||||
class SYSTEMSHARED_EXPORT PictureWriter {
|
class SYSTEMSHARED_EXPORT PictureWriter {
|
||||||
public:
|
public:
|
||||||
|
PictureWriter();
|
||||||
|
virtual ~PictureWriter();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Start saving the picture in a file.
|
* @brief Start saving the picture in a file.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -31,11 +31,18 @@ class PictureWriter;
|
||||||
class Time;
|
class Time;
|
||||||
class RandomGenerator;
|
class RandomGenerator;
|
||||||
|
|
||||||
extern RandomGenerator &RandomGeneratorDefault;
|
extern SYSTEMSHARED_EXPORT RandomGenerator &RandomGeneratorDefault;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
using namespace paysages::system;
|
using namespace paysages::system;
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
// Some useful casts
|
||||||
|
#define to_double(_x_) (static_cast<double>(_x_))
|
||||||
|
#define round_to_int(_x_) (static_cast<int>(round(_x_)))
|
||||||
|
#define floor_to_int(_x_) (static_cast<int>(floor(_x_)))
|
||||||
|
#define ceil_to_int(_x_) (static_cast<int>(ceil(_x_)))
|
||||||
|
#define to_size(_x_) (static_cast<unsigned long>(_x_))
|
||||||
|
|
||||||
#endif // SYSTEM_GLOBAL_H
|
#endif // SYSTEM_GLOBAL_H
|
||||||
|
|
Loading…
Reference in a new issue