UWP (#111)
* project restructure * editor fix: camera shouldn't reset on render path change
This commit is contained in:
+168
-167
@@ -324,6 +324,9 @@ void EditorComponent::ResizeLayout()
|
||||
helpButton->SetPos(XMFLOAT2(screenW - 50 - 55, 0));
|
||||
helpButton->SetSize(XMFLOAT2(50, 40));
|
||||
|
||||
helpLabel->SetSize(XMFLOAT2(screenW / 2.0f, screenH / 1.5f));
|
||||
helpLabel->SetPos(XMFLOAT2(screenW / 2.0f - helpLabel->scale.x / 2.0f, screenH / 2.0f - helpLabel->scale.y / 2.0f));
|
||||
|
||||
exitButton->SetPos(XMFLOAT2(screenW - 50, 0));
|
||||
exitButton->SetSize(XMFLOAT2(50, 40));
|
||||
|
||||
@@ -752,50 +755,44 @@ void EditorComponent::Load()
|
||||
helpButton->SetColor(wiColor(34, 158, 214, 180), wiWidget::WIDGETSTATE::IDLE);
|
||||
helpButton->SetColor(wiColor(113, 183, 214, 255), wiWidget::WIDGETSTATE::FOCUS);
|
||||
helpButton->OnClick([=](wiEventArgs args) {
|
||||
static wiLabel* helpLabel = nullptr;
|
||||
if (helpLabel == nullptr)
|
||||
{
|
||||
stringstream ss("");
|
||||
ss << "Help: " << endl << "############" << endl;
|
||||
ss << "Move camera: WASD, or Contoller left stick or D-pad" << endl;
|
||||
ss << "Look: Middle mouse button / arrow keys / controller right stick" << endl;
|
||||
ss << "Select: Right mouse button" << endl;
|
||||
ss << "Place decal, interact with water: Left mouse button when nothing is selected" << endl;
|
||||
ss << "Camera speed: SHIFT button or controller R2/RT" << endl;
|
||||
ss << "Camera up: E, down: Q" << endl;
|
||||
ss << "Duplicate entity: Ctrl + D" << endl;
|
||||
ss << "Select All: Ctrl + A" << endl;
|
||||
ss << "Undo: Ctrl + Z" << endl;
|
||||
ss << "Redo: Ctrl + Y" << endl;
|
||||
ss << "Copy: Ctrl + C" << endl;
|
||||
ss << "Paste: Ctrl + V" << endl;
|
||||
ss << "Delete: DELETE button" << endl;
|
||||
ss << "Place Instances: Ctrl + Shift + Left mouse click (place clipboard onto clicked surface)" << endl;
|
||||
ss << "Script Console / backlog: HOME button" << endl;
|
||||
ss << endl;
|
||||
ss << "You can find sample scenes in the models directory. Try to load one." << endl;
|
||||
ss << "You can also import models from .OBJ, .GLTF, .GLB files." << endl;
|
||||
ss << "You can find a program configuration file at Editor/config.ini" << endl;
|
||||
ss << "You can find sample LUA scripts in the scripts directory. Try to load one." << endl;
|
||||
ss << "You can find a startup script at Editor/startup.lua (this will be executed on program start)" << endl;
|
||||
ss << endl << endl << "For questions, bug reports, feedback, requests, please open an issue at:" << endl;
|
||||
ss << "https://github.com/turanszkij/WickedEngine" << endl;
|
||||
|
||||
float screenW = (float)wiRenderer::GetDevice()->GetScreenWidth();
|
||||
float screenH = (float)wiRenderer::GetDevice()->GetScreenHeight();
|
||||
|
||||
helpLabel = new wiLabel("HelpLabel");
|
||||
helpLabel->SetText(ss.str());
|
||||
helpLabel->SetSize(XMFLOAT2(screenW / 2.0f, screenH / 1.5f));
|
||||
helpLabel->SetPos(XMFLOAT2(screenW / 2.0f - helpLabel->scale.x / 2.0f, screenH / 2.0f - helpLabel->scale.y / 2.0f));
|
||||
helpLabel->SetVisible(false);
|
||||
GetGUI().AddWidget(helpLabel);
|
||||
}
|
||||
|
||||
helpLabel->SetVisible(!helpLabel->IsVisible());
|
||||
});
|
||||
GetGUI().AddWidget(helpButton);
|
||||
|
||||
{
|
||||
stringstream ss("");
|
||||
ss << "Help:" << endl;
|
||||
ss << "Move camera: WASD, or Contoller left stick or D-pad" << endl;
|
||||
ss << "Look: Middle mouse button / arrow keys / controller right stick" << endl;
|
||||
ss << "Select: Right mouse button" << endl;
|
||||
ss << "Place decal, interact with water: Left mouse button when nothing is selected" << endl;
|
||||
ss << "Camera speed: SHIFT button or controller R2/RT" << endl;
|
||||
ss << "Camera up: E, down: Q" << endl;
|
||||
ss << "Duplicate entity: Ctrl + D" << endl;
|
||||
ss << "Select All: Ctrl + A" << endl;
|
||||
ss << "Undo: Ctrl + Z" << endl;
|
||||
ss << "Redo: Ctrl + Y" << endl;
|
||||
ss << "Copy: Ctrl + C" << endl;
|
||||
ss << "Paste: Ctrl + V" << endl;
|
||||
ss << "Delete: DELETE button" << endl;
|
||||
ss << "Place Instances: Ctrl + Shift + Left mouse click (place clipboard onto clicked surface)" << endl;
|
||||
ss << "Script Console / backlog: HOME button" << endl;
|
||||
ss << endl;
|
||||
ss << "You can find sample scenes in the models directory. Try to load one." << endl;
|
||||
ss << "You can also import models from .OBJ, .GLTF, .GLB files." << endl;
|
||||
ss << "You can find a program configuration file at Editor/config.ini" << endl;
|
||||
ss << "You can find sample LUA scripts in the scripts directory. Try to load one." << endl;
|
||||
ss << "You can find a startup script at Editor/startup.lua (this will be executed on program start)" << endl;
|
||||
ss << endl << "For questions, bug reports, feedback, requests, please open an issue at:" << endl;
|
||||
ss << "https://github.com/turanszkij/WickedEngine" << endl;
|
||||
ss << endl << "Devblog: https://wickedengine.net/" << endl;
|
||||
ss << "Discord: https://discord.gg/CFjRYmE" << endl;
|
||||
|
||||
helpLabel = new wiLabel("HelpLabel");
|
||||
helpLabel->SetText(ss.str());
|
||||
helpLabel->SetVisible(false);
|
||||
GetGUI().AddWidget(helpLabel);
|
||||
}
|
||||
|
||||
exitButton = new wiButton("X");
|
||||
exitButton->SetTooltip("Exit");
|
||||
@@ -1029,135 +1026,139 @@ void EditorComponent::Update(float dt)
|
||||
cinemaModeCheckBox->SetCheck(false);
|
||||
}
|
||||
|
||||
// Camera control:
|
||||
static XMFLOAT4 originalMouse = XMFLOAT4(0, 0, 0, 0);
|
||||
static bool camControlStart = true;
|
||||
if (camControlStart)
|
||||
{
|
||||
originalMouse = wiInput::GetPointer();
|
||||
}
|
||||
|
||||
XMFLOAT4 currentMouse = wiInput::GetPointer();
|
||||
float xDif = 0, yDif = 0;
|
||||
|
||||
if (wiInput::Down(wiInput::MOUSE_BUTTON_MIDDLE))
|
||||
{
|
||||
camControlStart = false;
|
||||
xDif = currentMouse.x - originalMouse.x;
|
||||
yDif = currentMouse.y - originalMouse.y;
|
||||
xDif = 0.1f * xDif * (1.0f / 60.0f);
|
||||
yDif = 0.1f * yDif * (1.0f / 60.0f);
|
||||
#ifdef PLATFORM_UWP
|
||||
originalMouse = currentMouse;
|
||||
#else
|
||||
wiInput::SetPointer(originalMouse);
|
||||
#endif // PLATFORM_UWP
|
||||
wiInput::HidePointer(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
camControlStart = true;
|
||||
wiInput::HidePointer(false);
|
||||
}
|
||||
|
||||
const float buttonrotSpeed = 2.0f / 60.0f;
|
||||
if (wiInput::Down(wiInput::KEYBOARD_BUTTON_LEFT))
|
||||
{
|
||||
xDif -= buttonrotSpeed;
|
||||
}
|
||||
if (wiInput::Down(wiInput::KEYBOARD_BUTTON_RIGHT))
|
||||
{
|
||||
xDif += buttonrotSpeed;
|
||||
}
|
||||
if (wiInput::Down(wiInput::KEYBOARD_BUTTON_UP))
|
||||
{
|
||||
yDif -= buttonrotSpeed;
|
||||
}
|
||||
if (wiInput::Down(wiInput::KEYBOARD_BUTTON_DOWN))
|
||||
{
|
||||
yDif += buttonrotSpeed;
|
||||
}
|
||||
|
||||
const XMFLOAT4 leftStick = wiInput::GetAnalog(wiInput::GAMEPAD_ANALOG_THUMBSTICK_L, 0);
|
||||
const XMFLOAT4 rightStick = wiInput::GetAnalog(wiInput::GAMEPAD_ANALOG_THUMBSTICK_R, 0);
|
||||
const XMFLOAT4 rightTrigger = wiInput::GetAnalog(wiInput::GAMEPAD_ANALOG_TRIGGER_R, 0);
|
||||
|
||||
const float jostickrotspeed = 0.05f;
|
||||
xDif += rightStick.x * jostickrotspeed;
|
||||
yDif += rightStick.y * jostickrotspeed;
|
||||
|
||||
xDif *= cameraWnd->rotationspeedSlider->GetValue();
|
||||
yDif *= cameraWnd->rotationspeedSlider->GetValue();
|
||||
|
||||
|
||||
if (cameraWnd->fpsCheckBox->GetCheck())
|
||||
{
|
||||
// FPS Camera
|
||||
const float clampedDT = min(dt, 0.1f); // if dt > 100 millisec, don't allow the camera to jump too far...
|
||||
|
||||
const float speed = ((wiInput::Down(wiInput::KEYBOARD_BUTTON_LSHIFT) ? 10.0f : 1.0f) + rightTrigger.x * 10.0f) * cameraWnd->movespeedSlider->GetValue() * clampedDT;
|
||||
static XMVECTOR move = XMVectorSet(0, 0, 0, 0);
|
||||
XMVECTOR moveNew = XMVectorSet(leftStick.x, 0, leftStick.y, 0);
|
||||
|
||||
if (!wiInput::Down(wiInput::KEYBOARD_BUTTON_LCONTROL))
|
||||
{
|
||||
// Only move camera if control not pressed
|
||||
if (wiInput::Down((wiInput::BUTTON)'A') || wiInput::Down(wiInput::GAMEPAD_BUTTON_LEFT)) { moveNew += XMVectorSet(-1, 0, 0, 0); }
|
||||
if (wiInput::Down((wiInput::BUTTON)'D') || wiInput::Down(wiInput::GAMEPAD_BUTTON_RIGHT)) { moveNew += XMVectorSet(1, 0, 0, 0); }
|
||||
if (wiInput::Down((wiInput::BUTTON)'W') || wiInput::Down(wiInput::GAMEPAD_BUTTON_UP)) { moveNew += XMVectorSet(0, 0, 1, 0); }
|
||||
if (wiInput::Down((wiInput::BUTTON)'S') || wiInput::Down(wiInput::GAMEPAD_BUTTON_DOWN)) { moveNew += XMVectorSet(0, 0, -1, 0); }
|
||||
if (wiInput::Down((wiInput::BUTTON)'E') || wiInput::Down(wiInput::GAMEPAD_BUTTON_2)) { moveNew += XMVectorSet(0, 1, 0, 0); }
|
||||
if (wiInput::Down((wiInput::BUTTON)'Q') || wiInput::Down(wiInput::GAMEPAD_BUTTON_1)) { moveNew += XMVectorSet(0, -1, 0, 0); }
|
||||
moveNew += XMVector3Normalize(moveNew);
|
||||
}
|
||||
moveNew *= speed;
|
||||
|
||||
move = XMVectorLerp(move, moveNew, 0.18f * clampedDT / 0.0166f); // smooth the movement a bit
|
||||
float moveLength = XMVectorGetX(XMVector3Length(move));
|
||||
|
||||
if (moveLength < 0.0001f)
|
||||
{
|
||||
move = XMVectorSet(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
if (abs(xDif) + abs(yDif) > 0 || moveLength > 0.0001f)
|
||||
{
|
||||
XMMATRIX camRot = XMMatrixRotationQuaternion(XMLoadFloat4(&cameraWnd->camera_transform.rotation_local));
|
||||
XMVECTOR move_rot = XMVector3TransformNormal(move, camRot);
|
||||
XMFLOAT3 _move;
|
||||
XMStoreFloat3(&_move, move_rot);
|
||||
cameraWnd->camera_transform.Translate(_move);
|
||||
cameraWnd->camera_transform.RotateRollPitchYaw(XMFLOAT3(yDif, xDif, 0));
|
||||
camera.SetDirty();
|
||||
}
|
||||
|
||||
cameraWnd->camera_transform.UpdateTransform();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Orbital Camera
|
||||
|
||||
if (wiInput::Down(wiInput::KEYBOARD_BUTTON_LSHIFT))
|
||||
{
|
||||
XMVECTOR V = XMVectorAdd(camera.GetRight() * xDif, camera.GetUp() * yDif) * 10;
|
||||
XMFLOAT3 vec;
|
||||
XMStoreFloat3(&vec, V);
|
||||
cameraWnd->camera_target.Translate(vec);
|
||||
}
|
||||
else if (wiInput::Down(wiInput::KEYBOARD_BUTTON_LCONTROL) || currentMouse.z != 0.0f)
|
||||
{
|
||||
cameraWnd->camera_transform.Translate(XMFLOAT3(0, 0, yDif * 4 + currentMouse.z));
|
||||
cameraWnd->camera_transform.translation_local.z = std::min(0.0f, cameraWnd->camera_transform.translation_local.z);
|
||||
camera.SetDirty();
|
||||
}
|
||||
else if (abs(xDif) + abs(yDif) > 0)
|
||||
{
|
||||
cameraWnd->camera_target.RotateRollPitchYaw(XMFLOAT3(yDif * 2, xDif * 2, 0));
|
||||
camera.SetDirty();
|
||||
}
|
||||
|
||||
cameraWnd->camera_target.UpdateTransform();
|
||||
cameraWnd->camera_transform.UpdateTransform_Parented(cameraWnd->camera_target);
|
||||
}
|
||||
|
||||
if (!wiBackLog::isActive() && !GetGUI().HasFocus())
|
||||
{
|
||||
// Camera control:
|
||||
static XMFLOAT4 originalMouse = XMFLOAT4(0, 0, 0, 0);
|
||||
static bool camControlStart = true;
|
||||
if (camControlStart)
|
||||
{
|
||||
originalMouse = wiInput::GetPointer();
|
||||
}
|
||||
|
||||
XMFLOAT4 currentMouse = wiInput::GetPointer();
|
||||
float xDif = 0, yDif = 0;
|
||||
|
||||
if (wiInput::Down(wiInput::MOUSE_BUTTON_MIDDLE))
|
||||
{
|
||||
camControlStart = false;
|
||||
xDif = currentMouse.x - originalMouse.x;
|
||||
yDif = currentMouse.y - originalMouse.y;
|
||||
xDif = 0.1f*xDif*(1.0f / 60.0f);
|
||||
yDif = 0.1f*yDif*(1.0f / 60.0f);
|
||||
wiInput::SetPointer(originalMouse);
|
||||
wiInput::HidePointer(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
camControlStart = true;
|
||||
wiInput::HidePointer(false);
|
||||
}
|
||||
|
||||
const float buttonrotSpeed = 2.0f / 60.0f;
|
||||
if (wiInput::Down(wiInput::KEYBOARD_BUTTON_LEFT))
|
||||
{
|
||||
xDif -= buttonrotSpeed;
|
||||
}
|
||||
if (wiInput::Down(wiInput::KEYBOARD_BUTTON_RIGHT))
|
||||
{
|
||||
xDif += buttonrotSpeed;
|
||||
}
|
||||
if (wiInput::Down(wiInput::KEYBOARD_BUTTON_UP))
|
||||
{
|
||||
yDif -= buttonrotSpeed;
|
||||
}
|
||||
if (wiInput::Down(wiInput::KEYBOARD_BUTTON_DOWN))
|
||||
{
|
||||
yDif += buttonrotSpeed;
|
||||
}
|
||||
|
||||
const XMFLOAT4 leftStick = wiInput::GetAnalog(wiInput::GAMEPAD_ANALOG_THUMBSTICK_L, 0);
|
||||
const XMFLOAT4 rightStick = wiInput::GetAnalog(wiInput::GAMEPAD_ANALOG_THUMBSTICK_R, 0);
|
||||
const XMFLOAT4 rightTrigger = wiInput::GetAnalog(wiInput::GAMEPAD_ANALOG_TRIGGER_R, 0);
|
||||
|
||||
const float jostickrotspeed = 0.05f;
|
||||
xDif += rightStick.x * jostickrotspeed;
|
||||
yDif += rightStick.y * jostickrotspeed;
|
||||
|
||||
xDif *= cameraWnd->rotationspeedSlider->GetValue();
|
||||
yDif *= cameraWnd->rotationspeedSlider->GetValue();
|
||||
|
||||
|
||||
if (cameraWnd->fpsCheckBox->GetCheck())
|
||||
{
|
||||
// FPS Camera
|
||||
const float clampedDT = min(dt, 0.1f); // if dt > 100 millisec, don't allow the camera to jump too far...
|
||||
|
||||
const float speed = ((wiInput::Down(wiInput::KEYBOARD_BUTTON_LSHIFT) ? 10.0f : 1.0f) + rightTrigger.x * 10.0f) * cameraWnd->movespeedSlider->GetValue() * clampedDT;
|
||||
static XMVECTOR move = XMVectorSet(0, 0, 0, 0);
|
||||
XMVECTOR moveNew = XMVectorSet(leftStick.x, 0, leftStick.y, 0);
|
||||
|
||||
if (!wiInput::Down(wiInput::KEYBOARD_BUTTON_LCONTROL))
|
||||
{
|
||||
// Only move camera if control not pressed
|
||||
if (wiInput::Down((wiInput::BUTTON)'A') || wiInput::Down(wiInput::GAMEPAD_BUTTON_LEFT)) { moveNew += XMVectorSet(-1, 0, 0, 0); }
|
||||
if (wiInput::Down((wiInput::BUTTON)'D') || wiInput::Down(wiInput::GAMEPAD_BUTTON_RIGHT)) { moveNew += XMVectorSet(1, 0, 0, 0); }
|
||||
if (wiInput::Down((wiInput::BUTTON)'W') || wiInput::Down(wiInput::GAMEPAD_BUTTON_UP)) { moveNew += XMVectorSet(0, 0, 1, 0); }
|
||||
if (wiInput::Down((wiInput::BUTTON)'S') || wiInput::Down(wiInput::GAMEPAD_BUTTON_DOWN)) { moveNew += XMVectorSet(0, 0, -1, 0); }
|
||||
if (wiInput::Down((wiInput::BUTTON)'E') || wiInput::Down(wiInput::GAMEPAD_BUTTON_2)) { moveNew += XMVectorSet(0, 1, 0, 0); }
|
||||
if (wiInput::Down((wiInput::BUTTON)'Q') || wiInput::Down(wiInput::GAMEPAD_BUTTON_1)) { moveNew += XMVectorSet(0, -1, 0, 0); }
|
||||
moveNew += XMVector3Normalize(moveNew);
|
||||
}
|
||||
moveNew *= speed;
|
||||
|
||||
move = XMVectorLerp(move, moveNew, 0.18f * clampedDT / 0.0166f); // smooth the movement a bit
|
||||
float moveLength = XMVectorGetX(XMVector3Length(move));
|
||||
|
||||
if (moveLength < 0.0001f)
|
||||
{
|
||||
move = XMVectorSet(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
if (abs(xDif) + abs(yDif) > 0 || moveLength > 0.0001f)
|
||||
{
|
||||
XMMATRIX camRot = XMMatrixRotationQuaternion(XMLoadFloat4(&cameraWnd->camera_transform.rotation_local));
|
||||
XMVECTOR move_rot = XMVector3TransformNormal(move, camRot);
|
||||
XMFLOAT3 _move;
|
||||
XMStoreFloat3(&_move, move_rot);
|
||||
cameraWnd->camera_transform.Translate(_move);
|
||||
cameraWnd->camera_transform.RotateRollPitchYaw(XMFLOAT3(yDif, xDif, 0));
|
||||
camera.SetDirty();
|
||||
}
|
||||
|
||||
cameraWnd->camera_transform.UpdateTransform();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Orbital Camera
|
||||
|
||||
if (wiInput::Down(wiInput::KEYBOARD_BUTTON_LSHIFT))
|
||||
{
|
||||
XMVECTOR V = XMVectorAdd(camera.GetRight() * xDif, camera.GetUp() * yDif) * 10;
|
||||
XMFLOAT3 vec;
|
||||
XMStoreFloat3(&vec, V);
|
||||
cameraWnd->camera_target.Translate(vec);
|
||||
}
|
||||
else if (wiInput::Down(wiInput::KEYBOARD_BUTTON_LCONTROL) || currentMouse.z != 0.0f)
|
||||
{
|
||||
cameraWnd->camera_transform.Translate(XMFLOAT3(0, 0, yDif * 4 + currentMouse.z));
|
||||
cameraWnd->camera_transform.translation_local.z = std::min(0.0f, cameraWnd->camera_transform.translation_local.z);
|
||||
camera.SetDirty();
|
||||
}
|
||||
else if(abs(xDif) + abs(yDif) > 0)
|
||||
{
|
||||
cameraWnd->camera_target.RotateRollPitchYaw(XMFLOAT3(yDif*2, xDif*2, 0));
|
||||
camera.SetDirty();
|
||||
}
|
||||
|
||||
cameraWnd->camera_target.UpdateTransform();
|
||||
cameraWnd->camera_transform.UpdateTransform_Parented(cameraWnd->camera_target);
|
||||
}
|
||||
|
||||
// Begin picking:
|
||||
UINT pickMask = rendererWnd->GetPickType();
|
||||
RAY pickRay = wiRenderer::GetPickRay((long)currentMouse.x, (long)currentMouse.y);
|
||||
|
||||
Reference in New Issue
Block a user