mirror of
https://github.com/HarbourMasters/SpaghettiKart
synced 2026-07-10 15:14:33 -04:00
gizmo work
This commit is contained in:
@@ -35,28 +35,62 @@ Editor::Editor() {
|
||||
void Editor::Load() {
|
||||
eObjectPicker.Load();
|
||||
for (auto& object : eGameObjects) {
|
||||
GenerateCollisionMesh(object, object.Model);
|
||||
GenerateCollisionMesh(object, object.Model, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::Tick() {
|
||||
auto wnd = GameEngine::Instance->context->GetWindow();
|
||||
|
||||
// GetMouseState
|
||||
if (wnd->MouseClick(Ship::LUS_MOUSE_BTN_LEFT)) {
|
||||
eObjectPicker.SelectObject(eGameObjects);
|
||||
static bool wasMouseDown = false;
|
||||
static bool isDragging = false;
|
||||
static Ship::Coords mouseStartPos;
|
||||
|
||||
Ship::Coords mousePos = wnd->GetMousePos();
|
||||
bool isMouseDown = wnd->GetMouseState(Ship::LUS_MOUSE_BTN_LEFT);
|
||||
|
||||
if (isMouseDown && !wasMouseDown) {
|
||||
// Mouse just pressed (Pressed state)
|
||||
mouseStartPos = mousePos;
|
||||
isDragging = false;
|
||||
}
|
||||
|
||||
if (isMouseDown) {
|
||||
// Mouse is being held (Held state)
|
||||
int dx = mousePos.x - mouseStartPos.x;
|
||||
int dy = mousePos.y - mouseStartPos.y;
|
||||
int dragThreshold = 5; // Adjust as needed
|
||||
|
||||
if ((dx * dx + dy * dy) > (dragThreshold * dragThreshold)) {
|
||||
// Squared distance check to avoid unnecessary sqrt()
|
||||
isDragging = true;
|
||||
eObjectPicker.DragHandle(); // Call drag logic
|
||||
}
|
||||
}
|
||||
|
||||
if (!isMouseDown && wasMouseDown) {
|
||||
// Mouse just released (Released state)
|
||||
eObjectPicker.eGizmo.SelectedHandle = Gizmo::GizmoHandle::None;
|
||||
if (!isDragging) {
|
||||
eObjectPicker.SelectObject(eGameObjects);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
wasMouseDown = isMouseDown; // Update previous state
|
||||
|
||||
eObjectPicker.Tick();
|
||||
}
|
||||
|
||||
void Editor::Draw() {
|
||||
eObjectPicker.Draw();
|
||||
}
|
||||
|
||||
void Editor::AddObject(FVector* pos, Gfx* model, CollisionType collision, float boundingBoxSize) {
|
||||
void Editor::AddObject(FVector* pos, Gfx* model, float scale, CollisionType collision, float boundingBoxSize) {
|
||||
|
||||
if (model != NULL) {
|
||||
eGameObjects.push_back({pos, model, {}, collision, boundingBoxSize});
|
||||
GenerateCollisionMesh(eGameObjects.back(), model);
|
||||
GenerateCollisionMesh(eGameObjects.back(), model, scale);
|
||||
} else { // to bounding box or sphere collision
|
||||
eGameObjects.push_back({pos, model, {}, CollisionType::BOUNDING_BOX, 2.0f});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user