public void ScenePrepare(DrawDetails dd) { if (PoseSource != null) { PoseSource.Get(out world_); } // if animating, then pose it if (instance_ != null) { Matrix temp; Keyframe[] kfs = instance_.CurrentPose; unchecked { int i = 0, n = matrices_.Length; foreach (Keyframe kf in kfs) { if (i == n) { break; } if (kf != null) { kf.ToMatrix(out temp); // set up the model in parent-relative pose model_.Bones[i].Transform = temp; } ++i; } } } else { } // get the object-relative matrices (object->world is separate) model_.CopyAbsoluteBoneTransformsTo(matrices_); #if DRAW_SKELETON // draw the skeleton, but only in debug mode foreach (ModelBone mb in model_.Bones) { if (mb.Parent != null) { Matrix m = matrices_[mb.Index]; Vector3 c = m.Translation; DebugLines.Global.AddLine( c, matrices_[mb.Parent.Index].Translation, Color.White); DebugLines.Global.AddLine( c, c + m.Right * 0.5f, Color.Red); DebugLines.Global.AddLine( c, c + m.Up * 0.5f, Color.Green); DebugLines.Global.AddLine( c, c + m.Backward * 0.5f, Color.Blue); } } #endif // If I have a 3x4 matrix pose, then generate that for skinning if (pose_ != null) { GeneratePose(); } }
public static string GetTraceState(this MotionControllerState state, PoseSource filterInput, bool allChanges, out bool hasNonDefaultValue, out bool hasEvent) { StringBuilder sb = new StringBuilder(); hasNonDefaultValue = false; hasEvent = false; float vector3ThresholdForDifference = 0.2f; float floatThresholdForDifference = 0.02f; if (state.IsLeftHand) { sb.Append(leftPrefix); diffState = pastLeft; } else if (state.IsRightHand) { sb.Append(rightPrefix); diffState = pastRight; } if (state.SelectPressed) { hasEvent = true; sb.AppendFormat("Select Pressed ({0});", state.SelectValue); } if (state.TouchPadPressed || state.TouchPadTouched) { hasEvent = true; sb.AppendFormat("TouchPad {0} {1} ({2},{3});", state.TouchPadPressed ? "Pressed" : "", state.TouchPadTouched ? "Touched" : "", state.TouchPadXValue, state.TouchPadYValue); } if (state.ThumbstickPressed) { hasEvent = true; sb.AppendFormat("Thumbstick pressed({0},{1});", state.ThumbstickXValue, state.ThumbstickYValue); } if (state.MenuPressed) { hasEvent = true; sb.Append("Menu Pressed;"); } if (state.GraspPressed) { hasEvent = true; sb.Append("Grasp Pressed;"); } // Grip position if ((filterInput & PoseSource.Grip) != PoseSource.None) { if (allChanges || (IsDifferent(state.GripPosition, diffState.GripPosition, vector3ThresholdForDifference))) { hasNonDefaultValue = true; sb.AppendFormat("Pos:{0},Rot:{1}", state.GripPosition, state.GripRotation); } } // Pointer position if ((filterInput & PoseSource.Pointer) != PoseSource.None) { if (allChanges || (IsDifferent(state.PointerPosition, diffState.PointerPosition, vector3ThresholdForDifference))) { hasNonDefaultValue = true; sb.AppendFormat("PointPos:{0},PointRot:{1}", state.PointerPosition, state.PointerRotation); } } if (allChanges || (IsDifferent(state.ThumbstickXValue, diffState.ThumbstickXValue, floatThresholdForDifference) || IsDifferent(state.ThumbstickYValue, diffState.ThumbstickYValue, floatThresholdForDifference))) { hasNonDefaultValue = true; sb.AppendFormat("Thumb:{0},{1}", state.ThumbstickXValue, state.ThumbstickYValue); } string message = sb.ToString(); #if TRACING_VERBOSE if (hasNonDefaultValue || HasContent(message)) { Debug.Log(message); } #endif if (state.IsLeftHand) { pastLeft = state; } else if (state.IsRightHand) { pastRight = state; } return(message); }
public static void TraceState(this ControllerState state, PoseSource filterInput, bool onlyDifferences = true) { StringBuilder sb = new StringBuilder(); bool allChanges = !onlyDifferences; float diffV3Threshold = 0.2f; float fThreshold = 0.02f; float diffV2Threshold = 0.14f; bool isEvent = false; bool isDifferent = false; if (state.IsLeftHand) { sb.Append(leftPrefix); diffState = pastLeft; } else if (state.IsRightHand) { sb.Append(rightPrefix); diffState = pastRight; } if (state.SelectPressed) { isEvent = true; sb.AppendFormat("Select Pressed ({0});", state.SelectValue); } if (state.TouchPadPressed || state.TouchPadTouched) { isEvent = true; sb.AppendFormat("TouchPad {0} {1} ({2},{3});", state.TouchPadPressed ? "Pressed" : "", state.TouchPadTouched ? "Touched" : "", state.TouchPadXValue, state.TouchPadYValue); } if (state.ThumbstickPressed) { isEvent = true; sb.AppendFormat("Thumbstick pressed({0},{1});", state.ThumbstickXValue, state.ThumbstickYValue); } if (state.MenuPressed) { isEvent = true; sb.Append("Menu Pressed;"); } if (state.GraspPressed) { isEvent = true; sb.Append("Grasp Pressed;"); } // Grip position if ((filterInput & PoseSource.Grip) != PoseSource.None) { if (allChanges || (IsDifferent(state.Position, diffState.Position, diffV3Threshold))) { isDifferent = true; sb.AppendFormat("Pos:{0},Rot:{1}", state.Position, state.Rotation); } } // Pointer position if ((filterInput & PoseSource.Pointer) != PoseSource.None) { if (allChanges || (IsDifferent(state.PointerPosition, diffState.PointerPosition, diffV3Threshold))) { isDifferent = true; sb.AppendFormat("PointPos:{0},PointRot:{1}", state.PointerPosition, state.PointerRotation); } } if (allChanges || (IsDifferent(state.ThumbstickXValue, diffState.ThumbstickXValue, fThreshold) || IsDifferent(state.ThumbstickYValue, diffState.ThumbstickYValue, fThreshold))) { isDifferent = true; sb.AppendFormat("Thumb:{0},{1}", state.ThumbstickXValue, state.ThumbstickYValue); } string message = sb.ToString(); if (allChanges || HasContent(message)) { if (isEvent) { //TODO: should we de-bounce based on time? TraceHelper.LogDiff(message, TraceCacheGrouping.FullState); } else { TraceHelper.LogDiff(message, TraceCacheGrouping.FullState); } } if (isDifferent && !allChanges) { if (state.IsLeftHand) { pastLeft = state; } else if (state.IsRightHand) { pastRight = state; } } }