コード例 #1
0
ファイル: Main.cs プロジェクト: RythBlade/odin
        public Main()
        {
            InitializeComponent();

            receiver = new TelemetryReceiver(dataStream, translator);

            lastMousePosition = MousePosition;

            PlaneMeshId       = mainViewport.Renderer.Meshes.AddPlane(10, 10, new Vector3(-10.0f, 0.0f, -10.0f), new Vector3(10.0f, 0.0f, 10.0f));
            CubeMeshId        = mainViewport.Renderer.Meshes.AddCubeMesh();
            TetrahedronMeshId = mainViewport.Renderer.Meshes.AddTetrahedron();

            mainViewport.Renderer.Camera.CameraPosition = new Vector3(0.0f, 0.0f, 15.0f);

            RenderInstance instanceToRender = new RenderInstance(Matrix.Translation(0.0f, 0.0f, 0.0f), PlaneMeshId);

            instanceToRender.Fill = RenderInstance.FillMode.eWireFrame;
            instanceToRender.Material.ColourTint = new Vector4(0.0f, 0.0f, 0.0f, 1.0f);
            mainViewport.Renderer.InstanceList.Add(instanceToRender);

            clock.Start();
            updateTimer.Start();

            controller.FrameChanged    += Controller_FrameChanged;
            controller.MaxFrameChanged += Controller_MaxFrameChanged;
            controller.StateChanged    += Controller_StateChanged;

            controller.State = PlayBackState.eStaticFrame;

            sceneGraphView.SelectionChanged += SceneGraphView_SelectionChanged;

            BuildAndSetApplicationTitleString();

            graphChannelPropertyGrid.SelectedObject = channelCollection;
        }
コード例 #2
0
        private void Start()
        {
            ApplyLods();

            Count = MaxMemoryAllocation;
            for (int i = 0; i < Count; i++)
            {
                InstancesArray[i] = new RenderInstance(
                    new Vector3(Random.Range(0f, 51f), 2.5f, Random.Range(-51f, -102f)),
                    Quaternion.Euler(Vector3.up * Random.Range(0, 360) + Vector3.right * Random.Range(-45, 45)),
                    Vector3.one * Random.Range(0.1f, 0.6f)
                    );
            }
            BakeInstances();
        }
コード例 #3
0
ファイル: Main.cs プロジェクト: RythBlade/odin
        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);
            }
        }