vectozavr-shooter/engine/Object.h

74 lines
2.3 KiB
C
Raw Normal View History

2021-09-13 15:53:43 +03:00
//
// Created by Иван Ильин on 15.03.2021.
//
#ifndef ENGINE_OBJECT_H
#define ENGINE_OBJECT_H
2021-10-02 20:36:07 +03:00
#include <map>
#include "Vec3D.h"
2021-10-09 13:41:12 +03:00
#include <string>
2021-10-17 10:21:10 +03:00
#include <utility>
2021-10-23 15:02:25 +03:00
#include <memory>
2021-10-17 10:21:10 +03:00
2021-10-17 11:41:58 +03:00
class ObjectNameTag final {
2021-10-17 10:21:10 +03:00
private:
const std::string _name;
public:
explicit ObjectNameTag(std::string name = "") : _name(std::move(name)) {}
[[nodiscard]] std::string str() const { return _name; }
bool operator==(const ObjectNameTag& tag) const { return _name == tag._name; }
bool operator!=(const ObjectNameTag& tag) const { return _name != tag._name; }
bool operator<(const ObjectNameTag& tag) const { return _name < tag._name; }
};
2021-09-13 15:53:43 +03:00
class Object {
2021-10-28 16:58:02 +03:00
private:
bool checkIfAttached(Object* obj);
const ObjectNameTag _nameTag;
2021-09-13 15:53:43 +03:00
protected:
2021-10-28 16:58:02 +03:00
Vec3D _left {1, 0, 0}; // internal X
Vec3D _up {0, 1, 0}; // internal Y
Vec3D _lookAt {0, 0, 1}; // internal Z
2021-10-02 20:36:07 +03:00
2021-10-28 16:58:02 +03:00
std::map<ObjectNameTag, std::weak_ptr<Object>> _attachedObjects;
2021-09-13 15:53:43 +03:00
2021-10-28 16:58:02 +03:00
Vec3D _position {0, 0, 0};
Vec3D _angle {0, 0, 0};
Vec3D _angleLeftUpLookAt{0, 0, 0};
2021-09-13 15:53:43 +03:00
public:
2021-10-28 16:58:02 +03:00
Object(ObjectNameTag nameTag) : _nameTag(nameTag) {};
2021-09-13 15:53:43 +03:00
virtual void translate(const Vec3D& dv);
virtual void translateToPoint(const Vec3D& point);
virtual void scale(const Vec3D& s);
virtual void rotate(const Vec3D& r);
virtual void rotate(const Vec3D& v, double rv);
virtual void rotateToAngle(const Vec3D& v);
virtual void rotateRelativePoint(const Vec3D& s, const Vec3D& r);
virtual void rotateRelativePoint(const Vec3D& s, const Vec3D& v, double r);
void rotateLeft(double rl);
void rotateUp(double ru);
void rotateLookAt(double rlAt);
2021-10-28 16:58:02 +03:00
[[nodiscard]] Vec3D position() const { return _position; }
[[nodiscard]] Vec3D angle() const { return _angle; }
[[nodiscard]] Vec3D angleLeftUpLookAt() const { return _angleLeftUpLookAt; }
2021-10-28 16:58:02 +03:00
[[nodiscard]] Vec3D left() const { return _left; }
[[nodiscard]] Vec3D up() const { return _up; }
[[nodiscard]] Vec3D lookAt() const { return _lookAt; }
2021-09-13 15:53:43 +03:00
2021-10-28 16:58:02 +03:00
void attach(std::shared_ptr<Object> object);
2021-10-17 10:21:10 +03:00
void unattach(const ObjectNameTag& tag);
std::shared_ptr<Object> attached(const ObjectNameTag& tag);
2021-10-16 20:22:55 +03:00
2021-10-28 16:58:02 +03:00
ObjectNameTag name() const { return _nameTag; }
2021-10-16 20:22:55 +03:00
virtual ~Object();
2021-10-02 20:36:07 +03:00
};
2021-09-13 15:53:43 +03:00
#endif //MINECRAFT_3DZAVR_OBJECT_H