Example #1
0
        private void UpdateViewContainers()
        {
            var  containers  = Services.VisManager().ViewContainers;
            long currentTime = Services.StudyManager().CurrentTimestamp;

            foreach (var element in containers)
            {
                var id            = element.Key;
                var viewContainer = element.Value;
                if (viewContainer.ParentId != -1)
                {
                    // This view container has a parent and could have changed its transform.
                    // get the AnalysisObject that is this container's parent
                    var parent = dataSets.Find(
                        delegate(AnalysisObject obj)
                    {
                        return(obj.Id == viewContainer.ParentId);
                    });

                    // skip this container if the parent is not part of our list of AnalysisObjects
                    if (parent == null)
                    {
                        viewContainer.gameObject.SetActive(false);
                        continue;
                    }

                    // skip this container if more than one session or condition is selected
                    if (sessions.Count != 1 || conditions.Count != 1)
                    {
                        viewContainer.gameObject.SetActive(false);
                        continue;

                        // ToDo: support multiple sessions and conditions. Ideally, automatically create one ViewContainer per session/condition, keep its settings synced to the others and only show data for the current session/condition
                    }
                    else
                    {
                        // (Settings.Sessions.Count == 1 && Settings.Conditions.Count == 1)
                        if (currentTime < currentTimeFilterMin || currentTime > currentTimeFilterMax)
                        {
                            viewContainer.gameObject.SetActive(false);
                            continue;
                        }

                        viewContainer.gameObject.SetActive(true);

                        // get parent position and orientation at current time stamp
                        int        session   = sessions[0];
                        int        condition = conditions[0];
                        Vector3    parentPosition;
                        Quaternion parentOrientation;

                        int earlierIndex  = parent.GetIndexFromTimestamp(currentTime, session, condition);
                        var earlierSample = parent.GetInfoObjects(session, condition)[earlierIndex];
                        if (earlierIndex + 1 >= parent.GetInfoObjects(session, condition).Count || earlierSample.Timestamp >= currentTime)
                        {
                            parentPosition    = earlierSample.Position;
                            parentOrientation = earlierSample.Rotation;
                        }
                        else
                        {
                            int   laterIndex  = earlierIndex + 1;
                            var   laterSample = parent.GetInfoObjects(session, condition)[laterIndex];
                            float interpolant = (currentTime - earlierSample.Timestamp) * 1.0f / (laterSample.Timestamp - earlierSample.Timestamp) * 1.0f;
                            parentPosition    = Vector3.Lerp(earlierSample.Position, laterSample.Position, interpolant);
                            parentOrientation = Quaternion.Lerp(earlierSample.Rotation, laterSample.Rotation, interpolant);
                        }

                        // update child container transform accordingly
                        Quaternion newRotation = parentOrientation;
                        Vector3    newPosition = parentPosition + (newRotation * viewContainer.PositionOffset);
                        if (newRotation != viewContainer.transform.localRotation || newPosition != viewContainer.transform.localPosition)
                        {
                            viewContainer.UpdateTransform(newPosition, newRotation);
                            ////viewContainer.transform.localRotation = newRotation;
                            ////viewContainer.transform.localPosition = newPosition;
                            ////viewContainer.transform.hasChanged = true;
                        }
                    }
                }
            }
        }
Example #2
0
 private void UpdateSessionFilter()
 {
     sessions   = Services.StudyManager().CurrentStudySessions;
     conditions = Services.StudyManager().CurrentStudyConditions;
 }