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 "PackStream.h"
|
||||
#include <cmath>
|
||||
#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;
|
||||
}
|
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 \
|
||||
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 {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "formclouds.h"
|
||||
|
||||
#include "tools/euclid.h"
|
||||
#include "RenderingScenery.h"
|
||||
#include "BasePreview.h"
|
||||
#include "renderer.h"
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <QSlider>
|
||||
#include <cmath>
|
||||
|
||||
#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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#include <QDateTime>
|
||||
#include "terrain/paintingbrush.h"
|
||||
#include "CameraDefinition.h"
|
||||
#include "tools/euclid.h"
|
||||
#include "renderer.h"
|
||||
#include "terrain/public.h"
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <QPaintEngine>
|
||||
#include <QMouseEvent>
|
||||
#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;
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
#include "../rendering_global.h"
|
||||
#include "../tools/lighting.h"
|
||||
#include "../tools/euclid.h"
|
||||
#include "../shared/types.h"
|
||||
#include "Color.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.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
#include "rendering_global.h"
|
||||
|
||||
#include "../tools/euclid.h"
|
||||
#include "Color.h"
|
||||
#include "Vector3.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include "../rendering_global.h"
|
||||
#include "../shared/types.h"
|
||||
#include "../tools/euclid.h"
|
||||
#include "Color.h"
|
||||
|
||||
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_
|
||||
|
||||
#include "../rendering_global.h"
|
||||
#include "euclid.h"
|
||||
#include "Color.h"
|
||||
#include "Vector3.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include "../rendering_global.h"
|
||||
#include "../shared/types.h"
|
||||
#include "../tools/lighting.h"
|
||||
#include "../tools/euclid.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#include "BaseTestCase.h"
|
||||
|
||||
#include <cmath>
|
||||
#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)
|
||||
|
|
Loading…
Reference in a new issue