fix: change scale to size
This commit is contained in:
parent
fe0dca875c
commit
50f1466fe2
7 changed files with 17 additions and 17 deletions
|
@ -49,7 +49,7 @@ int main() {
|
||||||
workspace()->AddChild(Part::New({
|
workspace()->AddChild(Part::New({
|
||||||
.position = glm::vec3(0, -5, 0),
|
.position = glm::vec3(0, -5, 0),
|
||||||
.rotation = glm::vec3(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),
|
.color = glm::vec3(0.388235, 0.372549, 0.384314),
|
||||||
.anchored = true,
|
.anchored = true,
|
||||||
}));
|
}));
|
||||||
|
@ -57,7 +57,7 @@ int main() {
|
||||||
workspace()->AddChild(lastPart = Part::New({
|
workspace()->AddChild(lastPart = Part::New({
|
||||||
.position = glm::vec3(0),
|
.position = glm::vec3(0),
|
||||||
.rotation = 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),
|
.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({
|
workspace()->AddChild(lastPart = Part::New({
|
||||||
.position = camera.cameraPos + camera.cameraFront * glm::vec3(3),
|
.position = camera.cameraPos + camera.cameraFront * glm::vec3(3),
|
||||||
.rotation = glm::vec3(0),
|
.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),
|
.color = glm::vec3(1.0f, 0.5f, 0.31f),
|
||||||
}));
|
}));
|
||||||
syncPartPhysics(lastPart);
|
syncPartPhysics(lastPart);
|
||||||
|
@ -179,15 +179,15 @@ void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods
|
||||||
}
|
}
|
||||||
} else if (mode == 1) {
|
} else if (mode == 1) {
|
||||||
if (key == GLFW_KEY_X && action == GLFW_PRESS) {
|
if (key == GLFW_KEY_X && action == GLFW_PRESS) {
|
||||||
lastPart->scale.x += shiftFactor;
|
lastPart->size.x += shiftFactor;
|
||||||
syncPartPhysics(lastPart);
|
syncPartPhysics(lastPart);
|
||||||
}
|
}
|
||||||
if (key == GLFW_KEY_Y && action == GLFW_PRESS) {
|
if (key == GLFW_KEY_Y && action == GLFW_PRESS) {
|
||||||
lastPart->scale.y += shiftFactor;
|
lastPart->size.y += shiftFactor;
|
||||||
syncPartPhysics(lastPart);
|
syncPartPhysics(lastPart);
|
||||||
}
|
}
|
||||||
if (key == GLFW_KEY_Z && action == GLFW_PRESS) {
|
if (key == GLFW_KEY_Z && action == GLFW_PRESS) {
|
||||||
lastPart->scale.z += shiftFactor;
|
lastPart->size.z += shiftFactor;
|
||||||
syncPartPhysics(lastPart);
|
syncPartPhysics(lastPart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ void MainGLWidget::handleObjectDrag(QMouseEvent* evt) {
|
||||||
|
|
||||||
if (!rayHit) return;
|
if (!rayHit) return;
|
||||||
Data::Vector3 vec = rayHit->worldPoint;
|
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;
|
draggingObject->lock()->cframe = draggingObject->lock()->cframe.Rotation() + vec;
|
||||||
syncPartPhysics(draggingObject->lock());
|
syncPartPhysics(draggingObject->lock());
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ void MainGLWidget::keyPressEvent(QKeyEvent* evt) {
|
||||||
workspace()->AddChild(lastPart = Part::New({
|
workspace()->AddChild(lastPart = Part::New({
|
||||||
.position = camera.cameraPos + camera.cameraFront * glm::vec3(3),
|
.position = camera.cameraPos + camera.cameraFront * glm::vec3(3),
|
||||||
.rotation = glm::vec3(0),
|
.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),
|
.color = glm::vec3(1.0f, 0.5f, 0.31f),
|
||||||
}));
|
}));
|
||||||
syncPartPhysics(lastPart);
|
syncPartPhysics(lastPart);
|
||||||
|
|
|
@ -86,7 +86,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
workspace()->AddChild(ui->mainWidget->lastPart = Part::New({
|
workspace()->AddChild(ui->mainWidget->lastPart = Part::New({
|
||||||
.position = glm::vec3(0, -5, 0),
|
.position = glm::vec3(0, -5, 0),
|
||||||
.rotation = glm::vec3(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),
|
.color = glm::vec3(0.388235, 0.372549, 0.384314),
|
||||||
.anchored = true,
|
.anchored = true,
|
||||||
}));
|
}));
|
||||||
|
@ -96,7 +96,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
workspace()->AddChild(ui->mainWidget->lastPart = Part::New({
|
workspace()->AddChild(ui->mainWidget->lastPart = Part::New({
|
||||||
.position = glm::vec3(0),
|
.position = glm::vec3(0),
|
||||||
.rotation = 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),
|
.color = glm::vec3(0.639216f, 0.635294f, 0.647059f),
|
||||||
}));
|
}));
|
||||||
syncPartPhysics(ui->mainWidget->lastPart);
|
syncPartPhysics(ui->mainWidget->lastPart);
|
||||||
|
|
|
@ -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)),
|
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 {
|
this->memberMap = std::make_unique<MemberMap>(MemberMap {
|
||||||
.super = std::move(this->memberMap),
|
.super = std::move(this->memberMap),
|
||||||
.members = {
|
.members = {
|
||||||
|
@ -87,7 +87,7 @@ Part::Part(PartConstructParams params): Instance(&TYPE), cframe(Data::CFrame(par
|
||||||
.codec = fieldCodecOf<Data::CFrame>(),
|
.codec = fieldCodecOf<Data::CFrame>(),
|
||||||
.updateCallback = memberFunctionOf(&Part::onUpdated, this),
|
.updateCallback = memberFunctionOf(&Part::onUpdated, this),
|
||||||
} }, { "Size", {
|
} }, { "Size", {
|
||||||
.backingField = &scale,
|
.backingField = &size,
|
||||||
.type = &Data::Vector3::TYPE,
|
.type = &Data::Vector3::TYPE,
|
||||||
.codec = fieldCodecOf<Data::Vector3, glm::vec3>(),
|
.codec = fieldCodecOf<Data::Vector3, glm::vec3>(),
|
||||||
.updateCallback = memberFunctionOf(&Part::onUpdated, this)
|
.updateCallback = memberFunctionOf(&Part::onUpdated, this)
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace rp = reactphysics3d;
|
||||||
struct PartConstructParams {
|
struct PartConstructParams {
|
||||||
glm::vec3 position;
|
glm::vec3 position;
|
||||||
glm::quat rotation = glm::identity<glm::quat>();
|
glm::quat rotation = glm::identity<glm::quat>();
|
||||||
glm::vec3 scale;
|
glm::vec3 size;
|
||||||
Data::Color3 color;
|
Data::Color3 color;
|
||||||
|
|
||||||
bool anchored = false;
|
bool anchored = false;
|
||||||
|
@ -30,7 +30,7 @@ public:
|
||||||
const static InstanceType TYPE;
|
const static InstanceType TYPE;
|
||||||
|
|
||||||
Data::CFrame cframe;
|
Data::CFrame cframe;
|
||||||
glm::vec3 scale;
|
glm::vec3 size;
|
||||||
Data::Color3 color;
|
Data::Color3 color;
|
||||||
bool selected = false;
|
bool selected = false;
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ void syncPartPhysics(std::shared_ptr<Part> part) {
|
||||||
part->rigidBody->setTransform(transform);
|
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) {
|
if (part->rigidBody->getNbColliders() > 0) {
|
||||||
part->rigidBody->removeCollider(part->rigidBody->getCollider(0));
|
part->rigidBody->removeCollider(part->rigidBody->getCollider(0));
|
||||||
|
|
|
@ -126,7 +126,7 @@ void renderParts() {
|
||||||
// );
|
// );
|
||||||
|
|
||||||
glm::mat4 model = part->cframe;
|
glm::mat4 model = part->cframe;
|
||||||
model = glm::scale(model, part->scale);
|
model = glm::scale(model, part->size);
|
||||||
shader->set("model", model);
|
shader->set("model", model);
|
||||||
shader->set("material", Material {
|
shader->set("material", Material {
|
||||||
.diffuse = part->color,
|
.diffuse = part->color,
|
||||||
|
@ -135,7 +135,7 @@ void renderParts() {
|
||||||
});
|
});
|
||||||
glm::mat3 normalMatrix = glm::mat3(glm::transpose(glm::inverse(model)));
|
glm::mat3 normalMatrix = glm::mat3(glm::transpose(glm::inverse(model)));
|
||||||
shader->set("normalMatrix", normalMatrix);
|
shader->set("normalMatrix", normalMatrix);
|
||||||
shader->set("texScale", part->scale);
|
shader->set("texScale", part->size);
|
||||||
|
|
||||||
CUBE_MESH->bind();
|
CUBE_MESH->bind();
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||||
|
|
Loading…
Add table
Reference in a new issue