diff --git a/autogen/src/data/codegen.cpp b/autogen/src/data/codegen.cpp index 217a071..57354fc 100644 --- a/autogen/src/data/codegen.cpp +++ b/autogen/src/data/codegen.cpp @@ -9,7 +9,6 @@ using namespace data; static std::map MAPPED_TYPE = { - { "glm::vec3", "Vector3" }, }; static std::map LUA_CHECK_FUNCS = { diff --git a/autogen/src/object/codegen.cpp b/autogen/src/object/codegen.cpp index 17c9529..fce06ca 100644 --- a/autogen/src/object/codegen.cpp +++ b/autogen/src/object/codegen.cpp @@ -16,11 +16,9 @@ static std::map CATEGORY_STR = { }; static std::map MAPPED_TYPE = { - { "glm::vec3", "Vector3" }, }; static std::map TYPEINFO_REFS = { - { "glm::vec3", "Vector3::TYPE" }, { "bool", "BOOL_TYPE" }, { "int", "INT_TYPE" }, { "float", "FLOAT_TYPE" }, diff --git a/client/src/main.cpp b/client/src/main.cpp index 67da5a0..bbbe31e 100644 --- a/client/src/main.cpp +++ b/client/src/main.cpp @@ -170,15 +170,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->size.x += shiftFactor; + lastPart->size += Vector3(1, 0, 0) * shiftFactor; gWorkspace()->SyncPartPhysics(lastPart); } if (key == GLFW_KEY_Y && action == GLFW_PRESS) { - lastPart->size.y += shiftFactor; + lastPart->size += Vector3(0, 1, 0) * shiftFactor; gWorkspace()->SyncPartPhysics(lastPart); } if (key == GLFW_KEY_Z && action == GLFW_PRESS) { - lastPart->size.z += shiftFactor; + lastPart->size += Vector3(0, 0, 1) * shiftFactor; gWorkspace()->SyncPartPhysics(lastPart); } } diff --git a/core/src/datatypes/vector.cpp b/core/src/datatypes/vector.cpp index ed6922b..e35dee5 100644 --- a/core/src/datatypes/vector.cpp +++ b/core/src/datatypes/vector.cpp @@ -48,6 +48,10 @@ Vector3 Vector3::operator *(Vector3 other) const { return Vector3(this->X() * other.X(), this->Y() * other.Y(), this->Z() * other.Z()); } +Vector3 Vector3::operator /(Vector3 other) const { + return Vector3(this->X() / other.X(), this->Y() / other.Y(), this->Z() / other.Z()); +} + Vector3 Vector3::operator +(Vector3 other) const { return Vector3(this->X() + other.X(), this->Y() + other.Y(), this->Z() + other.Z()); } diff --git a/core/src/datatypes/vector.h b/core/src/datatypes/vector.h index 7f58426..e134efe 100644 --- a/core/src/datatypes/vector.h +++ b/core/src/datatypes/vector.h @@ -15,6 +15,7 @@ class DEF_DATA Vector3 { public: DEF_DATA_CTOR Vector3(); DEF_DATA_CTOR Vector3(float x, float y, float z); + inline Vector3(float value) : Vector3(value, value, value) {} Vector3(const glm::vec3&); Vector3(const reactphysics3d::Vector3&); virtual ~Vector3(); @@ -47,6 +48,7 @@ public: DEF_DATA_OP Vector3 operator *(float) const; DEF_DATA_OP Vector3 operator /(float) const; DEF_DATA_OP Vector3 operator *(Vector3) const; // Component-wise + DEF_DATA_OP Vector3 operator /(Vector3) const; // Component-wise DEF_DATA_OP Vector3 operator +(Vector3) const; DEF_DATA_OP Vector3 operator -(Vector3) const; DEF_DATA_OP Vector3 operator -() const; @@ -55,6 +57,14 @@ public: DEF_DATA_OP bool operator >(Vector3) const; DEF_DATA_OP bool operator ==(Vector3) const; + + // Augmented shorthands + inline Vector3 operator *=(float factor) const { return *this * factor; } + inline Vector3 operator /=(float factor) const { return *this / factor; } + inline Vector3 operator *=(Vector3 factor) const { return *this * factor; } + inline Vector3 operator /=(Vector3 factor) const { return *this / factor; } + inline Vector3 operator +=(Vector3 vector) const { return *this + vector; } + inline Vector3 operator -=(Vector3 vector) const { return *this + vector; } }; inline void printVec(Vector3 vec) { diff --git a/core/src/handles.cpp b/core/src/handles.cpp index e0ad9df..1e28759 100644 --- a/core/src/handles.cpp +++ b/core/src/handles.cpp @@ -40,7 +40,7 @@ CFrame partCFrameFromHandlePos(HandleFace face, Vector3 newPos) { CFrame localFrame = editorToolHandles.worldMode ? CFrame::IDENTITY + adornee->position() : adornee->cframe; CFrame inverseFrame = localFrame.Inverse(); - Vector3 handleOffset = editorToolHandles.worldMode ? ((Vector3::ONE * 2.f) + adornee->GetAABB() * 0.5f) : Vector3(2.f + adornee->size * 0.5f); + Vector3 handleOffset = editorToolHandles.worldMode ? ((Vector3::ONE * 2.f) + adornee->GetAABB() * 0.5f) : Vector3(2.f) + adornee->size * 0.5f; Vector3 handlePos = localFrame * (handleOffset * face.normal); diff --git a/core/src/objects/part.cpp b/core/src/objects/part.cpp index 64a0196..9e416af 100644 --- a/core/src/objects/part.cpp +++ b/core/src/objects/part.cpp @@ -83,7 +83,7 @@ Vector3 Part::GetAABB() { Vector3 min(0, 0, 0); Vector3 max(0, 0, 0); for (Vector3 vert : verts) { - Vector3 worldVert = this->cframe.Rotation() * ((Vector3)this->size * vert); + Vector3 worldVert = this->cframe.Rotation() * (this->size * vert); expandMaxExtents(&min, &max, worldVert); } diff --git a/core/src/objects/part.h b/core/src/objects/part.h index bf70a80..954f2eb 100644 --- a/core/src/objects/part.h +++ b/core/src/objects/part.h @@ -18,9 +18,9 @@ namespace rp = reactphysics3d; // For easy construction from C++. Maybe should be removed? struct PartConstructParams { - glm::vec3 position; - glm::vec3 rotation; - glm::vec3 size; + Vector3 position; + Vector3 rotation; + Vector3 size; Color3 color; bool anchored = false; @@ -58,7 +58,7 @@ public: CFrame cframe; DEF_PROP_CATEGORY(PART) - DEF_PROP_(on_update=onUpdated) glm::vec3 size; + DEF_PROP_(on_update=onUpdated) Vector3 size; DEF_PROP_CATEGORY(APPEARANCE) DEF_PROP Color3 color; diff --git a/core/src/partassembly.cpp b/core/src/partassembly.cpp index c5f120c..ed37f4a 100644 --- a/core/src/partassembly.cpp +++ b/core/src/partassembly.cpp @@ -69,7 +69,7 @@ void PartAssembly::Scale(Vector3 newSize, bool scaleUp) { if (parts.size() == 1) { parts[0]->size = newSize; parts[0]->UpdateProperty("Size"); - sendPropertyUpdatedSignal(parts[0], "Size", Variant((Vector3)parts[0]->size)); + sendPropertyUpdatedSignal(parts[0], "Size", Variant(parts[0]->size)); _bounds = newSize; return; } @@ -85,7 +85,7 @@ void PartAssembly::Scale(Vector3 newSize, bool scaleUp) { sendPropertyUpdatedSignal(part, "CFrame", Variant(part->cframe)); part->size *= factor; part->UpdateProperty("Size"); - sendPropertyUpdatedSignal(part, "Size", Variant((Vector3)part->size)); + sendPropertyUpdatedSignal(part, "Size", Variant(part->size)); } _bounds = _bounds * factor; diff --git a/core/src/rendering/renderer.cpp b/core/src/rendering/renderer.cpp index c472878..ea64e9c 100644 --- a/core/src/rendering/renderer.cpp +++ b/core/src/rendering/renderer.cpp @@ -140,7 +140,7 @@ void renderParts() { } else { glm::mat4 model = part->cframe; // if (part->name == "camera") model = camera.getLookAt(); - model = glm::scale(model, part->size); + model = glm::scale(model, (glm::vec3)part->size); shader->set("model", model); shader->set("material", Material { .diffuse = part->color, @@ -170,7 +170,7 @@ void renderParts() { std::shared_ptr part = it->second; glm::mat4 model = part->cframe; // if (part->name == "camera") model = camera.getLookAt(); - model = glm::scale(model, part->size); + model = glm::scale(model, (glm::vec3)part->size); shader->set("model", model); shader->set("material", Material { .diffuse = part->color,