feat: added vector3 type
This commit is contained in:
parent
8127d5b8f4
commit
c7ea5c5563
8 changed files with 62 additions and 5 deletions
|
@ -31,7 +31,7 @@ QVariant PropertiesModel::data(const QModelIndex &index, int role) const {
|
|||
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 selectedItem->GetPropertyValue(propertyName)->get<Data::Bool>() ? Qt::Checked : Qt::Unchecked;
|
||||
return {};
|
||||
// case Qt::DecorationRole:
|
||||
// return iconOf(item->GetClass());
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
|
||||
#define DEF_WRAPPER_CLASS(CLASS_NAME, WRAPPED_TYPE) class CLASS_NAME : public Data::Base { \
|
||||
public: \
|
||||
const WRAPPED_TYPE value; \
|
||||
public: \
|
||||
CLASS_NAME(WRAPPED_TYPE); \
|
||||
~CLASS_NAME(); \
|
||||
operator WRAPPED_TYPE(); \
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "base.h"
|
||||
#include "vector.h"
|
||||
#include <variant>
|
||||
|
||||
// #define __VARIANT_TYPE std::variant< \
|
||||
|
@ -17,7 +18,8 @@ namespace Data {
|
|||
Bool,
|
||||
Int,
|
||||
Float,
|
||||
String
|
||||
String,
|
||||
Vector3
|
||||
> __VARIANT_TYPE;
|
||||
|
||||
class Variant {
|
||||
|
|
19
src/datatypes/vector.cpp
Normal file
19
src/datatypes/vector.cpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include "vector.h"
|
||||
|
||||
Data::Vector3::Vector3(const glm::vec3& src) : vector(src) {};
|
||||
Data::Vector3::Vector3(const rp::Vector3& src) : vector(glm::vec3(src.x, src.y, src.z)) {};
|
||||
Data::Vector3::Vector3(float x, const float y, float z) : vector(glm::vec3(x, y, z)) {};
|
||||
|
||||
Data::Vector3::~Vector3() = default;
|
||||
const Data::TypeInfo Data::Vector3::TYPE = {
|
||||
.name = "Vector3",
|
||||
};
|
||||
|
||||
const Data::TypeInfo& Data::Vector3::GetType() const { return Data::Vector3::TYPE; };
|
||||
|
||||
const Data::String Data::Vector3::ToString() const {
|
||||
return std::to_string(X()) + ", " + std::to_string(Y()) + ", " + std::to_string(Z());
|
||||
}
|
||||
|
||||
Data::Vector3::operator glm::vec3() const { return vector; };
|
||||
Data::Vector3::operator rp::Vector3() const { return rp::Vector3(X(), Y(), Z()); };
|
33
src/datatypes/vector.h
Normal file
33
src/datatypes/vector.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
#pragma once
|
||||
|
||||
#include "base.h"
|
||||
#include <glm/ext/quaternion_geometric.hpp>
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <reactphysics3d/reactphysics3d.h>
|
||||
|
||||
namespace rp = reactphysics3d;
|
||||
|
||||
namespace Data {
|
||||
class Vector3 : Base {
|
||||
const glm::vec3 vector;
|
||||
|
||||
public:
|
||||
Vector3(float x, float y, float z);
|
||||
Vector3(const glm::vec3&);
|
||||
Vector3(const rp::Vector3&);
|
||||
~Vector3();
|
||||
|
||||
virtual const TypeInfo& GetType() const override;
|
||||
static const TypeInfo TYPE;
|
||||
|
||||
virtual const Data::String ToString() const override;
|
||||
|
||||
operator glm::vec3() const;
|
||||
operator rp::Vector3() const;
|
||||
|
||||
inline float X() const { return vector.x; }
|
||||
inline float Y() const { return vector.y; }
|
||||
inline float Z() const { return vector.z; }
|
||||
inline float Magnitude() const { return glm::length(vector); }
|
||||
};
|
||||
}
|
|
@ -17,7 +17,7 @@ struct FieldCodec {
|
|||
|
||||
template <typename T, typename U>
|
||||
void _writeCodec(Data::Variant source, void* destination) {
|
||||
*(U*)destination = source.get<T>().value;
|
||||
*(U*)destination = (U)source.get<T>();
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "part.h"
|
||||
#include "base/instance.h"
|
||||
#include "datatypes/base.h"
|
||||
#include "datatypes/vector.h"
|
||||
#include "objects/base/member.h"
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
@ -25,7 +26,8 @@ Part::Part(PartConstructParams params): Instance(&TYPE), position(params.positio
|
|||
this->memberMap = std::make_unique<MemberMap>(MemberMap {
|
||||
.super = std::move(this->memberMap),
|
||||
.members = {
|
||||
{ "Anchored", { .backingField = &anchored, .type = &Data::Bool::TYPE, .codec = fieldCodecOf<Data::Bool, bool>(), .updateCallback = memberFunctionOf(&Part::onUpdated, this) } }
|
||||
{ "Anchored", { .backingField = &anchored, .type = &Data::Bool::TYPE, .codec = fieldCodecOf<Data::Bool, bool>(), .updateCallback = memberFunctionOf(&Part::onUpdated, this) } },
|
||||
{ "Position", { .backingField = &position, .type = &Data::Vector3::TYPE, .codec = fieldCodecOf<Data::Vector3, glm::vec3>(), .updateCallback = memberFunctionOf(&Part::onUpdated, this) } }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
#include "../rendering/material.h"
|
||||
#include "datatypes/vector.h"
|
||||
#include <reactphysics3d/reactphysics3d.h>
|
||||
|
||||
namespace rp = reactphysics3d;
|
||||
|
|
Loading…
Add table
Reference in a new issue