Пример #1
0
    public IntersectionSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;
      var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
      {
        RenderCallback = Render,
      };
      GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

      // Add a custom game object which controls the camera.
      _cameraObject = new CameraObject(Services, 10);
      _cameraObject.ResetPose(new Vector3F(0, 0, -4), ConstantsF.Pi, 0);
      GameObjectService.Objects.Add(_cameraObject);

      // Create a new scene with some lights.
      _scene = new Scene();
      SceneSample.InitializeDefaultXnaLights(_scene);

      _meshRenderer = new MeshRenderer();
      _debugRenderer = new DebugRenderer(GraphicsService, null);

      _intersectionRenderer = new IntersectionRenderer(GraphicsService, ContentManager)
      {
        DownsampleFactor = 1,
      };

      //_submeshA = MeshHelper.CreateSubmesh(GraphicsService.GraphicsDevice, new SphereShape(0.5f).GetMesh(0.001f, 5), MathHelper.ToRadians(70));
      //_submeshB = MeshHelper.CreateSubmesh(GraphicsService.GraphicsDevice, new BoxShape(1, 1, 2).GetMesh(0.001f, 5), MathHelper.ToRadians(70));

      var meshNodeA = CreateMeshNode(new[]
      {
        MeshHelper.CreateTorus(GraphicsService.GraphicsDevice, 1, 0.3f, 30),
        MeshHelper.CreateSubmesh(GraphicsService.GraphicsDevice, new BoxShape(1, 1, 2).GetMesh(0.001f, 5), MathHelper.ToRadians(70)),
      },
      Color.DarkBlue);
      meshNodeA.PoseWorld = new Pose(RandomHelper.Random.NextVector3F(-0.5f, 0.5f),
                                    RandomHelper.Random.NextQuaternionF());
      _scene.Children.Add(meshNodeA);
      _debugRenderer.DrawObject(meshNodeA, Color.Green, true, false);

      var shape = new TransformedShape(
        new GeometricObject(new SphereShape(0.5f), new Pose(new Vector3F(1, 0, 0))));
      var meshNodeB = CreateMeshNode(new[]
      {
        MeshHelper.CreateTorus(GraphicsService.GraphicsDevice, 1, 0.3f, 30),
        MeshHelper.CreateSubmesh(GraphicsService.GraphicsDevice, shape.GetMesh(0.001f, 4), MathHelper.ToRadians(90)),
      },
      Color.Gray);
      meshNodeB.PoseWorld = new Pose(RandomHelper.Random.NextVector3F(-1f, 1f),
                                    RandomHelper.Random.NextQuaternionF());
      _scene.Children.Add(meshNodeB);
      _debugRenderer.DrawObject(meshNodeB, Color.Green, true, false);

      var meshNodeC = CreateMeshNode(new[]
      {
        MeshHelper.CreateBox(GraphicsService.GraphicsDevice),
        MeshHelper.CreateSubmesh(GraphicsService.GraphicsDevice, new BoxShape(1, 1, 2).GetMesh(0.001f, 5), MathHelper.ToRadians(70))
      },
      Color.DarkGreen);
      meshNodeC.PoseWorld = new Pose(RandomHelper.Random.NextVector3F(-1f, 1f),
                                    RandomHelper.Random.NextQuaternionF());
      meshNodeC.ScaleLocal = new Vector3F(0.1f, 1f, 0.5f);
      _scene.Children.Add(meshNodeC);
      _debugRenderer.DrawObject(meshNodeC, Color.Green, true, false);

      _meshNodePairs.Add(new Pair<MeshNode>(meshNodeA, meshNodeB));
      _meshNodePairs.Add(new Pair<MeshNode>(meshNodeA, meshNodeC));
      _meshNodePairs.Add(new Pair<MeshNode>(meshNodeB, meshNodeC));

      CreateGuiControls();
    }
Пример #2
0
        public IntersectionSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            SampleFramework.IsMouseVisible = false;
            var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = Render,
            };

            GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

            // Add a custom game object which controls the camera.
            _cameraObject = new CameraObject(Services, 10);
            _cameraObject.ResetPose(new Vector3(0, 0, -4), ConstantsF.Pi, 0);
            GameObjectService.Objects.Add(_cameraObject);

            // Create a new scene with some lights.
            _scene = new Scene();
            SceneSample.InitializeDefaultXnaLights(_scene);

            _meshRenderer  = new MeshRenderer();
            _debugRenderer = new DebugRenderer(GraphicsService, null);

            _intersectionRenderer = new IntersectionRenderer(GraphicsService, ContentManager)
            {
                DownsampleFactor = 1,
            };

            //_submeshA = MeshHelper.CreateSubmesh(GraphicsService.GraphicsDevice, new SphereShape(0.5f).GetMesh(0.001f, 5), MathHelper.ToRadians(70));
            //_submeshB = MeshHelper.CreateSubmesh(GraphicsService.GraphicsDevice, new BoxShape(1, 1, 2).GetMesh(0.001f, 5), MathHelper.ToRadians(70));

            var meshNodeA = CreateMeshNode(new[]
            {
                MeshHelper.CreateTorus(GraphicsService.GraphicsDevice, 1, 0.3f, 30),
                MeshHelper.CreateSubmesh(GraphicsService.GraphicsDevice, new BoxShape(1, 1, 2).GetMesh(0.001f, 5), MathHelper.ToRadians(70)),
            },
                                           Color.DarkBlue);

            meshNodeA.PoseWorld = new Pose(RandomHelper.Random.NextVector3(-0.5f, 0.5f),
                                           RandomHelper.Random.NextQuaternion());
            _scene.Children.Add(meshNodeA);
            _debugRenderer.DrawObject(meshNodeA, Color.Green, true, false);

            var shape = new TransformedShape(
                new GeometricObject(new SphereShape(0.5f), new Pose(new Vector3(1, 0, 0))));
            var meshNodeB = CreateMeshNode(new[]
            {
                MeshHelper.CreateTorus(GraphicsService.GraphicsDevice, 1, 0.3f, 30),
                MeshHelper.CreateSubmesh(GraphicsService.GraphicsDevice, shape.GetMesh(0.001f, 4), MathHelper.ToRadians(90)),
            },
                                           Color.Gray);

            meshNodeB.PoseWorld = new Pose(RandomHelper.Random.NextVector3(-1f, 1f),
                                           RandomHelper.Random.NextQuaternion());
            _scene.Children.Add(meshNodeB);
            _debugRenderer.DrawObject(meshNodeB, Color.Green, true, false);

            var meshNodeC = CreateMeshNode(new[]
            {
                MeshHelper.CreateBox(GraphicsService.GraphicsDevice),
                MeshHelper.CreateSubmesh(GraphicsService.GraphicsDevice, new BoxShape(1, 1, 2).GetMesh(0.001f, 5), MathHelper.ToRadians(70))
            },
                                           Color.DarkGreen);

            meshNodeC.PoseWorld = new Pose(RandomHelper.Random.NextVector3(-1f, 1f),
                                           RandomHelper.Random.NextQuaternion());
            meshNodeC.ScaleLocal = new Vector3(0.1f, 1f, 0.5f);
            _scene.Children.Add(meshNodeC);
            _debugRenderer.DrawObject(meshNodeC, Color.Green, true, false);

            _meshNodePairs.Add(new Pair <MeshNode>(meshNodeA, meshNodeB));
            _meshNodePairs.Add(new Pair <MeshNode>(meshNodeA, meshNodeC));
            _meshNodePairs.Add(new Pair <MeshNode>(meshNodeB, meshNodeC));

            CreateGuiControls();
        }