2013-12-29 13:14:49 +00:00
|
|
|
#ifndef TERRAINRAYWALKER_H
|
|
|
|
#define TERRAINRAYWALKER_H
|
|
|
|
|
|
|
|
#include "software_global.h"
|
|
|
|
|
|
|
|
#include "Vector3.h"
|
|
|
|
|
|
|
|
namespace paysages {
|
|
|
|
namespace software {
|
|
|
|
|
2016-01-03 18:21:23 +00:00
|
|
|
/**
|
|
|
|
* Ray walker to find intersections with terrain.
|
2013-12-29 13:14:49 +00:00
|
|
|
*
|
|
|
|
* This walker can be used to find a hard intersection between
|
|
|
|
* a ray and the terrain (e.g. for raytracing), or a soft intersection
|
|
|
|
* (e.g. for shadows).
|
|
|
|
*/
|
2015-11-09 21:30:46 +00:00
|
|
|
class SOFTWARESHARED_EXPORT TerrainRayWalker {
|
|
|
|
public:
|
2013-12-29 13:14:49 +00:00
|
|
|
typedef struct {
|
|
|
|
Vector3 hit_location; // Location of the hit
|
2013-12-29 17:18:18 +00:00
|
|
|
double escape_angle; // Angle used to shift the ray to escape the terrain (0.0 if no escape was possible)
|
2013-12-29 13:14:49 +00:00
|
|
|
} TerrainHitResult;
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
public:
|
|
|
|
TerrainRayWalker(SoftwareRenderer *renderer);
|
2013-12-29 13:14:49 +00:00
|
|
|
|
2015-09-10 16:16:57 +00:00
|
|
|
/**
|
|
|
|
* Set the walker quality.
|
|
|
|
*
|
2016-01-03 18:21:23 +00:00
|
|
|
* displacement_safety - Safety factor (around 1.0) to detect when displacement textures need to be applied
|
|
|
|
* minimal_step - Minimal length of a walking step
|
|
|
|
* maximal_step - Maximal length of a walking step
|
|
|
|
* step_factor - Precision factor of steps, depending on terrain proximity
|
|
|
|
* max_distance - Maximal distance allowed to travel before considering an escape
|
|
|
|
* escape_step - Angle step when allowing an escape angle
|
2015-09-10 16:16:57 +00:00
|
|
|
*/
|
2015-11-09 21:30:46 +00:00
|
|
|
void setQuality(double displacement_safety, double minimal_step, double maximal_step, double step_factor,
|
|
|
|
double max_distance, double escape_step);
|
2015-09-10 16:16:57 +00:00
|
|
|
void setQuality(double factor);
|
|
|
|
|
2016-01-03 18:21:23 +00:00
|
|
|
/**
|
|
|
|
* Update the walker internal data, from the renderer and scenery.
|
2013-12-29 13:14:49 +00:00
|
|
|
*/
|
|
|
|
void update();
|
|
|
|
|
2016-01-03 18:21:23 +00:00
|
|
|
/**
|
|
|
|
* Start the walking process to find intersection
|
|
|
|
*
|
|
|
|
* start - Point of origin of the ray
|
|
|
|
* direction - Ray direction (normalized vector)
|
|
|
|
* escape_angle - Maximal angle allowed to escape the terrain on hit (mainly for shadows computing)
|
|
|
|
* result - Object to store the results info
|
2013-12-29 13:14:49 +00:00
|
|
|
*
|
2016-01-03 18:21:23 +00:00
|
|
|
* Returns true if there was a hit.
|
2013-12-29 13:14:49 +00:00
|
|
|
*/
|
2015-09-10 16:16:57 +00:00
|
|
|
bool startWalking(const Vector3 &start, Vector3 direction, double escape_angle, TerrainHitResult &result);
|
2013-12-29 13:14:49 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
private:
|
|
|
|
SoftwareRenderer *renderer;
|
2013-12-29 13:14:49 +00:00
|
|
|
double ymin;
|
|
|
|
double ymax;
|
2015-09-10 16:16:57 +00:00
|
|
|
double displacement_base;
|
|
|
|
|
|
|
|
// Quality control
|
|
|
|
double displacement_safety;
|
|
|
|
double minimal_step;
|
|
|
|
double maximal_step;
|
|
|
|
double step_factor;
|
|
|
|
double max_distance;
|
|
|
|
double escape_step;
|
2013-12-29 13:14:49 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // TERRAINRAYWALKER_H
|