Esempio n. 1
0
        private void UpdateTelemetry()
        {
            if (dataStream.Connected)
            {
                bool dataIsDirty = isTelemetryDataDirty;

                // lock the queues and flush their contents to our render data
                lock (receiver.LockObject)
                {
                    while (receiver.ReceivedFrameSnapshots.Count > 0)
                    {
                        frameData.Frames.Add(receiver.ReceivedFrameSnapshots.Dequeue());
                        isTelemetryDataDirty = true;
                    }

                    while (receiver.ReceivedFrameStats.Count > 0)
                    {
                        frameData.FrameStats.Add(receiver.ReceivedFrameStats.Dequeue());
                        isTelemetryDataDirty = true;
                    }

                    while (receiver.ReceivedShapes.Count > 0)
                    {
                        PacketTranslator.CollectedFrameShapes collectedShapes = receiver.ReceivedShapes.Dequeue();
                        isTelemetryDataDirty = true;

                        foreach (BaseShape addedShape in collectedShapes.Shapes)
                        {
                            switch (addedShape.ShapeType)
                            {
                            case ShapeType.eConvexHull:
                                ConvexHullShape convexShape       = (ConvexHullShape)addedShape;
                                int             shapeRenderHandle = GenerateMeshForConvexHull(convexShape);

                                ShapeFrameIdPair pair = frameData.ShapeData.AddNewShape(collectedShapes.FrameId, convexShape);

                                // store a binding for this mesh version
                                shapeRenderMeshBindings.Add(pair, shapeRenderHandle);
                                break;

                            case ShapeType.eObb:
                            case ShapeType.eSphere:
                            case ShapeType.eCone:
                            case ShapeType.eTetrahedron:
                            default:
                                frameData.ShapeData.AddNewShape(collectedShapes.FrameId, addedShape);
                                break;
                            }
                        }
                    }
                }

                if (dataIsDirty != isTelemetryDataDirty)
                {
                    BuildAndSetApplicationTitleString();
                }

                FramesAdded();
            }
        }
Esempio n. 2
0
        private TreeNode BuildDisplayTree()
        {
            TreeNode rootNode = null;

            if (FrameData != null && FrameData.Frames.Count > 0)
            {
                rootNode = new TreeNode($"Frame ID: {frameIdToDisplay}");
                TreeNode worldRoot = rootNode.Nodes.Add("World 1");

                {
                    //////////////////////////////////////////////////////////////////
                    // rigid body data
                    TreeNode rigidBodyRoot = worldRoot.Nodes.Add("Rigid Bodies");

                    foreach (RigidBody body in FrameData.Frames[frameIdToDisplay].RigidBodies.Values)
                    {
                        RigidBodyTreeNode bodyNode = new RigidBodyTreeNode(body);
                        rigidBodyRoot.Nodes.Add(bodyNode);

                        foreach (uint shapeId in body.CollisionShapeIds)
                        {
                            ShapeFrameIdPair actualShapePair = FrameData.ShapeData.RetrieveShapeForFrame(shapeId, FrameData.Frames[FrameIdToDisplay].FrameId);

                            ShapeTreeNode shapeNode = new ShapeTreeNode(actualShapePair.Shape);
                            bodyNode.Nodes.Add(shapeNode);
                        }
                    }
                }

                {
                    //////////////////////////////////////////////////////////////////
                    // Shape iteration data
                    TreeNode shapeIterationRoot = rootNode.Nodes.Add("Shape Iterations");

                    foreach (KeyValuePair <uint, ShapeIterations> iterationPair in FrameData.ShapeData.ShapeData)
                    {
                        string objectTypeString = iterationPair.Value.Iterations.Count > 0 ? iterationPair.Value.Iterations[0].Shape.ShapeType.ToString() : "Unknown";

                        TreeNode iterationNode = shapeIterationRoot.Nodes.Add($"ID: {iterationPair.Key}, {objectTypeString}");

                        foreach (ShapeFrameIdPair shapePair in iterationPair.Value.Iterations)
                        {
                            ShapeFrameIdPairTreeNode shapeIterationPairNode = new ShapeFrameIdPairTreeNode(shapePair);
                            iterationNode.Nodes.Add(shapeIterationPairNode);

                            ShapeTreeNode shapeNode = new ShapeTreeNode(shapePair.Shape);
                            shapeIterationPairNode.Nodes.Add(shapeNode);
                        }
                    }
                }
            }
            else
            {
                rootNode = new TreeNode("No data");
            }

            return(rootNode);
        }
Esempio n. 3
0
        public PropertyDescriptorCollection GetProperties()
        {
            // Create a new collection object PropertyDescriptorCollection
            PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);

            // Iterate the list of employees
            for (int i = 0; i < WrappedShapeIds.Count; i++)
            {
                ShapeFrameIdPair pair = ShapeDataManager.RetrieveShapeForFrame(WrappedShapeIds[i], FrameId);

                ShapePropertyDescriptor pd = new ShapePropertyDescriptor(pair.Shape, $"[{i}]");
                pds.Add(pd);
            }
            return(pds);
        }
Esempio n. 4
0
        public ShapeFrameIdPairTreeNode(ShapeFrameIdPair pairToDisplay)
        {
            PairToDisplay = pairToDisplay;

            Text = $"FrameId: {pairToDisplay.FrameId}";
        }
Esempio n. 5
0
        private void RenderFrame(int frameIndex)
        {
            float time = animate ? clock.ElapsedMilliseconds / 1000.0f : 0.0f;

            FrameSnapshot latestFrame = frameData.Frames != null && frameData.Frames.Count > 0 ? frameData.Frames[frameIndex] : null;

            if (latestFrame != null)
            {
                int nextRenderInstanceId = 1; // the first instance is the world reference plane

                foreach (RigidBody rigidBody in latestFrame.RigidBodies.Values)
                {
                    foreach (uint shapeId in rigidBody.CollisionShapeIds)
                    {
                        RenderInstance instanceToRender = null;

                        ShapeFrameIdPair actualShapePair = frameData.ShapeData.RetrieveShapeForFrame(shapeId, frameData.Frames[frameIndex].FrameId);

                        if (actualShapePair != null)
                        {
                            if (nextRenderInstanceId < mainViewport.Renderer.InstanceList.Count)
                            {
                                instanceToRender = mainViewport.Renderer.InstanceList[nextRenderInstanceId];
                            }
                            else
                            {
                                instanceToRender = new RenderInstance(Matrix.Translation(5.0f, 0.0f, 5.0f), TetrahedronMeshId);
                                mainViewport.Renderer.InstanceList.Add(instanceToRender);
                            }

                            // todo - do the rest of the shape types and properly setup the position of the shapes
                            switch (actualShapePair.Shape.ShapeType)
                            {
                            case ShapeType.eObb:
                                instanceToRender.MeshId = CubeMeshId;
                                break;

                            case ShapeType.eSphere:
                                break;

                            case ShapeType.eCone:
                                break;

                            case ShapeType.eConvexHull:
                                instanceToRender.MeshId = shapeRenderMeshBindings[actualShapePair];
                                break;

                            case ShapeType.eTetrahedron:
                                instanceToRender.MeshId = TetrahedronMeshId;
                                break;

                            default:
                                break;
                            }

                            instanceToRender.UserDataValue = actualShapePair.Shape.Id;

                            Matrix rotationAnimation = Matrix.RotationX(time) * Matrix.RotationY(time * 2.0f) * Matrix.RotationZ(time * 0.7f);

                            Matrix translationMatrix = Matrix.Translation(
                                rigidBody.WorldMatrix.Translation.X
                                , rigidBody.WorldMatrix.Translation.Y
                                , rigidBody.WorldMatrix.Translation.Z);

                            if (actualShapePair.Shape.HasLocalMatrix)
                            {
                                Matrix localMatrix = Matrix.Translation(
                                    actualShapePair.Shape.LocalMatrix.Translation.X
                                    , actualShapePair.Shape.LocalMatrix.Translation.Y
                                    , actualShapePair.Shape.LocalMatrix.Translation.Z);

                                instanceToRender.WorldMatrix = localMatrix * rotationAnimation * translationMatrix;
                            }
                            else
                            {
                                instanceToRender.WorldMatrix = rotationAnimation * translationMatrix;
                            }

                            if (actualShapePair.Shape.Id == selectedShapeId)
                            {
                                instanceToRender.Material.ColourTint           = new Vector4(0.5f, 1.0f, 0.5f, 1.0f);
                                instanceToRender.Material.AmbientLightStrength = 0.6f;
                            }
                            else if (actualShapePair.Shape.Id == highlightedShapeId)
                            {
                                instanceToRender.Material.ColourTint           = new Vector4(0.5f, 1.0f, 0.5f, 1.0f);
                                instanceToRender.Material.AmbientLightStrength = 0.3f;
                            }
                            else
                            {
                                instanceToRender.Material.ColourTint           = new Vector4(0.0f, 1.0f, 0.0f, 1.0f);
                                instanceToRender.Material.AmbientLightStrength = 0.1f;
                            }

                            ++nextRenderInstanceId;
                        }
                    }
                }

                int differenceInRenderInstances = mainViewport.Renderer.InstanceList.Count - nextRenderInstanceId;
                mainViewport.Renderer.InstanceList.RemoveRange(mainViewport.Renderer.InstanceList.Count - differenceInRenderInstances, differenceInRenderInstances);
            }
        }
Esempio n. 6
0
        private void UpdateInput()
        {
            System.Drawing.Point currentMousePosition = Control.MousePosition;
            System.Drawing.Point mouseDifference      = new System.Drawing.Point(
                currentMousePosition.X - lastMousePosition.X
                , currentMousePosition.Y - lastMousePosition.Y);

            lastMousePosition = currentMousePosition;

            System.Drawing.Point pixelCooord = mainViewport.PointToClient(Control.MousePosition);
            if (pixelCooord.X >= 0 && pixelCooord.Y >= 0 && pixelCooord.X < mainViewport.Size.Width && pixelCooord.Y < mainViewport.Size.Height)
            {
                highlightedShapeId = GraphicsDevice.Instance.PixelUserData[pixelCooord.X, pixelCooord.Y];
            }
            else
            {
                highlightedShapeId = uint.MaxValue;
            }

            if (ContainsFocus)
            {
                if (MouseButtons == MouseButtons.Left)
                {
                    selectedShapeId = highlightedShapeId;

                    if (selectedShapeId != uint.MaxValue)
                    {
                        ShapeFrameIdPair pair = frameData.ShapeData.RetrieveShapeForFrame(selectedShapeId, controller.CurrentFrameId);

                        if (pair != null)
                        {
                            DisplayShapeInObjectDetailsPropertyGrid(pair.Shape);
                        }
                    }
                }

                if (MouseButtons == MouseButtons.Right)
                {
                    mainViewport.Renderer.Camera.Pitch -= mouseDifference.Y * s_cameraScrollSpeed;
                    mainViewport.Renderer.Camera.Yaw   += mouseDifference.X * s_cameraScrollSpeed;
                }

                float modifier    = Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift) ? s_cameraSpeedModifier : 1.0f;
                float cameraSpeed = s_cameraMoveSpeed * modifier;

                if (Keyboard.IsKeyDown(Key.W))
                {
                    mainViewport.Renderer.Camera.MoveCameraLongitudinal(cameraSpeed);
                }
                else if (Keyboard.IsKeyDown(Key.S))
                {
                    mainViewport.Renderer.Camera.MoveCameraLongitudinal(-cameraSpeed);
                }

                if (Keyboard.IsKeyDown(Key.A))
                {
                    mainViewport.Renderer.Camera.MoveCameraLateral(-cameraSpeed);
                }
                else if (Keyboard.IsKeyDown(Key.D))
                {
                    mainViewport.Renderer.Camera.MoveCameraLateral(cameraSpeed);
                }

                if (Keyboard.IsKeyDown(Key.E))
                {
                    mainViewport.Renderer.Camera.MoveCameraUp(cameraSpeed);
                }
                else if (Keyboard.IsKeyDown(Key.Q))
                {
                    mainViewport.Renderer.Camera.MoveCameraUp(-cameraSpeed);
                }
            }
        }