Compare commits

..

No commits in common. "f9683a69bebbac28215c6bdcd21a244f6e766561" and "49066db8fbf62922fca599518fd5b21656ba9fac" have entirely different histories.

10 changed files with 19 additions and 73 deletions

View file

@ -24,7 +24,6 @@ void processInput(GLFWwindow* window);
void mouseCallback(GLFWwindow* window, double xpos, double ypos); void mouseCallback(GLFWwindow* window, double xpos, double ypos);
// void scroll_callback(GLFWwindow* window, double xoffset, double yoffset); // void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
void mouseButtonCallback(GLFWwindow* window, int button, int action, int mods); void mouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
void resizeCallback(GLFWwindow* window, int width, int height);
std::shared_ptr<Part> lastPart; std::shared_ptr<Part> lastPart;
@ -36,13 +35,12 @@ int main() {
glfwSetKeyCallback(window, keyCallback); glfwSetKeyCallback(window, keyCallback);
glfwSetMouseButtonCallback(window, mouseButtonCallback); glfwSetMouseButtonCallback(window, mouseButtonCallback);
glfwSetCursorPosCallback(window, mouseCallback); glfwSetCursorPosCallback(window, mouseCallback);
glfwSetFramebufferSizeCallback(window, resizeCallback);
glfwMakeContextCurrent(window); glfwMakeContextCurrent(window);
glewInit(); glewInit();
simulationInit(); simulationInit();
renderInit(window, 1200, 900); renderInit(window);
// Baseplate // Baseplate
workspace->AddChild(Part::New({ workspace->AddChild(Part::New({
@ -206,9 +204,4 @@ void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods
if (key == GLFW_KEY_M && action == GLFW_PRESS) mode = 0; if (key == GLFW_KEY_M && action == GLFW_PRESS) mode = 0;
if (key == GLFW_KEY_E && action == GLFW_PRESS) mode = 1; // Enlarge if (key == GLFW_KEY_E && action == GLFW_PRESS) mode = 1; // Enlarge
if (key == GLFW_KEY_R && action == GLFW_PRESS) mode = 2; if (key == GLFW_KEY_R && action == GLFW_PRESS) mode = 2;
}
void resizeCallback(GLFWwindow* window, int width, int height) {
glViewport(0, 0, width, height);
setViewport(width, height);
} }

View file

@ -21,18 +21,14 @@ MainGLWidget::MainGLWidget(QWidget* parent): QOpenGLWidget(parent) {
void MainGLWidget::initializeGL() { void MainGLWidget::initializeGL() {
glewInit(); glewInit();
renderInit(NULL, width(), height()); renderInit(NULL);
} }
extern int vpx, vpy;
void MainGLWidget::resizeGL(int w, int h) { void MainGLWidget::resizeGL(int w, int h) {
// Update projection matrix and other size related settings: // Update projection matrix and other size related settings:
// m_projection.setToIdentity(); // m_projection.setToIdentity();
// m_projection.perspective(45.0f, w / float(h), 0.01f, 100.0f); // m_projection.perspective(45.0f, w / float(h), 0.01f, 100.0f);
// ... // ...
// glViewport(0, 0, w, h);
setViewport(w, h);
} }
void MainGLWidget::paintGL() { void MainGLWidget::paintGL() {

View file

@ -1,6 +1,4 @@
#include "propertiesmodel.h" #include "propertiesmodel.h"
#include "datatypes/base.h"
#include "objects/base/member.h"
#include "qnamespace.h" #include "qnamespace.h"
PropertiesModel::PropertiesModel(InstanceRef selectedItem, QWidget *parent) PropertiesModel::PropertiesModel(InstanceRef selectedItem, QWidget *parent)
@ -17,22 +15,14 @@ QVariant PropertiesModel::data(const QModelIndex &index, int role) const {
return {}; return {};
std::string propertyName = propertiesList[index.row()]; std::string propertyName = propertiesList[index.row()];
PropertyMeta meta = selectedItem->GetPropertyMeta(propertyName).value();
switch (role) { switch (role) {
case Qt::EditRole: case Qt::EditRole:
case Qt::DisplayRole: case Qt::DisplayRole:
if (index.column() == 0) if (index.column() == 0)
return QString::fromStdString(propertyName); return QString::fromStdString(propertyName);
else if (index.column() == 1 && meta.type != &Data::Bool::TYPE) { else if (index.column() == 1)
return QString::fromStdString(selectedItem->GetPropertyValue(propertyName).value().ToString()); return QString::fromStdString(selectedItem->GetPropertyValue(propertyName).value().ToString());
}
return {};
case Qt::CheckStateRole:
if (index.column() == 0) return {};
else if (index.column() == 1 && meta.type == &Data::Bool::TYPE)
return selectedItem->GetPropertyValue(propertyName)->get<Data::Bool>().value ? Qt::Checked : Qt::Unchecked;
return {};
// case Qt::DecorationRole: // case Qt::DecorationRole:
// return iconOf(item->GetClass()); // return iconOf(item->GetClass());
} }
@ -41,27 +31,10 @@ QVariant PropertiesModel::data(const QModelIndex &index, int role) const {
} }
bool PropertiesModel::setData(const QModelIndex &index, const QVariant &value, int role) { bool PropertiesModel::setData(const QModelIndex &index, const QVariant &value, int role) {
if (index.column() != 1) return false; if (index.column() != 1 && role != Qt::EditRole) return false;
std::string propertyName = propertiesList[index.row()]; selectedItem->SetPropertyValue(propertiesList[index.row()], value.toString().toStdString());
PropertyMeta meta = selectedItem->GetPropertyMeta(propertyName).value(); return true;
switch (role) {
case Qt::EditRole:
if (meta.type != &Data::String::TYPE)
return false;
selectedItem->SetPropertyValue(propertyName, value.toString().toStdString());
return true;
case Qt::CheckStateRole:
if (meta.type != &Data::Bool::TYPE)
return false;
selectedItem->SetPropertyValue(propertyName, Data::Bool(value.toBool()));
return true;
}
return false;
} }
Qt::ItemFlags PropertiesModel::flags(const QModelIndex &index) const { Qt::ItemFlags PropertiesModel::flags(const QModelIndex &index) const {
@ -71,15 +44,8 @@ Qt::ItemFlags PropertiesModel::flags(const QModelIndex &index) const {
if (index.column() == 0) if (index.column() == 0)
return Qt::ItemIsEnabled; return Qt::ItemIsEnabled;
std::string propertyName = propertiesList[index.row()]; if (index.column() == 1)
PropertyMeta meta = selectedItem->GetPropertyMeta(propertyName).value(); return Qt::ItemIsEnabled | Qt::ItemIsEditable;
if (index.column() == 1) {
if (meta.type == &Data::Bool::TYPE)
return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
else
return Qt::ItemIsEnabled | Qt::ItemIsEditable;
}
return Qt::NoItemFlags; return Qt::NoItemFlags;
}; };

View file

@ -18,7 +18,6 @@ public: \
namespace Data { namespace Data {
struct TypeInfo { struct TypeInfo {
std::string name; std::string name;
TypeInfo(const TypeInfo&) = delete;
}; };
class String; class String;

View file

@ -30,7 +30,7 @@ Instance::Instance(InstanceType* type) {
this->memberMap = std::make_unique<MemberMap>( MemberMap { this->memberMap = std::make_unique<MemberMap>( MemberMap {
.super = std::nullopt, .super = std::nullopt,
.members = { .members = {
{ "Name", { .backingField = &name, .type = &Data::String::TYPE, .codec = fieldCodecOf<Data::String, std::string>() } } { "Name", { .backingField = &name, .codec = fieldCodecOf<Data::String, std::string>() } }
} }
}); });
} }

View file

@ -34,7 +34,7 @@ constexpr FieldCodec fieldCodecOf() {
struct PropertyMeta { struct PropertyMeta {
void* backingField; void* backingField;
const Data::TypeInfo* type; Data::TypeInfo type;
FieldCodec codec; FieldCodec codec;
}; };

View file

@ -23,11 +23,11 @@ Part::Part(): Part(PartConstructParams {}) {
Part::Part(PartConstructParams params): Instance(&TYPE_), position(params.position), rotation(params.rotation), Part::Part(PartConstructParams params): Instance(&TYPE_), position(params.position), rotation(params.rotation),
scale(params.scale), material(params.material), anchored(params.anchored) { scale(params.scale), material(params.material), anchored(params.anchored) {
this->memberMap = std::make_unique<MemberMap>(MemberMap { this->memberMap = std::make_unique<MemberMap>(MemberMap {
.super = std::move(this->memberMap), .super = std::move(this->memberMap),
.members = { .members = {
{ "Anchored", { .backingField = &anchored, .type = &Data::Bool::TYPE, .codec = fieldCodecOf<Data::Bool, bool>() } } { "Anchored", { .backingField = &anchored, .codec = fieldCodecOf<Data::Bool, bool>() } }
} }
}); });
} }

View file

@ -55,7 +55,7 @@ void syncPartPhysics(std::shared_ptr<Part> part) {
} }
if (part->rigidBody->getNbColliders() == 0) if (part->rigidBody->getNbColliders() == 0)
part->rigidBody->addCollider(shape, rp::Transform()); part->rigidBody->addCollider(shape, rp::Transform());
part->rigidBody->setType(part->anchored ? rp::BodyType::STATIC : rp::BodyType::DYNAMIC); part->rigidBody->setType(part->anchored ? rp::BodyType::STATIC : rp::BodyType::DYNAMIC);
world->setEventListener(&eventListener); world->setEventListener(&eventListener);

View file

@ -28,11 +28,8 @@ extern Camera camera;
Skybox* skyboxTexture = NULL; Skybox* skyboxTexture = NULL;
Texture3D* studsTexture = NULL; Texture3D* studsTexture = NULL;
static int viewportWidth, viewportHeight; void renderInit(GLFWwindow* window) {
glViewport(0, 0, 1200, 900);
void renderInit(GLFWwindow* window, int width, int height) {
viewportWidth = width, viewportHeight = height;
glViewport(0, 0, width, height);
initMeshes(); initMeshes();
@ -67,7 +64,7 @@ void renderParts() {
// shader->set("lightColor", glm::vec3(1.0f, 1.0f, 1.0f)); // shader->set("lightColor", glm::vec3(1.0f, 1.0f, 1.0f));
// view/projection transformations // view/projection transformations
glm::mat4 projection = glm::perspective(glm::radians(45.f), (float)viewportWidth / (float)viewportHeight, 0.1f, 100.0f); glm::mat4 projection = glm::perspective(glm::radians(45.f), (float)1200 / (float)900, 0.1f, 100.0f);
glm::mat4 view = camera.getLookAt(); glm::mat4 view = camera.getLookAt();
shader->set("projection", projection); shader->set("projection", projection);
shader->set("view", view); shader->set("view", view);
@ -129,7 +126,7 @@ void renderSkyBox() {
skyboxShader->use(); skyboxShader->use();
glm::mat4 projection = glm::perspective(glm::radians(45.f), (float)viewportWidth / (float)viewportHeight, 0.1f, 100.0f); glm::mat4 projection = glm::perspective(glm::radians(45.f), (float)1200 / (float)900, 0.1f, 100.0f);
// Remove translation component of view, making us always at (0, 0, 0) // Remove translation component of view, making us always at (0, 0, 0)
glm::mat4 view = glm::mat4(glm::mat3(camera.getLookAt())); glm::mat4 view = glm::mat4(glm::mat3(camera.getLookAt()));
@ -148,8 +145,4 @@ void render(GLFWwindow* window) {
renderSkyBox(); renderSkyBox();
renderParts(); renderParts();
}
void setViewport(int width, int height) {
viewportWidth = width, viewportHeight = height;
} }

View file

@ -1,6 +1,5 @@
#pragma once #pragma once
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
void renderInit(GLFWwindow* window, int width, int height); void renderInit(GLFWwindow* window);
void render(GLFWwindow* window); void render(GLFWwindow* window);
void setViewport(int width, int height);