Difference between revisions of "User:DavidJCobb/Rotation Library"
Jump to navigation
Jump to search
Major fixes
imported>DavidJCobb m |
imported>DavidJCobb (Major fixes) |
||
Line 8: | Line 8: | ||
== Changelog == | == Changelog == | ||
;5/5/2015 | |||
:Fixed a severe bug stemming from an incorrect attempt at simplifying Chesko's code. The relevant changes may also yield minor performance improvements. | |||
;2/11/2015 | ;2/11/2015 | ||
:Updated it based on my private copy. Fewer cross-script function calls. More options for using the library. Should work and be backward-compatible, if I pasted the right stuff into the right places. | :Updated it based on my private copy. Fewer cross-script function calls. More options for using the library. Should work and be backward-compatible, if I pasted the right stuff into the right places. | ||
Line 348: | Line 350: | ||
qOut[2] = v[2] | qOut[2] = v[2] | ||
return qOut | return qOut | ||
EndFunction | |||
Float[] Function MatrixMultiplyByColumn(Float[] amMatrix, Float[] avColumn) Global | |||
{Multiplies a matrix by a column vector, and returns the resulting column vector.} | |||
Float[] vResult = new Float[3] | |||
vResult[0] = amMatrix[0]*avColumn[0] + amMatrix[1]*avColumn[1] + amMatrix[2]*avColumn[2] | |||
vResult[1] = amMatrix[3]*avColumn[0] + amMatrix[4]*avColumn[1] + amMatrix[5]*avColumn[2] | |||
vResult[2] = amMatrix[6]*avColumn[0] + amMatrix[7]*avColumn[1] + amMatrix[8]*avColumn[2] | |||
Return vResult | |||
EndFunction | EndFunction | ||
Line 353: | Line 364: | ||
{Given two sets of positions and rotations -- those of a parent object, and those of a child object relative to the parent -- this function returns an array of the form [XPos, YPos, ZPos, XAng, YAng, ZAng]. These are the positions and rotations of the child object relative to the world. In other words, this function exists as an alternative to MoveObjectRelativeToObject, allowing you to move objects however you wish. | {Given two sets of positions and rotations -- those of a parent object, and those of a child object relative to the parent -- this function returns an array of the form [XPos, YPos, ZPos, XAng, YAng, ZAng]. These are the positions and rotations of the child object relative to the world. In other words, this function exists as an alternative to MoveObjectRelativeToObject, allowing you to move objects however you wish. | ||
Position code | Position code was inspired by GetPosXYZRotateAroundRef, a function authored by Chesko that can be found on the Creation Kit wiki.} | ||
; | |||
; CONSTRUCT POSITION. | |||
; | ; | ||
; | ; Child world position = parent rotation as matrix * child parent-relative position | ||
; | ; | ||
Float[] fOutput = new Float[6] | Float[] fOutput = new Float[6] | ||
Float[] fVector = new Float[3] | Float[] fVector = new Float[3] | ||
Float[] mParentRotation = EulerToMatrix(afParentRotation[0], afParentRotation[1], afParentRotation[2]) | |||
Float[] vChildPosition = MatrixMultiplyByColumn(mParentRotation, afOffsetPosition) | |||
vChildPosition[0] = vChildPosition[0] + afParentPosition[0] | |||
vChildPosition[1] = vChildPosition[1] + afParentPosition[1] | |||
vChildPosition[2] = vChildPosition[2] + afParentPosition[2] | |||
fOutput[0] = vChildPosition[0] | |||
fOutput[1] = vChildPosition[1] | |||
fOutput[2] = vChildPosition[2] | |||
fOutput[0] = | |||
fOutput[1] = | |||
fOutput[2] = | |||
; | ; | ||
; CONSTRUCT ROTATION USING THIS LIBRARY: | ; CONSTRUCT ROTATION USING THIS LIBRARY: |