229 lines
4.7 KiB
C++
229 lines
4.7 KiB
C++
// This only works with opengl!!!!
|
|
|
|
#ifndef JOBJECT_H
|
|
#define JOBJECT_H
|
|
|
|
#include "Archimedes.h"
|
|
|
|
#include "modules/WindowModule/WindowModule.h"
|
|
#include "modules/ImguiModule/ImguiModule.h"
|
|
|
|
#include "utils/Objects/Body.h"
|
|
#include "utils/Objects/Camera.h"
|
|
|
|
#include "JObject.h"
|
|
|
|
class Sandbox : public Archimedes::Module {
|
|
|
|
public:
|
|
Sandbox(Archimedes::App*, void*);
|
|
|
|
Sandbox() { name = "Sandbox"; }
|
|
|
|
~Sandbox();
|
|
|
|
void onLoad() override;
|
|
|
|
void run() override;
|
|
|
|
bool onEvent(const Archimedes::Event& e) override;
|
|
|
|
private:
|
|
|
|
Archimedes::Window* window;
|
|
|
|
std::string cubeVS = "#version 430 core\n"
|
|
"layout (location = 0) in vec3 aPos;\n"
|
|
"uniform mat4 model;\n"
|
|
"uniform mat4 view;\n"
|
|
"uniform mat4 proj;\n"
|
|
"uniform vec4 color;\n"
|
|
"void main()\n"
|
|
"{\n"
|
|
" gl_Position = proj * view * model * vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
|
|
"}\0";
|
|
|
|
std::string cubeFS = "#version 430 core\n"
|
|
"out vec4 FragColor;\n"
|
|
"uniform mat4 model;\n"
|
|
"uniform mat4 view;\n"
|
|
"uniform mat4 proj;\n"
|
|
"uniform vec4 color;\n"
|
|
"void main()\n"
|
|
"{\n"
|
|
" FragColor = color;\n"
|
|
"}\n\0";
|
|
|
|
Archimedes::JObject jObject;
|
|
|
|
Archimedes::Shader cubeShader, gridShader;
|
|
Archimedes::Body cube, grid, hexagon;
|
|
|
|
Archimedes::VertexLayout layout = Archimedes::VertexLayout({
|
|
Archimedes::LayoutElement(Archimedes::LayoutElement::Type::Float, 3)
|
|
});
|
|
|
|
Archimedes::Camera camera;
|
|
|
|
std::vector<float> gridVertices = {
|
|
-1.0f, 0.0f, 1.0f,
|
|
1.0f, 0.0f, 1.0f,
|
|
1.0f, 0.0f, -1.0f,
|
|
-1.0f, 0.0f, -1.0f,
|
|
};
|
|
|
|
std::vector<unsigned int> gridIndices = {
|
|
0,
|
|
1,
|
|
2,
|
|
2,
|
|
3,
|
|
0
|
|
};
|
|
|
|
std::vector<float> vertices = {
|
|
-0.5f, -0.5f, 0.5f,
|
|
0.5f, -0.5f, 0.5f,
|
|
0.5f, 0.5f, 0.5f,
|
|
-0.5f, 0.5f, 0.5f,
|
|
|
|
|
|
-0.5f, -0.5f, -0.5f,
|
|
0.5f, -0.5f, -0.5f,
|
|
0.5f, 0.5f, -0.5f,
|
|
-0.5f, 0.5f, -0.5f,
|
|
|
|
};
|
|
|
|
std::vector<unsigned int> indices = {
|
|
0,
|
|
1,
|
|
2,
|
|
2,
|
|
3,
|
|
0,
|
|
|
|
|
|
4,
|
|
5,
|
|
6,
|
|
6,
|
|
7,
|
|
4,
|
|
|
|
|
|
0,
|
|
1,
|
|
5,
|
|
5,
|
|
4,
|
|
0,
|
|
|
|
|
|
3,
|
|
2,
|
|
6,
|
|
6,
|
|
7,
|
|
3,
|
|
|
|
|
|
0,
|
|
3,
|
|
7,
|
|
7,
|
|
4,
|
|
0,
|
|
|
|
|
|
1,
|
|
2,
|
|
6,
|
|
6,
|
|
5,
|
|
1,
|
|
|
|
};
|
|
|
|
Archimedes::Body readOBJ(std::string path, Archimedes::Shader shader) {
|
|
|
|
std::ifstream file(path);
|
|
|
|
if(!file.is_open()) return Archimedes::Body();
|
|
|
|
std::string s;
|
|
|
|
std::vector<float> verticies;
|
|
std::vector<unsigned int> indicies;
|
|
|
|
verticies.reserve(3 * 100);
|
|
indicies.reserve(100);
|
|
|
|
unsigned int i = 0;
|
|
unsigned int j = 0;
|
|
|
|
float point;
|
|
unsigned int idx;
|
|
|
|
while(!file.eof()) {
|
|
getline(file, s, ' ');
|
|
|
|
//std::cout << "\nline start: " << s << std::endl;
|
|
|
|
if(s == "v") {
|
|
file >> point;
|
|
verticies.push_back(point);
|
|
//std::cout << "point1: " << point << std::endl;
|
|
|
|
file >> point;
|
|
verticies.push_back(point);
|
|
//std::cout << "point2: " << point << std::endl;
|
|
|
|
file >> point;
|
|
verticies.push_back(point);
|
|
//std::cout << "point3: " << point << std::endl;
|
|
|
|
//std::cout << "index: " << j << std::endl;
|
|
|
|
getline(file, s);
|
|
//file.ignore();
|
|
} else if(s == "f") {
|
|
|
|
file >> idx;
|
|
indicies.push_back(--idx);
|
|
file.ignore(5, ' ');
|
|
|
|
file >> idx;
|
|
indicies.push_back(--idx);
|
|
file.ignore(5, ' ');
|
|
|
|
file >> idx;
|
|
indicies.push_back(--idx);
|
|
getline(file, s);
|
|
|
|
} else {
|
|
getline(file, s);
|
|
}
|
|
}
|
|
|
|
file.close();
|
|
|
|
return Archimedes::Body(
|
|
Archimedes::VertexBuffer(verticies),
|
|
Archimedes::IndexArray(indicies),
|
|
Archimedes::VertexLayout({
|
|
Archimedes::LayoutElement(Archimedes::LayoutElement::Type::Float, 3),
|
|
}),
|
|
shader
|
|
);
|
|
}
|
|
|
|
};
|
|
|
|
#ifdef SANDBOX_DYNAMIC
|
|
typedef Sandbox mtype;
|
|
#include "endModule.h"
|
|
#endif
|
|
|
|
#endif
|