diff --git a/extensions/community/Quaternions.json b/extensions/community/Quaternions.json new file mode 100644 index 000000000..74180d7c1 --- /dev/null +++ b/extensions/community/Quaternions.json @@ -0,0 +1,731 @@ +{ + "author": "", + "category": "Advanced", + "extensionNamespace": "", + "fullName": "Quaternions", + "gdevelopVersion": "", + "helpPath": "", + "iconUrl": "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAyMy4wLjMsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iSWNvbnMiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Ig0KCSB2aWV3Qm94PSIwIDAgMzIgMzIiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDMyIDMyOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+DQo8cGF0aCBkPSJNMTcuOCw1LjVjMS4yLTAuNywyLjMtMS4zLDMuNS0xLjdDMjQuMywyLjcsMjYuOCwyLjcsMjgsNGMxLDEsMS4yLDIuOSwwLjYsNS40Yy0wLjEsMC41LDAuMiwxLjEsMC43LDEuMg0KCWMwLjUsMC4xLDEuMS0wLjIsMS4yLTAuN2MwLjktMy4yLDAuNS01LjctMS4xLTcuM2MtMS44LTEuOC01LTItOC45LTAuNmMtMS41LDAuNi0zLDEuNC00LjYsMi4zYy0xLjUtMS0zLjEtMS44LTQuNi0yLjMNCgljLTMuOS0xLjUtNy0xLjMtOC45LDAuNkMtMC4xLDUuMiwwLjgsMTAuNCw0LjMsMTZjLTEsMS41LTEuOCwzLjEtMi4zLDQuNm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OC0wLjFjMS4xLDAuNCwyLjMsMSwzLjUsMS43QzEyLjYsNi43LDExLDgsOS41LDkuNXoiLz4NCjwvc3ZnPg0K", + "name": "Quaternions", + "previewIconUrl": "https://asset-resources.gdevelop.io/public-resources/Icons/Glyphster Pack/Master/SVG/Virtual Reality/344b986fa75d79abe56b0ce583ab81b90de003d34196795a564739e33b737b33_Virtual Reality_360_rotate_vr_movement.svg", + "shortDescription": "Allows for 3d rotations without gimble lock and ordering errors of euler rotations.", + "version": "0.1.2", + "description": [ + "Current functions:", + "Euler to Quaternion", + "Quaternion to Euler", + "Quaternion unit/normalisation", + "Quaternion Multiplication", + "Quaternion Inverse", + "", + "Intended functions:", + "", + "Complete implentation of 3d vector math", + "Slerp interperlation", + "Support Direct Var to Var conversion instead of individual Conversion-almost", + "Add Expression versions of each function to use without needing to convert to var.", + "", + "I made this because of a stupid role the ball through the maze game, it worked fine, but I just wanted every single edge case and those ridiculous 45 degree angles." + ], + "origin": { + "identifier": "Quaternions", + "name": "gdevelop-extension-store" + }, + "tags": [ + "Math", + "Quaternions", + "3d" + ], + "authorIds": [ + "lHJ85XZ2cKaqM9XGy99RK1UNWgz2" + ], + "dependencies": [], + "globalVariables": [], + "sceneVariables": [], + "eventsFunctions": [ + { + "description": "Will change x y z rotations from euler to Quaternion and store in a stuct with x y z w (xyzw are not axis look up how quaternions work).\nStructure Variable must have XYZW as children before using event.", + "fullName": "Euler TO Quaternion in variable", + "functionType": "Action", + "group": "EulerTransform", + "name": "Euler_To_Quaternion", + "sentence": "Convert Euler with angles _PARAM1_ _PARAM2_ _PARAM3_ and output in _PARAM4_", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "Quat.W", + "=", + "cos(ToRad(Zaxis)/2) * cos(ToRad(Yaxis)/2) * cos(ToRad(Xaxis)/2)\n + sin(ToRad(Zaxis)/2) * sin(ToRad(Yaxis)/2) * sin(ToRad(Xaxis)/2)\n\n" + ] + }, + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "Quat.X", + "=", + "cos(ToRad(Zaxis)/2) * cos(ToRad(Yaxis)/2) * sin(ToRad(Xaxis)/2)\n - sin(ToRad(Zaxis)/2) * sin(ToRad(Yaxis)/2) * cos(ToRad(Xaxis)/2)" + ] + }, + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "Quat.Y", + "=", + "cos(ToRad(Zaxis)/2) * sin(ToRad(Yaxis)/2) * cos(ToRad(Xaxis)/2)\n + sin(ToRad(Zaxis)/2) * cos(ToRad(Yaxis)/2) * sin(ToRad(Xaxis)/2)" + ] + }, + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "Quat.Z", + "=", + "sin(ToRad(Zaxis)/2) * cos(ToRad(Yaxis)/2) * cos(ToRad(Xaxis)/2)\n - cos(ToRad(Zaxis)/2) * sin(ToRad(Yaxis)/2) * sin(ToRad(Xaxis)/2)" + ] + }, + { + "type": { + "value": "CopyVariableToArgument2" + }, + "parameters": [ + "\"Var\"", + "Quat" + ] + } + ], + "variables": [ + { + "name": "Quat", + "type": "structure", + "children": [ + { + "name": "W", + "type": "number", + "value": 0 + }, + { + "name": "X", + "type": "number", + "value": 0 + }, + { + "name": "Y", + "type": "number", + "value": 0 + }, + { + "name": "Z", + "type": "number", + "value": 0 + } + ] + } + ] + } + ], + "parameters": [ + { + "description": "Rotation on Z axis", + "name": "Zaxis", + "type": "expression" + }, + { + "description": "Rotation on Y axis", + "name": "Yaxis", + "type": "expression" + }, + { + "description": "Rotation on X axis", + "name": "Xaxis", + "type": "expression" + }, + { + "description": "Variable To store Quart. Must be Struct", + "name": "Var", + "type": "variable" + } + ], + "objectGroups": [] + }, + { + "description": "Will change x y z w rotations from Quaternion to Euler and store in a stuct with x y z (xyz are axis this time).\nIMPORTANT:\nStructure variable must have XYZ as children before using event\nAlso almost always only use on normalised vectors.", + "fullName": "Quaternion TO Euler in variable", + "functionType": "Action", + "group": "EulerTransform", + "name": "Quaternion_To_Euler", + "sentence": "Convert quaternion with _PARAM1_ _PARAM2_ _PARAM3_ _PARAM4_ and output Euler in _PARAM5_", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "Euler.Z", + "=", + "ToDeg(atan2(2*(WQuat*XQuat + YQuat*ZQuat), 1 - 2*(XQuat*XQuat + YQuat*YQuat)))\n" + ] + }, + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "Euler.Y", + "=", + "ToDeg(asin(2*(WQuat*YQuat - ZQuat*XQuat)))\n" + ] + }, + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "Euler.X", + "=", + "ToDeg(atan2(2*(WQuat*ZQuat + XQuat*YQuat), 1 - 2*(YQuat*YQuat + ZQuat*ZQuat)))" + ] + }, + { + "type": { + "value": "CopyVariableToArgument2" + }, + "parameters": [ + "\"Var\"", + "Euler" + ] + } + ], + "variables": [ + { + "name": "Euler", + "type": "structure", + "children": [ + { + "name": "X", + "type": "number", + "value": 0 + }, + { + "name": "Y", + "type": "number", + "value": 0 + }, + { + "name": "Z", + "type": "number", + "value": 0 + } + ] + } + ] + } + ], + "parameters": [ + { + "description": "Quaternion value of Z", + "name": "ZQuat", + "type": "expression" + }, + { + "description": "Quaternion value of Y", + "name": "YQuat", + "type": "expression" + }, + { + "description": "Quaternion value of X", + "name": "XQuat", + "type": "expression" + }, + { + "description": "Quaternion value of W", + "name": "WQuat", + "type": "expression" + }, + { + "description": "Variable To store Euler. Must be Struct", + "name": "Var", + "type": "variable" + } + ], + "objectGroups": [] + }, + { + "description": "Will change the X Y Z W values of a Quaternion so that it's magnitude becomes 1.\nEssential to convert back and forth from Euler to Quaternion.\nNew Variable must be a Struct with X Y Z W as children.", + "fullName": "Normalise Quaternion", + "functionType": "Action", + "group": "Quaternion Multiplication", + "name": "Normalise_Quaternion", + "sentence": "Normalise Quaternion with _PARAM1_ _PARAM2_ _PARAM3_ _PARAM4_ and output in _PARAM5_", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "Quat.X", + "=", + "XQuat / sqrt(XQuat*XQuat + YQuat*YQuat + ZQuat*ZQuat + WQuat*WQuat)\n" + ] + }, + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "Quat.Y", + "=", + "YQuat / sqrt(XQuat*XQuat + YQuat*YQuat + ZQuat*ZQuat + WQuat*WQuat)\n" + ] + }, + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "Quat.Z", + "=", + "ZQuat / sqrt(XQuat*XQuat + YQuat*YQuat + ZQuat*ZQuat + WQuat*WQuat)\n" + ] + }, + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "Quat.W", + "=", + "WQuat / sqrt(XQuat*XQuat + YQuat*YQuat + ZQuat*ZQuat + WQuat*WQuat)\n" + ] + }, + { + "type": { + "value": "CopyVariableToArgument2" + }, + "parameters": [ + "\"Var\"", + "Quat" + ] + } + ], + "variables": [ + { + "name": "Quat", + "type": "structure", + "children": [ + { + "name": "W", + "type": "number", + "value": 0 + }, + { + "name": "X", + "type": "number", + "value": 0 + }, + { + "name": "Y", + "type": "number", + "value": 0 + }, + { + "name": "Z", + "type": "number", + "value": 0 + } + ] + } + ] + } + ], + "parameters": [ + { + "description": "Quaternion value of Z", + "name": "ZQuat", + "type": "expression" + }, + { + "description": "Quaternion value of Y", + "name": "YQuat", + "type": "expression" + }, + { + "description": "Quaternion value of X", + "name": "XQuat", + "type": "expression" + }, + { + "description": "Quaternion value of W", + "name": "WQuat", + "type": "expression" + }, + { + "description": "Variable To store Quaternion. Must be Struct", + "name": "Var", + "type": "variable" + } + ], + "objectGroups": [] + }, + { + "description": "Will multiply 1 Quaternion by another Quaternion and store it in a variable.\nThe first two variables will be multiplied.\nIMPORTANT this is not regular multiplication and Q1*Q2 will NOT equal Q2*Q1. Be careful with order.\nLast variable is the output.\nAll variables used should be struct with W X Y Z.", + "fullName": "Multiply Quaternion 1 by Quaternion 2", + "functionType": "Action", + "group": "Quaternion Multiplication", + "name": "Quaternion_Multiply", + "sentence": "Multiply _PARAM1_ by _PARAM2_ and output in _PARAM3_", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "CopyArgumentToVariable2" + }, + "parameters": [ + "\"Quaternion1\"", + "Quat1" + ] + }, + { + "type": { + "value": "CopyArgumentToVariable2" + }, + "parameters": [ + "\"Quaternion2\"", + "Quat2" + ] + }, + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "OutputQuat.W", + "=", + "Quat1.W * Quat2.W - Quat1.X * Quat2.X - Quat1.Y * Quat2.Y - Quat1.Z * Quat2.Z" + ] + }, + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "OutputQuat.X", + "=", + "Quat1.W * Quat2.X + Quat1.X * Quat2.W + Quat1.Y * Quat2.Z - Quat1.Z * Quat2.Y" + ] + }, + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "OutputQuat.Y", + "=", + "Quat1.W * Quat2.Y - Quat1.X * Quat2.Z + Quat1.Y * Quat2.W + Quat1.Z * Quat2.X" + ] + }, + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "OutputQuat.Z", + "=", + "Quat1.W * Quat2.Z + Quat1.X * Quat2.Y - Quat1.Y * Quat2.X + Quat1.Z * Quat2.W" + ] + }, + { + "type": { + "value": "CopyVariableToArgument2" + }, + "parameters": [ + "\"Output\"", + "OutputQuat" + ] + } + ], + "variables": [ + { + "name": "Quat1", + "type": "structure", + "children": [ + { + "name": "W", + "type": "number", + "value": 0 + }, + { + "name": "X", + "type": "number", + "value": 0 + }, + { + "name": "Y", + "type": "number", + "value": 0 + }, + { + "name": "Z", + "type": "number", + "value": 0 + } + ] + }, + { + "name": "Quat2", + "type": "structure", + "children": [ + { + "name": "W", + "type": "number", + "value": 0 + }, + { + "name": "X", + "type": "number", + "value": 0 + }, + { + "name": "Y", + "type": "number", + "value": 0 + }, + { + "name": "Z", + "type": "number", + "value": 0 + } + ] + }, + { + "name": "OutputQuat", + "type": "structure", + "children": [ + { + "name": "W", + "type": "number", + "value": 0 + }, + { + "name": "X", + "type": "number", + "value": 0 + }, + { + "name": "Y", + "type": "number", + "value": 0 + }, + { + "name": "Z", + "type": "number", + "value": 0 + } + ] + } + ] + } + ], + "parameters": [ + { + "description": "Quaternion 1", + "name": "Quaternion1", + "type": "variable" + }, + { + "description": "Quaternion 2", + "name": "Quaternion2", + "type": "variable" + }, + { + "description": "Output Quaternion", + "name": "Output", + "type": "variable" + } + ], + "objectGroups": [] + }, + { + "description": "Inverse the Quaternion. Q -> Q^-1\nNot entirely sure what this is used for but added it any way...\n\nAgain joking, it can be used to reverse a quaternion rotation.\n\nBoth Var must be struct with children W X Y Z.", + "fullName": "Quaternion Inverse", + "functionType": "Action", + "group": "Quaternion Multiplication", + "name": "Quaternion_inverse", + "sentence": "Get the inverse of _PARAM1_ and output in _PARAM2_", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "CopyArgumentToVariable2" + }, + "parameters": [ + "\"QuatIn\"", + "QuatInput" + ] + }, + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "NormSq", + "=", + "QuatInput.W*QuatInput.W + QuatInput.X*QuatInput.X + QuatInput.Y*QuatInput.Y + QuatInput.Z*QuatInput.Z" + ] + }, + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "QuatOut.W", + "=", + "QuatInput.W / NormSq" + ] + }, + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "QuatOut.X", + "=", + "-QuatInput.X / NormSq" + ] + }, + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "QuatOut.Y", + "=", + "-QuatInput.Y / NormSq" + ] + }, + { + "type": { + "value": "SetNumberVariable" + }, + "parameters": [ + "QuatOut.Z", + "=", + "-QuatInput.Z / NormSq" + ] + }, + { + "type": { + "value": "CopyVariableToArgument2" + }, + "parameters": [ + "\"OutputQuat\"", + "QuatOut" + ] + } + ], + "variables": [ + { + "folded": true, + "name": "QuatInput", + "type": "structure", + "children": [ + { + "name": "W", + "type": "number", + "value": 0 + }, + { + "name": "X", + "type": "number", + "value": 0 + }, + { + "name": "Y", + "type": "number", + "value": 0 + }, + { + "name": "Z", + "type": "number", + "value": 0 + } + ] + }, + { + "folded": true, + "name": "QuatOut", + "type": "structure", + "children": [ + { + "name": "W", + "type": "number", + "value": 0 + }, + { + "name": "X", + "type": "number", + "value": 0 + }, + { + "name": "Y", + "type": "number", + "value": 0 + }, + { + "name": "Z", + "type": "number", + "value": 0 + } + ] + }, + { + "name": "NormSq", + "type": "number", + "value": 0 + } + ] + } + ], + "parameters": [ + { + "description": "Input Quaternion", + "name": "QuatIn", + "type": "variable" + }, + { + "description": "Output Quaternion", + "name": "OutputQuat", + "type": "variable" + } + ], + "objectGroups": [] + } + ], + "eventsBasedBehaviors": [], + "eventsBasedObjects": [] +} \ No newline at end of file