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 scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
||||
void mouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
|
||||
void resizeCallback(GLFWwindow* window, int width, int height);
|
||||
|
||||
std::shared_ptr<Part> lastPart;
|
||||
|
||||
|
@ -35,12 +36,13 @@ int main() {
|
|||
glfwSetKeyCallback(window, keyCallback);
|
||||
glfwSetMouseButtonCallback(window, mouseButtonCallback);
|
||||
glfwSetCursorPosCallback(window, mouseCallback);
|
||||
glfwSetFramebufferSizeCallback(window, resizeCallback);
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glewInit();
|
||||
|
||||
simulationInit();
|
||||
renderInit(window);
|
||||
renderInit(window, 1200, 900);
|
||||
|
||||
// Baseplate
|
||||
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_E && action == GLFW_PRESS) mode = 1; // Enlarge
|
||||
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() {
|
||||
glewInit();
|
||||
renderInit(NULL);
|
||||
renderInit(NULL, width(), height());
|
||||
}
|
||||
|
||||
extern int vpx, vpy;
|
||||
|
||||
void MainGLWidget::resizeGL(int w, int h) {
|
||||
// Update projection matrix and other size related settings:
|
||||
// m_projection.setToIdentity();
|
||||
// m_projection.perspective(45.0f, w / float(h), 0.01f, 100.0f);
|
||||
// ...
|
||||
// glViewport(0, 0, w, h);
|
||||
setViewport(w, h);
|
||||
}
|
||||
|
||||
void MainGLWidget::paintGL() {
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#include "propertiesmodel.h"
|
||||
#include "datatypes/base.h"
|
||||
#include "objects/base/member.h"
|
||||
#include "qnamespace.h"
|
||||
|
||||
PropertiesModel::PropertiesModel(InstanceRef selectedItem, QWidget *parent)
|
||||
|
@ -15,14 +17,22 @@ QVariant PropertiesModel::data(const QModelIndex &index, int role) const {
|
|||
return {};
|
||||
|
||||
std::string propertyName = propertiesList[index.row()];
|
||||
PropertyMeta meta = selectedItem->GetPropertyMeta(propertyName).value();
|
||||
|
||||
switch (role) {
|
||||
case Qt::EditRole:
|
||||
case Qt::DisplayRole:
|
||||
if (index.column() == 0)
|
||||
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 {};
|
||||
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:
|
||||
// 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) {
|
||||
if (index.column() != 1 && role != Qt::EditRole) return false;
|
||||
if (index.column() != 1) return false;
|
||||
|
||||
selectedItem->SetPropertyValue(propertiesList[index.row()], value.toString().toStdString());
|
||||
return true;
|
||||
std::string propertyName = propertiesList[index.row()];
|
||||
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 {
|
||||
|
@ -44,8 +71,15 @@ Qt::ItemFlags PropertiesModel::flags(const QModelIndex &index) const {
|
|||
if (index.column() == 0)
|
||||
return Qt::ItemIsEnabled;
|
||||
|
||||
if (index.column() == 1)
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsEditable;
|
||||
std::string propertyName = propertiesList[index.row()];
|
||||
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;
|
||||
};
|
||||
|
|
|
@ -18,6 +18,7 @@ public: \
|
|||
namespace Data {
|
||||
struct TypeInfo {
|
||||
std::string name;
|
||||
TypeInfo(const TypeInfo&) = delete;
|
||||
};
|
||||
|
||||
class String;
|
||||
|
|
|
@ -30,7 +30,7 @@ Instance::Instance(InstanceType* type) {
|
|||
this->memberMap = std::make_unique<MemberMap>( MemberMap {
|
||||
.super = std::nullopt,
|
||||
.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 {
|
||||
void* backingField;
|
||||
Data::TypeInfo type;
|
||||
const Data::TypeInfo* type;
|
||||
FieldCodec codec;
|
||||
};
|
||||
|
||||
|
|
|
@ -23,11 +23,11 @@ Part::Part(): Part(PartConstructParams {}) {
|
|||
|
||||
Part::Part(PartConstructParams params): Instance(&TYPE_), position(params.position), rotation(params.rotation),
|
||||
scale(params.scale), material(params.material), anchored(params.anchored) {
|
||||
|
||||
|
||||
this->memberMap = std::make_unique<MemberMap>(MemberMap {
|
||||
.super = std::move(this->memberMap),
|
||||
.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)
|
||||
part->rigidBody->addCollider(shape, rp::Transform());
|
||||
part->rigidBody->addCollider(shape, rp::Transform());
|
||||
part->rigidBody->setType(part->anchored ? rp::BodyType::STATIC : rp::BodyType::DYNAMIC);
|
||||
|
||||
world->setEventListener(&eventListener);
|
||||
|
|
|
@ -28,8 +28,11 @@ extern Camera camera;
|
|||
Skybox* skyboxTexture = NULL;
|
||||
Texture3D* studsTexture = NULL;
|
||||
|
||||
void renderInit(GLFWwindow* window) {
|
||||
glViewport(0, 0, 1200, 900);
|
||||
static int viewportWidth, viewportHeight;
|
||||
|
||||
void renderInit(GLFWwindow* window, int width, int height) {
|
||||
viewportWidth = width, viewportHeight = height;
|
||||
glViewport(0, 0, width, height);
|
||||
|
||||
initMeshes();
|
||||
|
||||
|
@ -64,7 +67,7 @@ void renderParts() {
|
|||
// shader->set("lightColor", glm::vec3(1.0f, 1.0f, 1.0f));
|
||||
|
||||
// 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();
|
||||
shader->set("projection", projection);
|
||||
shader->set("view", view);
|
||||
|
@ -126,7 +129,7 @@ void renderSkyBox() {
|
|||
|
||||
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)
|
||||
glm::mat4 view = glm::mat4(glm::mat3(camera.getLookAt()));
|
||||
|
||||
|
@ -145,4 +148,8 @@ void render(GLFWwindow* window) {
|
|||
|
||||
renderSkyBox();
|
||||
renderParts();
|
||||
}
|
||||
|
||||
void setViewport(int width, int height) {
|
||||
viewportWidth = width, viewportHeight = height;
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
void renderInit(GLFWwindow* window);
|
||||
void render(GLFWwindow* window);
|
||||
void renderInit(GLFWwindow* window, int width, int height);
|
||||
void render(GLFWwindow* window);
|
||||
void setViewport(int width, int height);
|
Loading…
Add table
Reference in a new issue