public void Awake() { skeletonController = FindObjectOfType(typeof(RUISSkeletonController)) as RUISSkeletonController; pointTracker = GetComponent<RUISPointTracker>(); skeletonManager = FindObjectOfType(typeof(RUISSkeletonManager)) as RUISSkeletonManager; ResetProgress(); }
public void Awake() { skeletonController = FindObjectOfType(typeof(RUISSkeletonController)) as RUISSkeletonController; pointTracker = GetComponent <RUISPointTracker>(); skeletonManager = FindObjectOfType(typeof(RUISSkeletonManager)) as RUISSkeletonManager; ResetProgress(); }
// Use this for initialization void Start() { ballInitialPosition = ball.transform.position; indicatorInitialPosition = indicator.GetComponent <RectTransform>().position; indicatorTransform = indicator.GetComponent <RectTransform>(); barRedTransform = barRed.GetComponent <RectTransform>(); barYellowTransform = barYellow.GetComponent <RectTransform>(); barGreenTransform = barGreen.GetComponent <RectTransform>(); hipLeftAngle = 0f; hipRightAngle = 0f; kneeLeftAngle = 0f; kneeRightAngle = 0f; legLeftOrientation = new Vector2(); legRightOrientation = new Vector2(); firstThreshold = false; secondThreshold = false; thirdThreshold = false; firstOrientation = false; secondOrientation = false; thirdOrientation = false; tempPosition = new Vector2(); leftVector = new Vector2(leftHip.position.x, Mathf.Abs(leftHip.position.z)); rightVector = new Vector2(rightHip.position.x, Mathf.Abs(rightHip.position.z)); GameObject go = GameObject.Find("Porl KinectKinect"); skeleton = go.GetComponent <RUISSkeletonController>(); }
void Awake() { inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager; skeletonManager = FindObjectOfType(typeof(RUISSkeletonManager)) as RUISSkeletonManager; stabilizingCollider = GetComponentInChildren<RUISCharacterStabilizingCollider>(); lastJumpTime = 0; skeletonController = gameObject.GetComponentInChildren<RUISSkeletonController>(); }
void Awake() { inputManager = FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager; skeletonManager = FindObjectOfType(typeof(RUISSkeletonManager)) as RUISSkeletonManager; stabilizingCollider = GetComponentInChildren <RUISCharacterStabilizingCollider>(); lastJumpTime = 0; skeletonController = gameObject.GetComponentInChildren <RUISSkeletonController>(); }
void LateUpdate() { if (Input.GetKeyDown(button)) { gestureWasTriggered = !gestureWasTriggered; } if (animateFist && skeletonController) { if (Input.GetKey(button)) //if(Input.GetKeyDown(button)) { if (leftOrRightFist == RUISFistGestureRecognizer.fistSide.RightFist) { skeletonController.externalRightStatus = RUISSkeletonManager.Skeleton.handState.closed; } if (leftOrRightFist == RUISFistGestureRecognizer.fistSide.LeftFist) { skeletonController.externalLeftStatus = RUISSkeletonManager.Skeleton.handState.closed; } } else //if(Input.GetKeyUp(button)) { if (leftOrRightFist == RUISFistGestureRecognizer.fistSide.RightFist) { skeletonController.externalRightStatus = RUISSkeletonManager.Skeleton.handState.open; } if (leftOrRightFist == RUISFistGestureRecognizer.fistSide.LeftFist) { skeletonController.externalLeftStatus = RUISSkeletonManager.Skeleton.handState.open; } } } // Original skeletonController has been destroyed because the GameObject which had // it has been split in three parts: Kinect, Mecanim, Blended. Lets fetch the new one. if (!combinerChildrenInstantiated && kinectAndMecanimCombinerExists) { if (skeletonParent) { RUISKinectAndMecanimCombiner combiner = skeletonParent.GetComponentInChildren <RUISKinectAndMecanimCombiner>(); if (combiner && combiner.isChildrenInstantiated()) { skeletonController = combiner.skeletonController; if (skeletonController == null) { Debug.LogError("Could not find Component " + typeof(RUISSkeletonController) + " from " + "children of " + gameObject.transform.parent.name + ", something is very wrong with this character setup!"); } combinerChildrenInstantiated = true; } } } }
public void Awake() { skeletonController = FindObjectOfType(typeof(RUISSkeletonController)) as RUISSkeletonController; skeletonManager = FindObjectOfType(typeof(RUISSkeletonManager)) as RUISSkeletonManager; hand = GameObject.FindGameObjectWithTag ("hand"); shoulder = GameObject.FindGameObjectWithTag ("Shoulder"); head = GameObject.FindGameObjectWithTag ("head"); MagicFactory.AddMagic ("throw", 0); magic = MagicFactory.GetMagic ("throw"); scale = CalculateDistance (); }
public void Awake() { skeletonController = FindObjectOfType(typeof(RUISSkeletonController)) as RUISSkeletonController; skeletonManager = FindObjectOfType(typeof(RUISSkeletonManager)) as RUISSkeletonManager; hand = GameObject.FindGameObjectWithTag("hand"); neck = GameObject.FindGameObjectWithTag("neck"); head = GameObject.FindGameObjectWithTag("head"); MagicFactory.AddMagic("throw", 0); magic = MagicFactory.GetMagic("throw"); scale = CalculateDistance(); }
void Update() { if (!combinerChildrenInstantiated) { skeletonController = getSkeletonController(); } // Check whether character collider (aka stabilizingCollider) is grounded raycastPosition = (stabilizingCollider? stabilizingCollider.transform.position : transform.position); distanceToRaycast = (stabilizingCollider ? stabilizingCollider.colliderHeight / 2 : 1.5f); distanceToRaycast += groundedErrorTweaker; distanceToRaycast = Mathf.Max(distanceToRaycast * transform.lossyScale.y, float.Epsilon); tempGrounded = Physics.Raycast(raycastPosition, -transform.up, distanceToRaycast, groundLayers.value); // Check if feet are grounded if (!tempGrounded && feetAlsoAffectGrounding) { foreach (Transform bodyPart in bodyParts) { if (bodyPart && bodyPart.GetComponent <Collider>()) { raycastPosition = bodyPart.GetComponent <Collider>().bounds.center; distanceToRaycast = (bodyPart.GetComponent <Collider>().bounds.extents.y + groundedErrorTweaker) * transform.lossyScale.y; rayIntersected = Physics.Raycast(raycastPosition, -transform.up, out hitInfo, distanceToRaycast, groundLayers.value); if (rayIntersected && hitInfo.rigidbody) { if (!hitInfo.rigidbody.isKinematic) { tempGrounded = true; break; } } } } } grounded = tempGrounded; // *** HACK: for fixing weird drift that is probably related to RUISKinectAndMecanimCombiner's transform.position update and possibly stabilizing collider & others // TODO: Does such miniscular position update affect how physics collision is handled? N.B. MovePosition is not used in RUISKinectAndMecanimCombiner right now if ((transform.position - previousPosition).magnitude * Mathf.Max(Mathf.Abs(transform.lossyScale.x), Mathf.Max(Mathf.Abs(transform.lossyScale.y), Mathf.Abs(transform.lossyScale.z))) < 0.0009f) { transform.position = previousPosition; } previousPosition = transform.position; }
void Start() { coordinateSystem = FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem; if (transform.parent) { skeletonController = transform.parent.gameObject.GetComponentInChildren(typeof(RUISSkeletonController)) as RUISSkeletonController; if (skeletonController) { playerId = skeletonController.playerId; bodyTrackingDeviceID = skeletonController.bodyTrackingDeviceID; } } // if(transform.parent) // characterController = transform.parent.GetComponent<RUISCharacterController>(); }
void Start() { coordinateSystem = FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem; if (transform.parent) { // FIXME: if skeletonControllers are nested below produces wrong results (e.g. case of pilot inside her mecha) skeletonController = transform.parent.gameObject.GetComponentInChildren(typeof(RUISSkeletonController)) as RUISSkeletonController; if (skeletonController) { playerId = skeletonController.playerId; bodyTrackingDeviceID = skeletonController.bodyTrackingDeviceID; } } // if(transform.parent) // characterController = transform.parent.GetComponent<RUISCharacterController>(); }
RUISSkeletonController getSkeletonController() { // Original skeletonController has been destroyed because the GameObject which had // it has been split in three parts: Kinect, Mecanim, Blended. Lets fetch the new one. if (!combinerChildrenInstantiated && kinectAndMecanimCombinerExists) { RUISKinectAndMecanimCombiner combiner = GetComponentInChildren <RUISKinectAndMecanimCombiner>(); if (combiner && combiner.isChildrenInstantiated()) { skeletonController = combiner.skeletonController; if (skeletonController == null) { Debug.LogError("Could not find Component " + typeof(RUISSkeletonController) + " from " + "children of " + gameObject.name + ", something is very wrong with this character setup!"); } combinerChildrenInstantiated = true; } } return(skeletonController); }
void Start() { colliding = false; grounded = false; skeletonController = gameObject.GetComponentInChildren<RUISSkeletonController>(); if(skeletonController) { bodyParts.Add(skeletonController.leftFoot); bodyParts.Add(skeletonController.rightFoot); kinectPlayerId = skeletonController.playerId; } else { Debug.LogError( "RUISCharacterController script in game object '" + gameObject.name + "' did not find RUISSkeletonController component from it's child objects!"); } if(stabilizingCollider) { colliderComponent = stabilizingCollider.gameObject.collider; if(colliderComponent) { if( characterPivotType == CharacterPivotType.KinectHead || characterPivotType == CharacterPivotType.KinectTorso) { RUISCoordinateSystem coordinateSystem = FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem; if(coordinateSystem && inputManager.enableKinect && !coordinateSystem.setKinectOriginToFloor) Debug.LogWarning("It is best to enable 'setKinectOriginToFloor' from RUISCoordinateSystem " + "when using Kinect and RUISCharacterController script."); } if(colliderComponent.material) originalMaterial = colliderComponent.material; else { colliderComponent.material = new PhysicMaterial(); originalMaterial = colliderComponent.material; } if(dynamicMaterial == null) { dynamicMaterial = new PhysicMaterial(); dynamicMaterial.dynamicFriction = 0; dynamicMaterial.staticFriction = 0; dynamicMaterial.frictionCombine = PhysicMaterialCombine.Minimum; if(colliderComponent.material) { dynamicMaterial.bounceCombine = originalMaterial.bounceCombine; dynamicMaterial.bounciness = originalMaterial.bounciness; dynamicMaterial.staticFriction2 = originalMaterial.staticFriction2; dynamicMaterial.dynamicFriction2 = originalMaterial.dynamicFriction2; dynamicMaterial.frictionDirection2 = originalMaterial.frictionDirection2; } } } } if(( characterPivotType == CharacterPivotType.KinectHead || characterPivotType == CharacterPivotType.KinectTorso) && (skeletonController && skeletonController.playerId != kinectPlayerId)) Debug.LogError( "The 'Kinect Player Id' variable in RUISCharacterController script in gameObject '" + gameObject.name + "is different from the Kinect Player Id of the RUISSkeletonController script (located in child " + "object '" + skeletonController.gameObject.name + "). Make sure that these two values are " + "the same."); }
void Start() { colliding = false; grounded = false; skeletonController = gameObject.GetComponentInChildren <RUISSkeletonController>(); if (skeletonController) { bodyParts.Add(skeletonController.leftFoot); bodyParts.Add(skeletonController.rightFoot); kinectPlayerId = skeletonController.playerId; } else { Debug.LogError("RUISCharacterController script in game object '" + gameObject.name + "' did not find RUISSkeletonController component from it's child objects!"); } if (stabilizingCollider) { colliderComponent = stabilizingCollider.gameObject.collider; if (colliderComponent) { if (colliderComponent.material) { originalMaterial = colliderComponent.material; } else { colliderComponent.material = new PhysicMaterial(); originalMaterial = colliderComponent.material; } if (dynamicMaterial == null) { dynamicMaterial = new PhysicMaterial(); dynamicMaterial.dynamicFriction = 0; dynamicMaterial.staticFriction = 0; dynamicMaterial.frictionCombine = PhysicMaterialCombine.Minimum; if (colliderComponent.material) { dynamicMaterial.bounceCombine = originalMaterial.bounceCombine; dynamicMaterial.bounciness = originalMaterial.bounciness; dynamicMaterial.staticFriction2 = originalMaterial.staticFriction2; dynamicMaterial.dynamicFriction2 = originalMaterial.dynamicFriction2; dynamicMaterial.frictionDirection2 = originalMaterial.frictionDirection2; } } } } if ((characterPivotType == CharacterPivotType.KinectHead || characterPivotType == CharacterPivotType.KinectTorso) && (skeletonController && skeletonController.playerId != kinectPlayerId)) { Debug.LogError("The 'Kinect Player Id' variable in RUISCharacterController script in gameObject '" + gameObject.name + "is different from the Kinect Player Id of the RUISSkeletonController script (located in child " + "object '" + skeletonController.gameObject.name + "). Make sure that these two values are " + "the same."); } }
public void OnEnable() { bodyTrackingDevice = serializedObject.FindProperty("bodyTrackingDevice"); playerId = serializedObject.FindProperty("playerId"); switchToAvailableKinect = serializedObject.FindProperty("switchToAvailableKinect"); useHierarchicalModel = serializedObject.FindProperty("useHierarchicalModel"); updateRootPosition = serializedObject.FindProperty("updateRootPosition"); updateJointPositions = serializedObject.FindProperty("updateJointPositions"); updateJointRotations = serializedObject.FindProperty("updateJointRotations"); rootSpeedScaling = serializedObject.FindProperty("rootSpeedScaling"); oculusRotatesHead = serializedObject.FindProperty("oculusRotatesHead"); scaleHierarchicalModelBones = serializedObject.FindProperty("scaleHierarchicalModelBones"); scaleBoneLengthOnly = serializedObject.FindProperty("scaleBoneLengthOnly"); boneLengthAxis = serializedObject.FindProperty("boneLengthAxis"); torsoThickness = serializedObject.FindProperty("torsoThickness"); rightArmThickness = serializedObject.FindProperty("rightArmThickness"); leftArmThickness = serializedObject.FindProperty("leftArmThickness"); rightLegThickness = serializedObject.FindProperty("rightLegThickness"); leftLegThickness = serializedObject.FindProperty("leftLegThickness"); filterRotations = serializedObject.FindProperty("filterRotations"); rotationNoiseCovariance = serializedObject.FindProperty("rotationNoiseCovariance"); thumbZRotationOffset = serializedObject.FindProperty("thumbZRotationOffset"); rootBone = serializedObject.FindProperty("root"); headBone = serializedObject.FindProperty("head"); neckBone = serializedObject.FindProperty("neck"); torsoBone = serializedObject.FindProperty("torso"); leftClavicleBone = serializedObject.FindProperty("leftClavicle"); leftShoulderBone = serializedObject.FindProperty("leftShoulder"); leftElbowBone = serializedObject.FindProperty("leftElbow"); leftHandBone = serializedObject.FindProperty("leftHand"); rightShoulderBone = serializedObject.FindProperty("rightShoulder"); rightElbowBone = serializedObject.FindProperty("rightElbow"); rightHandBone = serializedObject.FindProperty("rightHand"); leftHipBone = serializedObject.FindProperty("leftHip"); leftKneeBone = serializedObject.FindProperty("leftKnee"); leftFootBone = serializedObject.FindProperty("leftFoot"); rightHipBone = serializedObject.FindProperty("rightHip"); rightKneeBone = serializedObject.FindProperty("rightKnee"); rightFootBone = serializedObject.FindProperty("rightFoot"); leftThumb = serializedObject.FindProperty ("leftThumb"); rightThumb = serializedObject.FindProperty ("rightThumb"); trackWrist = serializedObject.FindProperty ("trackWrist"); trackAnkle = serializedObject.FindProperty ("trackAnkle"); // rotateWristFromElbow = serializedObject.FindProperty ("rotateWristFromElbow"); // adjustVerticalTorsoPosition = serializedObject.FindProperty("adjustVerticalTorsoPosition"); adjustVerticalHipsPosition = serializedObject.FindProperty("adjustVerticalHipsPosition"); maxScaleFactor = serializedObject.FindProperty("maxScaleFactor"); minimumConfidenceToUpdate = serializedObject.FindProperty("minimumConfidenceToUpdate"); rotationDamping = serializedObject.FindProperty("rotationDamping"); neckHeightTweaker = serializedObject.FindProperty("neckHeightTweaker"); forearmLengthTweaker = serializedObject.FindProperty("forearmLengthRatio"); shinLengthTweaker = serializedObject.FindProperty("shinLengthRatio"); fistCurlFingers = serializedObject.FindProperty("fistCurlFingers"); trackThumbs = serializedObject.FindProperty("trackThumbs"); customRoot = serializedObject.FindProperty("customRoot"); customHead = serializedObject.FindProperty("customHead"); customNeck = serializedObject.FindProperty("customNeck"); customTorso = serializedObject.FindProperty("customTorso"); customRightShoulder = serializedObject.FindProperty("customRightShoulder"); customRightElbow = serializedObject.FindProperty("customRightElbow"); customRightHand = serializedObject.FindProperty("customRightHand"); customRightHip = serializedObject.FindProperty("customRightHip"); customRightKnee = serializedObject.FindProperty("customRightKnee"); customRightFoot = serializedObject.FindProperty("customRightFoot"); customLeftClavicle = serializedObject.FindProperty("customLeftClavicle"); customLeftShoulder = serializedObject.FindProperty("customLeftShoulder"); customLeftElbow = serializedObject.FindProperty("customLeftElbow"); customLeftHand = serializedObject.FindProperty("customLeftHand"); customLeftHip = serializedObject.FindProperty("customLeftHip"); customLeftKnee = serializedObject.FindProperty("customLeftKnee"); customLeftFoot = serializedObject.FindProperty("customLeftFoot"); customLeftThumb = serializedObject.FindProperty("customLeftThumb"); customRightThumb = serializedObject.FindProperty("customRightThumb"); skeletonController = target as RUISSkeletonController; }
void Start() { coordinateSystem = FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem; if(transform.parent) { skeletonController = transform.parent.gameObject.GetComponentInChildren(typeof(RUISSkeletonController)) as RUISSkeletonController; if(skeletonController) { playerId = skeletonController.playerId; bodyTrackingDeviceID = skeletonController.bodyTrackingDeviceID; } } // if(transform.parent) // characterController = transform.parent.GetComponent<RUISCharacterController>(); }
void FixedUpdate () { // if(characterController != null && characterController.useOculusPositionalTracking /*&& UnityEditorInternal.InternalEditorUtility.HasPro()*/) // { // if(OVRDevice.IsCameraTracking() && oculusHmdObject != null) // { // ovrTrackingState trackingState = oculusHmdObject.GetTrackingState(Hmd.GetTimeInSeconds()); // // headPosition = new Vector3(trackingState.HeadPose.ThePose.Position.x, trackingState.HeadPose.ThePose.Position.y, trackingState.HeadPose.ThePose.Position.z); // torsoPosition = coordinateSystem.ConvertLocation(coordinateSystem.ConvertRawOculusDK2Location(headPosition), RUISDevice.Oculus_DK2); // // measuredPos[0] = torsoPosition.x; // measuredPos[1] = torsoPosition.y; // measuredPos[2] = torsoPosition.z; // positionKalman.setR(Time.fixedDeltaTime * positionNoiseCovariance); // positionKalman.predict(); // positionKalman.update(measuredPos); // pos = positionKalman.getState(); // torsoPosition.x = (float) pos[0]; // torsoPosition.y = (float) pos[1] - coordinateYOffset; // torsoPosition.z = (float) pos[2]; // // newLocalPosition = torsoPosition; // newLocalPosition.y = (torsoPosition.y)/ 2 + coordinateYOffset; // } // } // Tuukka: // Original skeletonController has been destroyed because the GameObject which had // it has been split in three parts: Kinect, Mecanim, Blended. Lets fetch the new one. if (!combinerChildrenInstantiated && kinectAndMecanimCombinerExists) { if (gameObject.transform.parent != null) { RUISKinectAndMecanimCombiner combiner = gameObject.transform.parent.GetComponentInChildren<RUISKinectAndMecanimCombiner>(); if (combiner && combiner.isChildrenInstantiated()) { skeletonController = combiner.skeletonController; if(skeletonController == null) Debug.LogError( "Could not find Component " + typeof(RUISSkeletonController) + " from " + "children of " + gameObject.transform.parent.name + ", something is very wrong with this character setup!"); bodyTrackingDeviceID = skeletonController.bodyTrackingDeviceID; playerId = skeletonController.playerId; combinerChildrenInstantiated = true; } } } if (!skeletonManager || !skeletonManager.skeletons [bodyTrackingDeviceID, playerId].isTracking) { colliderHeight = defaultColliderHeight; if (combinerChildrenInstantiated) { if ( skeletonController.followOculusController || skeletonController.followMoveController ) { // TODO *** Check that this works with other models. Before with grandma model torsoPos value was: //torsoPos = skeletonController.transform.localPosition + defaultColliderHeight * Vector3.up; torsoPosition = skeletonController.transform.localPosition; torsoPosition.y = defaultColliderHeight; // torsoPos.y is lerped and 0 doesn't seem to work newLocalPosition = torsoPosition; newLocalPosition.y = defaultColliderPosition.y; measuredPos[0] = torsoPosition.x; measuredPos[1] = torsoPosition.y; measuredPos[2] = torsoPosition.z; positionKalman.setR(Time.fixedDeltaTime * positionSmoothing); positionKalman.predict(); positionKalman.update(measuredPos); pos = positionKalman.getState(); torsoPosition.x = (float) pos[0]; torsoPosition.y = (float) pos[1]; torsoPosition.z = (float) pos[2]; } else { //colliderHeight = defaultColliderHeight; //transform.localPosition = defaultColliderPosition; return; } } else { //colliderHeight = defaultColliderHeight; //transform.localPosition = defaultColliderPosition; return; } } else { if(coordinateSystem && ( coordinateSystem.applyToRootCoordinates || (bodyTrackingDeviceID == RUISSkeletonManager.kinect2SensorID && coordinateSystem.rootDevice == RUISDevice.Kinect_2) || (bodyTrackingDeviceID == RUISSkeletonManager.kinect1SensorID && coordinateSystem.rootDevice == RUISDevice.Kinect_1))) { coordinateYOffset = coordinateSystem.positionOffset.y; } // Apply root scaling if(skeletonController) torsoPosition = Vector3.Scale(skeletonManager.skeletons [bodyTrackingDeviceID, playerId].torso.position, skeletonController.rootSpeedScaling); else torsoPosition = skeletonManager.skeletons [bodyTrackingDeviceID, playerId].torso.position; measuredPos[0] = torsoPosition.x; measuredPos[1] = torsoPosition.y; measuredPos[2] = torsoPosition.z; positionKalman.setR(Time.fixedDeltaTime * positionSmoothing); positionKalman.predict(); positionKalman.update(measuredPos); pos = positionKalman.getState(); torsoPosition.x = (float) pos[0]; torsoPosition.y = (float) pos[1] - coordinateYOffset; torsoPosition.z = (float) pos[2]; // Capsule collider is from floor up till torsoPos, therefore the capsule's center point is half of that newLocalPosition = torsoPosition; newLocalPosition.y = (torsoPosition.y)/ 2 + coordinateYOffset; } // Updated collider height (from floor to torsoPos) colliderHeight = Mathf.Lerp(capsuleCollider.height, torsoPosition.y + colliderHeightTweaker, maxHeightChange * Time.fixedDeltaTime); // Updated collider position transform.localPosition = Vector3.MoveTowards(transform.localPosition, newLocalPosition, maxPositionChange * Time.fixedDeltaTime); }
void Start() { Vector3 initialLocalScale = transform.localScale; skeletonManager = FindObjectOfType(typeof(RUISSkeletonManager)) as RUISSkeletonManager; skeletonController = GetComponent<RUISSkeletonController>(); // if ( !inputManager.enableKinect && !inputManager.enableKinect2 // && (skeletonController.bodyTrackingDevice != RUISSkeletonController.bodyTrackingDeviceType.GenericMotionTracker)) if(skeletonController != null && ( skeletonController.followOculusController || inputManager == null || ( skeletonController.followMoveController && ( (skeletonController.bodyTrackingDeviceID == RUISSkeletonManager.kinect1SensorID && !inputManager.enableKinect ) || (skeletonController.bodyTrackingDeviceID == RUISSkeletonManager.kinect2SensorID && !inputManager.enableKinect2))))) { // Without the below if-clause the legs will twist with PS Move head tracker (when Move is enabled but Kinect is not) //if(!inputManager.enablePSMove) torsoBlendWeight = 1; headBlendWeight = 1; rightArmBlendWeight = 1; leftArmBlendWeight = 1; rightLegBlendWeight = 1; leftLegBlendWeight = 1; // forceArmStartPosition = false; // forceLegStartPosition = false; } if (!childrenInstantiated) { childrenInstantiated = true; kinectGameObject = Instantiate(gameObject, transform.position, transform.rotation) as GameObject; kinectGameObject.name = name + "Kinect"; kinectGameObject.transform.parent = transform.parent; kinectGameObject.transform.localScale = initialLocalScale; //kinectGameObject.GetComponent<RUISKinectAndMecanimCombiner>().childrenInstantiated = true; Destroy(kinectGameObject.GetComponent<RUISKinectAndMecanimCombiner>()); Destroy(kinectGameObject.GetComponent<Animator>()); Destroy(kinectGameObject.GetComponent<RUISCharacterAnimationController>()); foreach (Collider collider in kinectGameObject.GetComponentsInChildren<Collider>()) { Destroy(collider); } foreach (Renderer meshRenderer in kinectGameObject.GetComponentsInChildren<Renderer>()) { Destroy(meshRenderer); } mecanimGameObject = Instantiate(gameObject, transform.position, transform.rotation) as GameObject; mecanimGameObject.name = name + "Mecanim"; mecanimGameObject.transform.parent = transform.parent; mecanimGameObject.transform.localScale = initialLocalScale; Destroy(mecanimGameObject.GetComponent<RUISKinectAndMecanimCombiner>()); Destroy(mecanimGameObject.GetComponent<RUISCharacterAnimationController>()); Destroy(mecanimGameObject.GetComponent<RUISSkeletonController>()); foreach (Collider collider in mecanimGameObject.GetComponentsInChildren<Collider>()) { Destroy(collider); } foreach (Renderer meshRenderer in mecanimGameObject.GetComponentsInChildren<Renderer>()) { Destroy(meshRenderer); } Destroy(GetComponent<RUISSkeletonController>()); Destroy(GetComponent<Animator>()); GetComponent<RUISCharacterAnimationController>().animator = mecanimGameObject.GetComponent<Animator>(); skeletonController = kinectGameObject.GetComponent<RUISSkeletonController>(); mecanimAnimator = mecanimGameObject.GetComponent<Animator>(); if(!skeletonController) Debug.LogError("Script " + typeof(RUISSkeletonController) + " is not found by " + this.GetType().Name + "!"); torsoIsRoot = skeletonController.root == skeletonController.torso; Transform kinectRootBone = skeletonController.root; Transform mecanimRootBone = FindBone(mecanimAnimator.transform, kinectRootBone.name); Transform blendedRootBone = FindBone(transform, kinectRootBone.name); skeletonRoot = new BoneTriplet(kinectRootBone, mecanimRootBone, blendedRootBone, BodypartClassification.Root); if (torsoIsRoot) { torsoRoot = skeletonRoot; AddChildren(ref torsoRoot, BodypartClassification.Torso); } else { AddChildren(ref skeletonRoot, BodypartClassification.Root); } } }
void Start() { colliding = false; grounded = false; // Second substitution, because RUISKinectAndMecanimCombiner might have already erased the original one and re-created it skeletonController = gameObject.GetComponentInChildren<RUISSkeletonController>(); if(skeletonController) { bodyParts.Add(skeletonController.leftFoot); bodyParts.Add(skeletonController.rightFoot); kinectPlayerId = skeletonController.playerId; bodyTrackingDeviceID = skeletonController.bodyTrackingDeviceID; } else { Debug.LogError( "RUISCharacterController script in game object '" + gameObject.name + "' did not find RUISSkeletonController component from it's child objects!"); } coordinateSystem = FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem; if(stabilizingCollider) { colliderComponent = stabilizingCollider.gameObject.GetComponent<Collider>(); if(colliderComponent) { if( characterPivotType == CharacterPivotType.KinectHead || characterPivotType == CharacterPivotType.KinectTorso) { if(coordinateSystem && inputManager.enableKinect && !coordinateSystem.setKinectOriginToFloor) Debug.LogWarning("It is best to enable 'setKinectOriginToFloor' from RUISCoordinateSystem " + "when using Kinect and RUISCharacterController script."); } if(colliderComponent.material) originalMaterial = colliderComponent.material; else { colliderComponent.material = new PhysicMaterial(); originalMaterial = colliderComponent.material; } if(dynamicMaterial == null) { dynamicMaterial = new PhysicMaterial(); dynamicMaterial.dynamicFriction = 0; dynamicMaterial.staticFriction = 0; dynamicMaterial.frictionCombine = PhysicMaterialCombine.Minimum; if(colliderComponent.material) { dynamicMaterial.bounceCombine = originalMaterial.bounceCombine; dynamicMaterial.bounciness = originalMaterial.bounciness; // dynamicMaterial.staticFriction2 = originalMaterial.staticFriction2; // dynamicMaterial.dynamicFriction2 = originalMaterial.dynamicFriction2; // dynamicMaterial.frictionDirection2 = originalMaterial.frictionDirection2; } } } } if(( characterPivotType == CharacterPivotType.KinectHead || characterPivotType == CharacterPivotType.KinectTorso) && (skeletonController && skeletonController.playerId != kinectPlayerId)) Debug.LogError( "The 'Kinect Player Id' variable in RUISCharacterController script in gameObject '" + gameObject.name + "is different from the Kinect Player Id of the RUISSkeletonController script (located in child " + "object '" + skeletonController.gameObject.name + "). Make sure that these two values are " + "the same."); //#if UNITY_EDITOR //if(UnityEditorInternal.InternalEditorUtility.HasPro()) //#endif { try { bool isRiftConnected = false; if(OVRManager.display != null) isRiftConnected = OVRManager.display.isPresent; if(OVRManager.capiHmd != null) ovrHmdVersion = OVRManager.capiHmd.GetDesc().Type; if(useOculusPositionalTracking && ovrHmdVersion == Ovr.HmdType.DK1 || ovrHmdVersion == Ovr.HmdType.DKHD || ovrHmdVersion == Ovr.HmdType.None) { Debug.LogError("Can't use Oculus Rift's tracked position as a pivot with Oculus Rift " + ovrHmdVersion); useOculusPositionalTracking = false; } if(useOculusPositionalTracking && !isRiftConnected) { Debug.LogError("Can't use Oculus Rift's tracked position as a pivot because Oculus Rift is not connected."); useOculusPositionalTracking = false; } } catch(UnityException e) { useOculusPositionalTracking = false; Debug.LogError(e); } } if(GetComponentInChildren<RUISKinectAndMecanimCombiner>()) kinectAndMecanimCombinerExists = true; previousPosition = transform.position; }
public void OnEnable() { bodyTrackingDevice = serializedObject.FindProperty("bodyTrackingDevice"); playerId = serializedObject.FindProperty("playerId"); switchToAvailableKinect = serializedObject.FindProperty("switchToAvailableKinect"); useHierarchicalModel = serializedObject.FindProperty("useHierarchicalModel"); updateRootPosition = serializedObject.FindProperty("updateRootPosition"); updateJointPositions = serializedObject.FindProperty("updateJointPositions"); updateJointRotations = serializedObject.FindProperty("updateJointRotations"); rootSpeedScaling = serializedObject.FindProperty("rootSpeedScaling"); oculusRotatesHead = serializedObject.FindProperty("oculusRotatesHead"); scaleHierarchicalModelBones = serializedObject.FindProperty("scaleHierarchicalModelBones"); scaleBoneLengthOnly = serializedObject.FindProperty("scaleBoneLengthOnly"); boneLengthAxis = serializedObject.FindProperty("boneLengthAxis"); torsoThickness = serializedObject.FindProperty("torsoThickness"); rightArmThickness = serializedObject.FindProperty("rightArmThickness"); leftArmThickness = serializedObject.FindProperty("leftArmThickness"); rightLegThickness = serializedObject.FindProperty("rightLegThickness"); leftLegThickness = serializedObject.FindProperty("leftLegThickness"); filterRotations = serializedObject.FindProperty("filterRotations"); rotationNoiseCovariance = serializedObject.FindProperty("rotationNoiseCovariance"); thumbZRotationOffset = serializedObject.FindProperty("thumbZRotationOffset"); rootBone = serializedObject.FindProperty("root"); headBone = serializedObject.FindProperty("head"); neckBone = serializedObject.FindProperty("neck"); torsoBone = serializedObject.FindProperty("torso"); leftShoulderBone = serializedObject.FindProperty("leftShoulder"); leftElbowBone = serializedObject.FindProperty("leftElbow"); leftHandBone = serializedObject.FindProperty("leftHand"); rightShoulderBone = serializedObject.FindProperty("rightShoulder"); rightElbowBone = serializedObject.FindProperty("rightElbow"); rightHandBone = serializedObject.FindProperty("rightHand"); leftHipBone = serializedObject.FindProperty("leftHip"); leftKneeBone = serializedObject.FindProperty("leftKnee"); leftFootBone = serializedObject.FindProperty("leftFoot"); rightHipBone = serializedObject.FindProperty("rightHip"); rightKneeBone = serializedObject.FindProperty("rightKnee"); rightFootBone = serializedObject.FindProperty("rightFoot"); leftThumb = serializedObject.FindProperty("leftThumb"); rightThumb = serializedObject.FindProperty("rightThumb"); trackWrist = serializedObject.FindProperty("trackWrist"); trackAnkle = serializedObject.FindProperty("trackAnkle"); // rotateWristFromElbow = serializedObject.FindProperty ("rotateWristFromElbow"); // adjustVerticalTorsoPosition = serializedObject.FindProperty("adjustVerticalTorsoPosition"); adjustVerticalHipsPosition = serializedObject.FindProperty("adjustVerticalHipsPosition"); maxScaleFactor = serializedObject.FindProperty("maxScaleFactor"); minimumConfidenceToUpdate = serializedObject.FindProperty("minimumConfidenceToUpdate"); rotationDamping = serializedObject.FindProperty("rotationDamping"); neckHeightTweaker = serializedObject.FindProperty("neckHeightTweaker"); forearmLengthTweaker = serializedObject.FindProperty("forearmLengthRatio"); shinLengthTweaker = serializedObject.FindProperty("shinLengthRatio"); fistCurlFingers = serializedObject.FindProperty("fistCurlFingers"); trackThumbs = serializedObject.FindProperty("trackThumbs"); customRoot = serializedObject.FindProperty("customRoot"); customHead = serializedObject.FindProperty("customHead"); customNeck = serializedObject.FindProperty("customNeck"); customTorso = serializedObject.FindProperty("customTorso"); customRightShoulder = serializedObject.FindProperty("customRightShoulder"); customRightElbow = serializedObject.FindProperty("customRightElbow"); customRightHand = serializedObject.FindProperty("customRightHand"); customRightHip = serializedObject.FindProperty("customRightHip"); customRightKnee = serializedObject.FindProperty("customRightKnee"); customRightFoot = serializedObject.FindProperty("customRightFoot"); customLeftShoulder = serializedObject.FindProperty("customLeftShoulder"); customLeftElbow = serializedObject.FindProperty("customLeftElbow"); customLeftHand = serializedObject.FindProperty("customLeftHand"); customLeftHip = serializedObject.FindProperty("customLeftHip"); customLeftKnee = serializedObject.FindProperty("customLeftKnee"); customLeftFoot = serializedObject.FindProperty("customLeftFoot"); customLeftThumb = serializedObject.FindProperty("customLeftThumb"); customRightThumb = serializedObject.FindProperty("customRightThumb"); skeletonController = target as RUISSkeletonController; }
void FixedUpdate() { // if(characterController != null && characterController.useOculusPositionalTracking /*&& UnityEditorInternal.InternalEditorUtility.HasPro()*/) // { // if(OVRDevice.IsCameraTracking() && oculusHmdObject != null) // { // ovrTrackingState trackingState = oculusHmdObject.GetTrackingState(Hmd.GetTimeInSeconds()); // // headPosition = new Vector3(trackingState.HeadPose.ThePose.Position.x, trackingState.HeadPose.ThePose.Position.y, trackingState.HeadPose.ThePose.Position.z); // torsoPosition = coordinateSystem.ConvertLocation(coordinateSystem.ConvertRawOculusDK2Location(headPosition), RUISDevice.Oculus_DK2); // // measuredPos[0] = torsoPosition.x; // measuredPos[1] = torsoPosition.y; // measuredPos[2] = torsoPosition.z; // positionKalman.setR(Time.fixedDeltaTime * positionNoiseCovariance); // positionKalman.predict(); // positionKalman.update(measuredPos); // pos = positionKalman.getState(); // torsoPosition.x = (float) pos[0]; // torsoPosition.y = (float) pos[1] - coordinateYOffset; // torsoPosition.z = (float) pos[2]; // // newLocalPosition = torsoPosition; // newLocalPosition.y = (torsoPosition.y)/ 2 + coordinateYOffset; // } // } // Tuukka: // Original skeletonController has been destroyed because the GameObject which had // it has been split in three parts: Kinect, Mecanim, Blended. Lets fetch the new one. if (!combinerChildrenInstantiated && kinectAndMecanimCombinerExists) { if (gameObject.transform.parent != null) { RUISKinectAndMecanimCombiner combiner = gameObject.transform.parent.GetComponentInChildren <RUISKinectAndMecanimCombiner>(); if (combiner && combiner.isChildrenInstantiated()) { skeletonController = combiner.skeletonController; if (skeletonController == null) { Debug.LogError("Could not find Component " + typeof(RUISSkeletonController) + " from " + "children of " + gameObject.transform.parent.name + ", something is very wrong with this character setup!"); } bodyTrackingDeviceID = skeletonController.bodyTrackingDeviceID; playerId = skeletonController.playerId; combinerChildrenInstantiated = true; } } } if (!skeletonManager || !skeletonManager.skeletons [bodyTrackingDeviceID, playerId].isTracking) { colliderHeight = defaultColliderHeight; if (combinerChildrenInstantiated) { if (skeletonController.followOculusController || skeletonController.followMoveController) { // TODO *** Check that this works with other models. Before with grandma model torsoPos value was: //torsoPos = skeletonController.transform.localPosition + defaultColliderHeight * Vector3.up; torsoPosition = skeletonController.transform.localPosition; torsoPosition.y = defaultColliderHeight; // torsoPos.y is lerped and 0 doesn't seem to work newLocalPosition = torsoPosition; newLocalPosition.y = defaultColliderPosition.y; measuredPos[0] = torsoPosition.x; measuredPos[1] = torsoPosition.y; measuredPos[2] = torsoPosition.z; positionKalman.setR(Time.fixedDeltaTime * positionSmoothing); positionKalman.predict(); positionKalman.update(measuredPos); pos = positionKalman.getState(); torsoPosition.x = (float)pos[0]; torsoPosition.y = (float)pos[1]; torsoPosition.z = (float)pos[2]; } else { //colliderHeight = defaultColliderHeight; //transform.localPosition = defaultColliderPosition; return; } } else { //colliderHeight = defaultColliderHeight; //transform.localPosition = defaultColliderPosition; return; } } else { if (coordinateSystem && (coordinateSystem.applyToRootCoordinates || (bodyTrackingDeviceID == RUISSkeletonManager.kinect2SensorID && coordinateSystem.rootDevice == RUISDevice.Kinect_2) || (bodyTrackingDeviceID == RUISSkeletonManager.kinect1SensorID && coordinateSystem.rootDevice == RUISDevice.Kinect_1))) { coordinateYOffset = coordinateSystem.positionOffset.y; } // Apply root scaling if (skeletonController) { torsoPosition = Vector3.Scale(skeletonManager.skeletons [bodyTrackingDeviceID, playerId].torso.position, skeletonController.rootSpeedScaling); } else { torsoPosition = skeletonManager.skeletons [bodyTrackingDeviceID, playerId].torso.position; } measuredPos[0] = torsoPosition.x; measuredPos[1] = torsoPosition.y; measuredPos[2] = torsoPosition.z; positionKalman.setR(Time.fixedDeltaTime * positionSmoothing); positionKalman.predict(); positionKalman.update(measuredPos); pos = positionKalman.getState(); torsoPosition.x = (float)pos[0]; torsoPosition.y = (float)pos[1] - coordinateYOffset; torsoPosition.z = (float)pos[2]; // Capsule collider is from floor up till torsoPos, therefore the capsule's center point is half of that newLocalPosition = torsoPosition; newLocalPosition.y = (torsoPosition.y) / 2 + coordinateYOffset; } // Updated collider height (from floor to torsoPos) colliderHeight = Mathf.Lerp(capsuleCollider.height, torsoPosition.y + colliderHeightTweaker, maxHeightChange * Time.fixedDeltaTime); // Updated collider position transform.localPosition = Vector3.MoveTowards(transform.localPosition, newLocalPosition, maxPositionChange * Time.fixedDeltaTime); }
void Start() { Vector3 initialLocalScale = transform.localScale; skeletonManager = FindObjectOfType(typeof(RUISSkeletonManager)) as RUISSkeletonManager; skeletonController = GetComponent <RUISSkeletonController>(); // if ( !inputManager.enableKinect && !inputManager.enableKinect2 // && (skeletonController.bodyTrackingDevice != RUISSkeletonController.bodyTrackingDeviceType.GenericMotionTracker)) if (skeletonController != null && (skeletonController.followHmdPosition || inputManager == null || (skeletonController.followMoveController && ((skeletonController.bodyTrackingDeviceID == RUISSkeletonManager.kinect1SensorID && !inputManager.enableKinect) || (skeletonController.bodyTrackingDeviceID == RUISSkeletonManager.kinect2SensorID && !inputManager.enableKinect2))))) { // Without the below if-clause the legs will twist with PS Move head tracker (when Move is enabled but Kinect is not) //if(!inputManager.enablePSMove) torsoBlendWeight = 1; headBlendWeight = 1; rightArmBlendWeight = 1; leftArmBlendWeight = 1; rightLegBlendWeight = 1; leftLegBlendWeight = 1; // forceArmStartPosition = false; // forceLegStartPosition = false; } if (!childrenInstantiated) { childrenInstantiated = true; kinectGameObject = Instantiate(gameObject, transform.position, transform.rotation) as GameObject; kinectGameObject.name = name + "Kinect"; kinectGameObject.transform.parent = transform.parent; kinectGameObject.transform.localScale = initialLocalScale; //kinectGameObject.GetComponent<RUISKinectAndMecanimCombiner>().childrenInstantiated = true; Destroy(kinectGameObject.GetComponent <RUISKinectAndMecanimCombiner>()); Destroy(kinectGameObject.GetComponent <Animator>()); Destroy(kinectGameObject.GetComponent <RUISCharacterAnimationController>()); foreach (Collider collider in kinectGameObject.GetComponentsInChildren <Collider>()) { Destroy(collider); } foreach (Renderer meshRenderer in kinectGameObject.GetComponentsInChildren <Renderer>()) { Destroy(meshRenderer); } mecanimGameObject = Instantiate(gameObject, transform.position, transform.rotation) as GameObject; mecanimGameObject.name = name + "Mecanim"; mecanimGameObject.transform.parent = transform.parent; mecanimGameObject.transform.localScale = initialLocalScale; Destroy(mecanimGameObject.GetComponent <RUISKinectAndMecanimCombiner>()); Destroy(mecanimGameObject.GetComponent <RUISCharacterAnimationController>()); Destroy(mecanimGameObject.GetComponent <RUISSkeletonController>()); foreach (Collider collider in mecanimGameObject.GetComponentsInChildren <Collider>()) { Destroy(collider); } foreach (Renderer meshRenderer in mecanimGameObject.GetComponentsInChildren <Renderer>()) { Destroy(meshRenderer); } Destroy(GetComponent <RUISSkeletonController>()); Destroy(GetComponent <Animator>()); GetComponent <RUISCharacterAnimationController>().animator = mecanimGameObject.GetComponent <Animator>(); skeletonController = kinectGameObject.GetComponent <RUISSkeletonController>(); mecanimAnimator = mecanimGameObject.GetComponent <Animator>(); if (!skeletonController) { Debug.LogError("Script " + typeof(RUISSkeletonController) + " is not found by " + this.GetType().Name + "!"); } torsoIsRoot = skeletonController.root == skeletonController.torso; Transform kinectRootBone = skeletonController.root; Transform mecanimRootBone = FindBone(mecanimAnimator.transform, kinectRootBone.name); Transform blendedRootBone = FindBone(transform, kinectRootBone.name); skeletonRoot = new BoneTriplet(kinectRootBone, mecanimRootBone, blendedRootBone, BodypartClassification.Root); if (torsoIsRoot) { torsoRoot = skeletonRoot; AddChildren(ref torsoRoot, BodypartClassification.Torso); } else { AddChildren(ref skeletonRoot, BodypartClassification.Root); } } }
void Start() { if (!childrenInstantiated) { childrenInstantiated = true; kinectGameObject = Instantiate(gameObject, transform.position, transform.rotation) as GameObject; kinectGameObject.name = name + "Kinect"; kinectGameObject.transform.parent = transform.parent; //kinectGameObject.GetComponent<RUISKinectAndMecanimCombiner>().childrenInstantiated = true; Destroy(kinectGameObject.GetComponent <RUISKinectAndMecanimCombiner>()); Destroy(kinectGameObject.GetComponent <Animator>()); Destroy(kinectGameObject.GetComponent <RUISCharacterAnimationController>()); foreach (Collider collider in kinectGameObject.GetComponentsInChildren <Collider>()) { Destroy(collider); } foreach (Renderer meshRenderer in kinectGameObject.GetComponentsInChildren <Renderer>()) { Destroy(meshRenderer); } mecanimGameObject = Instantiate(gameObject, transform.position, transform.rotation) as GameObject; mecanimGameObject.name = name + "Mecanim"; mecanimGameObject.transform.parent = transform.parent; Destroy(mecanimGameObject.GetComponent <RUISKinectAndMecanimCombiner>()); Destroy(mecanimGameObject.GetComponent <RUISCharacterAnimationController>()); Destroy(mecanimGameObject.GetComponent <RUISSkeletonController>()); foreach (Collider collider in mecanimGameObject.GetComponentsInChildren <Collider>()) { Destroy(collider); } foreach (Renderer meshRenderer in mecanimGameObject.GetComponentsInChildren <Renderer>()) { Destroy(meshRenderer); } Destroy(GetComponent <RUISSkeletonController>()); Destroy(GetComponent <Animator>()); GetComponent <RUISCharacterAnimationController>().animator = mecanimGameObject.GetComponent <Animator>(); skeletonController = kinectGameObject.GetComponent <RUISSkeletonController>(); mecanimAnimator = mecanimGameObject.GetComponent <Animator>(); torsoIsRoot = skeletonController.root == skeletonController.torso; Transform kinectRootBone = skeletonController.root; Transform mecanimRootBone = FindBone(mecanimAnimator.transform, kinectRootBone.name); Transform blendedRootBone = FindBone(transform, kinectRootBone.name); skeletonRoot = new BoneTriplet(kinectRootBone, mecanimRootBone, blendedRootBone, BodypartClassification.Root); if (torsoIsRoot) { torsoRoot = skeletonRoot; AddChildren(ref torsoRoot, BodypartClassification.Torso); } else { AddChildren(ref skeletonRoot, BodypartClassification.Root); } } }
public RUISKinect2ToKinectCalibrationProcess(RUISCalibrationProcessSettings calibrationSettings) { this.inputDevice1 = RUISDevice.Kinect_2; this.inputDevice2 = RUISDevice.Kinect_1; this.numberOfSamplesToTake = calibrationSettings.numberOfSamplesToTake; this.numberOfSamplesPerSecond = calibrationSettings.numberOfSamplesPerSecond; trackingIDs = new trackedBody[6]; for (int y = 0; y < trackingIDs.Length; y++) { trackingIDs[y] = new trackedBody(-1, false, 1); } kinectSelection = MonoBehaviour.FindObjectOfType(typeof(NIPlayerManagerCOMSelection)) as NIPlayerManagerCOMSelection; settingsManager = MonoBehaviour.FindObjectOfType(typeof(OpenNISettingsManager)) as OpenNISettingsManager; inputManager = MonoBehaviour.FindObjectOfType(typeof(RUISInputManager)) as RUISInputManager; coordinateSystem = MonoBehaviour.FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem; kinect2SourceManager = MonoBehaviour.FindObjectOfType(typeof(Kinect2SourceManager)) as Kinect2SourceManager; this.timeSinceScriptStart = 0; this.timeBetweenSamples = 1 / (float)numberOfSamplesPerSecond; // Limit sample rate if (this.timeBetweenSamples < 0.1f) { this.timeBetweenSamples = 0.1f; } calibrationSpheres = new List <GameObject>(); samples_Kinect1 = new List <Vector3>(); samples_Kinect2 = new List <Vector3>(); this.calibrationCube = calibrationSettings.calibrationCubePrefab; this.calibrationSphere = calibrationSettings.calibrationSpherePrefab; this.calibrationPhaseObjects = calibrationSettings.calibrationPhaseObjects; this.calibrationResultPhaseObjects = calibrationSettings.calibrationResultPhaseObjects; this.deviceModelObjects = calibrationSettings.deviceModelObjects; this.depthViewObjects = calibrationSettings.depthViewObjects; this.iconObjects = calibrationSettings.iconObjects; if (GameObject.Find("PSMoveWand") != null) { GameObject.Find("PSMoveWand").SetActive(false); } // Models this.kinect1ModelObject = GameObject.Find("KinectCamera"); this.kinect2ModelObject = GameObject.Find("Kinect2Camera"); RUISSkeletonController skeletonController = Component.FindObjectOfType <RUISSkeletonController>(); Transform rightHand = null; if (skeletonController) { rightHand = skeletonController.rightHand; } FixedFollowTransform followTransform = Component.FindObjectOfType <FixedFollowTransform>(); if (followTransform && rightHand) { followTransform.transformToFollow = rightHand; } // Depth view this.depthView = GameObject.Find("KinectDepthView"); this.depthView2 = GameObject.Find("Kinect2DepthView"); // Icons this.Kinect1Icon = GameObject.Find("Kinect Icon"); this.Kinect2Icon = GameObject.Find("Kinect2 Icon"); this.floorPlane = GameObject.Find("Floor"); if (this.Kinect1Icon && this.Kinect1Icon.GetComponent <GUITexture>()) { this.Kinect1Icon.GetComponent <GUITexture>().pixelInset = new Rect(5.1f, 10.0f, 70.0f, 70.0f); } foreach (Transform child in this.deviceModelObjects.transform) { child.gameObject.SetActive(false); } foreach (Transform child in this.depthViewObjects.transform) { child.gameObject.SetActive(false); } foreach (Transform child in this.iconObjects.transform) { child.gameObject.SetActive(false); } if (this.kinect1ModelObject) { this.kinect1ModelObject.SetActive(true); } if (this.kinect2ModelObject) { this.kinect2ModelObject.SetActive(true); } if (this.Kinect1Icon) { this.Kinect1Icon.SetActive(true); } if (this.Kinect2Icon) { this.Kinect2Icon.SetActive(true); } if (this.calibrationPhaseObjects) { this.calibrationPhaseObjects.SetActive(true); } if (this.calibrationResultPhaseObjects) { this.calibrationResultPhaseObjects.SetActive(false); } if (this.depthView) { this.depthView.SetActive(true); } if (this.depthView2) { this.depthView2.SetActive(true); } this.xmlFilename = calibrationSettings.xmlFilename; }
void Start() { colliding = false; grounded = false; // Second substitution, because RUISKinectAndMecanimCombiner might have already erased the original one and re-created it skeletonController = gameObject.GetComponentInChildren <RUISSkeletonController>(); if (skeletonController) { bodyParts.Add(skeletonController.leftFoot); bodyParts.Add(skeletonController.rightFoot); kinectPlayerId = skeletonController.playerId; bodyTrackingDeviceID = skeletonController.bodyTrackingDeviceID; } else { Debug.LogError("RUISCharacterController script in game object '" + gameObject.name + "' did not find RUISSkeletonController component from it's child objects!"); } coordinateSystem = FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem; if (stabilizingCollider) { colliderComponent = stabilizingCollider.gameObject.GetComponent <Collider>(); if (colliderComponent) { if (characterPivotType == CharacterPivotType.KinectHead || characterPivotType == CharacterPivotType.KinectTorso) { if (coordinateSystem && inputManager.enableKinect && !coordinateSystem.setKinectOriginToFloor) { Debug.LogWarning("It is best to enable 'setKinectOriginToFloor' from RUISCoordinateSystem " + "when using Kinect and RUISCharacterController script."); } } if (colliderComponent.material) { originalMaterial = colliderComponent.material; } else { colliderComponent.material = new PhysicMaterial(); originalMaterial = colliderComponent.material; } if (dynamicMaterial == null) { dynamicMaterial = new PhysicMaterial(); dynamicMaterial.dynamicFriction = 0; dynamicMaterial.staticFriction = 0; dynamicMaterial.frictionCombine = PhysicMaterialCombine.Minimum; if (colliderComponent.material) { /*dynamicMaterial.bounceCombine = originalMaterial.bounceCombine; * dynamicMaterial.bounciness = originalMaterial.bounciness; * dynamicMaterial.staticFriction2 = originalMaterial.staticFriction2; * dynamicMaterial.dynamicFriction2 = originalMaterial.dynamicFriction2; * dynamicMaterial.frictionDirection2 = originalMaterial.frictionDirection2;*/ } } } } if ((characterPivotType == CharacterPivotType.KinectHead || characterPivotType == CharacterPivotType.KinectTorso) && (skeletonController && skeletonController.playerId != kinectPlayerId)) { Debug.LogError("The 'Kinect Player Id' variable in RUISCharacterController script in gameObject '" + gameObject.name + "is different from the Kinect Player Id of the RUISSkeletonController script (located in child " + "object '" + skeletonController.gameObject.name + "). Make sure that these two values are " + "the same."); } //#if UNITY_EDITOR //if(UnityEditorInternal.InternalEditorUtility.HasPro()) //#endif { try { bool isRiftConnected = false; if (OVRManager.display != null) { isRiftConnected = OVRManager.display.isPresent; } if (OVRManager.capiHmd != null) { ovrHmdVersion = OVRManager.capiHmd.GetDesc().Type; } if (useOculusPositionalTracking && ovrHmdVersion == Ovr.HmdType.DK1 || ovrHmdVersion == Ovr.HmdType.DKHD || ovrHmdVersion == Ovr.HmdType.None) { Debug.LogError("Can't use Oculus Rift's tracked position as a pivot with Oculus Rift " + ovrHmdVersion); useOculusPositionalTracking = false; } if (useOculusPositionalTracking && !isRiftConnected) { Debug.LogError("Can't use Oculus Rift's tracked position as a pivot because Oculus Rift is not connected."); useOculusPositionalTracking = false; } } catch (UnityException e) { useOculusPositionalTracking = false; Debug.LogError(e); } } if (GetComponentInChildren <RUISKinectAndMecanimCombiner>()) { kinectAndMecanimCombinerExists = true; } previousPosition = transform.position; }
void Update() { if(!combinerChildrenInstantiated) skeletonController = getSkeletonController(); // Check whether character collider (aka stabilizingCollider) is grounded raycastPosition = (stabilizingCollider? stabilizingCollider.transform.position : transform.position ); distanceToRaycast = (stabilizingCollider ? stabilizingCollider.colliderHeight / 2 : 1.5f); distanceToRaycast += groundedErrorTweaker; distanceToRaycast = Mathf.Max(distanceToRaycast * transform.lossyScale.y, float.Epsilon); tempGrounded = Physics.Raycast(raycastPosition, -transform.up, distanceToRaycast, groundLayers.value); // Check if feet are grounded if(!tempGrounded && feetAlsoAffectGrounding) { foreach(Transform bodyPart in bodyParts) { if(bodyPart && bodyPart.GetComponent<Collider>()) { raycastPosition = bodyPart.GetComponent<Collider>().bounds.center; distanceToRaycast = (bodyPart.GetComponent<Collider>().bounds.extents.y + groundedErrorTweaker) * transform.lossyScale.y; rayIntersected = Physics.Raycast(raycastPosition, -transform.up, out hitInfo, distanceToRaycast, groundLayers.value ); if(rayIntersected && hitInfo.rigidbody) { if(!hitInfo.rigidbody.isKinematic) { tempGrounded = true; break; } } } } } grounded = tempGrounded; // *** HACK: for fixing weird drift that is probably related to RUISKinectAndMecanimCombiner's transform.position update and possibly stabilizing collider & others // TODO: Does such miniscular position update affect how physics collision is handled? N.B. MovePosition is not used in RUISKinectAndMecanimCombiner right now if((transform.position - previousPosition).magnitude * Mathf.Max(Mathf.Abs(transform.lossyScale.x), Mathf.Max( Mathf.Abs(transform.lossyScale.y), Mathf.Abs(transform.lossyScale.z))) < 0.0009f) transform.position = previousPosition; previousPosition = transform.position; }
void FixedUpdate() { if(coordinateSystem) { coordinateYOffset = coordinateSystem.positionOffset.y; } Vector3 torsoPos; Vector3 newLocalPosition; if (!skeletonManager || !skeletonManager.skeletons[playerId].isTracking) { colliderHeight = defaultColliderHeight; // Tuukka: // Original skeletonController has been destroyed because the GameObject which had // it has been split in three parts: Kinect, Mecanim, Blended. Lets fetch the new one. if (!combinerChildrenInstantiated && kinectAndMecanimCombinerExists) { if (gameObject.transform.parent != null) { RUISKinectAndMecanimCombiner combiner = gameObject.transform.parent.GetComponentInChildren<RUISKinectAndMecanimCombiner>(); if (combiner && combiner.isChildrenInstantiated()) { skeletonController = combiner.skeletonController; combinerChildrenInstantiated = true; } } } if (combinerChildrenInstantiated) { if (skeletonController.followMoveController) { // TODO *** Check that this works with other models. Before with grandma model torsoPos value was: //torsoPos = skeletonController.transform.localPosition + defaultColliderHeight * Vector3.up; torsoPos = skeletonController.transform.localPosition; torsoPos.y = defaultColliderHeight; // torsoPos.y is lerped and 0 doesn't seem to work newLocalPosition = torsoPos; newLocalPosition.y = defaultColliderPosition.y; measuredPos[0] = torsoPos.x; measuredPos[1] = torsoPos.y; measuredPos[2] = torsoPos.z; positionKalman.setR(Time.fixedDeltaTime * positionNoiseCovariance); positionKalman.predict(); positionKalman.update(measuredPos); pos = positionKalman.getState(); torsoPos.x = (float) pos[0]; torsoPos.y = (float) pos[1]; torsoPos.z = (float) pos[2]; } else { colliderHeight = defaultColliderHeight; transform.localPosition = defaultColliderPosition; return; } } else { colliderHeight = defaultColliderHeight; transform.localPosition = defaultColliderPosition; return; } } else { torsoPos = skeletonManager.skeletons[playerId].torso.position; measuredPos[0] = torsoPos.x; measuredPos[1] = torsoPos.y; measuredPos[2] = torsoPos.z; positionKalman.setR(Time.fixedDeltaTime * positionNoiseCovariance); positionKalman.predict(); positionKalman.update(measuredPos); pos = positionKalman.getState(); torsoPos.x = (float) pos[0]; torsoPos.y = (float) pos[1] - coordinateYOffset; torsoPos.z = (float) pos[2]; // Capsule collider is from floor up till torsoPos, therefore the capsule's center point is half of that newLocalPosition = torsoPos; newLocalPosition.y = (torsoPos.y)/ 2 + coordinateYOffset; } // Updated collider height (from floor to torsoPos) colliderHeight = Mathf.Lerp(capsuleCollider.height, torsoPos.y + colliderHeightTweaker, maxHeightChange * Time.fixedDeltaTime); // Updated collider position transform.localPosition = Vector3.MoveTowards(transform.localPosition, newLocalPosition, maxPositionChange * Time.fixedDeltaTime); }
public void Awake() { skeletonController = FindObjectOfType(typeof(RUISSkeletonController)) as RUISSkeletonController; pointTrackerLeftHand = leftHandWithPointTracker.GetComponent<RUISPointTracker>(); pointTrackerRightHand = rightHandWithPointTracker.GetComponent<RUISPointTracker>(); skeletonManager = FindObjectOfType(typeof(RUISSkeletonManager)) as RUISSkeletonManager; ResetProgress(); }
RUISSkeletonController getSkeletonController() { // Original skeletonController has been destroyed because the GameObject which had // it has been split in three parts: Kinect, Mecanim, Blended. Lets fetch the new one. if (!combinerChildrenInstantiated && kinectAndMecanimCombinerExists) { RUISKinectAndMecanimCombiner combiner = GetComponentInChildren<RUISKinectAndMecanimCombiner>(); if (combiner && combiner.isChildrenInstantiated()) { skeletonController = combiner.skeletonController; if(skeletonController == null) Debug.LogError( "Could not find Component " + typeof(RUISSkeletonController) + " from " + "children of " + gameObject.name + ", something is very wrong with this character setup!"); combinerChildrenInstantiated = true; } } return skeletonController; }
void Start() { if (!childrenInstantiated) { childrenInstantiated = true; kinectGameObject = Instantiate(gameObject, transform.position, transform.rotation) as GameObject; kinectGameObject.name = name + "Kinect"; kinectGameObject.transform.parent = transform.parent; //kinectGameObject.GetComponent<RUISKinectAndMecanimCombiner>().childrenInstantiated = true; Destroy(kinectGameObject.GetComponent<RUISKinectAndMecanimCombiner>()); Destroy(kinectGameObject.GetComponent<Animator>()); Destroy(kinectGameObject.GetComponent<RUISCharacterAnimationController>()); foreach (Collider collider in kinectGameObject.GetComponentsInChildren<Collider>()) { Destroy(collider); } foreach (Renderer meshRenderer in kinectGameObject.GetComponentsInChildren<Renderer>()) { Destroy(meshRenderer); } mecanimGameObject = Instantiate(gameObject, transform.position, transform.rotation) as GameObject; mecanimGameObject.name = name + "Mecanim"; mecanimGameObject.transform.parent = transform.parent; Destroy(mecanimGameObject.GetComponent<RUISKinectAndMecanimCombiner>()); Destroy(mecanimGameObject.GetComponent<RUISCharacterAnimationController>()); Destroy(mecanimGameObject.GetComponent<RUISSkeletonController>()); foreach (Collider collider in mecanimGameObject.GetComponentsInChildren<Collider>()) { Destroy(collider); } foreach (Renderer meshRenderer in mecanimGameObject.GetComponentsInChildren<Renderer>()) { Destroy(meshRenderer); } Destroy(GetComponent<RUISSkeletonController>()); Destroy(GetComponent<Animator>()); GetComponent<RUISCharacterAnimationController>().animator = mecanimGameObject.GetComponent<Animator>(); skeletonController = kinectGameObject.GetComponent<RUISSkeletonController>(); mecanimAnimator = mecanimGameObject.GetComponent<Animator>(); torsoIsRoot = skeletonController.root == skeletonController.torso; Transform kinectRootBone = skeletonController.root; Transform mecanimRootBone = FindBone(mecanimAnimator.transform, kinectRootBone.name); Transform blendedRootBone = FindBone(transform, kinectRootBone.name); skeletonRoot = new BoneTriplet(kinectRootBone, mecanimRootBone, blendedRootBone, BodypartClassification.Root); if (torsoIsRoot) { torsoRoot = skeletonRoot; AddChildren(ref torsoRoot, BodypartClassification.Torso); } else { AddChildren(ref skeletonRoot, BodypartClassification.Root); } } }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.PropertyField(characterPivotType, new GUIContent("CharacterCamera Pivot Type", "Rotation pivot for the character, in other words, " + "what is the rotation center for the character when turning with the " + typeof(RUISCharacterLocomotion).Name + " script. Pivot orientation also defines " + "the Forward movement direction. Currently 'Kinect Head' is NOT recommended.")); RUISSkeletonController.bodyTrackingDeviceType bodyTrackingDevice = RUISSkeletonController.bodyTrackingDeviceType.Kinect1; int kinectPlayerId = 0; if (characterController) { RUISSkeletonController skeletonController = characterController.GetComponentInChildren(typeof(RUISSkeletonController)) as RUISSkeletonController; if (skeletonController) { kinectPlayerId = skeletonController.playerId; bodyTrackingDevice = skeletonController.bodyTrackingDevice; } } EditorGUI.indentLevel += 2; switch (characterPivotType.enumValueIndex) { case (int)RUISCharacterController.CharacterPivotType.KinectHead: EditorGUILayout.LabelField(new GUIContent(bodyTrackingDevice.ToString() + " Skeleton ID " + kinectPlayerId, "You can change this value from " + typeof(RUISSkeletonController).ToString() + " script that is in one of the child objects.")); break; case (int)RUISCharacterController.CharacterPivotType.KinectTorso: EditorGUILayout.LabelField(new GUIContent(bodyTrackingDevice.ToString() + " Skeleton ID " + kinectPlayerId, "You can change this value from " + typeof(RUISSkeletonController).ToString() + " script that is in one of the child objects.")); break; case (int)RUISCharacterController.CharacterPivotType.MoveController: { moveControllerId.intValue = Mathf.Clamp(moveControllerId.intValue, 0, maxPSMoveControllers - 1); EditorGUILayout.PropertyField(moveControllerId, new GUIContent("PS Move ID", "Between 0 and 3")); EditorGUILayout.PropertyField(psmoveOffset, new GUIContent("Position Offset (meters)", "PS Move controller's position in " + "the tracked pivot's local coordinate system. Set these values " + "according to the controller's offset from the tracked pivot's " + "origin (torso center point etc.).")); break; } } EditorGUILayout.PropertyField(useOculusPositionalTracking, new GUIContent("Oculus Is Pivot", "Use Oculus Rift's tracked position (DK2 or newer) as " + "the primary character pivot position, and fall back to the above defined pivot only in " + "situations where Oculus Rift is not seen by its camera. Leave this option disabled if you " + "do not know what you are doing! NOTE: The above defined pivot device (Kinect/PS Move) must " + "have its coordinate system calibrated with Oculus Rift DK2 using the RUIS device calibration.")); EditorGUILayout.PropertyField(headRotatesBody, new GUIContent("Head Rotates Body", "Set the model of the avatar to have the same rotation as the tracked head. " + "This only has effect when both Kinects are disabled from " + typeof(RUISInputManager) + " or " + "PS Move is set as the CharacterCamera Pivot.")); EditorGUILayout.PropertyField(headPointsWalkingDirection, new GUIContent("Head Points Walking Direction", "Let the tracked head forward direction to determine " + "the walk forward direction for character locomotion controls. This only has effect " + "when both Kinects are disabled from " + typeof(RUISInputManager) + " or " + "PS Move is set as the CharacterCamera Pivot.")); EditorGUI.indentLevel -= 2; EditorGUILayout.PropertyField(ignorePitchAndRoll, new GUIContent("Ignore Pitch and Roll", "Should the pitch and roll values of the pivot " + "rotation be taken into account when transforming directions into character " + "coordinates? In most cases this should be enabled.")); EditorGUILayout.PropertyField(groundLayers, new GUIContent("Ground Layers", "The layers to take into account when checking whether the character is grounded " + "(and able to jump).")); EditorGUILayout.PropertyField(groundedErrorTweaker, new GUIContent("Ground Distance Tweaker", "This value (in meters) can be adjusted to allow for some " + "leniency in the checks whether the character is grounded. Should be above zero.")); EditorGUILayout.PropertyField(dynamicFriction, new GUIContent("Dynamic Friction", "Enable this if you want the character collider to switch " + "to a different Physics Material whenever the character is not grounded. We " + "recommend that you enable this.")); if (dynamicFriction.boolValue) { EditorGUI.indentLevel += 2; EditorGUILayout.PropertyField(dynamicMaterial, new GUIContent("Dynamic Material", "We recommend that you leave this to None. Then a " + "frictionless material will be used and the character won't be able to " + "climb walls with friction, and he will slide down steep hills.")); EditorGUI.indentLevel -= 2; } EditorGUILayout.PropertyField(feetAlsoAffectGrounding, new GUIContent("Feet Affect Grounding", "When this option is disabled, the " + "avatar is grounded (and able to jump) only if its Stabilizing Collider is " + "standing on a collider from Ground Layers. By enabling this option, " + "the avatar will also be grounded when at least one of its feet is " + "standing on a non-kinematic Rigidbody from Ground Layers. We recommend " + "that you enable this.")); serializedObject.ApplyModifiedProperties(); }
void Start() { skelController = MechBlendChar.GetComponent<RUISSkeletonController>(); }
void Awake () { Cursor.visible = true; // Incase cursor was hidden in previous scene // Check if calibration settings were chosen on previous scene ruisNGUIMenu = FindObjectOfType(typeof(RUISMenuNGUI)) as RUISMenuNGUI; if(ruisNGUIMenu != null) { if(ruisNGUIMenu.currentMenuState == RUISMenuNGUI.RUISMenuStates.calibration) { numberOfSamplesToTake = 50; samplesPerSecond = 5; switch(ruisNGUIMenu.calibrationDropDownSelection) { case "Kinect - Kinect2": firstDevice = RUISDevice.Kinect_1; secondDevice = RUISDevice.Kinect_2; break; case "Kinect - PSMove": firstDevice = RUISDevice.Kinect_1; secondDevice = RUISDevice.PS_Move; break; case "Kinect 2 - PSMove": firstDevice = RUISDevice.Kinect_2; secondDevice = RUISDevice.PS_Move; break; case "Kinect 2 - Oculus DK2": firstDevice = RUISDevice.Kinect_2; secondDevice = RUISDevice.Oculus_DK2; break; case "Kinect - Oculus DK2": firstDevice = RUISDevice.Kinect_1; secondDevice = RUISDevice.Oculus_DK2; break; case "PSMove - Oculus DK2": firstDevice = RUISDevice.PS_Move; secondDevice = RUISDevice.Oculus_DK2; break; case "Kinect floor data": firstDevice = RUISDevice.Kinect_1; secondDevice = RUISDevice.Kinect_1; break; case "Kinect 2 floor data": firstDevice = RUISDevice.Kinect_2; secondDevice = RUISDevice.Kinect_2; break; default: firstDevice = RUISDevice.Null; secondDevice = RUISDevice.Null; break; } } } // Init scene objects this.floorPlane = GameObject.Find ("Floor"); this.calibrationPhaseObjects = GameObject.Find("CalibrationPhase"); this.calibrationResultPhaseObjects = GameObject.Find("ResultPhase"); this.depthViews = GameObject.Find ("Depth views"); this.deviceModels = GameObject.Find ("Device models"); this.icons = GameObject.Find ("Icons"); upperText = GameObject.Find ("Upper Text").GetComponent<GUIText>(); lowerText = GameObject.Find ("Lower Text").GetComponent<GUIText>(); skeletonController = FindObjectOfType(typeof(RUISSkeletonController)) as RUISSkeletonController; coordinateSystem = FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem; // Pass variables and objects to calibrationProcess calibrationProcessSettings = new RUISCalibrationProcessSettings(); calibrationProcessSettings.xmlFilename = xmlFilename; calibrationProcessSettings.numberOfSamplesToTake = numberOfSamplesToTake; calibrationProcessSettings.numberOfSamplesPerSecond = samplesPerSecond; calibrationProcessSettings.calibrationCubePrefab = this.sampleCube; calibrationProcessSettings.calibrationSpherePrefab = this.sampleSphere; calibrationProcessSettings.calibrationPhaseObjects = this.calibrationPhaseObjects; calibrationProcessSettings.calibrationResultPhaseObjects = this.calibrationResultPhaseObjects; calibrationProcessSettings.deviceModelObjects = deviceModels; calibrationProcessSettings.depthViewObjects = depthViews; calibrationProcessSettings.iconObjects = icons; }
void Awake() { Cursor.visible = true; // Incase cursor was hidden in previous scene // Check if calibration settings were chosen on previous scene ruisNGUIMenu = FindObjectOfType(typeof(RUISMenuNGUI)) as RUISMenuNGUI; if (ruisNGUIMenu != null) { if (ruisNGUIMenu.currentMenuState == RUISMenuNGUI.RUISMenuStates.calibration) { numberOfSamplesToTake = 50; samplesPerSecond = 5; switch (ruisNGUIMenu.calibrationDropDownSelection) { case "Kinect - Kinect2": firstDevice = RUISDevice.Kinect_1; secondDevice = RUISDevice.Kinect_2; break; case "Kinect - PSMove": firstDevice = RUISDevice.Kinect_1; secondDevice = RUISDevice.PS_Move; break; case "Kinect 2 - PSMove": firstDevice = RUISDevice.Kinect_2; secondDevice = RUISDevice.PS_Move; break; case "Kinect 2 - Oculus DK2": firstDevice = RUISDevice.Kinect_2; secondDevice = RUISDevice.Oculus_DK2; break; case "Kinect - Oculus DK2": firstDevice = RUISDevice.Kinect_1; secondDevice = RUISDevice.Oculus_DK2; break; case "PSMove - Oculus DK2": firstDevice = RUISDevice.PS_Move; secondDevice = RUISDevice.Oculus_DK2; break; case "Kinect floor data": firstDevice = RUISDevice.Kinect_1; secondDevice = RUISDevice.Kinect_1; break; case "Kinect 2 floor data": firstDevice = RUISDevice.Kinect_2; secondDevice = RUISDevice.Kinect_2; break; default: firstDevice = RUISDevice.Null; secondDevice = RUISDevice.Null; break; } } } // Init scene objects this.floorPlane = GameObject.Find("Floor"); this.calibrationPhaseObjects = GameObject.Find("CalibrationPhase"); this.calibrationResultPhaseObjects = GameObject.Find("ResultPhase"); this.depthViews = GameObject.Find("Depth views"); this.deviceModels = GameObject.Find("Device models"); this.icons = GameObject.Find("Icons"); upperText = GameObject.Find("Upper Text").GetComponent <GUIText>(); lowerText = GameObject.Find("Lower Text").GetComponent <GUIText>(); skeletonController = FindObjectOfType(typeof(RUISSkeletonController)) as RUISSkeletonController; coordinateSystem = FindObjectOfType(typeof(RUISCoordinateSystem)) as RUISCoordinateSystem; // Pass variables and objects to calibrationProcess calibrationProcessSettings = new RUISCalibrationProcessSettings(); calibrationProcessSettings.xmlFilename = xmlFilename; calibrationProcessSettings.numberOfSamplesToTake = numberOfSamplesToTake; calibrationProcessSettings.numberOfSamplesPerSecond = samplesPerSecond; calibrationProcessSettings.calibrationCubePrefab = this.sampleCube; calibrationProcessSettings.calibrationSpherePrefab = this.sampleSphere; calibrationProcessSettings.calibrationPhaseObjects = this.calibrationPhaseObjects; calibrationProcessSettings.calibrationResultPhaseObjects = this.calibrationResultPhaseObjects; calibrationProcessSettings.deviceModelObjects = deviceModels; calibrationProcessSettings.depthViewObjects = depthViews; calibrationProcessSettings.iconObjects = icons; }
void FixedUpdate() { Vector3 torsoPos; Vector3 newLocalPosition; if (!skeletonManager || !skeletonManager.skeletons[playerId].isTracking) { colliderHeight = defaultColliderHeight; // Tuukka: // Original skeletonController has been destroyed because the GameObject which had // it has been split in three parts: Kinect, Mecanim, Blended. Lets fetch the new one. if (!combinerChildrenInstantiated && kinectAndMecanimCombinerExists) { if (gameObject.transform.parent != null) { RUISKinectAndMecanimCombiner combiner = gameObject.transform.parent.GetComponentInChildren <RUISKinectAndMecanimCombiner>(); if (combiner && combiner.isChildrenInstantiated()) { skeletonController = combiner.skeletonController; combinerChildrenInstantiated = true; } } } if (combinerChildrenInstantiated) { if (skeletonController.followMoveController) { // TODO *** Check that this works with other models. Before with grandma model torsoPos value was: //torsoPos = skeletonController.transform.localPosition + defaultColliderHeight * Vector3.up; torsoPos = skeletonController.transform.localPosition; torsoPos.y = defaultColliderHeight; // torsoPos.y is lerped and 0 doesn't seem to work newLocalPosition = torsoPos; newLocalPosition.y = defaultColliderPosition.y; measuredPos[0] = torsoPos.x; measuredPos[1] = torsoPos.y; measuredPos[2] = torsoPos.z; positionKalman.setR(Time.fixedDeltaTime * positionNoiseCovariance); positionKalman.predict(); positionKalman.update(measuredPos); pos = positionKalman.getState(); torsoPos.x = (float)pos[0]; torsoPos.y = (float)pos[1]; torsoPos.z = (float)pos[2]; } else { colliderHeight = defaultColliderHeight; transform.localPosition = defaultColliderPosition; return; } } else { colliderHeight = defaultColliderHeight; transform.localPosition = defaultColliderPosition; return; } } else { torsoPos = skeletonManager.skeletons[playerId].torso.position; measuredPos[0] = torsoPos.x; measuredPos[1] = torsoPos.y; measuredPos[2] = torsoPos.z; positionKalman.setR(Time.fixedDeltaTime * positionNoiseCovariance); positionKalman.predict(); positionKalman.update(measuredPos); pos = positionKalman.getState(); torsoPos.x = (float)pos[0]; torsoPos.y = (float)pos[1]; torsoPos.z = (float)pos[2]; // Capsule collider is from floor up till torsoPos, therefore the capsule's center point is half of that newLocalPosition = torsoPos; newLocalPosition.y = torsoPos.y / 2; } // Updated collider height (from floor to torsoPos) colliderHeight = Mathf.Lerp(capsuleCollider.height, torsoPos.y + colliderHeightTweaker, maxHeightChange * Time.fixedDeltaTime); // Updated collider position transform.localPosition = Vector3.MoveTowards(transform.localPosition, newLocalPosition, maxPositionChange * Time.fixedDeltaTime); }