Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with the orbit rotation #4

Open
DavidLastra8 opened this issue Oct 30, 2024 · 2 comments
Open

Problems with the orbit rotation #4

DavidLastra8 opened this issue Oct 30, 2024 · 2 comments

Comments

@DavidLastra8
Copy link

Hello teacher! I have a problem with the orbit rotation of our engine, I tried to make it, but when i compile the engine, when I press Alt and the left button of the mouse, the camera doesn't rotate, I belive that the problem is in those two fragments of code, can you take a look and see if you can find the error?

Thanks,

David :D

if (button == SDL_BUTTON_LEFT) {
if (leftMousePressed) {
// Guarda la posición del ratón al hacer clic
lastMousePosition = ivec2(x, y);
glm::vec2 mouseScreenPos = getMousePosition();
glm::mat4 projection = glm::perspective(glm::radians(45.0f), (float)WINDOW_SIZE.x / WINDOW_SIZE.y, 0.1f, 100.0f);
glm::mat4 view = camera.view();
selectedObject = raycastFromMouseToGameObject(mouseScreenPos.x, mouseScreenPos.y, projection, view, WINDOW_SIZE);
// Establece el objetivo de la órbita
if (selectedObject != nullptr) {
target = selectedObject->transform().pos();
}
else {
target = glm::vec3(0, 0, 0);
}
}
else {
leftMousePressed = false;
}
}

if (leftMousePressed) {
if (leftMousePressed && state[SDL_SCANCODE_LALT]) {
glm::vec2 mouseScreenPos = getMousePosition();
ivec2 delta = ivec2(mouseScreenPos) - lastMousePosition; // calcula el cambio
lastMousePosition = ivec2(mouseScreenPos); // actualiza la última posición del ratón
orbitCamera(target, delta.x, delta.y); // llama a la función de órbita
}
}

@pepcots
Copy link
Member

pepcots commented Oct 31, 2024

Hello @DavidLastra8 ! You have to tag me if you want me to react quickly ;)
Is it working now?

@DavidLastra8
Copy link
Author

Yes, I managed to make it work after a while

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants