Created
March 15, 2017 17:16
-
-
Save chrisdukey/73ca8211c33f305981cd7000a6b2c62d to your computer and use it in GitHub Desktop.
This file contains 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
function getMatrix4FromStreamedMatrix(streamedMatrix){ | |
var finalMatrix = new THREE.Matrix4() | |
var divisor = 1 | |
var Rot1X = streamedMatrix[0]; | |
var Rot1Y = streamedMatrix[1] ; | |
var Rot1Z = streamedMatrix[2] ; | |
var Rot2X = streamedMatrix[3] ; | |
var Rot2Y = streamedMatrix[4] ; | |
var Rot2Z = streamedMatrix[5] ; | |
var Rot3X = streamedMatrix[6] ; | |
var Rot3Y = streamedMatrix[7] ; | |
var Rot3Z = streamedMatrix[8] ; | |
// See answer here http://stackoverflow.com/questions/4833380/how-to-convert-a-3x3-rotation-matrix-into-4x4-matrix | |
finalMatrix.set( Rot1X, Rot1Y, Rot1Z, 0, | |
Rot2X, Rot2Y, Rot2Z, 0, | |
Rot3X, Rot3Y, Rot3Z, 0, | |
0, 0, 0, 1 ) | |
console.log('FINAL MATRIX ' + JSON.stringify(finalMatrix)) | |
return finalMatrix | |
} | |
var lowerLegRotMatrix = getMatrix4FromStreamedMatrix([-0.0726933181285858,0.95655220746994,0.282353401184082,0.0472477078437805,-0.279481798410416,0.958987742662429,0.996234536170959,0.0830524861812592,-0.0248785316944122]) | |
var upperLegRotMatrix = getMatrix4FromStreamedMatrix([0.13940124027431,-0.10846203379333,-0.98427812103182,-0.0556552428752184,0.991554081439971,-0.117146134376526,0.988670787774026,0.0711105465888977,0.132187373004854]) | |
// Calculate the upper device's forward vector | |
var upperLegForwardVector = new THREE.Vector3( 0, 1, 0) // V | |
upperLegForwardVector = upperLegForwardVector.applyMatrix4(upperLegRotMatrix) | |
// Calculate the lower device's forward vector in global space | |
var lowerLegForwardVector = new THREE.Vector3( 0, 1, 0 ) // V | |
lowerLegForwardVector = lowerLegForwardVector.applyMatrix4(lowerLegRotMatrix) | |
console.log("DOT PRODUCT " + upperLegForwardVector.dot(lowerLegForwardVector)) | |
var angle = Math.acos(upperLegForwardVector.dot(lowerLegForwardVector)) | |
console.log("ANGLE " + angle) | |
var theta = 180 - (THREE.Math.radToDeg(angle)) | |
console.log("FINAL " + theta) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment