fix: change scale to size

This commit is contained in:
maelstrom 2025-02-09 11:35:19 +01:00
parent fe0dca875c
commit 50f1466fe2
7 changed files with 17 additions and 17 deletions

View file

@ -49,7 +49,7 @@ int main() {
workspace()->AddChild(Part::New({
.position = glm::vec3(0, -5, 0),
.rotation = glm::vec3(0),
.scale = glm::vec3(512, 1.2, 512),
.size = glm::vec3(512, 1.2, 512),
.color = glm::vec3(0.388235, 0.372549, 0.384314),
.anchored = true,
}));
@ -57,7 +57,7 @@ int main() {
workspace()->AddChild(lastPart = Part::New({
.position = glm::vec3(0),
.rotation = glm::vec3(0),
.scale = glm::vec3(4, 1.2, 2),
.size = glm::vec3(4, 1.2, 2),
.color = glm::vec3(0.639216f, 0.635294f, 0.647059f),
}));
@ -157,7 +157,7 @@ void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods
workspace()->AddChild(lastPart = Part::New({
.position = camera.cameraPos + camera.cameraFront * glm::vec3(3),
.rotation = glm::vec3(0),
.scale = glm::vec3(1, 1, 1),
.size = glm::vec3(1, 1, 1),
.color = glm::vec3(1.0f, 0.5f, 0.31f),
}));
syncPartPhysics(lastPart);
@ -179,15 +179,15 @@ void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods
}
} else if (mode == 1) {
if (key == GLFW_KEY_X && action == GLFW_PRESS) {
lastPart->scale.x += shiftFactor;
lastPart->size.x += shiftFactor;
syncPartPhysics(lastPart);
}
if (key == GLFW_KEY_Y && action == GLFW_PRESS) {
lastPart->scale.y += shiftFactor;
lastPart->size.y += shiftFactor;
syncPartPhysics(lastPart);
}
if (key == GLFW_KEY_Z && action == GLFW_PRESS) {
lastPart->scale.z += shiftFactor;
lastPart->size.z += shiftFactor;
syncPartPhysics(lastPart);
}
}

View file

@ -74,7 +74,7 @@ void MainGLWidget::handleObjectDrag(QMouseEvent* evt) {
if (!rayHit) return;
Data::Vector3 vec = rayHit->worldPoint;
vec = vec + Data::Vector3(rpToGlm(rayHit->worldNormal) * draggingObject->lock()->scale / 2.f);
vec = vec + Data::Vector3(rpToGlm(rayHit->worldNormal) * draggingObject->lock()->size / 2.f);
draggingObject->lock()->cframe = draggingObject->lock()->cframe.Rotation() + vec;
syncPartPhysics(draggingObject->lock());
}
@ -156,7 +156,7 @@ void MainGLWidget::keyPressEvent(QKeyEvent* evt) {
workspace()->AddChild(lastPart = Part::New({
.position = camera.cameraPos + camera.cameraFront * glm::vec3(3),
.rotation = glm::vec3(0),
.scale = glm::vec3(1, 1, 1),
.size = glm::vec3(1, 1, 1),
.color = glm::vec3(1.0f, 0.5f, 0.31f),
}));
syncPartPhysics(lastPart);

View file

@ -86,7 +86,7 @@ MainWindow::MainWindow(QWidget *parent)
workspace()->AddChild(ui->mainWidget->lastPart = Part::New({
.position = glm::vec3(0, -5, 0),
.rotation = glm::vec3(0),
.scale = glm::vec3(512, 1.2, 512),
.size = glm::vec3(512, 1.2, 512),
.color = glm::vec3(0.388235, 0.372549, 0.384314),
.anchored = true,
}));
@ -96,7 +96,7 @@ MainWindow::MainWindow(QWidget *parent)
workspace()->AddChild(ui->mainWidget->lastPart = Part::New({
.position = glm::vec3(0),
.rotation = glm::vec3(0),
.scale = glm::vec3(4, 1.2, 2),
.size = glm::vec3(4, 1.2, 2),
.color = glm::vec3(0.639216f, 0.635294f, 0.647059f),
}));
syncPartPhysics(ui->mainWidget->lastPart);

View file

@ -60,7 +60,7 @@ Part::Part(): Part(PartConstructParams { .color = Data::Color3(0.639216f, 0.6352
}
Part::Part(PartConstructParams params): Instance(&TYPE), cframe(Data::CFrame(params.position, params.rotation)),
scale(params.scale), color(params.color), anchored(params.anchored) {
size(params.size), color(params.color), anchored(params.anchored) {
this->memberMap = std::make_unique<MemberMap>(MemberMap {
.super = std::move(this->memberMap),
.members = {
@ -87,7 +87,7 @@ Part::Part(PartConstructParams params): Instance(&TYPE), cframe(Data::CFrame(par
.codec = fieldCodecOf<Data::CFrame>(),
.updateCallback = memberFunctionOf(&Part::onUpdated, this),
} }, { "Size", {
.backingField = &scale,
.backingField = &size,
.type = &Data::Vector3::TYPE,
.codec = fieldCodecOf<Data::Vector3, glm::vec3>(),
.updateCallback = memberFunctionOf(&Part::onUpdated, this)

View file

@ -16,7 +16,7 @@ namespace rp = reactphysics3d;
struct PartConstructParams {
glm::vec3 position;
glm::quat rotation = glm::identity<glm::quat>();
glm::vec3 scale;
glm::vec3 size;
Data::Color3 color;
bool anchored = false;
@ -30,7 +30,7 @@ public:
const static InstanceType TYPE;
Data::CFrame cframe;
glm::vec3 scale;
glm::vec3 size;
Data::Color3 color;
bool selected = false;

View file

@ -53,7 +53,7 @@ void syncPartPhysics(std::shared_ptr<Part> part) {
part->rigidBody->setTransform(transform);
}
rp::BoxShape* shape = physicsCommon->createBoxShape(glmToRp(part->scale * glm::vec3(0.5f)));
rp::BoxShape* shape = physicsCommon->createBoxShape(glmToRp(part->size * glm::vec3(0.5f)));
if (part->rigidBody->getNbColliders() > 0) {
part->rigidBody->removeCollider(part->rigidBody->getCollider(0));

View file

@ -126,7 +126,7 @@ void renderParts() {
// );
glm::mat4 model = part->cframe;
model = glm::scale(model, part->scale);
model = glm::scale(model, part->size);
shader->set("model", model);
shader->set("material", Material {
.diffuse = part->color,
@ -135,7 +135,7 @@ void renderParts() {
});
glm::mat3 normalMatrix = glm::mat3(glm::transpose(glm::inverse(model)));
shader->set("normalMatrix", normalMatrix);
shader->set("texScale", part->scale);
shader->set("texScale", part->size);
CUBE_MESH->bind();
glDrawArrays(GL_TRIANGLES, 0, 36);