Started tests on pespective correct mapping

This commit is contained in:
Michaël Lemaire 2013-05-28 14:56:50 +02:00 committed by Michael Lemaire
parent fbc64abb81
commit a6ab7f7146
6 changed files with 79 additions and 33 deletions

View file

@ -382,12 +382,16 @@ static void _scanGetDiff(ScanPoint* v1, ScanPoint* v2, ScanPoint* result)
static void _scanInterpolate(ScanPoint* v1, ScanPoint* diff, double value, ScanPoint* result)
{
double v1depth = v1->pixel.z;
double v2depth = (v1->pixel.z + diff->pixel.z);
double factor = ((1.0 - value) / v1depth + value / v2depth);
result->pixel.x = v1->pixel.x + diff->pixel.x * value;
result->pixel.y = v1->pixel.y + diff->pixel.y * value;
result->pixel.z = v1->pixel.z + diff->pixel.z * value;
result->location.x = v1->location.x + diff->location.x * value;
result->location.y = v1->location.y + diff->location.y * value;
result->location.z = v1->location.z + diff->location.z * value;
result->pixel.z = ((1.0 - value) * (v1->pixel.z / v1depth) + value * (v1->pixel.z + diff->pixel.z) / v2depth) / factor;
result->location.x = ((1.0 - value) * (v1->location.x / v1depth) + value * (v1->location.x + diff->location.x) / v2depth) / factor;
result->location.y = ((1.0 - value) * (v1->location.y / v1depth) + value * (v1->location.y + diff->location.y) / v2depth) / factor;
result->location.z = ((1.0 - value) * (v1->location.z / v1depth) + value * (v1->location.z + diff->location.z) / v2depth) / factor;
result->callback = v1->callback;
}

View file

@ -40,7 +40,6 @@ static Vector3 _getCameraDirection(Renderer* renderer, Vector3 target)
static double _getPrecision(Renderer* renderer, Vector3 location)
{
UNUSED(renderer);
UNUSED(location);
return 0.0;
@ -48,21 +47,16 @@ static double _getPrecision(Renderer* renderer, Vector3 location)
static Vector3 _projectPoint(Renderer* renderer, Vector3 point)
{
UNUSED(renderer);
return point;
return cameraProject(renderer->render_camera, point);
}
static Vector3 _unprojectPoint(Renderer* renderer, Vector3 point)
{
UNUSED(renderer);
return point;
return cameraUnproject(renderer->render_camera, point);
}
static void _pushTriangle(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, f_RenderFragmentCallback callback, void* callback_data)
{
Vector3 p1, p2, p3;
p1 = renderer->projectPoint(renderer, v1);
@ -74,14 +68,12 @@ static void _pushTriangle(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3
static void _pushQuad(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, f_RenderFragmentCallback callback, void* callback_data)
{
renderer->pushTriangle(renderer, v2, v3, v1, callback, callback_data);
renderer->pushTriangle(renderer, v4, v1, v3, callback, callback_data);
}
static void _pushDisplacedTriangle(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, Vector3 ov1, Vector3 ov2, Vector3 ov3, f_RenderFragmentCallback callback, void* callback_data)
{
Vector3 p1, p2, p3;
p1 = renderer->projectPoint(renderer, v1);
@ -93,20 +85,17 @@ static void _pushDisplacedTriangle(Renderer* renderer, Vector3 v1, Vector3 v2, V
static void _pushDisplacedQuad(Renderer* renderer, Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, Vector3 ov1, Vector3 ov2, Vector3 ov3, Vector3 ov4, f_RenderFragmentCallback callback, void* callback_data)
{
renderer->pushDisplacedTriangle(renderer, v2, v3, v1, ov2, ov3, ov1, callback, callback_data);
renderer->pushDisplacedTriangle(renderer, v4, v1, v3, ov4, ov1, ov3, callback, callback_data);
}
static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds)
{
return _RAYCASTING_NULL;
}
static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial* material)
{
LightStatus* light = lightingCreateStatus(renderer->lighting, location, renderer->getCameraLocation(renderer, location));
renderer->atmosphere->getLightingStatus(renderer, light, normal, 0);
Color result = lightingApplyStatus(light, normal, material);
@ -116,7 +105,6 @@ static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vecto
static Color _applyMediumTraversal(Renderer* renderer, Vector3 location, Color color)
{
color = renderer->atmosphere->applyAerialPerspective(renderer, location, color).final;
color = renderer->clouds->getColor(renderer, color, renderer->getCameraLocation(renderer, location), location);
return color;
@ -124,7 +112,6 @@ static Color _applyMediumTraversal(Renderer* renderer, Vector3 location, Color c
Renderer* rendererCreate()
{
Renderer* result = malloc(sizeof (Renderer));
RenderParams params = {1, 1, 1, 5};
@ -168,7 +155,6 @@ Renderer* rendererCreate()
void rendererDelete(Renderer* renderer)
{
cameraDeleteDefinition(renderer->render_camera);
lightingManagerDelete(renderer->lighting);
@ -185,7 +171,6 @@ void rendererDelete(Renderer* renderer)
void rendererSetPreviewCallbacks(Renderer* renderer, RenderCallbackStart start, RenderCallbackDraw draw, RenderCallbackUpdate update)
{
renderSetPreviewCallbacks(renderer->render_area, start, draw, update);
}

View file

@ -186,16 +186,6 @@ static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector
return result;
}
static Vector3 _projectPoint(Renderer* renderer, Vector3 point)
{
return cameraProject(renderer->render_camera, point);
}
static Vector3 _unprojectPoint(Renderer* renderer, Vector3 point)
{
return cameraUnproject(renderer->render_camera, point);
}
static double _getPrecision(Renderer* renderer, Vector3 location)
{
Vector3 projected;
@ -216,8 +206,6 @@ Renderer* sceneryCreateStandardRenderer()
cameraCopyDefinition(_camera, result->render_camera);
result->rayWalking = _rayWalking;
result->projectPoint = _projectPoint;
result->unprojectPoint = _unprojectPoint;
result->getPrecision = _getPrecision;
sceneryBindRenderer(result);

View file

@ -8,6 +8,8 @@
#include <math.h>
#include <string.h>
extern int tests_cpu_count;
static inline void _add_methods_to_case(TCase* tc, ...)
{
void* method;

View file

@ -2,10 +2,13 @@
#include <stdlib.h>
#include "rendering/main.h"
#include "rendering/system.h"
int tests_cpu_count;
extern void test_euclid_case(Suite* s);
extern void test_camera_case(Suite* s);
extern void test_clouds_case(Suite* s);
extern void test_render_case(Suite* s);
int main(int argc, char** argv)
{
@ -14,10 +17,13 @@ int main(int argc, char** argv)
paysagesInit();
tests_cpu_count = systemGetCoreCount();
/* TODO Find a way to automate this */
test_euclid_case(s);
test_camera_case(s);
test_clouds_case(s);
test_render_case(s);
SRunner *sr = srunner_create(s);
srunner_run_all(sr, CK_NORMAL);

61
src/testing/test_render.c Normal file
View file

@ -0,0 +1,61 @@
#include "testing/common.h"
#include <math.h>
#include "rendering/renderer.h"
#include "rendering/tools.h"
static Color _postProcessFragment(Renderer* renderer, Vector3 location, void* data)
{
UNUSED(renderer);
UNUSED(data);
/* Checker-board */
double x = fmod(location.x, 0.2);
double z = fmod(location.z, 0.2);
if (x < 0.0)
{
x = 0.2 + x;
}
if (z < 0.0)
{
z = 0.2 + z;
}
if (x > 0.1 ^ z > 0.1)
{
return COLOR_WHITE;
}
else
{
return COLOR_BLACK;
}
}
START_TEST(test_render_quad)
{
Renderer* renderer = rendererCreate();
renderer->render_width = 800;
renderer->render_height = 600;
renderer->render_quality = 1;
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);
RenderParams params = {renderer->render_width, renderer->render_height, 1, 1};
renderSetParams(renderer->render_area, params);
renderSetBackgroundColor(renderer->render_area, &COLOR_BLUE);
renderClear(renderer->render_area);
renderer->pushQuad(renderer, v3(-1.0, 0.0, 1.0), v3(-1.0, 0.0, -1.0), v3(1.0, 0.0, -1.0), v3(1.0, 0.0, 1.0), _postProcessFragment, NULL);
renderPostProcess(renderer->render_area, renderer, tests_cpu_count);
renderSaveToFile(renderer->render_area, "./output/test_render_quad.png");
rendererDelete(renderer);
}
END_TEST
TEST_CASE(render, test_render_quad)