2012-12-28 11:28:01 +00:00
|
|
|
#include "public.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2013-01-20 21:17:03 +00:00
|
|
|
#include "../tools.h"
|
2013-01-19 22:42:50 +00:00
|
|
|
#include "../tools/lighting.h"
|
2012-12-28 11:28:01 +00:00
|
|
|
#include "../renderer.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Terrain previews.
|
|
|
|
*/
|
|
|
|
|
2013-01-20 21:17:03 +00:00
|
|
|
static void _getLightingStatus(Renderer* renderer, LightStatus* status, Vector3 normal, int opaque)
|
|
|
|
{
|
|
|
|
LightDefinition light;
|
|
|
|
|
|
|
|
UNUSED(renderer);
|
|
|
|
UNUSED(normal);
|
|
|
|
UNUSED(opaque);
|
|
|
|
|
|
|
|
light.color.r = 0.6;
|
|
|
|
light.color.g = 0.6;
|
|
|
|
light.color.b = 0.6;
|
|
|
|
light.direction.x = -1.0;
|
|
|
|
light.direction.y = -0.5;
|
2013-01-27 19:57:43 +00:00
|
|
|
light.direction.z = 1.0;
|
2013-01-20 21:17:03 +00:00
|
|
|
light.direction = v3Normalize(light.direction);
|
|
|
|
light.altered = 1;
|
2013-03-07 14:07:12 +00:00
|
|
|
light.reflection = 0.0;
|
2013-01-20 21:17:03 +00:00
|
|
|
lightingPushLight(status, &light);
|
|
|
|
|
|
|
|
light.color.r = 0.2;
|
|
|
|
light.color.g = 0.2;
|
|
|
|
light.color.b = 0.2;
|
|
|
|
light.direction.x = 1.0;
|
|
|
|
light.direction.y = -0.5;
|
2013-01-27 19:57:43 +00:00
|
|
|
light.direction.z = -1.0;
|
2013-01-20 21:17:03 +00:00
|
|
|
light.direction = v3Normalize(light.direction);
|
|
|
|
light.altered = 0;
|
|
|
|
light.reflection = 0.0;
|
|
|
|
lightingPushLight(status, &light);
|
|
|
|
}
|
|
|
|
|
2013-01-31 15:10:11 +00:00
|
|
|
static Vector3 _getCameraLocation(Renderer* renderer, Vector3 location)
|
|
|
|
{
|
|
|
|
UNUSED(renderer);
|
|
|
|
location.x -= 10.0;
|
|
|
|
location.y += 15.0;
|
|
|
|
location.z += 10.0;
|
|
|
|
return location;
|
|
|
|
}
|
|
|
|
|
2013-01-20 15:07:45 +00:00
|
|
|
Renderer* terrainCreatePreviewRenderer()
|
2012-12-28 11:28:01 +00:00
|
|
|
{
|
2013-01-20 15:07:45 +00:00
|
|
|
Renderer* result = rendererCreate();
|
2012-12-28 11:28:01 +00:00
|
|
|
|
2013-01-20 15:07:45 +00:00
|
|
|
result->render_quality = 3;
|
2013-01-31 15:10:11 +00:00
|
|
|
result->getCameraLocation = _getCameraLocation;
|
2013-01-20 21:17:03 +00:00
|
|
|
result->atmosphere->getLightingStatus = _getLightingStatus;
|
2012-12-28 11:28:01 +00:00
|
|
|
|
2013-04-11 14:38:40 +00:00
|
|
|
TexturesDefinition* textures;
|
|
|
|
textures = TexturesDefinitionClass.create();
|
2013-10-02 20:00:08 +00:00
|
|
|
layersClear(textures->layers);
|
2013-04-11 14:38:40 +00:00
|
|
|
TexturesLayerDefinition* layer = layersGetLayer(textures->layers, layersAddLayer(textures->layers, NULL));
|
|
|
|
layer->displacement_height = 0.0;
|
2013-09-18 15:10:34 +00:00
|
|
|
layer->material.base = colorToHSL(COLOR_WHITE);
|
2013-04-11 14:38:40 +00:00
|
|
|
layer->material.reflection = 0.05;
|
|
|
|
layer->material.shininess = 2.0;
|
2013-10-02 20:00:08 +00:00
|
|
|
TexturesDefinitionClass.validate(textures);
|
2013-04-11 14:38:40 +00:00
|
|
|
noiseClearLevels(layer->_detail_noise);
|
|
|
|
|
|
|
|
TexturesRendererClass.bind(result, textures);
|
|
|
|
|
|
|
|
TexturesDefinitionClass.destroy(textures);
|
|
|
|
|
2012-12-28 11:28:01 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Color terrainGetPreviewColor(Renderer* renderer, double x, double z, double detail)
|
|
|
|
{
|
|
|
|
Vector3 point;
|
|
|
|
|
|
|
|
point.x = x;
|
2013-01-14 12:08:38 +00:00
|
|
|
point.y = renderer->terrain->getHeight(renderer, x, z, 1);
|
2012-12-28 11:28:01 +00:00
|
|
|
point.z = z;
|
|
|
|
|
|
|
|
return renderer->terrain->getFinalColor(renderer, point, detail);
|
|
|
|
}
|