-
Notifications
You must be signed in to change notification settings - Fork 4
Mouse events, Finish events in general #6
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
Open
saveman71
wants to merge
12
commits into
master
Choose a base branch
from
finish-events
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
28561c7
Remove Mouse.cpp, make Mouse.h virtual
saveman71 5d90cc8
Use an undordered_map for performance
saveman71 58d1020
Remove Mouse.cpp, make Mouse.h virtual
saveman71 02bb003
Use an undordered_map for performance
saveman71 861b816
Mouse_SFML impl. Handle all events in Window_SFML
saveman71 2208f81
Better (idk) access to event providers
saveman71 c1b8c28
Merge branch 'master' into finish-events
Quentin01 88122f5
Bind mouse for rotating the camera
Quentin01 e753e50
Merge branch 'master' into finish-events
Nokitoo d9b18f2
Merge branch 'master' into finish-events
saveman71 15b0ab2
Better mouse movements
saveman71 7bc7335
Better event type equivalence
saveman71 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| #include "MiniEngine/D3D12/D3D12RenderSystem.h" | ||
| #include "MiniEngine/D3D12/D3D12RenderWindow.h" | ||
|
|
||
| MainApplication::MainApplication(const std::string &windowType, HINSTANCE hInstance) : MiniEngine::Application(), _window(nullptr) | ||
| MainApplication::MainApplication(const std::string &windowType, HINSTANCE hInstance) : MiniEngine::Application(), _window(nullptr), _hasFocus(true) | ||
| { | ||
| float clearColor[4] = { 0.2f, 0.2f, 0.2f, 0.0f }; | ||
|
|
||
|
|
@@ -49,6 +49,9 @@ MainApplication::MainApplication(const std::string &windowType, HINSTANCE hInsta | |
| _node = _sceneManager->getRootNode()->createChild(_root->getRenderSystem()->loadModel("./Assets/models/teapot.txt")); | ||
| } | ||
| } | ||
|
|
||
| _window->getMouse()->setPosition({(int)(_window->getWidth() / 2), (int)(_window->getHeight() / 2) }, *_window); | ||
| _window->setMouseCursorVisible(false); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -100,28 +103,43 @@ bool MainApplication::update(MiniEngine::Time elapsedTime) | |
| return (false); | ||
|
|
||
| float elapsedSeconds = elapsedTime.getSeconds(); | ||
| static Vector2f windowSize = Vector2f(_window->getWidth(), _window->getHeight()); | ||
| static Vector2f lastPos = _window->getMouse()->getPosition(*_window); | ||
|
|
||
| if (_hasFocus) { | ||
| Vector2f mousePos = _window->getMouse()->getPosition(*_window); | ||
| Vector2f deltaPos = mousePos - lastPos; | ||
| if (lastPos != mousePos) | ||
| { | ||
| lastPos = mousePos; | ||
|
|
||
| if (_window->isKeyPressed(Keyboard::Left)) | ||
| _camera->rotate(100 * elapsedSeconds, Vector3f(0, 1, 0), MiniEngine::TS_WORLD); | ||
| if (_window->isKeyPressed(Keyboard::Right)) | ||
| _camera->rotate(100 * elapsedSeconds, Vector3f(0, -1, 0), MiniEngine::TS_WORLD); | ||
| if (_window->isKeyPressed(Keyboard::Up)) | ||
| _camera->rotate(100 * elapsedSeconds, Vector3f(1, 0, 0), MiniEngine::TS_LOCAL); | ||
| if (_window->isKeyPressed(Keyboard::Down)) | ||
| _camera->rotate(100 * elapsedSeconds, Vector3f(-1, 0, 0), MiniEngine::TS_LOCAL); | ||
| _camera->rotate(15 * elapsedSeconds * -deltaPos.x, Vector3f(0, 1, 0), MiniEngine::TS_WORLD); | ||
| _camera->rotate(15 * elapsedSeconds * -deltaPos.y, Vector3f(1, 0, 0), MiniEngine::TS_LOCAL); | ||
|
|
||
| if (_window->isKeyPressed(Keyboard::Z)) | ||
| if (lastPos.x < windowSize.x * 0.05 || lastPos.x > windowSize.x * 0.95 | ||
| || lastPos.y < windowSize.y * 0.05 || lastPos.y > windowSize.y * 0.95) | ||
| { | ||
| Vector2f middle = Vector2f(windowSize.x / 2, windowSize.y / 2); | ||
| _window->setMouseCursorVisible(true); | ||
| _window->getMouse()->setPosition(middle, *_window); | ||
| _window->setMouseCursorVisible(false); | ||
| lastPos = middle; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (_window->getKeyboard()->isKeyPressed(Keyboard::Z)) | ||
| _camera->translate(Vector3f(0, 0, -100 * elapsedSeconds), MiniEngine::TS_LOCAL); | ||
| if (_window->isKeyPressed(Keyboard::S)) | ||
| if (_window->getKeyboard()->isKeyPressed(Keyboard::S)) | ||
| _camera->translate(Vector3f(0, 0, 100 * elapsedSeconds), MiniEngine::TS_LOCAL); | ||
| if (_window->isKeyPressed(Keyboard::Q)) | ||
| if (_window->getKeyboard()->isKeyPressed(Keyboard::Q)) | ||
| _camera->translate(Vector3f(-100 * elapsedSeconds, 0, 0), MiniEngine::TS_LOCAL); | ||
| if (_window->isKeyPressed(Keyboard::D)) | ||
| if (_window->getKeyboard()->isKeyPressed(Keyboard::D)) | ||
| _camera->translate(Vector3f(100 * elapsedSeconds, 0, 0), MiniEngine::TS_LOCAL); | ||
|
|
||
| if (_window->isKeyPressed(Keyboard::Space)) | ||
| if (_window->getKeyboard()->isKeyPressed(Keyboard::Space)) | ||
| _camera->translate(Vector3f(0, 100 * elapsedSeconds, 0), MiniEngine::TS_WORLD); | ||
| if (_window->isKeyPressed(Keyboard::LShift)) | ||
| if (_window->getKeyboard()->isKeyPressed(Keyboard::LShift)) | ||
| _camera->translate(Vector3f(0, -100 * elapsedSeconds, 0), MiniEngine::TS_WORLD); | ||
|
|
||
| Event event; | ||
|
|
@@ -135,13 +153,26 @@ bool MainApplication::update(MiniEngine::Time elapsedTime) | |
| _window->destroy(); | ||
| return (false); | ||
| } | ||
| else if (event.key.code == Keyboard::LAlt && _hasFocus) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as _hasFocus |
||
| { | ||
| _window->setMouseCursorVisible(true); | ||
| _hasFocus = false; | ||
| } | ||
| } | ||
|
|
||
| if (event.type == Event::Closed) | ||
| { | ||
| _window->destroy(); | ||
| return (false); | ||
| } | ||
|
|
||
| if (event.type == Event::MouseButtonPressed && !_hasFocus) | ||
| { | ||
| _window->setMouseCursorVisible(false); | ||
| _hasFocus = true; | ||
| Vector2f middle((int)(_window->getWidth() / 2), (int)(_window->getHeight() / 2)); | ||
| _window->getMouse()->setPosition(middle, *_window); | ||
| } | ||
| } | ||
|
|
||
| return (true); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -130,6 +130,14 @@ Matrix4f &SceneNode::getTransformationMatrix() | |
| return (_transform); | ||
| } | ||
|
|
||
| void SceneNode::setRotationMatrix(Matrix3f &m) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a TransformSpace? |
||
| { | ||
| Quatf q = Quatf::fromMatrix(m); | ||
| q.normalize(); | ||
|
|
||
| _rotation = q; | ||
| } | ||
|
|
||
| void MiniEngine::SceneNode::rotate(float w, Vector3f const &v, TransformSpace space) | ||
| { | ||
| Quatf q = Quatf::fromAxisRot(v, w); | ||
|
|
||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why _hasFocus is here? It's better to have a method in Window for that, don't you think?