@Override public Vector3f getPosition() { // the hmdPose comes in rotated funny, fix that here hmdPose.toTranslationVector(posStore); posStore.x = -posStore.x; posStore.z = -posStore.z; return posStore; }
@Override public Vector3f getPosition() { // the hmdPose comes in rotated funny, fix that here hmdPose.toTranslationVector(posStore); posStore.x = -posStore.x; posStore.z = -posStore.z; return posStore; }
@Override public Vector3f getHMDVectorPoseRightEye() { if( hmdPoseRightEyeVec == null ) { hmdPoseRightEyeVec = getHMDMatrixPoseRightEye().toTranslationVector(); // set default IPD if none or broken if( hmdPoseRightEyeVec.x >= 0.080f * 0.5f || hmdPoseRightEyeVec.x <= 0.040f * 0.5f ) { hmdPoseRightEyeVec.x = 0.065f * 0.5f; } if( flipEyes == false ) hmdPoseRightEyeVec.x *= -1f; // it seems these need flipping } return hmdPoseRightEyeVec; }
@Override public Vector3f getHMDVectorPoseLeftEye() { if( hmdPoseLeftEyeVec == null ) { hmdPoseLeftEyeVec = getHMDMatrixPoseLeftEye().toTranslationVector(); // set default IPD if none or broken if( hmdPoseLeftEyeVec.x <= 0.080f * -0.5f || hmdPoseLeftEyeVec.x >= 0.040f * -0.5f ) { hmdPoseLeftEyeVec.x = 0.065f * -0.5f; } if( flipEyes == false ) hmdPoseLeftEyeVec.x *= -1f; // it seems these need flipping } return hmdPoseLeftEyeVec; }
@Override public Vector3f getHMDVectorPoseRightEye() { if( hmdPoseRightEyeVec == null ) { hmdPoseRightEyeVec = getHMDMatrixPoseRightEye().toTranslationVector(); // set default IPD if none or broken if( hmdPoseRightEyeVec.x >= 0.080f * 0.5f || hmdPoseRightEyeVec.x <= 0.040f * 0.5f ) { hmdPoseRightEyeVec.x = 0.065f * 0.5f; } if( flipEyes == false ) hmdPoseRightEyeVec.x *= -1f; // it seems these need flipping } return hmdPoseRightEyeVec; }
@Override public Vector3f getHMDVectorPoseLeftEye() { if( hmdPoseLeftEyeVec == null ) { hmdPoseLeftEyeVec = getHMDMatrixPoseLeftEye().toTranslationVector(); // set default IPD if none or broken if( hmdPoseLeftEyeVec.x <= 0.080f * -0.5f || hmdPoseLeftEyeVec.x >= 0.040f * -0.5f ) { hmdPoseLeftEyeVec.x = 0.065f * -0.5f; } if( flipEyes == false ) hmdPoseLeftEyeVec.x *= -1f; // it seems these need flipping } return hmdPoseLeftEyeVec; }
@Override public void getPositionAndOrientation(Vector3f storePos, Quaternion storeRot) { hmdPose.toTranslationVector(storePos); storePos.x = -storePos.x; storePos.z = -storePos.z; storeRot.set(getOrientation()); }
@Override public void getPositionAndOrientation(Vector3f storePos, Quaternion storeRot) { hmdPose.toTranslationVector(storePos); storePos.x = -storePos.x; storePos.z = -storePos.z; storeRot.set(getOrientation()); }
@Override public Vector3f getPosition(int index) { if( isInputDeviceTracking(index) == false ){ return null; } if (environment != null){ if (environment.getVRHardware() instanceof OpenVR){ // the hmdPose comes in rotated funny, fix that here index = controllerIndex[index]; ((OpenVR)environment.getVRHardware()).poseMatrices[index].toTranslationVector(posStore[index]); posStore[index].x = -posStore[index].x; posStore[index].z = -posStore[index].z; return posStore[index]; } else { throw new IllegalStateException("VR hardware "+environment.getVRHardware().getClass().getSimpleName()+" is not a subclass of "+OpenVR.class.getSimpleName()); } } else { throw new IllegalStateException("VR input is not attached to a VR environment."); } }
@Override public Vector3f getPosition(int index) { if (isInputDeviceTracking(index) == false) { return null; } if (environment != null) { if (environment.getVRHardware() instanceof LWJGLOpenVR) { // the hmdPose comes in rotated funny, fix that here index = controllerIndex[index]; ((LWJGLOpenVR) environment.getVRHardware()).poseMatrices[index].toTranslationVector(posStore[index]); posStore[index].x = -posStore[index].x; posStore[index].z = -posStore[index].z; return posStore[index]; } else { throw new IllegalStateException("VR hardware " + environment.getVRHardware().getClass().getSimpleName() + " is not a subclass of " + LWJGLOpenVR.class.getSimpleName()); } } else { throw new IllegalStateException("VR input is not attached to a VR environment."); } }
@Override public Vector3f getSeatedToAbsolutePosition() { if( environment.isSeatedExperience() == false ) return Vector3f.ZERO; if( hmdSeatToStand == null ) { hmdSeatToStand = new Vector3f(); HmdMatrix34_t mat = vrsystemFunctions.GetSeatedZeroPoseToStandingAbsoluteTrackingPose.apply(); Matrix4f tempmat = new Matrix4f(); convertSteamVRMatrix3ToMatrix4f(mat, tempmat); tempmat.toTranslationVector(hmdSeatToStand); } return hmdSeatToStand; }
public void setWorldBindPose(Matrix4f worldBindPose) { if (cachedWorldBindPose != null) { if (!cachedWorldBindPose.equals(worldBindPose)) { throw new UnsupportedOperationException("Bind poses don't match"); } } cachedWorldBindPose = worldBindPose; this.jmeWorldBindPose = new Transform(); this.jmeWorldBindPose.setTranslation(worldBindPose.toTranslationVector()); this.jmeWorldBindPose.setRotation(worldBindPose.toRotationQuat()); this.jmeWorldBindPose.setScale(worldBindPose.toScaleVector()); System.out.println("\tBind Pose for " + getName()); System.out.println(jmeWorldBindPose); float[] angles = new float[3]; jmeWorldBindPose.getRotation().toAngles(angles); System.out.println("Angles: " + angles[0] * FastMath.RAD_TO_DEG + ", " + angles[1] * FastMath.RAD_TO_DEG + ", " + angles[2] * FastMath.RAD_TO_DEG); }
@Override public Vector3f getSeatedToAbsolutePosition() { if( environment.isSeatedExperience() == false ) return Vector3f.ZERO; if( hmdSeatToStand == null ) { hmdSeatToStand = new Vector3f(); HmdMatrix34 mat = HmdMatrix34.create(); VRSystem.VRSystem_GetSeatedZeroPoseToStandingAbsoluteTrackingPose(mat); Matrix4f tempmat = new Matrix4f(); convertSteamVRMatrix3ToMatrix4f(mat, tempmat); tempmat.toTranslationVector(hmdSeatToStand); } return hmdSeatToStand; }
public void fromTransformMatrix(Matrix4f mat) { TempVars vars = TempVars.get(); translation.set(mat.toTranslationVector(vars.vect1)); rot.set(mat.toRotationQuat(vars.quat1)); scale.set(mat.toScaleVector(vars.vect2)); vars.release(); }
@Override public void bake(Space ownerSpace, Space targetSpace, Transform targetTransform, float influence) { if (influence == 0 || targetTransform == null) { return;// no need to do anything } Object target = this.getTarget();// Bone or Node Object owner = this.getOwner();// Bone or Node if (!target.getClass().equals(owner.getClass())) { ConstraintHelper constraintHelper = blenderContext.getHelper(ConstraintHelper.class); TempVars tempVars = TempVars.get(); Matrix4f m = constraintHelper.toMatrix(targetTransform, tempVars.tempMat4); tempVars.tempMat42.set(BoneContext.BONE_ARMATURE_TRANSFORMATION_MATRIX); if (target instanceof Bone) { tempVars.tempMat42.invertLocal(); } m = m.multLocal(tempVars.tempMat42); tempVars.release(); targetTransform = new Transform(m.toTranslationVector(), m.toRotationQuat(), m.toScaleVector()); } this.applyOwnerTransform(targetTransform, ownerSpace); }
public void buildBindPoseBoneTransform() { if(bone != null) { Matrix4f t = bindTransform; if(t != null) { Matrix4f parentMatrix = parentFbxNode != null ? parentFbxNode.bindTransform : Matrix4f.IDENTITY; if(parentMatrix == null) parentMatrix = node.getLocalToWorldMatrix(null); t = parentMatrix.invert().multLocal(t); bone.setBindTransforms(t.toTranslationVector(), t.toRotationQuat(), t.toScaleVector()); } else { bone.setBindTransforms(node.getLocalTranslation(), node.getLocalRotation(), node.getLocalScale()); } } }
/** * This method calculates local transformation for the object. Parentage is * taken under consideration. * * @param objectStructure * the object's structure * @return objects transformation relative to its parent */ public Transform getTransformation(Structure objectStructure, BlenderContext blenderContext) { TempVars tempVars = TempVars.get(); Matrix4f parentInv = tempVars.tempMat4; Pointer pParent = (Pointer) objectStructure.getFieldValue("parent"); if (pParent.isNotNull()) { Structure parentObjectStructure = (Structure) blenderContext.getLoadedFeature(pParent.getOldMemoryAddress(), LoadedDataType.STRUCTURE); this.getMatrix(parentObjectStructure, "obmat", fixUpAxis, parentInv).invertLocal(); } else { parentInv.loadIdentity(); } Matrix4f globalMatrix = this.getMatrix(objectStructure, "obmat", fixUpAxis, tempVars.tempMat42); Matrix4f localMatrix = parentInv.multLocal(globalMatrix); this.getSizeSignums(objectStructure, tempVars.vect1); localMatrix.toTranslationVector(tempVars.vect2); localMatrix.toRotationQuat(tempVars.quat1); localMatrix.toScaleVector(tempVars.vect3); Transform t = new Transform(tempVars.vect2, tempVars.quat1.normalizeLocal(), tempVars.vect3.multLocal(tempVars.vect1)); tempVars.release(); return t; }
Matrix4f modelWorldMatrix = this.toMatrix(model.getWorldTransform(), tempVars.tempMat42); Matrix4f boneMatrixInWorldSpace = modelWorldMatrix.multLocal(boneModelMatrix); result = new Transform(boneMatrixInWorldSpace.toTranslationVector(), boneMatrixInWorldSpace.toRotationQuat(), boneMatrixInWorldSpace.toScaleVector()); break; case CONSTRAINT_SPACE_LOCAL: Matrix4f armatureInvertedWorldMatrix = this.toMatrix(feature.getWorldTransform(), tempVars.tempMat42).invertLocal(); Matrix4f bonePoseMatrix = armatureInvertedWorldMatrix.multLocal(boneWorldMatrix); result = new Transform(bonePoseMatrix.toTranslationVector(), bonePoseMatrix.toRotationQuat(), bonePoseMatrix.toScaleVector()); break; Matrix4f armatureInvertedWorldMatrix = this.toMatrix(feature.getWorldTransform(), tempVars.tempMat42).invertLocal(); Matrix4f bonePoseMatrix = armatureInvertedWorldMatrix.multLocal(boneWorldMatrix); result = new Transform(bonePoseMatrix.toTranslationVector(), bonePoseMatrix.toRotationQuat(), bonePoseMatrix.toScaleVector()); Bone parent = bone.getParent(); if(parent != null) {
Vector3f poseLocation = parent == null || !this.is(CONNECTED_TO_PARENT) ? boneLocalMatrix.toTranslationVector() : new Vector3f(0, parent.length, 0); Quaternion rotation = boneLocalMatrix.toRotationQuat().normalizeLocal(); Vector3f scale = boneLocalMatrix.toScaleVector();
boneMatrixInModelSpace = parentMatrixInModelSpace.invertLocal().multLocal(boneMatrixInModelSpace); bone.setBindTransforms(boneMatrixInModelSpace.toTranslationVector(), boneMatrixInModelSpace.toRotationQuat(), boneMatrixInModelSpace.toScaleVector()); break; boneMatrixInModelSpace = parentMatrixInModelSpace.invertLocal().multLocal(boneMatrixInModelSpace); bone.setBindTransforms(boneMatrixInModelSpace.toTranslationVector(), boneMatrixInModelSpace.toRotationQuat(), boneMatrixInModelSpace.toScaleVector()); break; bone.setBindTransforms(boneMatrixInModelSpace.toTranslationVector(), boneMatrixInModelSpace.toRotationQuat(), boneMatrixInModelSpace.toScaleVector()); break; default: tempVars.release(); transform.setTranslation(m.toTranslationVector()); transform.setRotation(m.toRotationQuat()); transform.setScale(m.toScaleVector());