Remove Vector3D and remove rotate from Shape

pull/218/head
James Ball 2024-01-07 16:37:22 +00:00
rodzic 8a91099c55
commit 70028c55b5
14 zmienionych plików z 41 dodań i 126 usunięć

Wyświetl plik

@ -5,6 +5,7 @@ RotateEffect::RotateEffect() {}
RotateEffect::~RotateEffect() {}
Point RotateEffect::apply(int index, Point input, const std::vector<double>& values, double sampleRate) {
input.rotate(nextPhase(values[0], sampleRate));
double phase = nextPhase(values[0], sampleRate);
input.rotate(phase, phase, 0);
return input;
}

Wyświetl plik

@ -27,10 +27,10 @@ std::vector<std::unique_ptr<Shape>> Camera::draw(WorldObject& object) {
edge.z2 = minZ;
}
Point start = project(edge.x1, edge.y1, edge.z1);
Point end = project(edge.x2, edge.y2, edge.z2);
Point start = Point(edge.x1, edge.y1, edge.z1);
Point end = Point(edge.x2, edge.y2, edge.z2);
shapes.push_back(std::make_unique<Line>(start.x, start.y, end.x, end.y));
shapes.push_back(std::make_unique<Line>(start.x, start.y, start.z, end.x, end.y, end.z));
}
return shapes;
}
@ -61,7 +61,7 @@ std::vector<Point> Camera::sampleVerticesInRender(WorldObject& object) {
for (int i = 0; i < SAMPLE_RENDER_SAMPLES - 1; i++) {
for (size_t j = 0; j < std::min(VERTEX_SAMPLES, object.numVertices); j++) {
Vector3D vertex{object.vs[j * 3], object.vs[j * 3 + 1], object.vs[j * 3 + 2]};
Point vertex{object.vs[j * 3], object.vs[j * 3 + 1], object.vs[j * 3 + 2]};
vertex.rotate(object.rotateX, object.rotateY, object.rotateZ);
vertices.push_back(project(vertex.x, vertex.y, vertex.z));
}

Wyświetl plik

@ -1,10 +1,11 @@
#include "Line3D.h"
#include "../shape/Point.h"
Line3D::Line3D(double x1, double y1, double z1, double x2, double y2, double z2) : x1(x1), y1(y1), z1(z1), x2(x2), y2(y2), z2(z2) {}
void Line3D::rotate(double rotateX, double rotateY, double rotateZ) {
Vector3D vector1(x1, y1, z1);
Vector3D vector2(x2, y2, z2);
Point vector1(x1, y1, z1);
Point vector2(x2, y2, z2);
vector1.rotate(rotateX, rotateY, rotateZ);
vector2.rotate(rotateX, rotateY, rotateZ);
x1 = vector1.x;
@ -14,25 +15,3 @@ void Line3D::rotate(double rotateX, double rotateY, double rotateZ) {
y2 = vector2.y;
z2 = vector2.z;
}
Vector3D::Vector3D(double x, double y, double z) : x(x), y(y), z(z) {}
void Vector3D::rotate(double rotateX, double rotateY, double rotateZ) {
// rotate around x-axis
double cosValue = std::cos(rotateX);
double sinValue = std::sin(rotateX);
double y2 = cosValue * y - sinValue * z;
double z2 = sinValue * y + cosValue * z;
// rotate around y-axis
cosValue = std::cos(rotateY);
sinValue = std::sin(rotateY);
double x2 = cosValue * x + sinValue * z2;
z = -sinValue * x + cosValue * z2;
// rotate around z-axis
cosValue = cos(rotateZ);
sinValue = sin(rotateZ);
x = cosValue * x2 - sinValue * y2;
y = sinValue * x2 + cosValue * y2;
}

Wyświetl plik

@ -9,13 +9,4 @@ public:
void rotate(double, double, double);
double x1, y1, z1, x2, y2, z2;
};
class Vector3D {
public:
Vector3D(double, double, double);
void rotate(double, double, double);
double x, y, z;
};

Wyświetl plik

@ -78,22 +78,22 @@ void ObjectServer::run() {
auto objects = *json.getProperty("objects", juce::Array<juce::var>()).getArray();
std::vector<std::vector<double>> allMatrices;
std::vector<std::vector<std::vector<Vector3D>>> allVertices;
std::vector<std::vector<std::vector<Point>>> allVertices;
double focalLength = json.getProperty("focalLength", 1);
for (int i = 0; i < objects.size(); i++) {
auto verticesArray = *objects[i].getProperty("vertices", juce::Array<juce::var>()).getArray();
std::vector<std::vector<Vector3D>> vertices;
std::vector<std::vector<Point>> vertices;
for (auto& vertexArrayVar : verticesArray) {
vertices.push_back(std::vector<Vector3D>());
vertices.push_back(std::vector<Point>());
auto& vertexArray = *vertexArrayVar.getArray();
for (auto& vertex : vertexArray) {
double x = vertex.getProperty("x", 0);
double y = vertex.getProperty("y", 0);
double z = vertex.getProperty("z", 0);
vertices[vertices.size() - 1].push_back(Vector3D(x, y, z));
vertices[vertices.size() - 1].push_back(Point(x, y, z));
}
}
auto matrix = *objects[i].getProperty("matrix", juce::Array<juce::var>()).getArray();
@ -103,7 +103,7 @@ void ObjectServer::run() {
allMatrices[i].push_back(value);
}
std::vector<std::vector<Vector3D>> reorderedVertices;
std::vector<std::vector<Point>> reorderedVertices;
if (vertices.size() > 0 && matrix.size() == 16) {
std::vector<bool> visited = std::vector<bool>(vertices.size(), false);
@ -136,7 +136,7 @@ void ObjectServer::run() {
}
for (int i = 0; i < vertices.size(); i++) {
std::vector<Vector3D> reorderedVertex;
std::vector<Point> reorderedVertex;
int index = order[i];
for (int j = 0; j < vertices[index].size(); j++) {
reorderedVertex.push_back(vertices[index][j]);

Wyświetl plik

@ -13,34 +13,6 @@ Point CircleArc::nextVector(double drawingProgress) {
);
}
void CircleArc::rotate(double theta) {
double cosTheta = std::cos(theta);
double sinTheta = std::sin(theta);
double newX = x * cosTheta - y * sinTheta;
double newY = x * sinTheta + y * cosTheta;
double newWidth = radiusX * cosTheta - radiusY * sinTheta;
double newHeight = radiusX * sinTheta + radiusY * cosTheta;
x = newX;
y = newY;
radiusX = newWidth;
radiusY = newHeight;
double newStartAngle = startAngle + theta;
double newEndAngle = endAngle + theta;
if (newStartAngle > 2 * std::numbers::pi) {
newStartAngle -= 2 * std::numbers::pi;
}
if (newEndAngle > 2 * std::numbers::pi) {
newEndAngle -= 2 * std::numbers::pi;
}
startAngle = newStartAngle;
endAngle = newEndAngle;
}
void CircleArc::scale(double x, double y) {
this->x *= x;
this->y *= y;

Wyświetl plik

@ -8,7 +8,6 @@ public:
CircleArc(double x, double y, double radiusX, double radiusY, double startAngle, double endAngle);
Point nextVector(double drawingProgress) override;
void rotate(double theta) override;
void scale(double x, double y) override;
void translate(double x, double y) override;
double length() override;

Wyświetl plik

@ -14,29 +14,6 @@ Point CubicBezierCurve::nextVector(double t) {
return Point(x, y);
}
void CubicBezierCurve::rotate(double theta) {
double cosTheta = std::cos(theta);
double sinTheta = std::sin(theta);
double newX1 = x1 * cosTheta - y1 * sinTheta;
double newY1 = x1 * sinTheta + y1 * cosTheta;
double newX2 = x2 * cosTheta - y2 * sinTheta;
double newY2 = x2 * sinTheta + y2 * cosTheta;
double newX3 = x3 * cosTheta - y3 * sinTheta;
double newY3 = x3 * sinTheta + y3 * cosTheta;
double newX4 = x4 * cosTheta - y4 * sinTheta;
double newY4 = x4 * sinTheta + y4 * cosTheta;
x1 = newX1;
y1 = newY1;
x2 = newX2;
y2 = newY2;
x3 = newX3;
y3 = newY3;
x4 = newX4;
y4 = newY4;
}
void CubicBezierCurve::scale(double x, double y) {
x1 *= x;
y1 *= y;

Wyświetl plik

@ -8,7 +8,6 @@ public:
CubicBezierCurve(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4);
Point nextVector(double drawingProgress) override;
void rotate(double theta) override;
void scale(double x, double y) override;
void translate(double x, double y) override;
double length() override;

Wyświetl plik

@ -1,29 +1,17 @@
#include "Line.h"
Line::Line(double x1, double y1, double x2, double y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
Line::Line(double x1, double y1, double x2, double y2) : x1(x1), y1(y1), z1(0), x2(x2), y2(y2), z2(0) {}
Line::Line(double x1, double y1, double z1, double x2, double y2, double z2) : x1(x1), y1(y1), z1(z1), x2(x2), y2(y2), z2(z2) {}
Point Line::nextVector(double drawingProgress) {
return Point(
x1 + (x2 - x1) * drawingProgress,
y1 + (y2 - y1) * drawingProgress
y1 + (y2 - y1) * drawingProgress,
z1 + (z2 - z1) * drawingProgress
);
}
void Line::rotate(double theta) {
double cosTheta = std::cos(theta);
double sinTheta = std::sin(theta);
double newX1 = x1 * cosTheta - y1 * sinTheta;
double newY1 = x1 * sinTheta + y1 * cosTheta;
double newX2 = x2 * cosTheta - y2 * sinTheta;
double newY2 = x2 * sinTheta + y2 * cosTheta;
x1 = newX1;
y1 = newY1;
x2 = newX2;
y2 = newY2;
}
void Line::scale(double x, double y) {
x1 *= x;
y1 *= y;

Wyświetl plik

@ -6,9 +6,9 @@
class Line : public Shape {
public:
Line(double x1, double y1, double x2, double y2);
Line(double x1, double y1, double z1, double x2, double y2, double z2);
Point nextVector(double drawingProgress) override;
void rotate(double theta) override;
void scale(double x, double y) override;
void translate(double x, double y) override;
static double length(double x1, double y1, double x2, double y2);
@ -16,6 +16,6 @@ public:
std::unique_ptr<Shape> clone() override;
std::string type() override;
double x1, y1, x2, y2;
double x1, y1, z1, x2, y2, z2;
};

Wyświetl plik

@ -12,15 +12,24 @@ Point Point::nextVector(double drawingProgress){
return Point(x, y, z);
}
void Point::rotate(double theta) {
double cosTheta = std::cos(theta);
double sinTheta = std::sin(theta);
double newX = x * cosTheta - y * sinTheta;
double newY = x * sinTheta + y * cosTheta;
void Point::rotate(double rotateX, double rotateY, double rotateZ) {
// rotate around x-axis
double cosValue = std::cos(rotateX);
double sinValue = std::sin(rotateX);
double y2 = cosValue * y - sinValue * z;
double z2 = sinValue * y + cosValue * z;
x = newX;
y = newY;
// rotate around y-axis
cosValue = std::cos(rotateY);
sinValue = std::sin(rotateY);
double x2 = cosValue * x + sinValue * z2;
z = -sinValue * x + cosValue * z2;
// rotate around z-axis
cosValue = cos(rotateZ);
sinValue = sin(rotateZ);
x = cosValue * x2 - sinValue * y2;
y = sinValue * x2 + cosValue * y2;
}
void Point::scale(double x, double y) {

Wyświetl plik

@ -12,7 +12,6 @@ public:
Point();
Point nextVector(double drawingProgress) override;
void rotate(double theta) override;
void scale(double x, double y) override;
void translate(double x, double y) override;
void reflectRelativeToVector(double x, double y);
@ -21,6 +20,8 @@ public:
std::unique_ptr<Shape> clone() override;
std::string type() override;
void rotate(double rotateX, double rotateY, double rotateZ);
// copy assignment operator
Point& operator=(const Point& other);

Wyświetl plik

@ -10,7 +10,6 @@ class Point;
class Shape {
public:
virtual Point nextVector(double drawingProgress) = 0;
virtual void rotate(double theta) = 0;
virtual void scale(double x, double y) = 0;
virtual void translate(double x, double y) = 0;
virtual double length() = 0;