aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/raytracer/raytracer.h1
-rw-r--r--src/utils/scenefilereader.cpp48
2 files changed, 31 insertions, 18 deletions
diff --git a/src/raytracer/raytracer.h b/src/raytracer/raytracer.h
index 4df9200..9bbeb5c 100644
--- a/src/raytracer/raytracer.h
+++ b/src/raytracer/raytracer.h
@@ -9,6 +9,7 @@
#include <QOpenGLWidget>
#include <QLabel>
#include <QElapsedTimer>
+#include <unordered_map>
// A forward declaration for the RaytraceScene class
diff --git a/src/utils/scenefilereader.cpp b/src/utils/scenefilereader.cpp
index ef06a7b..de5dce4 100644
--- a/src/utils/scenefilereader.cpp
+++ b/src/utils/scenefilereader.cpp
@@ -638,11 +638,11 @@ bool ScenefileReader::parseGroupData(const QJsonObject &object, SceneNode *node)
}
QJsonArray translateArray = object["translate"].toArray();
- if (translateArray.size() != 3) {
- std::cout << "group translate must have 3 elements" << std::endl;
+ if (translateArray.size() != 4) {
+ std::cout << "group translate must have 4 elements" << std::endl;
return false;
}
- if (!translateArray[0].isDouble() || !translateArray[1].isDouble() || !translateArray[2].isDouble()) {
+ if (!translateArray[0].isDouble() || !translateArray[1].isDouble() || !translateArray[2].isDouble() || !translateArray[3].isDouble()) {
std::cout << "group translate must contain floating-point values" << std::endl;
return false;
}
@@ -652,6 +652,7 @@ bool ScenefileReader::parseGroupData(const QJsonObject &object, SceneNode *node)
translation->translate.x = translateArray[0].toDouble();
translation->translate.y = translateArray[1].toDouble();
translation->translate.z = translateArray[2].toDouble();
+ translation->translate.w = translateArray[3].toDouble();
node->transformations.push_back(translation);
}
@@ -664,21 +665,24 @@ bool ScenefileReader::parseGroupData(const QJsonObject &object, SceneNode *node)
}
QJsonArray rotateArray = object["rotate"].toArray();
- if (rotateArray.size() != 4) {
- std::cout << "group rotate must have 4 elements" << std::endl;
+ if (rotateArray.size() != 7) {
+ std::cout << "group rotate must have 7 elements" << std::endl;
return false;
}
- if (!rotateArray[0].isDouble() || !rotateArray[1].isDouble() || !rotateArray[2].isDouble() || !rotateArray[3].isDouble()) {
+ if (!rotateArray[0].isDouble() || !rotateArray[1].isDouble() || !rotateArray[2].isDouble() || !rotateArray[3].isDouble() || !rotateArray[4].isDouble() || !rotateArray[5].isDouble() || !rotateArray[6].isDouble()) {
std::cout << "group rotate must contain floating-point values" << std::endl;
return false;
}
SceneTransformation *rotation = new SceneTransformation();
rotation->type = TransformationType::TRANSFORMATION_ROTATE;
-// rotation->rotate.x = rotateArray[0].toDouble();
-// rotation->rotate.y = rotateArray[1].toDouble();
-// rotation->rotate.z = rotateArray[2].toDouble();
- rotation->angle = rotateArray[3].toDouble() * M_PI / 180.f;
+ rotation->rotate3.x = rotateArray[0].toDouble();
+ rotation->rotate3.y = rotateArray[1].toDouble();
+ rotation->rotate3.z = rotateArray[2].toDouble();
+ rotation->rotateW.x = rotateArray[3].toDouble();
+ rotation->rotateW.y = rotateArray[4].toDouble();
+ rotation->rotateW.z = rotateArray[5].toDouble();
+ rotation->angle = rotateArray[6].toDouble() * M_PI / 180.f;
node->transformations.push_back(rotation);
}
@@ -691,11 +695,11 @@ bool ScenefileReader::parseGroupData(const QJsonObject &object, SceneNode *node)
}
QJsonArray scaleArray = object["scale"].toArray();
- if (scaleArray.size() != 3) {
- std::cout << "group scale must have 3 elements" << std::endl;
+ if (scaleArray.size() != 4) {
+ std::cout << "group scale must have 4 elements" << std::endl;
return false;
}
- if (!scaleArray[0].isDouble() || !scaleArray[1].isDouble() || !scaleArray[2].isDouble()) {
+ if (!scaleArray[0].isDouble() || !scaleArray[1].isDouble() || !scaleArray[2].isDouble() || !scaleArray[3].isDouble()) {
std::cout << "group scale must contain floating-point values" << std::endl;
return false;
}
@@ -705,6 +709,7 @@ bool ScenefileReader::parseGroupData(const QJsonObject &object, SceneNode *node)
scale->scale.x = scaleArray[0].toDouble();
scale->scale.y = scaleArray[1].toDouble();
scale->scale.z = scaleArray[2].toDouble();
+ scale->scale.w = scaleArray[3].toDouble();
node->transformations.push_back(scale);
}
@@ -717,8 +722,8 @@ bool ScenefileReader::parseGroupData(const QJsonObject &object, SceneNode *node)
}
QJsonArray matrixArray = object["matrix"].toArray();
- if (matrixArray.size() != 4) {
- std::cout << "group matrix must be 4x4" << std::endl;
+ if (matrixArray.size() != 5) {
+ std::cout << "group matrix must be 5x5" << std::endl;
return false;
}
@@ -726,16 +731,19 @@ bool ScenefileReader::parseGroupData(const QJsonObject &object, SceneNode *node)
matrixTransformation->type = TransformationType::TRANSFORMATION_MATRIX;
float *matrixPtr = glm::value_ptr(matrixTransformation->matrix);
+ float *matrixRightPtr = glm::value_ptr(matrixTransformation->matrixRight4d);
int rowIndex = 0;
for (auto row : matrixArray) {
+ if (rowIndex == 4) break; // skip the last row
+
if (!row.isArray()) {
std::cout << "group matrix must be of type array of array" << std::endl;
return false;
}
QJsonArray rowArray = row.toArray();
- if (rowArray.size() != 4) {
- std::cout << "group matrix must be 4x4" << std::endl;
+ if (rowArray.size() != 5) {
+ std::cout << "group matrix must be 5x5" << std::endl;
return false;
}
@@ -747,7 +755,11 @@ bool ScenefileReader::parseGroupData(const QJsonObject &object, SceneNode *node)
}
// fill in column-wise
- matrixPtr[colIndex * 4 + rowIndex] = (float)val.toDouble();
+ if (colIndex == 4) {
+ matrixRightPtr[rowIndex] = (float)val.toDouble();
+ } else {
+ matrixPtr[colIndex * 4 + rowIndex] = (float)val.toDouble();
+ }
colIndex++;
}
rowIndex++;