1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#pragma once
#include "SyntopiaCore/Math/Vector3.h"
#include "../Object3D.h"
namespace SyntopiaCore {
namespace GLEngine {
using namespace SyntopiaCore::Math;
/// See here for details about this approach:
/// http://www.devmaster.net/articles/raytracing_series/part4.php
class VoxelStepper {
public:
VoxelStepper(Vector3f minPos, Vector3f maxPos, int steps) ;
~VoxelStepper();
void registerObject(Object3D* obj) ;
QList<Object3D*>* setupRay(Vector3f pos, Vector3f dir, double& maxT);
inline double minn(double a, double b, double c) {
if (a<b) return (a<c ? a : c);
return (b<c ? b : c);
}
QList<Object3D*>* advance(double& maxT);
void setCopy(bool value) { this->copy = value; }
private:
bool copy;
double currentT;
double tDeltaX;
double tDeltaY;
double tDeltaZ;
double tMaxX;
double tMaxY;
double tMaxZ;
int stepX;
int stepY;
int stepZ;
int cx;
int cy;
int cz;
Vector3f pos;
Vector3f dir;
int steps;
Vector3f minPos;
Vector3f maxPos;
const Vector3f size;
QList<Object3D*>* grid;
};
}
}
|