.. Copyright (c) 2018-2024 William Emerison Six Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Rotation Fix Attempt 1 - Demo 08 ================================ Purpose ^^^^^^^ Fix the rotation problem from the previous demo in a seemingly intuitive way, but do it inelegantly. .. figure:: static/screenshots/demo08.png :align: center :alt: Demo 08 :figclass: align-center Demo 08 How to Execute ^^^^^^^^^^^^^^ On Linux or on MacOS, in a shell, type "python src/demo08/demo.py". On Windows, in a command prompt, type "python src\\demo08\\demo.py". Move the Paddles using the Keyboard ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ============== ================================ Keyboard Input Action ============== ================================ *w* Move Left Paddle Up *s* Move Left Paddle Down *k* Move Right Paddle Down *i* Move Right Paddle Up *d* Increase Left Paddle's Rotation *a* Decrease Left Paddle's Rotation *l* Increase Right Paddle's Rotation *j* Decrease Right Paddle's Rotation ============== ================================ Description ^^^^^^^^^^^ The problem in the last demo is that all rotations happen relative to World Space's (0,0) and axes. By translating our paddles to their position before rotating, they are rotated around World Space's origin, instead of being rotated around their modelspace's center. In this demo, we try to solve the problem by making a method to rotate around a given point in world space, in this case, the paddle's center. .. literalinclude:: ../src/demo08/demo.py :language: python :start-after: doc-region-begin 246327053a816d12360c1ce2d0496b8f157dcc92 :end-before: doc-region-end 246327053a816d12360c1ce2d0496b8f157dcc92 .. literalinclude:: ../src/demo08/demo.py :language: python :start-after: doc-region-begin 05f63ffd44373fab8d1d8bed3c4142660ae7d5c5 :end-before: doc-region-end 05f63ffd44373fab8d1d8bed3c4142660ae7d5c5 Within the event loop, this seems quite reasonable .. literalinclude:: ../src/demo08/demo.py :language: python :start-after: doc-region-begin 67ffd7b7adc42d01ca93bacdef858c0d4b678e38 :end-before: doc-region-end 67ffd7b7adc42d01ca93bacdef858c0d4b678e38 .. literalinclude:: ../src/demo08/demo.py :language: python :start-after: doc-region-begin b641b94ccea0c4270f96da2c06387477a7874816 :end-before: doc-region-end b641b94ccea0c4270f96da2c06387477a7874816 .. literalinclude:: ../src/demo08/demo.py :language: python :start-after: doc-region-begin ab2869a1b31bb2af60dadacfe48ea9b6f01f87f7 :end-before: doc-region-end ab2869a1b31bb2af60dadacfe48ea9b6f01f87f7 All we did was add a rotate around method, and call it, with the paddle's center as the rotate point. .. figure:: static/rotate-sloppy-forwards.gif :align: center :alt: :figclass: align-center Works but sloppy Although this works for now and looks like decent code, this is extremely sloppy, and not thought out well at all. We apply a transformation from paddle space to world space, then do the inverse, then rotate, and then do the first transformation from paddle space to world space again. The images of the transformation sequence below should show how brain-dead it is, and the Cayley graph is gross. But from this we will learn something important. .. figure:: static/rotate-sloppy-forwards-3.png :align: center :alt: Demo 08 :figclass: align-center translating back to the origin .. figure:: static/rotate-sloppy-forwards-4.png :align: center :alt: Demo 08 :figclass: align-center resetting the coordinate system .. figure:: static/rotate-sloppy-forwards-5.png :align: center :alt: Demo 08 :figclass: align-center rotating .. figure:: static/rotate-sloppy-forwards-6.png :align: center :alt: Demo 08 :figclass: align-center resetting the coordinate system .. figure:: static/rotate-sloppy-forwards-7.png :align: center :alt: Demo 08 :figclass: align-center and them translating them back to the paddle space origin .. figure:: static/rotate-sloppy-forwards-8.png :align: center :alt: Demo 08 :figclass: align-center Cayley Graph ^^^^^^^^^^^^ Note, this is gross, and the edge from the paddlespace to itself doesn't even make any sense, but the author did not know how else to represent this code. .. figure:: static/demo08.png :align: center :alt: Demo 08 :figclass: align-center