Difference between revisions of "User:DavidJCobb"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>DavidJCobb
imported>DavidJCobb
(And the library is LIVE!)
Line 1: Line 1:
I'm working on a Papyrus library for working with rotations. For now, this is my scratchpad. When the library's complete, I plan on posting it here. Searching for this information was a hellish task, and I'll gladly save others the trouble.
= My work =
;[[User:DavidJCobb/Rotation Library|Rotation library]]
:A library for working with rotations in Skyrim. If you need to position ''and'' rotate one object relative to another, this'd be the code to do that.


= Scratchpad =
= Scratchpad =
Line 7: Line 9:
**It's consistent: if it doesn't work for a file, then it will probably never work for that file (barring massive changes).
**It's consistent: if it doesn't work for a file, then it will probably never work for that file (barring massive changes).
**You can work around this by referencing all functions in the script to be imported as methods, e.g. ''ScriptToBeImported.FunctionName()''.
**You can work around this by referencing all functions in the script to be imported as methods, e.g. ''ScriptToBeImported.FunctionName()''.
== Progress made ==
* My code appears to be able to reliably convert Skyrim Euler rotations to rotation matrices and back again.
** There are edge-cases that need to be identified and fixed. Currently weeding them out one-by-one...
* My code appears to be able to reliably convert rotation matrices to axis-angles and back again.
* My code appears to be able to reliably convert axis-angles to quaternions, and to convert quaternions to rotation matrices.
* ''Thus, I can convert between all four rotation representations without getting ''too'' indirect.''
=== Remaining tasks ===
* Successfully put the library to use.
** Test quaternion conjugation, if necessary. Remove it if it turns out we've no need for it.
** Move my position-and-rotate-relative code from... my own personal project... to the library.
* Post the library here on the wiki, along with a tutorial on how to use it.
** Tutorial idea: a Dibella Statue that sets itself to a random orientation, and then positions (using [[Spatial functions and snippets#Rotation matrix|this code]]) and rotates (using my code) a Dragon Priest mask to cover the statue's face.
*** Step 1: Place a Dibella Statue at 0, 0, 0, unrotated.
*** Step 2: Place and rotate a Dragon Priest Mask as necessary to cover the statue's face.
*** Step 3: Note down the mask's position and rotation.
*** Step 4: Configure some sort of simple example script that I will provide, setting the mask position and rotation as properties.
*** Step 5: Slap the script down on the statue and test it!
== Rotation resources ==
[http://www.vectoralgebra.info/eulermatrix.html This page] generates forumlae to convert from Euler angles (in any convention) to rotation matrices.
[http://www.vectoralgebra.info/axisangle.html This page] and [http://www.vectoralgebra.info/euleranglesvector.html this page] together offer the information needed to convert from Euler angles (in any convention) to an axis-angle representation by way of rotation matrices. The axis you get won't be normalized.
[https://web.archive.org/web/20051124013711/http://skal.planet-d.net/demo/matrixfaq.htm#Q37 This page] describes how to pull right-handed Euler ZYX from a rotation matrix. It's easy to convert the math to left-handed if you use [http://www.vectoralgebra.info/eulermatrix.html the matrix formula generator linked earlier] and if you understand what atan2 does and why.
The process of converting from axis angle to quaternion (and vice versa) is one of the few rotation-related operations that [https://en.wikipedia.org/w/index.php?title=Axis%E2%80%93angle_representation&oldid=608157500#Unit_quaternions Wikipedia explains in plain English]. Ten bucks says a pack of PhDs will eventually come along and rewrite the article into gibberish, so that's a link to an archived version of the article as it existed when I found it.
In another rare instance of clarity, [https://en.wikipedia.org/w/index.php?title=Rotation_matrix&oldid=619323683#Rotation_matrix_from_axis_and_angle Wikipedia describes how to convert from axis-angle back to a rotation matrix]. The article doesn't state whether it's working with extrinsic rotations, or what the handedness of the system is, but it seems to line up with the math at [http://www.vectoralgebra.info/axisangle.html one of the previously-linked pages].
== Converting any Euler sequence to a rotation matrix ==
'''Source:''' https://web.archive.org/web/20110721191940/http://cgafaq.info/wiki/Euler_angles_from_matrix
Corrected (Wikipedia-compatible) versions of that site's LaTeX are as follows:
"Symmetries" equation 1
  P = \begin{bmatrix} 0&1&0\\0&0&1\\1&0&0 \end{bmatrix}
"Symmetries" equation 2
  P = \begin{bmatrix} 0&0&1\\0&1&0\\1&0&0 \end{bmatrix}
"First merger" equation 1
<pre style="white-space:pre-wrap">\begin{align} {\mathrm rot}({\mathbf{xzy}_s},\theta_x,\theta_z,\theta_y) &= {\mathrm rot}(y,\theta_y)\,{\mathrm rot}(z,\theta_z)\,{\mathrm rot}(x,\theta_x) \\ &= \begin{bmatrix} c_y c_z & s_y s_x - c_y s_z c_x & s_y c_x + c_y s_z s_x \\ s_z & c_z c_x & -c_z s_x \\ -s_y c_z & c_y s_x + s_y s_z c_x & c_y c_x - s_y s_z s_x \end{bmatrix} \end{align}</pre>
"First merger" equation 2
<pre style="white-space:pre-wrap">\begin{align} {\mathrm rot}({\mathbf{xzx}_s},\theta_x,\theta_z,\theta_{x'}) &= {\mathrm rot}(x,\theta_{x'})\,{\mathrm rot}(z,\theta_z)\,{\mathrm rot}(x,\theta_x) \\ &= \begin{bmatrix} c_z & -s_z c_x & s_z s_x \\ c_{x'} s_z & c_{x'} c_z c_x - s_{x'} s_x & -s_{x'} c_x - c_{x'} c_z s_x \\ s_{x'} s_z & s_{x'} c_z c_x + c_{x'} s_x & c_{x'} c_x - s_{x'} c_z s_x \end{bmatrix} \end{align}</pre>
"First merger" equation 3
<pre style="white-space:pre-wrap">{\mathrm rot}(z,\theta_z)\,{\mathrm rot}(x,\theta_x) = \begin{bmatrix} c_z & -s_z c_x & s_z s_x \\ s_z & c_z c_x & -c_z s_x \\ 0 & s_x & c_x \end{bmatrix}</pre>

Revision as of 23:59, 23 August 2014

My work

Rotation library
A library for working with rotations in Skyrim. If you need to position and rotate one object relative to another, this'd be the code to do that.

Scratchpad

  • Import is unreliable, and I don't know what makes it break. It works in some cases, but in others, it completely fails to import global functions from the target file.
    • Errors will not be generated when compiling in the Creation Kit. You'll only be able to detect the problem by checking the Papyrus logs, which will contain something like
      Error: Method ImportedFunctionName not found on EntityThatHasAScriptThatImportsStuff. Aborting call and returning None
    • It's consistent: if it doesn't work for a file, then it will probably never work for that file (barring massive changes).
    • You can work around this by referencing all functions in the script to be imported as methods, e.g. ScriptToBeImported.FunctionName().