add rail rendering and link and improve rendering performance by a bit

This commit is contained in:
DJMrTV 2024-03-18 19:26:47 +01:00
commit dbc1ad5b4b
8 changed files with 235 additions and 97 deletions

View file

@ -9,9 +9,11 @@ find_package(GLEW REQUIRED)
find_package(yaml-cpp REQUIRED)
find_package(glm REQUIRED)
add_library(SpoonMapTools STATIC src/Map.cpp include/Map.h include/LevelObject.h include/Transform.h "include/Vector3.h" src/Vectior3.cpp src/Transform.cpp src/LevelObject.cpp include/Link.h src/Link.cpp include/Rail.h src/Rail.cpp include/RailPoint.h src/RailPoint.cpp include/SpecialObjectParams.h src/SpecialObjectParams.cpp include/SpecialObjectParamVersions/All.h include/SpecialObjectParamVersions/Default.h include/Element.h src/Element.cpp)
target_include_directories(SpoonMapTools PUBLIC include)
target_link_libraries(SpoonMapTools PUBLIC Boost::filesystem Boost::iostreams GLEW::GLEW yaml-cpp)
target_link_libraries(SpoonMapTools PUBLIC Boost::filesystem Boost::iostreams GLEW::GLEW yaml-cpp glm::glm)

View file

@ -6,14 +6,59 @@
#define SPOONTOOL_TRANSFORM_H
#include<Vector3.h>
#include<yaml-cpp/yaml.h>
#include<glm/mat4x4.hpp>
#include "glm/ext/vector_float3.hpp"
#include "glm/ext/matrix_transform.hpp"
#include<glm/mat3x2.hpp>
#include<glm/mat3x3.hpp>
#include<glm/vec3.hpp>
#include<glm/vec2.hpp>
struct Transform{
inline Transform(): Position(0,0,0), Scale(1,1,1), Rotation(0,0,0),
LastPosition(0,0,0), LastScale(0,0,0), LastRotation(0,0,0){}
inline Transform(Vector3 pos, Vector3 scale, Vector3 rot): Position(pos), Scale(scale), Rotation(rot),
LastPosition(0,0,0), LastScale(0,0,0), LastRotation(0,0,0){}
inline Transform(): Position(0,0,0), Scale(1,1,1), Rotation(0,0,0) {}
inline void updateMatricies() {
glm::vec3& pos = *(glm::vec3*)&Position;
glm::vec3& rot = *(glm::vec3*)&Rotation;
glm::vec3& scale = *(glm::vec3*)&Scale;
glm::mat4 translationMatrix = glm::translate(glm::mat4(1),glm::vec3(pos.x,pos.y,pos.z));
glm::mat4 rotationMatrixZ = glm::rotate(glm::mat4(1),glm::radians(rot.z), glm::vec3(0,0,1));
glm::mat4 rotationMatrixY = glm::rotate(rotationMatrixZ,glm::radians(rot.y), glm::vec3(0,1,0));
rotationMatrix = glm::rotate(rotationMatrixY,glm::radians(rot.x), glm::vec3(1,0,0));
glm::mat4 scaleMatrix = glm::scale(glm::mat4(1),scale);
matrix = translationMatrix * rotationMatrix * scaleMatrix;
}
inline void recalcMatriciesIfNeeded() {
if( Position != LastPosition ||
Scale != LastScale ||
Rotation != LastRotation ) {
updateMatricies();
LastPosition = Position;
LastScale = Scale;
LastRotation = Rotation;
}
}
Vector3 Position,Scale,Rotation;
glm::mat4 matrix, rotationMatrix;
void InsertIntoYaml(YAML::Emitter &Emitter);
private:
Vector3 LastPosition,LastScale,LastRotation;
};
#endif //SPOONTOOL_TRANSFORM_H

View file

@ -25,5 +25,11 @@ struct Vector3{
Emitter << YAML::EndMap;
}
inline bool operator != (const Vector3& v) const{
return X != v.X ||
Y != v.Y ||
Z != v.Z;
}
};
#endif //SPOONTOOL_VECTOR3_H