|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MdxScene.Cameras;
using MdxScene.Controls;
using MdxScene.Lights;
using MdxScene.Shapes;
using MdxWpfInteroperability;
using Microsoft.DirectX.Direct3D;
namespace MdxScene.Example
{
/// <summary>
/// Interaction logic for SceneManipulationExampleWindow.xaml
/// </summary>
public partial class SceneManipulationExampleWindow : Window
{
private D3dScene _scene;
private MarkBox _pickMarkBox;
public SceneManipulationExampleWindow()
{
InitializeComponent();
InitScene();
}
private void InitScene()
{
_scene = new D3dScene
{
ClearColor = System.Drawing.Color.Gray
};
// Set the light.
_scene.Lights.Add(new D3dDirectionalLight
{
XDirection = 1,
YDirection = -1,
ZDirection = -1,
Diffuse = System.Drawing.Color.DimGray
});
_scene.Lights.Add(new D3dDirectionalLight
{
XDirection = -1,
YDirection = 1,
ZDirection = 1,
Diffuse = System.Drawing.Color.Gray
});
// Add shapes.
_scene.Shapes.Add(new Pyramid
{
DefaultMaterial = new Material {Diffuse = System.Drawing.Color.Red},
ScalingX = 200,
ScalingY = 200,
ScalingZ = 200
});
_scene.Shapes.Add(new Star
{
DefaultMaterial = new Material {Diffuse = System.Drawing.Color.Yellow},
ScalingX = 300,
ScalingY = 300,
ScalingZ = 300,
TranslationX = 600
});
_scene.Shapes.Add(new House
{
BodyMaterial = new Material {Diffuse = System.Drawing.Color.Green},
RoofMaterial = new Material {Diffuse = System.Drawing.Color.Red},
ScalingX = 150,
ScalingZ = 150,
ScalingY = 300,
TranslationX = -600
});
// Add the mouse-over mark.
_pickMarkBox = new MarkBox();
_scene.Shapes.Add(_pickMarkBox);
mdxSceneHost.Scene = _scene;
}
private void mdxSceneHost_D3dSurfaceMouseWheel(object sender, D3dSurfaceMouseWheelEventArgs e)
{
float relativeZoomDelta = e.MouseWheelEventArgs.Delta/1000f;
float scalingFactor = 1 - relativeZoomDelta;
D3dScenePresenter.UniformZoomCommand.Execute(scalingFactor, mdxSceneHost);
}
private void mdxSceneHost_MouseOverShapeChanged(object sender, MouseOverShapeChangedRoutedEventArgs e)
{
D3dShape pickedShape = e.NewShape;
mdxSceneHost.PerformSceneAction(() => _pickMarkBox.MarkedShape = pickedShape);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.