Compare commits
3 commits
49066db8fb
...
f9683a69be
Author | SHA1 | Date | |
---|---|---|---|
f9683a69be | |||
9932f2ed53 | |||
4ed32e44f0 |
10 changed files with 73 additions and 19 deletions
|
@ -24,6 +24,7 @@ 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;
|
||||||
|
|
||||||
|
@ -35,12 +36,13 @@ 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);
|
renderInit(window, 1200, 900);
|
||||||
|
|
||||||
// Baseplate
|
// Baseplate
|
||||||
workspace->AddChild(Part::New({
|
workspace->AddChild(Part::New({
|
||||||
|
@ -204,4 +206,9 @@ 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);
|
||||||
}
|
}
|
|
@ -21,14 +21,18 @@ MainGLWidget::MainGLWidget(QWidget* parent): QOpenGLWidget(parent) {
|
||||||
|
|
||||||
void MainGLWidget::initializeGL() {
|
void MainGLWidget::initializeGL() {
|
||||||
glewInit();
|
glewInit();
|
||||||
renderInit(NULL);
|
renderInit(NULL, width(), height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
#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)
|
||||||
|
@ -15,14 +17,22 @@ 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)
|
else if (index.column() == 1 && meta.type != &Data::Bool::TYPE) {
|
||||||
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());
|
||||||
}
|
}
|
||||||
|
@ -31,10 +41,27 @@ 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 && role != Qt::EditRole) return false;
|
if (index.column() != 1) return false;
|
||||||
|
|
||||||
selectedItem->SetPropertyValue(propertiesList[index.row()], value.toString().toStdString());
|
std::string propertyName = propertiesList[index.row()];
|
||||||
return true;
|
PropertyMeta meta = selectedItem->GetPropertyMeta(propertyName).value();
|
||||||
|
|
||||||
|
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 {
|
||||||
|
@ -44,8 +71,15 @@ Qt::ItemFlags PropertiesModel::flags(const QModelIndex &index) const {
|
||||||
if (index.column() == 0)
|
if (index.column() == 0)
|
||||||
return Qt::ItemIsEnabled;
|
return Qt::ItemIsEnabled;
|
||||||
|
|
||||||
if (index.column() == 1)
|
std::string propertyName = propertiesList[index.row()];
|
||||||
return Qt::ItemIsEnabled | Qt::ItemIsEditable;
|
PropertyMeta meta = selectedItem->GetPropertyMeta(propertyName).value();
|
||||||
|
|
||||||
|
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;
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,6 +18,7 @@ public: \
|
||||||
namespace Data {
|
namespace Data {
|
||||||
struct TypeInfo {
|
struct TypeInfo {
|
||||||
std::string name;
|
std::string name;
|
||||||
|
TypeInfo(const TypeInfo&) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
class String;
|
class String;
|
||||||
|
|
|
@ -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, .codec = fieldCodecOf<Data::String, std::string>() } }
|
{ "Name", { .backingField = &name, .type = &Data::String::TYPE, .codec = fieldCodecOf<Data::String, std::string>() } }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ constexpr FieldCodec fieldCodecOf() {
|
||||||
|
|
||||||
struct PropertyMeta {
|
struct PropertyMeta {
|
||||||
void* backingField;
|
void* backingField;
|
||||||
Data::TypeInfo type;
|
const Data::TypeInfo* type;
|
||||||
FieldCodec codec;
|
FieldCodec codec;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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, .codec = fieldCodecOf<Data::Bool, bool>() } }
|
{ "Anchored", { .backingField = &anchored, .type = &Data::Bool::TYPE, .codec = fieldCodecOf<Data::Bool, bool>() } }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -28,8 +28,11 @@ extern Camera camera;
|
||||||
Skybox* skyboxTexture = NULL;
|
Skybox* skyboxTexture = NULL;
|
||||||
Texture3D* studsTexture = NULL;
|
Texture3D* studsTexture = NULL;
|
||||||
|
|
||||||
void renderInit(GLFWwindow* window) {
|
static int viewportWidth, viewportHeight;
|
||||||
glViewport(0, 0, 1200, 900);
|
|
||||||
|
void renderInit(GLFWwindow* window, int width, int height) {
|
||||||
|
viewportWidth = width, viewportHeight = height;
|
||||||
|
glViewport(0, 0, width, height);
|
||||||
|
|
||||||
initMeshes();
|
initMeshes();
|
||||||
|
|
||||||
|
@ -64,7 +67,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)1200 / (float)900, 0.1f, 100.0f);
|
glm::mat4 projection = glm::perspective(glm::radians(45.f), (float)viewportWidth / (float)viewportHeight, 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);
|
||||||
|
@ -126,7 +129,7 @@ void renderSkyBox() {
|
||||||
|
|
||||||
skyboxShader->use();
|
skyboxShader->use();
|
||||||
|
|
||||||
glm::mat4 projection = glm::perspective(glm::radians(45.f), (float)1200 / (float)900, 0.1f, 100.0f);
|
glm::mat4 projection = glm::perspective(glm::radians(45.f), (float)viewportWidth / (float)viewportHeight, 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()));
|
||||||
|
|
||||||
|
@ -145,4 +148,8 @@ void render(GLFWwindow* window) {
|
||||||
|
|
||||||
renderSkyBox();
|
renderSkyBox();
|
||||||
renderParts();
|
renderParts();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setViewport(int width, int height) {
|
||||||
|
viewportWidth = width, viewportHeight = height;
|
||||||
}
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
void renderInit(GLFWwindow* window);
|
void renderInit(GLFWwindow* window, int width, int height);
|
||||||
void render(GLFWwindow* window);
|
void render(GLFWwindow* window);
|
||||||
|
void setViewport(int width, int height);
|
Loading…
Add table
Reference in a new issue