public DirectXPanel() { SetStyle( //ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | //ControlStyles.Opaque | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.DoubleBuffer , true); BackColor = Color.DarkGray; // Dieser Aufruf ist für den Windows Form-Designer erforderlich. InitializeComponent(); pause = false; vp = new ViewportSetting(); }
/// <summary> /// Used to Transfor the View of the Scene /// </summary> void SetupMatrices(bool bb) { if (vp == null) { vp = new ViewportSetting(); } if (true || (!bb)) { device.Transform.World = Matrix.Multiply( Matrix.Translation(-vp.ObjectCenter.X, -vp.ObjectCenter.Y, -vp.ObjectCenter.Z), Matrix.Multiply( Matrix.Scaling(-vp.Scale, vp.Scale, vp.Scale), Matrix.Multiply( Matrix.RotationZ(vp.AngelZ), Matrix.Multiply( Matrix.RotationX(vp.AngelX), Matrix.Multiply( Matrix.RotationY(vp.AngelY), Matrix.Translation(vp.X + vp.ObjectCenter.X, vp.Y + vp.ObjectCenter.Y, vp.Z + vp.ObjectCenter.Z) ) ) ) ) ); } else { device.Transform.World = Matrix.Multiply( Matrix.Scaling(vp.Scale, vp.Scale, vp.Scale), Matrix.Multiply( Matrix.Translation(-vp.X, -vp.Y, -vp.Z), Matrix.Multiply( Matrix.RotationZ(vp.AngelZ), Matrix.Multiply( Matrix.RotationX(vp.AngelX), Matrix.Multiply( Matrix.RotationY(vp.AngelY), Matrix.Multiply( Matrix.Scaling(vp.Scale, vp.Scale, vp.Scale), Matrix.Translation(vp.X, vp.Y, vp.Z) ) ) ) ) ) ); } device.Transform.View = Matrix.Multiply( Matrix.RotationX(0.3f), Matrix.Multiply( Matrix.RotationY(-0.2f), Matrix.Multiply( Matrix.RotationZ(0), Matrix.LookAtLH(vp.CameraPosition, vp.CameraTarget, vp.CameraUpVector) ) ) ); // For the projection matrix, we set up a perspective transform (which // transforms geometry from 3D view space to 2D viewport space, with // a perspective divide making objects smaller in the distance). To build // a perpsective transform, we need the field of view (1/4 pi is common), // the aspect ratio, and the near and far clipping planes (which define at // what distances geometry should be no longer be rendered). device.Transform.Projection = Matrix.PerspectiveFovLH(vp.FoV, vp.Aspect, vp.NearPlane, vp.FarPlane * 1000f); }