65 lines
1.9 KiB
C++
65 lines
1.9 KiB
C++
#include "SoftwareRayRenderer.h"
|
|
|
|
#include "CameraDefinition.h"
|
|
#include "CanvasPortion.h"
|
|
#include "Color.h"
|
|
#include "RayCastingManager.h"
|
|
#include "RenderProgress.h"
|
|
#include "Scenery.h"
|
|
#include "SkyIntersector.h"
|
|
#include "TerrainIntersector.h"
|
|
#include "Vector3.h"
|
|
#include "WaterIntersector.h"
|
|
|
|
class SoftwareRayRenderer::pimpl {
|
|
public:
|
|
RayCastingManager manager;
|
|
};
|
|
|
|
SoftwareRayRenderer::SoftwareRayRenderer(Scenery *scenery, bool standard)
|
|
: SoftwareCanvasRenderer(scenery), impl(new pimpl) {
|
|
if (standard) {
|
|
registerStandardIntersectors();
|
|
}
|
|
}
|
|
|
|
SoftwareRayRenderer::~SoftwareRayRenderer() {
|
|
}
|
|
|
|
void SoftwareRayRenderer::registerStandardIntersectors() {
|
|
impl->manager.unregisterAllIntersectors();
|
|
|
|
impl->manager.registerIntersector(make_shared<SkyIntersector>(getAtmosphereRenderer()));
|
|
impl->manager.registerIntersector(make_shared<TerrainIntersector>(getTerrainRenderer()));
|
|
impl->manager.registerIntersector(make_shared<WaterIntersector>(getWaterRenderer()));
|
|
}
|
|
|
|
void SoftwareRayRenderer::renderPortion(CanvasPortion *portion, RenderProgress *progress, bool *interrupt) {
|
|
int width = portion->getWidth();
|
|
int height = portion->getHeight();
|
|
|
|
portion->preparePixels();
|
|
progress->enterSub(width * height);
|
|
|
|
for (int x = 0; x < width; x++) {
|
|
for (int y = 0; y < height; y++) {
|
|
Vector3 direction =
|
|
Vector3(1.0, to_double(y) / to_double(height) - 0.5, to_double(x) / to_double(width) - 0.5).normalize();
|
|
Color color = impl->manager.getFinal(getCameraLocation(), direction);
|
|
portion->setColor(x, y, color);
|
|
progress->add();
|
|
}
|
|
if (*interrupt) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
portion->discardPixels();
|
|
progress->exitSub();
|
|
}
|
|
|
|
void SoftwareRayRenderer::prepare() {
|
|
SoftwareCanvasRenderer::prepare();
|
|
registerStandardIntersectors();
|
|
}
|