diff --git a/src/rendering/tools/euclid.cpp b/src/basics/Geometry.cpp similarity index 59% rename from src/rendering/tools/euclid.cpp rename to src/basics/Geometry.cpp index 801ab7f..0b91062 100644 --- a/src/rendering/tools/euclid.cpp +++ b/src/basics/Geometry.cpp @@ -1,9 +1,9 @@ -#include "euclid.h" +#include "Geometry.h" -#include -#include "PackStream.h" +#include +#include "Vector3.h" -double euclidGet2DAngle(double x, double y) +double Geometry::get2DAngle(double x, double y) { double nx, ny, d, ret; @@ -35,27 +35,25 @@ double euclidGet2DAngle(double x, double y) return ret < 0.0 ? ret + 2.0 * M_PI : ret; } -Vector3 euclidGetNormalFromTriangle(Vector3 center, Vector3 bottom, Vector3 right) +Vector3 Geometry::getNormalFromTriangle(const Vector3 ¢er, const Vector3 &bottom, const Vector3 &right) { - Vector3 dx = v3Sub(right, center); - Vector3 dz = v3Sub(bottom, center); - return v3Normalize(v3Cross(dz, dx)); + Vector3 dx = right.sub(center); + Vector3 dz = bottom.sub(center); + return dz.crossProduct(dx).normalize(); } -double euclidGetDistance2D(double x1, double y1, double x2, double y2) +double Geometry::getDistance2D(double x1, double y1, double x2, double y2) { double dx = x2 - x1; double dy = y2 - y1; return sqrt(dx * dx + dy * dy); } -int euclidRayIntersectSphere(Vector3 ray_point, Vector3 ray_direction, Vector3 sphere_center, double sphere_radius, Vector3* hit1, Vector3* hit2) +int Geometry::rayIntersectSphere(const Vector3 &ray_point, const Vector3 &ray_direction, const Vector3 &sphere_center, double sphere_radius, Vector3 *hit1, Vector3 *hit2) { - Vector3 ray_direction_sphere; + Vector3 ray_direction_sphere = ray_point.sub(sphere_center); double a, b, c, d; - ray_direction_sphere = v3Sub(ray_point, sphere_center); - a = ray_direction.x * ray_direction.x + ray_direction.y * ray_direction.y + ray_direction.z * ray_direction.z; b = 2 * (ray_direction.x * ray_direction_sphere.x + ray_direction.y * ray_direction_sphere.y + ray_direction.z * ray_direction_sphere.z); c = ray_direction_sphere.x * ray_direction_sphere.x + ray_direction_sphere.y * ray_direction_sphere.y + ray_direction_sphere.z * ray_direction_sphere.z - sphere_radius * sphere_radius; @@ -69,8 +67,8 @@ int euclidRayIntersectSphere(Vector3 ray_point, Vector3 ray_direction, Vector3 s { if (hit1 && hit2) { - *hit1 = v3Add(ray_point, v3Scale(ray_direction, (-b - sqrt(d)) / (2 * a))); - *hit2 = v3Add(ray_point, v3Scale(ray_direction, (-b + sqrt(d)) / (2 * a))); + *hit1 = ray_point.add(ray_direction.scale((-b - sqrt(d)) / (2 * a))); + *hit2 = ray_point.add(ray_direction.scale((-b + sqrt(d)) / (2 * a))); } return 2; } @@ -78,7 +76,7 @@ int euclidRayIntersectSphere(Vector3 ray_point, Vector3 ray_direction, Vector3 s { if (hit1) { - *hit1 = v3Add(ray_point, v3Scale(ray_direction, -b / (2 * a))); + *hit1 = ray_point.add(ray_direction.scale(-b / (2 * a))); } return 1; } diff --git a/src/basics/Geometry.h b/src/basics/Geometry.h new file mode 100644 index 0000000..ff3bd19 --- /dev/null +++ b/src/basics/Geometry.h @@ -0,0 +1,21 @@ +#ifndef GEOMETRY_H +#define GEOMETRY_H + +#include "basics_global.h" + +namespace paysages { +namespace basics { + +class Geometry +{ +public: + static double get2DAngle(double x, double y); + static Vector3 getNormalFromTriangle(const Vector3 ¢er, const Vector3 &bottom, const Vector3 &right); + static double getDistance2D(double x1, double y1, double x2, double y2); + static int rayIntersectSphere(const Vector3 &ray_point, const Vector3 &ray_direction, const Vector3 &sphere_center, double sphere_radius, Vector3 *hit1, Vector3 *hit2); +}; + +} +} + +#endif // GEOMETRY_H diff --git a/src/basics/basics.pro b/src/basics/basics.pro index decec0d..460ed73 100644 --- a/src/basics/basics.pro +++ b/src/basics/basics.pro @@ -28,7 +28,8 @@ SOURCES += \ BoundingBox.cpp \ Matrix4.cpp \ Curve.cpp \ - ColorProfile.cpp + ColorProfile.cpp \ + Geometry.cpp HEADERS +=\ basics_global.h \ @@ -44,7 +45,8 @@ HEADERS +=\ BoundingBox.h \ Matrix4.h \ Curve.h \ - ColorProfile.h + ColorProfile.h \ + Geometry.h unix:!symbian { maemo5 { diff --git a/src/interface/desktop/formclouds.cpp b/src/interface/desktop/formclouds.cpp index 1e07bb1..4f4b9f6 100644 --- a/src/interface/desktop/formclouds.cpp +++ b/src/interface/desktop/formclouds.cpp @@ -1,6 +1,5 @@ #include "formclouds.h" -#include "tools/euclid.h" #include "RenderingScenery.h" #include "BasePreview.h" #include "renderer.h" diff --git a/src/interface/desktop/formwater.cpp b/src/interface/desktop/formwater.cpp index 0023116..b2bdcdc 100644 --- a/src/interface/desktop/formwater.cpp +++ b/src/interface/desktop/formwater.cpp @@ -4,7 +4,6 @@ #include #include -#include "tools/euclid.h" #include "tools/lighting.h" #include "renderer.h" #include "water/public.h" @@ -64,7 +63,7 @@ FormWater::~FormWater() delete previewCoverage; delete previewColorRenderer; - delete previewCoverage; + delete previewColor; } void FormWater::revertConfig() diff --git a/src/interface/desktop/terrain/previewterrainshape.cpp b/src/interface/desktop/terrain/previewterrainshape.cpp index 19e61d2..ea97939 100644 --- a/src/interface/desktop/terrain/previewterrainshape.cpp +++ b/src/interface/desktop/terrain/previewterrainshape.cpp @@ -28,7 +28,8 @@ void PreviewTerrainShape::updateEvent() Color PreviewTerrainShape::getColor2D(double x, double y, double scaling) { - return waterGetPreviewCoverage(this, x, y, scaling, _highlight_enabled ? 1 : 0); + //return waterGetPreviewCoverage(this, x, y, scaling, _highlight_enabled ? 1 : 0); + return COLOR_BLACK; } void PreviewTerrainShape::toggleChangeEvent(QString key, bool value) diff --git a/src/interface/desktop/terrain/widgetheightmap.h b/src/interface/desktop/terrain/widgetheightmap.h index e276352..6fb4f3a 100644 --- a/src/interface/desktop/terrain/widgetheightmap.h +++ b/src/interface/desktop/terrain/widgetheightmap.h @@ -5,7 +5,6 @@ #include #include "terrain/paintingbrush.h" #include "CameraDefinition.h" -#include "tools/euclid.h" #include "renderer.h" #include "terrain/public.h" diff --git a/src/interface/desktop/widgetcurveeditor.cpp b/src/interface/desktop/widgetcurveeditor.cpp index f605c31..74b2226 100644 --- a/src/interface/desktop/widgetcurveeditor.cpp +++ b/src/interface/desktop/widgetcurveeditor.cpp @@ -4,7 +4,7 @@ #include #include #include "Curve.h" -#include "tools/euclid.h" +#include "Geometry.h" WidgetCurveEditor::WidgetCurveEditor(QWidget *parent, double xmin, double xmax, double ymin, double ymax) : QWidget(parent) { @@ -220,7 +220,7 @@ int WidgetCurveEditor::getPointAt(int x, int y) { _curve->getPoint(i, &point); curveToScreen(point.position, point.value, &dx, &dy); - ndistance = euclidGetDistance2D((double)x, (double)y, (double)dx, (double)dy); + ndistance = Geometry::getDistance2D((double)x, (double)y, (double)dx, (double)dy); if (nearest < 0 || ndistance < distance) { distance = ndistance; diff --git a/src/render/opengl/WidgetExplorer.cpp b/src/render/opengl/WidgetExplorer.cpp index 8105013..6fe5164 100644 --- a/src/render/opengl/WidgetExplorer.cpp +++ b/src/render/opengl/WidgetExplorer.cpp @@ -11,7 +11,6 @@ #include "OpenGLRenderer.h" #include "WaterDefinition.h" #include "SurfaceMaterial.h" -#include "tools/euclid.h" #include "renderer.h" #include "CameraDefinition.h" #include "atmosphere/public.h" diff --git a/src/rendering/atmosphere/public.h b/src/rendering/atmosphere/public.h index fb2ba04..c25e3ed 100644 --- a/src/rendering/atmosphere/public.h +++ b/src/rendering/atmosphere/public.h @@ -5,7 +5,6 @@ #include "../rendering_global.h" #include "../tools/lighting.h" -#include "../tools/euclid.h" #include "../shared/types.h" #include "Color.h" diff --git a/src/rendering/clouds/clo_walking.h b/src/rendering/clouds/clo_walking.h index c038d33..a355f66 100644 --- a/src/rendering/clouds/clo_walking.h +++ b/src/rendering/clouds/clo_walking.h @@ -2,7 +2,8 @@ #define _PAYSAGES_CLOUDS_WALKING_H_ #include "public.h" -#include "../tools/euclid.h" + +#include "Vector3.h" /** * Functions to walk through a cloud layer. diff --git a/src/rendering/clouds/public.h b/src/rendering/clouds/public.h index a2f0408..45b2f3a 100644 --- a/src/rendering/clouds/public.h +++ b/src/rendering/clouds/public.h @@ -5,7 +5,6 @@ #include "../shared/types.h" #include "../tools/lighting.h" -#include "../tools/euclid.h" #include "SurfaceMaterial.h" typedef Color (*FuncCloudsGetColor)(Renderer* renderer, Color base, Vector3 start, Vector3 end); diff --git a/src/rendering/render.h b/src/rendering/render.h index 0c94b2b..b1f5ff1 100644 --- a/src/rendering/render.h +++ b/src/rendering/render.h @@ -3,7 +3,6 @@ #include "rendering_global.h" #include "shared/types.h" -#include "tools/euclid.h" #include "Color.h" typedef Color (*f_RenderFragmentCallback)(Renderer* renderer, Vector3 location, void* data); diff --git a/src/rendering/rendering.pro b/src/rendering/rendering.pro index a4f4d5e..7f314eb 100644 --- a/src/rendering/rendering.pro +++ b/src/rendering/rendering.pro @@ -27,7 +27,6 @@ SOURCES += main.cpp \ tools/texture.cpp \ tools/parallel.cpp \ tools/lighting.cpp \ - tools/euclid.cpp \ tools/data.cpp \ tools/cache.cpp \ water/wat_render.cpp \ @@ -54,7 +53,6 @@ HEADERS += \ tools/texture.h \ tools/parallel.h \ tools/lighting.h \ - tools/euclid.h \ tools/data.h \ tools/cache.h \ water/public.h \ diff --git a/src/rendering/shared/types.h b/src/rendering/shared/types.h index ddc6950..a33dda8 100644 --- a/src/rendering/shared/types.h +++ b/src/rendering/shared/types.h @@ -3,8 +3,8 @@ #include "rendering_global.h" -#include "../tools/euclid.h" #include "Color.h" +#include "Vector3.h" typedef struct { diff --git a/src/rendering/terrain/public.h b/src/rendering/terrain/public.h index fab1ec1..772726e 100644 --- a/src/rendering/terrain/public.h +++ b/src/rendering/terrain/public.h @@ -3,7 +3,6 @@ #include "../rendering_global.h" #include "../shared/types.h" -#include "../tools/euclid.h" #include "Color.h" typedef struct diff --git a/src/rendering/tools/euclid.h b/src/rendering/tools/euclid.h deleted file mode 100644 index 13ffef0..0000000 --- a/src/rendering/tools/euclid.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _PAYSAGES_TOOLS_EUCLID_H_ -#define _PAYSAGES_TOOLS_EUCLID_H_ - -#include "../rendering_global.h" - -// TEMP -#include "Vector3.h" - -namespace paysages { -namespace system {class PackStream;} -} - -RENDERINGSHARED_EXPORT double euclidGet2DAngle(double x, double y); -RENDERINGSHARED_EXPORT Vector3 euclidGetNormalFromTriangle(Vector3 center, Vector3 bottom, Vector3 right); -RENDERINGSHARED_EXPORT double euclidGetDistance2D(double x1, double y1, double x2, double y2); -RENDERINGSHARED_EXPORT int euclidRayIntersectSphere(Vector3 ray_point, Vector3 ray_direction, Vector3 sphere_center, double sphere_radius, Vector3* hit1, Vector3* hit2); - -#endif diff --git a/src/rendering/tools/lighting.h b/src/rendering/tools/lighting.h index ac5b8c9..610a74d 100644 --- a/src/rendering/tools/lighting.h +++ b/src/rendering/tools/lighting.h @@ -2,8 +2,8 @@ #define _PAYSAGES_TOOLS_LIGHTING_H_ #include "../rendering_global.h" -#include "euclid.h" #include "Color.h" +#include "Vector3.h" typedef struct { diff --git a/src/rendering/water/public.h b/src/rendering/water/public.h index 5479847..36dcfdf 100644 --- a/src/rendering/water/public.h +++ b/src/rendering/water/public.h @@ -4,7 +4,6 @@ #include "../rendering_global.h" #include "../shared/types.h" #include "../tools/lighting.h" -#include "../tools/euclid.h" typedef struct { diff --git a/src/tests/Euclid_Test.cpp b/src/tests/Euclid_Test.cpp index e0aeca7..9e48c02 100644 --- a/src/tests/Euclid_Test.cpp +++ b/src/tests/Euclid_Test.cpp @@ -1,7 +1,8 @@ #include "BaseTestCase.h" #include -#include "tools/euclid.h" +#include "Geometry.h" +#include "Vector3.h" /*static inline int _Vector3_cmp(Vector3 v1, Vector3 v2) { @@ -16,28 +17,28 @@ DEFINE_COMPARE_ASSERT(Vector3, _Vector3_cmp, _Vector3_str);*/ TEST(Euclid, get2DAngle) { - EXPECT_DOUBLE_EQ(euclidGet2DAngle(0.0, 0.0), 0.0); + EXPECT_DOUBLE_EQ(Geometry::get2DAngle(0.0, 0.0), 0.0); - EXPECT_DOUBLE_EQ(euclidGet2DAngle(0.1, 0.0), 0.0); - EXPECT_DOUBLE_EQ(euclidGet2DAngle(1.0, 0.0), 0.0); - EXPECT_DOUBLE_EQ(euclidGet2DAngle(2.0, 0.0), 0.0); + EXPECT_DOUBLE_EQ(Geometry::get2DAngle(0.1, 0.0), 0.0); + EXPECT_DOUBLE_EQ(Geometry::get2DAngle(1.0, 0.0), 0.0); + EXPECT_DOUBLE_EQ(Geometry::get2DAngle(2.0, 0.0), 0.0); - EXPECT_DOUBLE_EQ(euclidGet2DAngle(0.0, 0.1), M_PI_2); - EXPECT_DOUBLE_EQ(euclidGet2DAngle(0.0, 1.0), M_PI_2); - EXPECT_DOUBLE_EQ(euclidGet2DAngle(0.0, 2.0), M_PI_2); + EXPECT_DOUBLE_EQ(Geometry::get2DAngle(0.0, 0.1), M_PI_2); + EXPECT_DOUBLE_EQ(Geometry::get2DAngle(0.0, 1.0), M_PI_2); + EXPECT_DOUBLE_EQ(Geometry::get2DAngle(0.0, 2.0), M_PI_2); - EXPECT_DOUBLE_EQ(euclidGet2DAngle(-0.1, 0.0), M_PI); - EXPECT_DOUBLE_EQ(euclidGet2DAngle(-1.0, 0.0), M_PI); - EXPECT_DOUBLE_EQ(euclidGet2DAngle(-2.0, 0.0), M_PI); + EXPECT_DOUBLE_EQ(Geometry::get2DAngle(-0.1, 0.0), M_PI); + EXPECT_DOUBLE_EQ(Geometry::get2DAngle(-1.0, 0.0), M_PI); + EXPECT_DOUBLE_EQ(Geometry::get2DAngle(-2.0, 0.0), M_PI); - EXPECT_DOUBLE_EQ(euclidGet2DAngle(0.0, -0.1), 3.0 * M_PI_2); - EXPECT_DOUBLE_EQ(euclidGet2DAngle(0.0, -1.0), 3.0 * M_PI_2); - EXPECT_DOUBLE_EQ(euclidGet2DAngle(0.0, -2.0), 3.0 * M_PI_2); + EXPECT_DOUBLE_EQ(Geometry::get2DAngle(0.0, -0.1), 3.0 * M_PI_2); + EXPECT_DOUBLE_EQ(Geometry::get2DAngle(0.0, -1.0), 3.0 * M_PI_2); + EXPECT_DOUBLE_EQ(Geometry::get2DAngle(0.0, -2.0), 3.0 * M_PI_2); - EXPECT_DOUBLE_EQ(euclidGet2DAngle(0.5, 0.5), M_PI_4); - EXPECT_DOUBLE_EQ(euclidGet2DAngle(0.5, -0.5), 7.0 * M_PI_4); - EXPECT_DOUBLE_EQ(euclidGet2DAngle(-0.5, 0.5), 3.0 * M_PI_4); - EXPECT_DOUBLE_EQ(euclidGet2DAngle(-0.5, -0.5), 5.0 * M_PI_4); + EXPECT_DOUBLE_EQ(Geometry::get2DAngle(0.5, 0.5), M_PI_4); + EXPECT_DOUBLE_EQ(Geometry::get2DAngle(0.5, -0.5), 7.0 * M_PI_4); + EXPECT_DOUBLE_EQ(Geometry::get2DAngle(-0.5, 0.5), 3.0 * M_PI_4); + EXPECT_DOUBLE_EQ(Geometry::get2DAngle(-0.5, -0.5), 5.0 * M_PI_4); } /*TEST(Euclid, Vector3)