Code-Cleanup: All samples now use the camera class and it's matrices
Cleaned up base class
This commit is contained in:
parent
27d5abc038
commit
ab38f8b150
42 changed files with 234 additions and 396 deletions
|
|
@ -42,6 +42,8 @@ private:
|
|||
matrices.view = transM * rotM;
|
||||
}
|
||||
|
||||
viewPos = glm::vec4(position, 0.0f) * glm::vec4(-1.0f, 1.0f, -1.0f, 1.0f);
|
||||
|
||||
updated = true;
|
||||
};
|
||||
public:
|
||||
|
|
@ -50,6 +52,7 @@ public:
|
|||
|
||||
glm::vec3 rotation = glm::vec3();
|
||||
glm::vec3 position = glm::vec3();
|
||||
glm::vec4 viewPos = glm::vec4();
|
||||
|
||||
float rotationSpeed = 1.0f;
|
||||
float movementSpeed = 1.0f;
|
||||
|
|
@ -113,7 +116,7 @@ public:
|
|||
{
|
||||
this->rotation = rotation;
|
||||
updateViewMatrix();
|
||||
};
|
||||
}
|
||||
|
||||
void rotate(glm::vec3 delta)
|
||||
{
|
||||
|
|
@ -133,6 +136,16 @@ public:
|
|||
updateViewMatrix();
|
||||
}
|
||||
|
||||
void setRotationSpeed(float rotationSpeed)
|
||||
{
|
||||
this->rotationSpeed = rotationSpeed;
|
||||
}
|
||||
|
||||
void setMovementSpeed(float movementSpeed)
|
||||
{
|
||||
this->movementSpeed = movementSpeed;
|
||||
}
|
||||
|
||||
void update(float deltaTime)
|
||||
{
|
||||
updated = false;
|
||||
|
|
|
|||
|
|
@ -336,20 +336,18 @@ void VulkanExampleBase::renderLoop()
|
|||
// Rotate
|
||||
if (std::abs(gamePadState.axisLeft.x) > deadZone)
|
||||
{
|
||||
rotation.y += gamePadState.axisLeft.x * 0.5f * rotationSpeed;
|
||||
camera.rotate(glm::vec3(0.0f, gamePadState.axisLeft.x * 0.5f, 0.0f));
|
||||
updateView = true;
|
||||
}
|
||||
if (std::abs(gamePadState.axisLeft.y) > deadZone)
|
||||
{
|
||||
rotation.x -= gamePadState.axisLeft.y * 0.5f * rotationSpeed;
|
||||
camera.rotate(glm::vec3(gamePadState.axisLeft.y * 0.5f, 0.0f, 0.0f));
|
||||
updateView = true;
|
||||
}
|
||||
// Zoom
|
||||
if (std::abs(gamePadState.axisRight.y) > deadZone)
|
||||
{
|
||||
zoom -= gamePadState.axisRight.y * 0.01f * zoomSpeed;
|
||||
camera.translate(glm::vec3(0.0f, 0.0f, gamePadState.axisRight.y * 0.01f));
|
||||
updateView = true;
|
||||
}
|
||||
if (updateView)
|
||||
|
|
@ -1180,8 +1178,7 @@ void VulkanExampleBase::handleMessages(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR
|
|||
case WM_MOUSEWHEEL:
|
||||
{
|
||||
short wheelDelta = GET_WHEEL_DELTA_WPARAM(wParam);
|
||||
zoom += (float)wheelDelta * 0.005f * zoomSpeed;
|
||||
camera.translate(glm::vec3(0.0f, 0.0f, (float)wheelDelta * 0.005f * zoomSpeed));
|
||||
camera.translate(glm::vec3(0.0f, 0.0f, (float)wheelDelta * 0.005f));
|
||||
viewUpdated = true;
|
||||
break;
|
||||
}
|
||||
|
|
@ -1292,15 +1289,12 @@ int32_t VulkanExampleBase::handleAppInput(struct android_app* app, AInputEvent*
|
|||
int32_t eventX = AMotionEvent_getX(event, 0);
|
||||
int32_t eventY = AMotionEvent_getY(event, 0);
|
||||
|
||||
float deltaX = (float)(vulkanExample->touchPos.y - eventY) * vulkanExample->rotationSpeed * 0.5f;
|
||||
float deltaY = (float)(vulkanExample->touchPos.x - eventX) * vulkanExample->rotationSpeed * 0.5f;
|
||||
float deltaX = (float)(vulkanExample->touchPos.y - eventY) * vulkanExample->camera.rotationSpeed * 0.5f;
|
||||
float deltaY = (float)(vulkanExample->touchPos.x - eventX) * vulkanExample->camera.rotationSpeed * 0.5f;
|
||||
|
||||
vulkanExample->camera.rotate(glm::vec3(deltaX, 0.0f, 0.0f));
|
||||
vulkanExample->camera.rotate(glm::vec3(0.0f, -deltaY, 0.0f));
|
||||
|
||||
vulkanExample->rotation.x += deltaX;
|
||||
vulkanExample->rotation.y -= deltaY;
|
||||
|
||||
vulkanExample->viewChanged();
|
||||
|
||||
vulkanExample->touchPos.x = eventX;
|
||||
|
|
@ -1494,8 +1488,7 @@ void VulkanExampleBase::pointerAxis(wl_pointer *pointer, uint32_t time,
|
|||
switch (axis)
|
||||
{
|
||||
case REL_X:
|
||||
zoom += d * 0.005f * zoomSpeed;
|
||||
camera.translate(glm::vec3(0.0f, 0.0f, d * 0.005f * zoomSpeed));
|
||||
camera.translate(glm::vec3(0.0f, 0.0f, d * 0.005f));
|
||||
viewUpdated = true;
|
||||
break;
|
||||
default:
|
||||
|
|
@ -2184,19 +2177,14 @@ void VulkanExampleBase::handleMouseMove(int32_t x, int32_t y)
|
|||
}
|
||||
|
||||
if (mouseButtons.left) {
|
||||
rotation.x += dy * 1.25f * rotationSpeed;
|
||||
rotation.y -= dx * 1.25f * rotationSpeed;
|
||||
camera.rotate(glm::vec3(dy * camera.rotationSpeed, -dx * camera.rotationSpeed, 0.0f));
|
||||
viewUpdated = true;
|
||||
}
|
||||
if (mouseButtons.right) {
|
||||
zoom += dy * .005f * zoomSpeed;
|
||||
camera.translate(glm::vec3(-0.0f, 0.0f, dy * .005f * zoomSpeed));
|
||||
camera.translate(glm::vec3(-0.0f, 0.0f, dy * .005f));
|
||||
viewUpdated = true;
|
||||
}
|
||||
if (mouseButtons.middle) {
|
||||
cameraPos.x -= dx * 0.01f;
|
||||
cameraPos.y -= dy * 0.01f;
|
||||
camera.translate(glm::vec3(-dx * 0.01f, -dy * 0.01f, 0.0f));
|
||||
viewUpdated = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -160,8 +160,6 @@ public:
|
|||
|
||||
VkClearColorValue defaultClearColor = { { 0.025f, 0.025f, 0.025f, 1.0f } };
|
||||
|
||||
float zoom = 0;
|
||||
|
||||
static std::vector<const char*> args;
|
||||
|
||||
// Defines a frame rate independent timer value clamped from -1.0...1.0
|
||||
|
|
@ -169,18 +167,9 @@ public:
|
|||
float timer = 0.0f;
|
||||
// Multiplier for speeding up (or slowing down) the global timer
|
||||
float timerSpeed = 0.25f;
|
||||
|
||||
bool paused = false;
|
||||
|
||||
// Use to adjust mouse rotation speed
|
||||
float rotationSpeed = 1.0f;
|
||||
// Use to adjust mouse zoom speed
|
||||
float zoomSpeed = 1.0f;
|
||||
|
||||
Camera camera;
|
||||
|
||||
glm::vec3 rotation = glm::vec3();
|
||||
glm::vec3 cameraPos = glm::vec3();
|
||||
glm::vec2 mousePos;
|
||||
|
||||
std::string title = "Vulkan Example";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue