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

View file

@ -33,37 +33,38 @@ glm::vec3 ToGlmVec3(Vector3 Vec3) {
return {Vec3.X, Vec3.Y, Vec3.Z};
}
bool IsArea(const std::string& Type) {
return std::any_of(Configs::g_areas.begin(), Configs::g_areas.end(),[&](const std::string &areatype){
bool IsArea(const std::string &Type) {
return std::any_of(Configs::g_areas.begin(), Configs::g_areas.end(), [&](const std::string &areatype) {
return Type == areatype;
});
}
MENU_ITEM_DISPLAY(Widgets,Viewport,ICON_FA_VIDEO " Viewport"){
MENU_ITEM_DISPLAY(Widgets, Viewport, ICON_FA_VIDEO " Viewport") {
Graphics::window->WidgetByName.find("Main Viewport")->second->Active ^= true;
}
MainViewport::MainViewport() : Graphics::ViewportWidget("Main Viewport", true), VP(1.0f), defaultShader("ForwardPass"), flatShader("FlatForwardPass") {
MainViewport::MainViewport() : Graphics::ViewportWidget("Main Viewport", true), VP(1.0f), defaultShader("ForwardPass"),
flatShader("FlatForwardPass"), linkLineShader("Link") {
MainVP = this;
m_internalFramebuf = std::make_unique<Graphics::Framebuffer>(
std::vector<Graphics::FramebufferTextureInfo>{
{GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GL_COLOR_ATTACHMENT0},
{GL_R32I, GL_RED_INTEGER, GL_INT, GL_COLOR_ATTACHMENT1},
{GL_RGBA16F, GL_RGBA, GL_FLOAT, GL_COLOR_ATTACHMENT2},
{GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH_STENCIL_ATTACHMENT}
{GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GL_COLOR_ATTACHMENT0}, // Albedo
{GL_R32I, GL_RED_INTEGER, GL_INT, GL_COLOR_ATTACHMENT1}, // Object Id
{GL_RGBA32F, GL_RGBA, GL_FLOAT, GL_COLOR_ATTACHMENT2}, // World Position
{GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH_STENCIL_ATTACHMENT} //Depth Stencil
},
defaultShader);
SunCam = std::make_unique<Graphics::Framebuffer>(
std::vector<Graphics::FramebufferTextureInfo>{
{GL_DEPTH_COMPONENT16,GL_DEPTH_COMPONENT,GL_FLOAT,GL_DEPTH_ATTACHMENT}
{GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_FLOAT, GL_DEPTH_ATTACHMENT}
},
Graphics::Shader("ShadowPass"),
Math::Vector2i(8192,8192));
Math::Vector2i(8192, 8192));
auto& tex = SunCam->getFbTexByAttachment(GL_DEPTH_ATTACHMENT);
auto &tex = SunCam->getFbTexByAttachment(GL_DEPTH_ATTACHMENT);
glBindTexture(GL_TEXTURE_2D, tex.m_texture->getId());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@ -72,7 +73,7 @@ MainViewport::MainViewport() : Graphics::ViewportWidget("Main Viewport", true),
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture(GL_TEXTURE_2D,0);
glBindTexture(GL_TEXTURE_2D, 0);
//ObjMesh = Graphics::Mesh();
@ -91,14 +92,59 @@ MainViewport::MainViewport() : Graphics::ViewportWidget("Main Viewport", true),
}
glm::vec3 calcBezier(const std::array<glm::vec3, 4> &points, float value) {
return points[0] * (1 * powf(1 - value, 3) * powf(value, 0)) +
points[1] * (3 * powf(1 - value, 2) * powf(value, 1)) +
points[2] * (3 * powf(1 - value, 1) * powf(value, 2)) +
points[3] * (1 * powf(1 - value, 0) * powf(value, 3));
}
void MainViewport::RenderRail(Rail *rail) {
static Model RailPointMdl = Model("St_RailPoint");
if (rail->Points.size() > 1) {
auto lastRailPoint = rail->Points.front();
if (rail->Points.size() >= 1) {
const RailPoint *lastRailPoint = &rail->Points.back();
if(!displayRailsAsLoop)
lastRailPoint = nullptr;
for (RailPoint &railPoint: rail->Points) {
RailPointMdl.Draw(railPoint.TF, m_internalFramebuf->m_shader, VP);
if (rail->m_railType == RailType::Linear) {
if(lastRailPoint) {
drawLine(*(glm::vec3 *) &railPoint.TF.Position, *(glm::vec3 *) &lastRailPoint->TF.Position,
{1.0, 1.0, 0.0, 1.0});
}
} else {
for (const Vector3 &vec: railPoint.m_controlPoints) {
Transform controlPointTransform = {vec, Vector3{0.25, 0.25, 0.25},
Vector3{0, 0, 0}};
RailPointMdl.Draw(controlPointTransform, m_internalFramebuf->m_shader, VP);
}
if(lastRailPoint) {
glm::vec3 lastPos = *(glm::vec3 *) &lastRailPoint->TF.Position;
std::array<glm::vec3, 4> points = {
*(glm::vec3 *) &lastRailPoint->TF.Position,
*(glm::vec3 *) &lastRailPoint->m_controlPoints[1],
*(glm::vec3 *) &railPoint.m_controlPoints[0],
*(glm::vec3 *) &railPoint.TF.Position
};
for (unsigned i = 1; i <= bezierSegments; i += 1) {
float val = (float) i / bezierSegments;
glm::vec3 nextPos = calcBezier(points, val);
drawLine(lastPos, nextPos,
{1.0, 1.0, 0.0, 1.0});
lastPos = nextPos;
}
}
}
lastRailPoint = &railPoint;
}
}
}
@ -106,7 +152,7 @@ void MainViewport::RenderRail(Rail *rail) {
void MainViewport::Draw() {
if(greenScreen) {
if (greenScreen) {
glClearColor(0, 1, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
}
@ -114,8 +160,6 @@ void MainViewport::Draw() {
m_internalFramebuf->m_shader.use();
static auto lasttime = boost::chrono::high_resolution_clock::now();
auto timenow = boost::chrono::high_resolution_clock::now();
@ -183,6 +227,8 @@ void MainViewport::Draw() {
if (ImGui::BeginPopup("Main VP Debug")) {
ImGui::DragFloat3("Camera Postion", &camPos.x, 0.01);
ImGui::DragFloat2("Camera Rotation", &camrot.x, 0.01);
ImGui::SliderFloat("FOV", &fov, 0, 180);
@ -196,8 +242,11 @@ void MainViewport::Draw() {
ImGui::DragFloat3("Light Direction", &LightDir.x, 0.01);
ImGui::Checkbox("Draw All Areas", &drawAllAreas);
ImGui::Checkbox("Green Screen", &greenScreen);
if(ImGui::Button("Switch Shading Modes")){
if(flatShading)
ImGui::Checkbox("Display rails as loop", &displayRailsAsLoop);
ImGui::InputInt("Bezier Segments", &bezierSegments);
bezierSegments = std::max(bezierSegments,0);
if (ImGui::Button("Switch Shading Modes")) {
if (flatShading)
m_internalFramebuf->m_shader = defaultShader;
else
m_internalFramebuf->m_shader = flatShader;
@ -215,7 +264,7 @@ void MainViewport::Draw() {
ImGui::EndPopup();
}
glUniform3f(CamPosLoc, camPos.x,camPos.y,camPos.z);
glUniform3f(CamPosLoc, camPos.x, camPos.y, camPos.z);
glUniform1f(distribLoc, m_smoothingFactor);
glUniform1f(shadHardLoc, m_shadowHardness);
@ -223,8 +272,8 @@ void MainViewport::Draw() {
m_internalFramebuf->m_shader.use();
if(!flatShading)
glUniform3f(LightDirId, LightDir.x , LightDir.y,LightDir.z);
if (!flatShading)
glUniform3f(LightDirId, LightDir.x, LightDir.y, LightDir.z);
glUniform4f(ObjColPos, 1, 1, 1, 1);
@ -243,11 +292,11 @@ void MainViewport::Draw() {
unsigned int ObjID = 16;
if(!flatShading) {
if (!flatShading) {
glm::vec3 SunPos = glm::normalize(LightDir) * 2000.0f;
glm::mat4 SunProj = glm::ortho(-shadowArea, shadowArea, -shadowArea, shadowArea, 500.0f, 3000.0f );
glm::mat4 SunProj = glm::ortho(-shadowArea, shadowArea, -shadowArea, shadowArea, 500.0f, 3000.0f);
glm::mat4 SunView = glm::lookAt(SunPos, {0, 0, 0}, {0, 1, 0});
@ -300,21 +349,30 @@ void MainViewport::Draw() {
tex.m_texture->setActive(5);
glUniformMatrix4fv(SunVpLoc,1,GL_FALSE,&SunVP[0][0]);
glUniformMatrix4fv(SunVpLoc, 1, GL_FALSE, &SunVP[0][0]);
}
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
for (auto &obj: loadedMap.Objects) {
glUniform1i(TeamId,(GLint)obj.Team);
if (&obj == selectedElem) {
for (const Link &link: obj.Links) {
if (Element *elem = loadedMap.GetElementById(link.Destination)) {
drawLine(*(glm::vec3 *) &obj.TF.Position, *(glm::vec3 *) &elem->TF.Position,
{1.0f, 0.0f, 0.0f, 1.0f});
}
}
}
glUniform1i(TeamId, (GLint) obj.Team);
if (IsArea(obj.Type) && !drawAllAreas) {
ObjID++;
@ -341,8 +399,9 @@ void MainViewport::Draw() {
auto &mdl = MdlFromObj.find(obj.Type)->second;
glUniform1i(ObjIdPos, ObjID);
if (&obj == selectedElem)
if (&obj == selectedElem) {
glUniform4f(ObjColPos, 1, .7, .7, 1);
}
mdl.Draw(obj.TF, m_internalFramebuf->m_shader, VP);
if (&obj == selectedElem)
@ -534,8 +593,8 @@ void MainViewport::HandleInput(InputEvent event) {
GLint y = event.y * m_internalFramebuf->getSize().y;
GLint x = event.x * m_internalFramebuf->getSize().x;
glReadBuffer(GL_COLOR_ATTACHMENT1);
glReadPixels(x, y, 1, 1, GL_RED_INTEGER, GL_UNSIGNED_INT, &HoveredObjId);
//glReadBuffer(GL_COLOR_ATTACHMENT1);
//glReadPixels(x, y, 1, 1, GL_RED_INTEGER, GL_UNSIGNED_INT, &HoveredObjId);
}
break;
case (InputType::MouseDownL): {
@ -638,7 +697,7 @@ void MainViewport::HandleInput(InputEvent event) {
auto iter = loadedMap.Objects.begin();
while(obj != 0){
while (obj != 0) {
iter++;
obj--;
}
@ -684,11 +743,11 @@ void MainViewport::HandleInput(InputEvent event) {
auto ClipSpaceEnd = (VP * Tf) * glm::vec4(GizmoDir, 1);
glm::vec2 ScreenSpaceStart = {
((ClipSpaceStart.x / ClipSpaceStart.w + 1) / 2) * (float)m_internalFramebuf->getSize().x,
((ClipSpaceStart.y / ClipSpaceStart.w + 1) / 2) * (float)m_internalFramebuf->getSize().y};
((ClipSpaceStart.x / ClipSpaceStart.w + 1) / 2) * (float) m_internalFramebuf->getSize().x,
((ClipSpaceStart.y / ClipSpaceStart.w + 1) / 2) * (float) m_internalFramebuf->getSize().y};
glm::vec2 ScreenSpaceEnd = {
((ClipSpaceEnd.x / ClipSpaceEnd.w + 1) / 2) * (float)m_internalFramebuf->getSize().x,
((ClipSpaceEnd.y / ClipSpaceEnd.w + 1) / 2) * (float)m_internalFramebuf->getSize().y};
((ClipSpaceEnd.x / ClipSpaceEnd.w + 1) / 2) * (float) m_internalFramebuf->getSize().x,
((ClipSpaceEnd.y / ClipSpaceEnd.w + 1) / 2) * (float) m_internalFramebuf->getSize().y};
glm::vec2 ScrenSpaceDir = ScreenSpaceEnd - ScreenSpaceStart;
@ -701,7 +760,7 @@ void MainViewport::HandleInput(InputEvent event) {
glReadBuffer(GL_COLOR_ATTACHMENT2);
glm::vec4 CurWDirPos = {0, 0, 0, 0};
glReadPixels((int)floorf(FixedMousePos.x), (int)floorf(FixedMousePos.y), 1, 1, GL_RGBA, GL_FLOAT,
glReadPixels((int) floorf(FixedMousePos.x), (int) floorf(FixedMousePos.y), 1, 1, GL_RGBA, GL_FLOAT,
glm::value_ptr(CurWDirPos));
//std::cout << glm::to_string(CurWDirPos) << std::endl;
@ -887,16 +946,16 @@ void MainViewport::clearModels() {
}
void MainViewport::cleanUnnescessary() {
for(auto mdlPairIter = MdlFromObj.begin(); mdlPairIter != MdlFromObj.end(); ){
for (auto mdlPairIter = MdlFromObj.begin(); mdlPairIter != MdlFromObj.end();) {
auto nextiter = mdlPairIter;
nextiter++;
if(nextiter == MdlFromObj.end())
if (nextiter == MdlFromObj.end())
break;
if(std::none_of(loadedMap.Objects.begin(), loadedMap.Objects.end(),[&](const LevelObject &obj){
if (std::none_of(loadedMap.Objects.begin(), loadedMap.Objects.end(), [&](const LevelObject &obj) {
return obj.Type == nextiter->first;
})){
})) {
MdlFromObj.erase(nextiter);
} else {
mdlPairIter = nextiter;
@ -904,6 +963,67 @@ void MainViewport::cleanUnnescessary() {
}
}
void MainViewport::drawLine(const glm::vec3 &pos1, const glm::vec3 &pos2, const glm::vec4 &color, float width) {
glm::vec4 cpos1 = VP * glm::vec4(pos1, 1.0f);
glm::vec4 cpos2 = VP * glm::vec4(pos2, 1.0f);
static GLuint VAO = []() -> GLuint {
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
GLuint VBO;
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, 0, {0}, GL_STATIC_DRAW);
glVertexAttribPointer(0, 0, GL_INT, GL_FALSE, 0, (void *) 0);
glEnableVertexAttribArray(0);
glBindVertexArray(0);
return VAO;
}();
glBindVertexArray(VAO);
glm::vec3 vecarr[2] = {};
vecarr[0] = {cpos1.x / cpos1.w, -(cpos1.y / cpos1.w), cpos1.z / cpos1.w};
vecarr[1] = {cpos2.x / cpos2.w, -(cpos2.y / cpos2.w), cpos2.z / cpos2.w};
for (glm::vec3 &vec: vecarr) {
if (vec.z > 1) {
vec.x = -vec.x;
vec.y = -vec.y;
}
}
this->linkLineShader.use();
static int posLoc = this->linkLineShader.getUniformLocation("position");
static int widthLoc = this->linkLineShader.getUniformLocation("width");
static int colorLoc = this->linkLineShader.getUniformLocation("color");
glm::vec2 screensize = {(float) m_internalFramebuf->getSize().x, (float) m_internalFramebuf->getSize().y};
glm::vec2 scaledWidth = glm::vec2(width, width) / screensize;
glUniform3fv(posLoc, 2, (const GLfloat *) (&vecarr[0].x));
glUniform2fv(widthLoc, 1, &scaledWidth.x);
glUniform4fv(colorLoc, 1, &color.x);
const GLenum buffers[] = {GL_COLOR_ATTACHMENT0};
glDrawBuffers(1, buffers);
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindVertexArray(0);
m_internalFramebuf->m_shader.use();
}
MainViewport *g_getMainViewport() {
return MainVP;
}

View file

@ -32,6 +32,8 @@ public:
void cleanUnnescessary();
void drawLine(const glm::vec3 &pos1, const glm::vec3 &pos2, const glm::vec4 &color = glm::vec4(1), float width = 2);
std::unordered_map<std::string,Model> MdlFromObj;
glm::mat4 VP;
@ -42,6 +44,7 @@ private:
Graphics::Shader flatShader;
Graphics::Shader defaultShader;
Graphics::Shader linkLineShader;
bool flatShading = false;
@ -68,6 +71,10 @@ private:
float m_smoothingFactor = 1.0f;
float m_shadowHardness = 2.5f;
int bezierSegments = 40;
bool displayRailsAsLoop = false;
glm::vec3 LightDir = {1,1,1};

View file

@ -87,7 +87,7 @@ public:
m_maptex.setActive(6);
for (const auto &item: loadedMap.Objects){
for (auto &item: loadedMap.Objects){
if(item.Layer == "Tmp")
continue;
if(!item.m_isStatic)

View file

@ -17,10 +17,12 @@
#include<glm/vec3.hpp>
#include<glm/vec2.hpp>
Assimp::Importer importer;
Model::Model(std::string modelname) {
auto modeltoload = boost::filesystem::current_path() / "Models" / modelname / (modelname + ".dae");
Assimp::Importer importer;
const aiScene* scene = importer.ReadFile( modeltoload.string(),
aiProcess_CalcTangentSpace |
aiProcess_Triangulate |
@ -80,33 +82,22 @@ Model::Model(std::string modelname) {
}
}
void Model::Draw(const Transform &tf, Graphics::Shader &shader, const glm::mat4 &VP) {
void Model::Draw(Transform &tf, Graphics::Shader &shader, const glm::mat4 &VP) {
unsigned int texnum = 0;
for(auto& mesh: Meshes){
tf.recalcMatriciesIfNeeded();
glm::vec3 pos(tf.Position.X,tf.Position.Y,tf.Position.Z);
glm::vec3 rot(tf.Rotation.X,tf.Rotation.Y,tf.Rotation.Z);
glm::vec3 normalRot(tf.Rotation.X,tf.Rotation.Y,tf.Rotation.Z);
glm::vec3 scale(tf.Scale.X,tf.Scale.Y,tf.Scale.Z);
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));
glm::mat4 rotationMatrix = glm::rotate(rotationMatrixY,glm::radians(rot.x), glm::vec3(1,0,0));
glm::mat4 scaleMatrix = glm::scale(glm::mat4(1),scale);
glm::mat4 matrix = VP * translationMatrix * rotationMatrix * scaleMatrix;
glm::mat4 ModelMatrix = translationMatrix * rotationMatrix * scaleMatrix;
glm::mat4 matrix = VP * tf.matrix;
GLuint MatrixID = shader.getUniformLocation("MVP");
glUniformMatrix4fv(MatrixID,1,GL_FALSE,&matrix[0][0]);
GLuint ModelMatrixID = shader.getUniformLocation("ModelMatrix");
glUniformMatrix4fv(ModelMatrixID,1,GL_FALSE,&ModelMatrix[0][0]);
glUniformMatrix4fv(ModelMatrixID,1,GL_FALSE,&tf.matrix[0][0]);
GLuint RotationMatrixID = shader.getUniformLocation("NormalRotationMatrix");
glUniformMatrix4fv(RotationMatrixID,1,GL_FALSE,&rotationMatrix[0][0]);
glUniformMatrix4fv(RotationMatrixID,1,GL_FALSE,&tf.rotationMatrix[0][0]);
mesh->Draw(*Materials[texnum]);
texnum++;
@ -114,40 +105,7 @@ void Model::Draw(const Transform &tf, Graphics::Shader &shader, const glm::mat4
}
void Model::DrawSelection(Transform tf, Graphics::Shader &shader, glm::mat4 VP) {
unsigned int texnum = 0;
static Graphics::Texture selectionTex = Graphics::Texture((boost::filesystem::current_path() / "Models" / "selected.png"));
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
for(auto &mesh: Meshes){
glm::vec3 pos(tf.Position.X,tf.Position.Y,tf.Position.Z);
glm::vec3 rot(-tf.Rotation.X,tf.Rotation.Y,tf.Rotation.Z);
glm::vec3 scale(tf.Scale.X,tf.Scale.Y,tf.Scale.Z);
glm::mat4 translationMatrix = glm::translate(glm::mat4(1),glm::vec3(pos.x,-pos.y,pos.z));
glm::mat4 translationNoYInvertMatrix = 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));
glm::mat4 rotationMatrix = glm::rotate(rotationMatrixY,glm::radians(rot.x), glm::vec3(1,0,0));
glm::mat4 scaleMatrix = glm::scale(glm::mat4(1),scale);
glm::mat4 matrix = VP * translationMatrix * rotationMatrix * scaleMatrix;
glm::mat4 noYInvertMatrix = translationNoYInvertMatrix * rotationMatrix * scaleMatrix;
GLuint MatrixID = shader.getUniformLocation("MVP");
glUniformMatrix4fv(MatrixID,1,GL_FALSE,&matrix[0][0]);
GLuint MatrixNoYInvID = shader.getUniformLocation("TransformationMatrixNoYInv");
glUniformMatrix4fv(MatrixNoYInvID,1,GL_FALSE,&noYInvertMatrix[0][0]);
mesh->Draw(*Materials[texnum]);
texnum++;
}
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
assert("This function is deprecated");
}

View file

@ -20,7 +20,7 @@ public:
Model(Model&&) = default;
void Draw(const Transform &tf, Graphics::Shader &shader, const glm::mat4 &VP);
void Draw(Transform &tf, Graphics::Shader &shader, const glm::mat4 &VP);
void DrawSelection(Transform tf, Graphics::Shader &shader, glm::mat4 VP);
protected: