diff --git a/DisplayGLFW/Debug/CL.read.1.tlog b/DisplayGLFW/Debug/CL.read.1.tlog deleted file mode 100644 index 371c86d..0000000 Binary files a/DisplayGLFW/Debug/CL.read.1.tlog and /dev/null differ diff --git a/DisplayGLFW/Debug/CL.write.1.tlog b/DisplayGLFW/Debug/CL.write.1.tlog deleted file mode 100644 index 1bdd0b3..0000000 Binary files a/DisplayGLFW/Debug/CL.write.1.tlog and /dev/null differ diff --git a/DisplayGLFW/Debug/Lib-link.read.1.tlog b/DisplayGLFW/Debug/Lib-link.read.1.tlog deleted file mode 100644 index 9b0bf7e..0000000 Binary files a/DisplayGLFW/Debug/Lib-link.read.1.tlog and /dev/null differ diff --git a/DisplayGLFW/Debug/Lib-link.write.1.tlog b/DisplayGLFW/Debug/Lib-link.write.1.tlog deleted file mode 100644 index b4fa77c..0000000 Binary files a/DisplayGLFW/Debug/Lib-link.write.1.tlog and /dev/null differ diff --git a/DisplayGLFW/Debug/cl.command.1.tlog b/DisplayGLFW/Debug/cl.command.1.tlog deleted file mode 100644 index e92b501..0000000 Binary files a/DisplayGLFW/Debug/cl.command.1.tlog and /dev/null differ diff --git a/DisplayGLFW/Debug/lib.command.1.tlog b/DisplayGLFW/Debug/lib.command.1.tlog deleted file mode 100644 index 916200f..0000000 Binary files a/DisplayGLFW/Debug/lib.command.1.tlog and /dev/null differ diff --git a/DisplayGLFW/DisplayGLFW.vcxproj b/DisplayGLFW/DisplayGLFW.vcxproj index 9fce475..84cdb17 100644 --- a/DisplayGLFW/DisplayGLFW.vcxproj +++ b/DisplayGLFW/DisplayGLFW.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -19,18 +19,19 @@ {0C9D56F3-8B06-460D-9017-D1C3E1F6DC51} DisplayGLFW + 10.0.17763.0 StaticLibrary true - v110 + v141 MultiByte StaticLibrary false - v110 + v141 true MultiByte diff --git a/DisplayGLFW/display.cpp b/DisplayGLFW/display.cpp index 1b21b81..492e5f9 100644 --- a/DisplayGLFW/display.cpp +++ b/DisplayGLFW/display.cpp @@ -36,7 +36,7 @@ void Display::addKeyCallBack(void(*keyCallback)(GLFWwindow *,int,int,int,int)) //glfwSetKeyCallback(m_window,[](GLFWwindow *window,int key,int scancode,int action,int mods){ // func(glfwGetWindowUserPointer(window),key,scancode,action,mods); //}); - //key_callback); + // key_callback); @@ -79,9 +79,9 @@ Display::~Display() //SDL_Quit(); } -void Display::Clear(float r, float g, float b, float a) +void Display::Clear(float r, float g, float my_curve, float a) { - glClearColor(r, g, b, a); + glClearColor(r, g, my_curve, a); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } diff --git a/EngineVideoGames.sln b/EngineVideoGames.sln index d1b9340..b346415 100644 --- a/EngineVideoGames.sln +++ b/EngineVideoGames.sln @@ -1,5 +1,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.489 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Game", "Game\Game.vcxproj", "{257FC222-2301-4B67-A02B-880548704235}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EngineVideoGames", "EngineVideoGames\EngineVideoGames.vcxproj", "{42AF4C92-9210-42BB-AFD2-30E6108E4CC4}" @@ -7,6 +9,9 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DisplayGLFW", "DisplayGLFW\DisplayGLFW.vcxproj", "{0C9D56F3-8B06-460D-9017-D1C3E1F6DC51}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "KDtree", "KDtree\KDtree.vcxproj", "{7CE449AF-34F9-48D2-8604-7C3D4910871D}" + ProjectSection(ProjectDependencies) = postProject + {257FC222-2301-4B67-A02B-880548704235} = {257FC222-2301-4B67-A02B-880548704235} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "linearSolver", "linearSolver\linearSolver\linearSolver.vcxproj", "{DECFCF3E-C42F-4674-B514-033BC0402038}" EndProject @@ -46,4 +51,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {11926EE0-CFD5-494D-8CCC-EC99FEDAF4B8} + EndGlobalSection EndGlobal diff --git a/EngineVideoGames/EngineVideoGames.vcxproj b/EngineVideoGames/EngineVideoGames.vcxproj index a6ac699..f0a0839 100644 --- a/EngineVideoGames/EngineVideoGames.vcxproj +++ b/EngineVideoGames/EngineVideoGames.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -13,18 +13,19 @@ {42AF4C92-9210-42BB-AFD2-30E6108E4CC4} EngineVideoGames + 10.0.17763.0 StaticLibrary true - v110 + v141 MultiByte StaticLibrary false - v110 + v141 true MultiByte diff --git a/EngineVideoGames/Mesh.cpp b/EngineVideoGames/Mesh.cpp index bdecfab..939bef6 100644 --- a/EngineVideoGames/Mesh.cpp +++ b/EngineVideoGames/Mesh.cpp @@ -1,4 +1,5 @@ #include "Mesh.h" +#include void IndexedModel::CalcNormals() { @@ -244,3 +245,76 @@ IndexedModel OctahedronGenerator() return model; } +bool BoundingBox::checkCollision(BoundingBox other) { + return this->checkCollision(*this, other) && this->checkCollision(other, *this); +} + +glm::mat4 getTransformation(glm::vec3 u, glm::vec3 v) { + glm::vec3 axis = glm::cross(u, v); + float angle = glm::acos(glm::dot(u, v)); + return glm::rotate(angle, axis); +} + +bool axsisCut(float b1min, float b1max, float b2min, float b2max) { + return (b1min <= b2max && b2max <= b1max) || (b1min <= b2min && b2min <= b1max) || (b1min >= b2min && b1max <= b2max); +} + +bool BoundingBox::checkCollision(BoundingBox b1, BoundingBox b2) { + glm::mat3 to_b1 = glm::mat3(); + to_b1[0] = glm::vec3(b1.xInit[0], b1.yInit[0], b1.zInit[0]); + to_b1[1] = glm::vec3(b1.xInit[1], b1.yInit[1], b1.zInit[1]); + to_b1[2] = glm::vec3(b1.xInit[2], b1.yInit[2], b1.zInit[2]); + + glm::mat3 to_b2 = glm::mat3(); + to_b2[0] = glm::vec3(b2.xInit[0], b2.yInit[0], b2.zInit[0]); + to_b2[1] = glm::vec3(b2.xInit[1], b2.yInit[1], b2.zInit[1]); + to_b2[2] = glm::vec3(b2.xInit[2], b2.yInit[2], b2.zInit[2]); + + glm::mat3 from_b1 = glm::inverse(to_b1); + + glm::mat3 b1_to_b2 = to_b2 * from_b1; + + glm::vec3 b1xb2 = b1_to_b2 * b1.xInit; + glm::vec3 b1yb2 = b1_to_b2 * b1.yInit; + glm::vec3 b1zb2 = b1_to_b2 * b1.zInit; + + float b1minx = std::numeric_limits::max(), b1maxx = std::numeric_limits::min() + , b1miny = std::numeric_limits::max(), b1maxy = std::numeric_limits::min() + , b1minz = std::numeric_limits::max(), b1maxz = std::numeric_limits::min(); + float b2minx = std::numeric_limits::max(), b2maxx = std::numeric_limits::min() + , b2miny = std::numeric_limits::max(), b2maxy = std::numeric_limits::min() + , b2minz = std::numeric_limits::max(), b2maxz = std::numeric_limits::min(); + + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + for (int k = -1; k < 2; k++) { + glm::vec3 p = b1.center + ((float)i * b1xb2) * b1.size.x + ((float)j * b1yb2) * b1.size.y + ((float)k * b1zb2) * b1.size.z; + b1minx = std::fmin(p.x, b1minx); + b1maxx = std::fmax(p.x, b1maxx); + b1miny = std::fmin(p.y, b1miny); + b1maxy = std::fmax(p.y, b1maxy); + b1minz = std::fmin(p.z, b1minz); + b1maxz = std::fmax(p.z, b1maxz); + } + } + } + + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + for (int k = -1; k < 2; k++) { + glm::vec3 p = b2.center + ((float)i * b2.xInit) * b2.size.x + ((float)j * b2.yInit) * b2.size.y + ((float)k * b2.zInit) * b2.size.z; + b2minx = std::fmin(p.x, b2minx); + b2maxx = std::fmax(p.x, b2maxx); + b2miny = std::fmin(p.y, b2miny); + b2maxy = std::fmax(p.y, b2maxy); + b2minz = std::fmin(p.z, b2minz); + b2maxz = std::fmax(p.z, b2maxz); + } + } + return axsisCut(b1minx, b1maxx, b2minx, b2maxx) + && axsisCut(b1miny, b1maxy, b2miny, b2maxy) + && axsisCut(b1minz, b1maxz, b2minz, b2maxz); + } + + +} diff --git a/EngineVideoGames/Mesh.h b/EngineVideoGames/Mesh.h index 7baff82..63ecc7f 100644 --- a/EngineVideoGames/Mesh.h +++ b/EngineVideoGames/Mesh.h @@ -1,5 +1,6 @@ #pragma once #include "glm/glm.hpp" +#include #include class IndexedModel @@ -59,14 +60,31 @@ struct LineVertex glm::vec3 color; }; +static const glm::vec3 x = glm::vec3(1, 0, 0); +static const glm::vec3 y = glm::vec3(0, 1, 0); +static const glm::vec3 z = glm::vec3(0, 0, 1); + class BoundingBox { +private: + bool checkCollision(BoundingBox b1, BoundingBox b2); +public: glm::vec3 center; // center coordinates glm::vec3 size; // distance between the center of the box to its side in each dimension glm::vec3 xInit; // x axis of the box. default value (1,0,0) glm::vec3 yInit; // y axis of the box. default value (0,1,0) glm::vec3 zInit; // z axis of the box. default value (0,0,1) //TODO: Add constructor and checkCollision function + + BoundingBox(glm::vec3 center, glm::vec3 size, glm::vec3 xInit= x, glm::vec3 yInit= y, glm::vec3 zInit= z) { + this->center = center; + this->size = size; + this->xInit = glm::normalize(xInit); + this->yInit = glm::normalize(yInit); + this->zInit = glm::normalize(zInit); + } + + bool checkCollision(BoundingBox other); }; IndexedModel CubeTriangles(); diff --git a/EngineVideoGames/MeshConstructor.cpp b/EngineVideoGames/MeshConstructor.cpp index 012fa59..2c0948b 100644 --- a/EngineVideoGames/MeshConstructor.cpp +++ b/EngineVideoGames/MeshConstructor.cpp @@ -36,15 +36,18 @@ MeshConstructor::MeshConstructor(const std::string& fileName) MeshConstructor::MeshConstructor(Bezier1D *curve,bool isSurface,unsigned int resT,unsigned int resS) { - //if(isSurface) - //{ - // Bezier2D surface(*curve,glm::vec3(0,0,1),4); - // InitMesh(surface.GetSurface(resT,resS)); - //} - //else - //{ - // InitLine( curve->GetLine(resT)); - //} + if(isSurface) + { + Bezier2D surface(*curve,glm::vec3(0,0,1),4); + InitMesh(surface.GetSurface(resT,resS)); + + //use this line for debugging + //InitLine(surface.GetSurface(10,7)); + } + else + { + InitLine( curve->GetLine(resT)); + } } MeshConstructor::MeshConstructor(const MeshConstructor &mesh) diff --git a/EngineVideoGames/MeshConstructor.h b/EngineVideoGames/MeshConstructor.h index 26946c2..7f7d038 100644 --- a/EngineVideoGames/MeshConstructor.h +++ b/EngineVideoGames/MeshConstructor.h @@ -5,13 +5,33 @@ #include "Mesh.h" #include "bezier1D.h" #include "kdtree.h" +#include "Mesh.h" + +class B_Node +{ +private: + BoundingBox bb; + int low; + int high; + B_Node* left; + B_Node* right; + BoundingBox getBoundingbox(int low, int high,std::vector* points[]); + BoundingBox getDefultBoundingbox(glm::vec3 point); +public: + B_Node(int low, int high, std::vector* points[]); + B_Node(const B_Node &other); + bool isColiding(glm::mat4 myMat, B_Node &other,glm::mat4 otherMat); + + ~B_Node(void); +}; class MeshConstructor { VertexArray vao; IndexBuffer *ib; //TO DO: add bounding box data base and build it in the constructor + B_Node boundingTree; std::vector vbs; bool is2D; int unsigned indicesNum; diff --git a/EngineVideoGames/bezier1D.cpp b/EngineVideoGames/bezier1D.cpp index 47e635d..44d3ab4 100644 --- a/EngineVideoGames/bezier1D.cpp +++ b/EngineVideoGames/bezier1D.cpp @@ -1,8 +1,181 @@ #include "bezier1D.h" - +#include +#include Bezier1D::Bezier1D(void) { + numberOfPoints = 10; + + glm::mat4 Model = glm::mat4(1.0); + + glm::vec4 Position0 = glm::vec4(-8.0, 0.0, 0.0, 0.0); + glm::vec4 Position1 = glm::vec4(-6.0, 1.0, 0.0, 0.0); + glm::vec4 Position2 = glm::vec4(-3.0, 1.0, 0.0, 0.0); + glm::vec4 Position3 = glm::vec4(-1.0, 1.0, 0.0, 0.0); + + + Model[0] = Position0; + Model[1] = Position1; + Model[2] = Position2; + Model[3] = Position3; + segments.push_back(Model); + + Position0 = glm::vec4(-1.0, 1.0, 0.0, 0.0); + Position1 = glm::vec4(2.0, 1.0, 0.0, 0.0); + Position2 = glm::vec4(4.0, 1.0, 0.0, 0.0); + Position3 = glm::vec4(6.0, 1.0, 0.0, 0.0); + + Model[0] = Position0; + Model[1] = Position1; + Model[2] = Position2; + Model[3] = Position3; + segments.push_back(Model); + + Position0 = glm::vec4(6.0, 1.0, 0.0, 0.0); + Position1 = glm::vec4(8.0, 1.0, 0.0, 0.0); + Position2 = glm::vec4(9.0, 1.0, 0.0, 0.0); + Position3 = glm::vec4(10.0, 0.0, 0.0, 0.0); + + Model[0] = Position0; + Model[1] = Position1; + Model[2] = Position2; + Model[3] = Position3; + segments.push_back(Model); + +} +IndexedModel Bezier1D::GetLine(int resT) { + + std::vector axisVertices; + glm::mat4 sector = segments[0]; + for (int s = 0; s < segments.size(); s++) + { + for (int i = 0; i < resT; i++) + { + double t = (double)i / (double)resT; + axisVertices.push_back(GetVertex(s, t)); + } + } + axisVertices.push_back(GetVertex(segments.size() - 1, 1)); + std::vector axisIndices; + + for (int i = 0; i < axisVertices.size() - 1; i++) + { + axisIndices.push_back(i); + axisIndices.push_back(i + 1); + } + axisIndices.push_back(axisVertices.size()); + + IndexedModel model; + for (unsigned int i = 0; i < axisVertices.size(); i++) + { + model.positions.push_back(*axisVertices[i].GetPos()); + model.colors.push_back(*axisVertices[i].GetColor()); + + } + for (unsigned int i = 0; i < axisIndices.size(); i++) + model.indices.push_back(axisIndices[i]); + + return model; + +} + +LineVertex Bezier1D::GetVertex(int segment, float t) { + LineVertex CP3 = GetControlPoint(segment, 0); + LineVertex CP2 = GetControlPoint(segment, 1); + LineVertex CP1 = GetControlPoint(segment, 2); + LineVertex CP0 = GetControlPoint(segment, 3); + + + + glm::vec3 myvertex( + (CP0.GetPos()->x * t*t*t) + (CP1.GetPos()->x * 3 * t*t*(1 - t)) + (CP2.GetPos()->x * 3 * t*(1 - t)*(1 - t)) + (CP3.GetPos()->x * (1 - t)*(1 - t)*(1 - t)), // point x + (CP0.GetPos()->y * t*t*t) + (CP1.GetPos()->y * 3 * t*t*(1 - t)) + (CP2.GetPos()->y * 3 * t*(1 - t)*(1 - t)) + (CP3.GetPos()->y * (1 - t)*(1 - t)*(1 - t)), //point y + (CP0.GetPos()->z * t*t*t) + (CP2.GetPos()->z * 3 * t*t*(1 - t)) + (CP2.GetPos()->z * 3 * t*(1 - t)*(1 - t)) + (CP3.GetPos()->z * (1 - t)*(1 - t)*(1 - t)) // point z + ); + + LineVertex output(myvertex, glm::vec3(0, 0, 1)); + return output; + +} +LineVertex Bezier1D::GetControlPoint(int seg, int index) +{ + if (seg == segments.size()) { + seg--; + index = 3; + } + glm::mat4 sector = segments[seg]; + glm::vec3 thepoint0(sector[index]); + LineVertex output(thepoint0, glm::vec3(0, 0, 1)); + return output; +} + +void Bezier1D::MoveControlPoint(int segment, int indx, bool preserveC1, glm::vec4 newPosition) { + + if (segment == segments.size()) { // and.. + segment = segment - 1; + indx = 3; + } + glm::mat4 sector = segments[segment]; + glm::vec4 oldpos(sector[indx]); + glm::vec4 diff(newPosition - oldpos); + + + + segments[segment][indx] = newPosition; + + if (indx == 0 && segment != 0) // we need to move the copy of the point on the previos seg + (segments[segment - 1])[3] = newPosition; + if (preserveC1) + { + if (segment == 0 && indx == 0) { + segments[segment][1] += diff; // segments[0][1] += diff; + return; + } + switch (indx) + { + case 0: + segments[segment - 1][2] += diff; + segments[segment][1] += diff; + break; + case 1: + if (segment != 0) + segments[segment - 1][2] -= diff; + break; + case 2: + if (segment != segments.size() - 1) + segments[segment + 1][1] -= diff; + break; + case 3: // last point on line + segments[segment][2] += diff; + } + + } + +} + + +glm::vec3 Bezier1D::GetVelosity(int segment, float t) { + glm::vec3 CP3 = *GetControlPoint(segment, 3).GetPos(); + glm::vec3 CP2 = *GetControlPoint(segment, 2).GetPos(); + glm::vec3 CP1 = *GetControlPoint(segment, 1).GetPos(); + glm::vec3 CP0 = *GetControlPoint(segment, 0).GetPos(); + //CP3.z = 0; + //CP2.z = 0; + //CP1.z = 0; + //CP0.z = 0; + float tp0 = -3 * pow((1 - t), 2); + float tp1 = 3 * (1 - t)*(1 - t) - 6 * t*(1 - t); //-3 * (-3 * t*t + 4 * t - 1); + float tp2 = 6 * t*(1 - t) - 3 * t*t; // -3 * (3 * pow(t, 2) - 2 * t); + float tp3 = 3 * pow(t, 2); + + return (CP3 * tp3 + CP2 * tp2 + CP1 * tp1 + CP0 * tp0); + // glm::vec3 myvertex( + // (CP0.GetPos()->x * 3 * t*t) + (CP1.GetPos()->x * 6 * t*t*(1 - t)) + (CP2.GetPos()->x * 3 * t*(1 - t)*(1 - t)) + (CP3.GetPos()->x * (1 - t)*(1 - t)*(1 - t)), // point x + // (CP0.GetPos()->y * t*t*t) + (CP1.GetPos()->y * 3 * t*t*(1 - t)) + (CP2.GetPos()->y * 3 * t*(1 - t)*(1 - t)) + (CP3.GetPos()->y * (1 - t)*(1 - t)*(1 - t)), //point y + // (CP0.GetPos()->z * t*t*t) + (CP2.GetPos()->z * 3 * t*t*(1 - t)) + (CP2.GetPos()->z * 3 * t*(1 - t)*(1 - t)) + (CP3.GetPos()->z * (1 - t)*(1 - t)*(1 - t)) // point z + //); + + //return myvertex; } diff --git a/EngineVideoGames/bezier1D.h b/EngineVideoGames/bezier1D.h index 6abd7e1..bc02b0d 100644 --- a/EngineVideoGames/bezier1D.h +++ b/EngineVideoGames/bezier1D.h @@ -15,6 +15,7 @@ class Bezier1D void MoveControlPoint(int segment, int indx,bool preserveC1, glm::vec4 newPosition); //change the positon of one control point. when preserveC1 is true it may affect other control points + int numberOfPoints; ~Bezier1D(void); }; diff --git a/EngineVideoGames/bezier2D.cpp b/EngineVideoGames/bezier2D.cpp index cf8f4f4..269148c 100644 --- a/EngineVideoGames/bezier2D.cpp +++ b/EngineVideoGames/bezier2D.cpp @@ -1,10 +1,179 @@ #include "bezier2D.h" +#include +#include Bezier2D::Bezier2D(void) { + my_curve = Bezier1D(); + circularSubdivision = 4; } +Bezier2D::Bezier2D(Bezier1D &my_curve, glm::vec3 axis, int circularSubdivision) { + this->my_curve = my_curve; + this->circularSubdivision = circularSubdivision; +} + +IndexedModel Bezier2D::GetSurface(int resT, int resS) { + + //std::vector axisVertices; + glm::vec3 my_colors[] = { + glm::vec3(0, 1, 1), + glm::vec3(1, 1, 0), + glm::vec3(0, 1, 0), + glm::vec3(1, 0, 1) + }; + int numberofSegments_in_curve = (my_curve.numberOfPoints - 1) / 3; + float t_step = 1 / (float)resT; + float s_step = 1 / (float)resS; + unsigned int i = 0; + IndexedModel ans = IndexedModel(); + std::vector colors = std::vector(); + std::vector texCoords = std::vector(); + std::vector normals = std::vector(); + std::vector positions = std::vector(); + std::vector weights = std::vector(); + std::vector joint_indices = std::vector(); + std::vector indices = std::vector(); + for (int T = 0; T < numberofSegments_in_curve; T++) { + for (float t = 0; t < 1; t = t + t_step) { + for (int S = 0; S < this->circularSubdivision; S++) { + for (float s = 0; s < 1; s = s + s_step) { + + float ct, cs; + ct = t; + cs = s; + Vertex p0 = this->GetVertex(T, S, ct, cs); + if (ct + t_step > 1) ct = 1; + else ct += t_step; + Vertex p1 = this->GetVertex(T, S, ct, cs); + if (cs + s_step > 1) cs = 1; + else cs += s_step; + Vertex p2 = this->GetVertex(T, S, ct, cs); + ct -= t_step; + Vertex p3 = this->GetVertex(T, S, ct, cs); + //push p0 + positions.push_back(*p0.GetPos()); + colors.push_back(my_colors[S]); + normals.push_back(*p0.GetNormal()); + texCoords.push_back(glm::vec2(0, 0)); + weights.push_back(glm::vec3(1, 1, 1)); // not sure + joint_indices.push_back(glm::ivec3(1, 1, 1)); // not sure + + //push p1 + positions.push_back(*p1.GetPos()); + colors.push_back(my_colors[S]); + normals.push_back(*p1.GetNormal()); + texCoords.push_back(glm::vec2(1, 0)); + weights.push_back(glm::vec3(1, 1, 1)); // not sure + joint_indices.push_back(glm::ivec3(1, 1, 1)); // not sure + + //push p2 + positions.push_back(*p2.GetPos()); + colors.push_back(my_colors[S]); + normals.push_back(*p2.GetNormal()); + texCoords.push_back(glm::vec2(1, 1)); + weights.push_back(glm::vec3(1, 1, 1)); // not sure + joint_indices.push_back(glm::ivec3(1, 1, 1)); // not sure + + //push p3 + positions.push_back(*p3.GetPos()); + colors.push_back(my_colors[S]); + normals.push_back(*p3.GetNormal()); + texCoords.push_back(glm::vec2(0, 1)); + weights.push_back(glm::vec3(1, 1, 1)); // not sure + joint_indices.push_back(glm::ivec3(1, 1, 1)); // not sure + //--------------------------------natai testing lines + /*glm::vec3 thepoint0(*p0.GetPos()); + LineVertex temp(thepoint0, glm::vec3(0, 0, 1)); + axisVertices.push_back(temp); + + glm::vec3 thepoint1(*p1.GetPos()); + LineVertex temp1(thepoint1, glm::vec3(0, 0, 1)); + axisVertices.push_back(temp1); + + glm::vec3 thepoint2(*p2.GetPos()); + LineVertex temp2(thepoint2, glm::vec3(0, 0, 1)); + axisVertices.push_back(temp2); + + glm::vec3 thepoint3(*p3.GetPos()); + LineVertex temp3(thepoint3, glm::vec3(0, 0, 1)); + axisVertices.push_back(temp3);*/ + //indices.push_back(i); + indices.push_back(i); + indices.push_back(i + 3); + indices.push_back(i + 1); + indices.push_back(i + 3); + indices.push_back(i + 1); + indices.push_back(i + 2); + i = i + 4; + //for (int j = 0; j < 4; j++) { + // indices.push_back(i); + // i++; + //} + } + //indices.push_back(i); + //indices.push_back(i); + } + } + + } + ans.positions = positions; + ans.colors = colors; + ans.texCoords = texCoords; + ans.normals = normals; + ans.weights = weights; + ans.joint_indices = joint_indices; + ans.indices = indices; + return ans; + + + //--------------------------------natai testing lines + /*std::vector axisIndices; + + for (int i = 0; i < axisVertices.size() - 1; i++) + { + axisIndices.push_back(i); + axisIndices.push_back(i + 1); + } + axisIndices.push_back(axisVertices.size()); + + IndexedModel model; + for (unsigned int i = 0; i < axisVertices.size(); i++) + { + model.positions.push_back(*axisVertices[i].GetPos()); + model.colors.push_back(*axisVertices[i].GetColor()); + + } + for (unsigned int i = 0; i < axisIndices.size(); i++) + model.indices.push_back(axisIndices[i]); + + return model;*/ + +} + + + +Vertex Bezier2D::GetVertex(int segmentT, int segmentS, float t, float s) { + glm::vec4 loc = glm::vec4(*my_curve.GetVertex(segmentT, t).GetPos(), 1); + float angle = (360 / circularSubdivision)*segmentS + (360 / circularSubdivision)*s; + glm::vec4 newloc = loc * glm::rotate(angle, glm::vec3(1, 0, 0)); + return Vertex(glm::vec3(newloc), glm::vec2(0, 0), GetNormal(segmentT, segmentS, t, s), *my_curve.GetVertex(segmentT, t).GetColor()); +} + +glm::vec3 Bezier2D::GetNormal(int segmentT, int segmentS, float t, float s) { + glm::vec4 normal_2d = glm::vec4(glm::cross(glm::vec3(0, 0, 1),this->my_curve.GetVelosity(segmentT, t)), 0); + float angle = (360 / circularSubdivision)*segmentS + (360 / circularSubdivision)*s; + if (angle >30 && angle <90 && t>0.3) + int e = 3; + glm::vec4 normal_3d = normal_2d * glm::rotate(angle , glm::vec3(1, 0, 0)); + float size = normal_3d.x*normal_3d.x + normal_3d.y*normal_3d.y + normal_3d.z*normal_3d.z; + size = glm::sqrt(size); + //printf("%f -", size); + glm::vec3 temp(1/size, 1/size, 1/size); + + return temp* glm::vec3(normal_3d); +} Bezier2D::~Bezier2D(void) { diff --git a/EngineVideoGames/scene.cpp b/EngineVideoGames/scene.cpp index 5131ea9..1103d5c 100644 --- a/EngineVideoGames/scene.cpp +++ b/EngineVideoGames/scene.cpp @@ -480,6 +480,7 @@ using namespace glm; shapes[shpIndx]->Hide(); else shapes[shpIndx]->Unhide(); + } Scene::~Scene(void) diff --git a/Game/Game.vcxproj b/Game/Game.vcxproj index ac3e2a5..6819cea 100644 --- a/Game/Game.vcxproj +++ b/Game/Game.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -13,18 +13,19 @@ {257FC222-2301-4B67-A02B-880548704235} Game + 10.0.17763.0 Application true - v110 + v141 MultiByte Application false - v110 + v141 true MultiByte diff --git a/Game/main.cpp b/Game/main.cpp index f76a7c6..54115f6 100644 --- a/Game/main.cpp +++ b/Game/main.cpp @@ -3,6 +3,7 @@ int main(int argc,char *argv[]) { + const int DISPLAY_WIDTH = 1200; const int DISPLAY_HEIGHT = 800; const float zFar = 100.0f; @@ -34,3 +35,37 @@ int main(int argc,char *argv[]) delete scn; return 0; } + + static void runfromkdtree() +{ + + const int DISPLAY_WIDTH = 1200; + const int DISPLAY_HEIGHT = 800; + const float zFar = 100.0f; + const float zNear = 1.0f; + const float CAM_ANGLE = 60.0f; + const float relation = (float)DISPLAY_WIDTH / (float)DISPLAY_HEIGHT; + + Game *scn = new Game(glm::vec3(0.0f, 0.0f, -1.0f), CAM_ANGLE, relation, zNear, zFar); + + Display display(DISPLAY_WIDTH, DISPLAY_HEIGHT, "OpenGL"); + + init(display); + + scn->Init(); + + scn->addShader("../res/shaders/basicShader"); + scn->addShader("../res/shaders/pickingShader"); + + display.setScene(scn); + + while (!display.closeWindow()) + { + display.Clear(1.0f, 1.0f, 1.0f, 1.0f); + scn->Draw(0, 0, true); + scn->Motion(); + display.SwapBuffers(); + display.PollEvents(); + } + delete scn; +} diff --git a/KDtree/main.cpp b/KDtree/main.cpp index 011013a..df6c96c 100644 --- a/KDtree/main.cpp +++ b/KDtree/main.cpp @@ -15,6 +15,8 @@ #include + + const int _numpts = 10; const int _dim = 3; diff --git a/res/libs/glfw3.lib b/res/libs/glfw3.lib index ca876eb..741756a 100644 Binary files a/res/libs/glfw3.lib and b/res/libs/glfw3.lib differ