Removed old euclid.h/c
This commit is contained in:
parent
4c49e2e757
commit
79080c756f
20 changed files with 67 additions and 72 deletions
|
@ -1,9 +1,9 @@
|
||||||
#include "euclid.h"
|
#include "Geometry.h"
|
||||||
|
|
||||||
#include <math.h>
|
#include <cmath>
|
||||||
#include "PackStream.h"
|
#include "Vector3.h"
|
||||||
|
|
||||||
double euclidGet2DAngle(double x, double y)
|
double Geometry::get2DAngle(double x, double y)
|
||||||
{
|
{
|
||||||
double nx, ny, d, ret;
|
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;
|
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 dx = right.sub(center);
|
||||||
Vector3 dz = v3Sub(bottom, center);
|
Vector3 dz = bottom.sub(center);
|
||||||
return v3Normalize(v3Cross(dz, dx));
|
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 dx = x2 - x1;
|
||||||
double dy = y2 - y1;
|
double dy = y2 - y1;
|
||||||
return sqrt(dx * dx + dy * dy);
|
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;
|
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;
|
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);
|
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;
|
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)
|
if (hit1 && hit2)
|
||||||
{
|
{
|
||||||
*hit1 = v3Add(ray_point, v3Scale(ray_direction, (-b - sqrt(d)) / (2 * a)));
|
*hit1 = ray_point.add(ray_direction.scale((-b - sqrt(d)) / (2 * a)));
|
||||||
*hit2 = v3Add(ray_point, v3Scale(ray_direction, (-b + sqrt(d)) / (2 * a)));
|
*hit2 = ray_point.add(ray_direction.scale((-b + sqrt(d)) / (2 * a)));
|
||||||
}
|
}
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
@ -78,7 +76,7 @@ int euclidRayIntersectSphere(Vector3 ray_point, Vector3 ray_direction, Vector3 s
|
||||||
{
|
{
|
||||||
if (hit1)
|
if (hit1)
|
||||||
{
|
{
|
||||||
*hit1 = v3Add(ray_point, v3Scale(ray_direction, -b / (2 * a)));
|
*hit1 = ray_point.add(ray_direction.scale(-b / (2 * a)));
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
21
src/basics/Geometry.h
Normal file
21
src/basics/Geometry.h
Normal file
|
@ -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
|
|
@ -28,7 +28,8 @@ SOURCES += \
|
||||||
BoundingBox.cpp \
|
BoundingBox.cpp \
|
||||||
Matrix4.cpp \
|
Matrix4.cpp \
|
||||||
Curve.cpp \
|
Curve.cpp \
|
||||||
ColorProfile.cpp
|
ColorProfile.cpp \
|
||||||
|
Geometry.cpp
|
||||||
|
|
||||||
HEADERS +=\
|
HEADERS +=\
|
||||||
basics_global.h \
|
basics_global.h \
|
||||||
|
@ -44,7 +45,8 @@ HEADERS +=\
|
||||||
BoundingBox.h \
|
BoundingBox.h \
|
||||||
Matrix4.h \
|
Matrix4.h \
|
||||||
Curve.h \
|
Curve.h \
|
||||||
ColorProfile.h
|
ColorProfile.h \
|
||||||
|
Geometry.h
|
||||||
|
|
||||||
unix:!symbian {
|
unix:!symbian {
|
||||||
maemo5 {
|
maemo5 {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "formclouds.h"
|
#include "formclouds.h"
|
||||||
|
|
||||||
#include "tools/euclid.h"
|
|
||||||
#include "RenderingScenery.h"
|
#include "RenderingScenery.h"
|
||||||
#include "BasePreview.h"
|
#include "BasePreview.h"
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include <QSlider>
|
#include <QSlider>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include "tools/euclid.h"
|
|
||||||
#include "tools/lighting.h"
|
#include "tools/lighting.h"
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "water/public.h"
|
#include "water/public.h"
|
||||||
|
@ -64,7 +63,7 @@ FormWater::~FormWater()
|
||||||
delete previewCoverage;
|
delete previewCoverage;
|
||||||
|
|
||||||
delete previewColorRenderer;
|
delete previewColorRenderer;
|
||||||
delete previewCoverage;
|
delete previewColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormWater::revertConfig()
|
void FormWater::revertConfig()
|
||||||
|
|
|
@ -28,7 +28,8 @@ void PreviewTerrainShape::updateEvent()
|
||||||
|
|
||||||
Color PreviewTerrainShape::getColor2D(double x, double y, double scaling)
|
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)
|
void PreviewTerrainShape::toggleChangeEvent(QString key, bool value)
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include "terrain/paintingbrush.h"
|
#include "terrain/paintingbrush.h"
|
||||||
#include "CameraDefinition.h"
|
#include "CameraDefinition.h"
|
||||||
#include "tools/euclid.h"
|
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "terrain/public.h"
|
#include "terrain/public.h"
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <QPaintEngine>
|
#include <QPaintEngine>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include "Curve.h"
|
#include "Curve.h"
|
||||||
#include "tools/euclid.h"
|
#include "Geometry.h"
|
||||||
|
|
||||||
WidgetCurveEditor::WidgetCurveEditor(QWidget *parent, double xmin, double xmax, double ymin, double ymax) : QWidget(parent)
|
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);
|
_curve->getPoint(i, &point);
|
||||||
curveToScreen(point.position, point.value, &dx, &dy);
|
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)
|
if (nearest < 0 || ndistance < distance)
|
||||||
{
|
{
|
||||||
distance = ndistance;
|
distance = ndistance;
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include "OpenGLRenderer.h"
|
#include "OpenGLRenderer.h"
|
||||||
#include "WaterDefinition.h"
|
#include "WaterDefinition.h"
|
||||||
#include "SurfaceMaterial.h"
|
#include "SurfaceMaterial.h"
|
||||||
#include "tools/euclid.h"
|
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "CameraDefinition.h"
|
#include "CameraDefinition.h"
|
||||||
#include "atmosphere/public.h"
|
#include "atmosphere/public.h"
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
#include "../rendering_global.h"
|
#include "../rendering_global.h"
|
||||||
#include "../tools/lighting.h"
|
#include "../tools/lighting.h"
|
||||||
#include "../tools/euclid.h"
|
|
||||||
#include "../shared/types.h"
|
#include "../shared/types.h"
|
||||||
#include "Color.h"
|
#include "Color.h"
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
#define _PAYSAGES_CLOUDS_WALKING_H_
|
#define _PAYSAGES_CLOUDS_WALKING_H_
|
||||||
|
|
||||||
#include "public.h"
|
#include "public.h"
|
||||||
#include "../tools/euclid.h"
|
|
||||||
|
#include "Vector3.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functions to walk through a cloud layer.
|
* Functions to walk through a cloud layer.
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
#include "../shared/types.h"
|
#include "../shared/types.h"
|
||||||
#include "../tools/lighting.h"
|
#include "../tools/lighting.h"
|
||||||
#include "../tools/euclid.h"
|
|
||||||
#include "SurfaceMaterial.h"
|
#include "SurfaceMaterial.h"
|
||||||
|
|
||||||
typedef Color (*FuncCloudsGetColor)(Renderer* renderer, Color base, Vector3 start, Vector3 end);
|
typedef Color (*FuncCloudsGetColor)(Renderer* renderer, Color base, Vector3 start, Vector3 end);
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include "rendering_global.h"
|
#include "rendering_global.h"
|
||||||
#include "shared/types.h"
|
#include "shared/types.h"
|
||||||
#include "tools/euclid.h"
|
|
||||||
#include "Color.h"
|
#include "Color.h"
|
||||||
|
|
||||||
typedef Color (*f_RenderFragmentCallback)(Renderer* renderer, Vector3 location, void* data);
|
typedef Color (*f_RenderFragmentCallback)(Renderer* renderer, Vector3 location, void* data);
|
||||||
|
|
|
@ -27,7 +27,6 @@ SOURCES += main.cpp \
|
||||||
tools/texture.cpp \
|
tools/texture.cpp \
|
||||||
tools/parallel.cpp \
|
tools/parallel.cpp \
|
||||||
tools/lighting.cpp \
|
tools/lighting.cpp \
|
||||||
tools/euclid.cpp \
|
|
||||||
tools/data.cpp \
|
tools/data.cpp \
|
||||||
tools/cache.cpp \
|
tools/cache.cpp \
|
||||||
water/wat_render.cpp \
|
water/wat_render.cpp \
|
||||||
|
@ -54,7 +53,6 @@ HEADERS += \
|
||||||
tools/texture.h \
|
tools/texture.h \
|
||||||
tools/parallel.h \
|
tools/parallel.h \
|
||||||
tools/lighting.h \
|
tools/lighting.h \
|
||||||
tools/euclid.h \
|
|
||||||
tools/data.h \
|
tools/data.h \
|
||||||
tools/cache.h \
|
tools/cache.h \
|
||||||
water/public.h \
|
water/public.h \
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
#include "rendering_global.h"
|
#include "rendering_global.h"
|
||||||
|
|
||||||
#include "../tools/euclid.h"
|
|
||||||
#include "Color.h"
|
#include "Color.h"
|
||||||
|
#include "Vector3.h"
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include "../rendering_global.h"
|
#include "../rendering_global.h"
|
||||||
#include "../shared/types.h"
|
#include "../shared/types.h"
|
||||||
#include "../tools/euclid.h"
|
|
||||||
#include "Color.h"
|
#include "Color.h"
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
|
|
@ -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
|
|
|
@ -2,8 +2,8 @@
|
||||||
#define _PAYSAGES_TOOLS_LIGHTING_H_
|
#define _PAYSAGES_TOOLS_LIGHTING_H_
|
||||||
|
|
||||||
#include "../rendering_global.h"
|
#include "../rendering_global.h"
|
||||||
#include "euclid.h"
|
|
||||||
#include "Color.h"
|
#include "Color.h"
|
||||||
|
#include "Vector3.h"
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include "../rendering_global.h"
|
#include "../rendering_global.h"
|
||||||
#include "../shared/types.h"
|
#include "../shared/types.h"
|
||||||
#include "../tools/lighting.h"
|
#include "../tools/lighting.h"
|
||||||
#include "../tools/euclid.h"
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#include "BaseTestCase.h"
|
#include "BaseTestCase.h"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include "tools/euclid.h"
|
#include "Geometry.h"
|
||||||
|
#include "Vector3.h"
|
||||||
|
|
||||||
/*static inline int _Vector3_cmp(Vector3 v1, Vector3 v2)
|
/*static inline int _Vector3_cmp(Vector3 v1, Vector3 v2)
|
||||||
{
|
{
|
||||||
|
@ -16,28 +17,28 @@ DEFINE_COMPARE_ASSERT(Vector3, _Vector3_cmp, _Vector3_str);*/
|
||||||
|
|
||||||
TEST(Euclid, get2DAngle)
|
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(Geometry::get2DAngle(0.1, 0.0), 0.0);
|
||||||
EXPECT_DOUBLE_EQ(euclidGet2DAngle(1.0, 0.0), 0.0);
|
EXPECT_DOUBLE_EQ(Geometry::get2DAngle(1.0, 0.0), 0.0);
|
||||||
EXPECT_DOUBLE_EQ(euclidGet2DAngle(2.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(Geometry::get2DAngle(0.0, 0.1), M_PI_2);
|
||||||
EXPECT_DOUBLE_EQ(euclidGet2DAngle(0.0, 1.0), M_PI_2);
|
EXPECT_DOUBLE_EQ(Geometry::get2DAngle(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, 2.0), M_PI_2);
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(euclidGet2DAngle(-0.1, 0.0), M_PI);
|
EXPECT_DOUBLE_EQ(Geometry::get2DAngle(-0.1, 0.0), M_PI);
|
||||||
EXPECT_DOUBLE_EQ(euclidGet2DAngle(-1.0, 0.0), M_PI);
|
EXPECT_DOUBLE_EQ(Geometry::get2DAngle(-1.0, 0.0), M_PI);
|
||||||
EXPECT_DOUBLE_EQ(euclidGet2DAngle(-2.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(Geometry::get2DAngle(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(Geometry::get2DAngle(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, -2.0), 3.0 * M_PI_2);
|
||||||
|
|
||||||
EXPECT_DOUBLE_EQ(euclidGet2DAngle(0.5, 0.5), M_PI_4);
|
EXPECT_DOUBLE_EQ(Geometry::get2DAngle(0.5, 0.5), M_PI_4);
|
||||||
EXPECT_DOUBLE_EQ(euclidGet2DAngle(0.5, -0.5), 7.0 * M_PI_4);
|
EXPECT_DOUBLE_EQ(Geometry::get2DAngle(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(Geometry::get2DAngle(-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), 5.0 * M_PI_4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*TEST(Euclid, Vector3)
|
/*TEST(Euclid, Vector3)
|
||||||
|
|
Loading…
Reference in a new issue