Files
WickedEngine/Editor/Translator.h
T
2022-07-13 13:50:26 +02:00

67 lines
1.9 KiB
C++

#pragma once
#include "CommonInclude.h"
#include "wiCanvas.h"
#include "wiVector.h"
#include "wiUnorderedSet.h"
class Translator
{
private:
bool dragging = false;
bool dragStarted = false;
bool dragEnded = false;
XMFLOAT3 intersection_start = XMFLOAT3(0, 0, 0);
XMFLOAT3 axis = XMFLOAT3(1, 0, 0);
float angle = 0;
float angle_start = 0;
public:
void Update(const wi::scene::CameraComponent& camera, const wi::Canvas& canvas);
void Draw(const wi::scene::CameraComponent& camera, wi::graphics::CommandList cmd) const;
// Attach selection to translator temporarily
void PreTranslate();
// Apply translator to selection
void PostTranslate();
wi::scene::TransformComponent transform;
wi::vector<wi::scene::PickResult> selected; // all the selected picks
wi::unordered_set<wi::ecs::Entity> selectedEntitiesLookup; // fast lookup for selected entities
wi::vector<wi::ecs::Entity> selectedEntitiesNonRecursive; // selected entities that don't contain entities that would be included in recursive iterations
bool enabled = false;
float scale_snap = 1;
float rotate_snap = XM_PIDIV4;
float translate_snap = 1;
enum TRANSLATOR_STATE
{
TRANSLATOR_IDLE,
TRANSLATOR_X,
TRANSLATOR_Y,
TRANSLATOR_Z,
TRANSLATOR_XY,
TRANSLATOR_XZ,
TRANSLATOR_YZ,
TRANSLATOR_XYZ,
} state = TRANSLATOR_IDLE;
XMMATRIX GetMirrorMatrix(TRANSLATOR_STATE state, const wi::scene::CameraComponent& camera) const;
void WriteAxisText(TRANSLATOR_STATE axis, const wi::scene::CameraComponent& camera, char* text) const;
float dist = 1;
bool isTranslator = true, isScalator = false, isRotator = false;
// Check if the drag started in this exact frame
bool IsDragStarted() const { return dragStarted; };
// Check if the drag ended in this exact frame
bool IsDragEnded() const { return dragEnded; };
wi::scene::TransformComponent transform_start;
wi::vector<XMFLOAT4X4> matrices_start;
wi::vector<XMFLOAT4X4> matrices_current;
};