refactor(autogen): changed type of size in Part to Vector3 and removed vec3 from autogen
This commit is contained in:
parent
2b650c0fed
commit
d5e24bf3ca
10 changed files with 27 additions and 16 deletions
|
@ -9,7 +9,6 @@
|
||||||
using namespace data;
|
using namespace data;
|
||||||
|
|
||||||
static std::map<std::string, std::string> MAPPED_TYPE = {
|
static std::map<std::string, std::string> MAPPED_TYPE = {
|
||||||
{ "glm::vec3", "Vector3" },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::map<std::string, std::string> LUA_CHECK_FUNCS = {
|
static std::map<std::string, std::string> LUA_CHECK_FUNCS = {
|
||||||
|
|
|
@ -16,11 +16,9 @@ static std::map<std::string, std::string> CATEGORY_STR = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::map<std::string, std::string> MAPPED_TYPE = {
|
static std::map<std::string, std::string> MAPPED_TYPE = {
|
||||||
{ "glm::vec3", "Vector3" },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::map<std::string, std::string> TYPEINFO_REFS = {
|
static std::map<std::string, std::string> TYPEINFO_REFS = {
|
||||||
{ "glm::vec3", "Vector3::TYPE" },
|
|
||||||
{ "bool", "BOOL_TYPE" },
|
{ "bool", "BOOL_TYPE" },
|
||||||
{ "int", "INT_TYPE" },
|
{ "int", "INT_TYPE" },
|
||||||
{ "float", "FLOAT_TYPE" },
|
{ "float", "FLOAT_TYPE" },
|
||||||
|
|
|
@ -170,15 +170,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->size.x += shiftFactor;
|
lastPart->size += Vector3(1, 0, 0) * shiftFactor;
|
||||||
gWorkspace()->SyncPartPhysics(lastPart);
|
gWorkspace()->SyncPartPhysics(lastPart);
|
||||||
}
|
}
|
||||||
if (key == GLFW_KEY_Y && action == GLFW_PRESS) {
|
if (key == GLFW_KEY_Y && action == GLFW_PRESS) {
|
||||||
lastPart->size.y += shiftFactor;
|
lastPart->size += Vector3(0, 1, 0) * shiftFactor;
|
||||||
gWorkspace()->SyncPartPhysics(lastPart);
|
gWorkspace()->SyncPartPhysics(lastPart);
|
||||||
}
|
}
|
||||||
if (key == GLFW_KEY_Z && action == GLFW_PRESS) {
|
if (key == GLFW_KEY_Z && action == GLFW_PRESS) {
|
||||||
lastPart->size.z += shiftFactor;
|
lastPart->size += Vector3(0, 0, 1) * shiftFactor;
|
||||||
gWorkspace()->SyncPartPhysics(lastPart);
|
gWorkspace()->SyncPartPhysics(lastPart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,10 @@ Vector3 Vector3::operator *(Vector3 other) const {
|
||||||
return Vector3(this->X() * other.X(), this->Y() * other.Y(), this->Z() * other.Z());
|
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 {
|
Vector3 Vector3::operator +(Vector3 other) const {
|
||||||
return Vector3(this->X() + other.X(), this->Y() + other.Y(), this->Z() + other.Z());
|
return Vector3(this->X() + other.X(), this->Y() + other.Y(), this->Z() + other.Z());
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ class DEF_DATA Vector3 {
|
||||||
public:
|
public:
|
||||||
DEF_DATA_CTOR Vector3();
|
DEF_DATA_CTOR Vector3();
|
||||||
DEF_DATA_CTOR Vector3(float x, float y, float z);
|
DEF_DATA_CTOR Vector3(float x, float y, float z);
|
||||||
|
inline Vector3(float value) : Vector3(value, value, value) {}
|
||||||
Vector3(const glm::vec3&);
|
Vector3(const glm::vec3&);
|
||||||
Vector3(const reactphysics3d::Vector3&);
|
Vector3(const reactphysics3d::Vector3&);
|
||||||
virtual ~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 /(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; // Component-wise
|
||||||
DEF_DATA_OP Vector3 operator +(Vector3) const;
|
DEF_DATA_OP Vector3 operator +(Vector3) const;
|
||||||
DEF_DATA_OP Vector3 operator -(Vector3) const;
|
DEF_DATA_OP Vector3 operator -(Vector3) const;
|
||||||
DEF_DATA_OP Vector3 operator -() 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;
|
||||||
|
|
||||||
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) {
|
inline void printVec(Vector3 vec) {
|
||||||
|
|
|
@ -40,7 +40,7 @@ CFrame partCFrameFromHandlePos(HandleFace face, Vector3 newPos) {
|
||||||
|
|
||||||
CFrame localFrame = editorToolHandles.worldMode ? CFrame::IDENTITY + adornee->position() : adornee->cframe;
|
CFrame localFrame = editorToolHandles.worldMode ? CFrame::IDENTITY + adornee->position() : adornee->cframe;
|
||||||
CFrame inverseFrame = localFrame.Inverse();
|
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);
|
Vector3 handlePos = localFrame * (handleOffset * face.normal);
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ Vector3 Part::GetAABB() {
|
||||||
Vector3 min(0, 0, 0);
|
Vector3 min(0, 0, 0);
|
||||||
Vector3 max(0, 0, 0);
|
Vector3 max(0, 0, 0);
|
||||||
for (Vector3 vert : verts) {
|
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);
|
expandMaxExtents(&min, &max, worldVert);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,9 @@ namespace rp = reactphysics3d;
|
||||||
|
|
||||||
// For easy construction from C++. Maybe should be removed?
|
// For easy construction from C++. Maybe should be removed?
|
||||||
struct PartConstructParams {
|
struct PartConstructParams {
|
||||||
glm::vec3 position;
|
Vector3 position;
|
||||||
glm::vec3 rotation;
|
Vector3 rotation;
|
||||||
glm::vec3 size;
|
Vector3 size;
|
||||||
Color3 color;
|
Color3 color;
|
||||||
|
|
||||||
bool anchored = false;
|
bool anchored = false;
|
||||||
|
@ -58,7 +58,7 @@ public:
|
||||||
CFrame cframe;
|
CFrame cframe;
|
||||||
|
|
||||||
DEF_PROP_CATEGORY(PART)
|
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_CATEGORY(APPEARANCE)
|
||||||
DEF_PROP Color3 color;
|
DEF_PROP Color3 color;
|
||||||
|
|
|
@ -69,7 +69,7 @@ void PartAssembly::Scale(Vector3 newSize, bool scaleUp) {
|
||||||
if (parts.size() == 1) {
|
if (parts.size() == 1) {
|
||||||
parts[0]->size = newSize;
|
parts[0]->size = newSize;
|
||||||
parts[0]->UpdateProperty("Size");
|
parts[0]->UpdateProperty("Size");
|
||||||
sendPropertyUpdatedSignal(parts[0], "Size", Variant((Vector3)parts[0]->size));
|
sendPropertyUpdatedSignal(parts[0], "Size", Variant(parts[0]->size));
|
||||||
_bounds = newSize;
|
_bounds = newSize;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ void PartAssembly::Scale(Vector3 newSize, bool scaleUp) {
|
||||||
sendPropertyUpdatedSignal(part, "CFrame", Variant(part->cframe));
|
sendPropertyUpdatedSignal(part, "CFrame", Variant(part->cframe));
|
||||||
part->size *= factor;
|
part->size *= factor;
|
||||||
part->UpdateProperty("Size");
|
part->UpdateProperty("Size");
|
||||||
sendPropertyUpdatedSignal(part, "Size", Variant((Vector3)part->size));
|
sendPropertyUpdatedSignal(part, "Size", Variant(part->size));
|
||||||
}
|
}
|
||||||
|
|
||||||
_bounds = _bounds * factor;
|
_bounds = _bounds * factor;
|
||||||
|
|
|
@ -140,7 +140,7 @@ void renderParts() {
|
||||||
} else {
|
} else {
|
||||||
glm::mat4 model = part->cframe;
|
glm::mat4 model = part->cframe;
|
||||||
// if (part->name == "camera") model = camera.getLookAt();
|
// 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("model", model);
|
||||||
shader->set("material", Material {
|
shader->set("material", Material {
|
||||||
.diffuse = part->color,
|
.diffuse = part->color,
|
||||||
|
@ -170,7 +170,7 @@ void renderParts() {
|
||||||
std::shared_ptr<Part> part = it->second;
|
std::shared_ptr<Part> part = it->second;
|
||||||
glm::mat4 model = part->cframe;
|
glm::mat4 model = part->cframe;
|
||||||
// if (part->name == "camera") model = camera.getLookAt();
|
// 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("model", model);
|
||||||
shader->set("material", Material {
|
shader->set("material", Material {
|
||||||
.diffuse = part->color,
|
.diffuse = part->color,
|
||||||
|
|
Loading…
Add table
Reference in a new issue