public static void NormalStart() { //render form Form = new RenderForm( ); Form.Text = "MMD Model Viewer"; ModForm.Show( ); ModForm.SetFactorBoxChanged( OnFactorTextChanged ); ModForm.SetRadiusBoxChanged( OnFactorTextChanged ); ModForm.SetAlphaBarChanged( OnAlphaBarChanged ); ModForm.SetOffsetBoxChanged( OnOffsetBoxChanged ); ModForm.SetMorphNameChanged( OnMorphNameChanged ); ModForm.SetScaleChanged( OnScaleChanged ); ModForm.SetRotChanged( OnRotTextChanged ); #region addEvent Form.MouseClick += Form_MouseClick; Form.MouseMove += Form_MouseMove; Form.MouseWheel += Form_MouseWheel; Form.KeyUp += Form_KeyUp; Form.FormClosed += Form_FormClosed; ; Debug = new VDBDebugger( ); #endregion using ( SharpDevice device = new SharpDevice( Form ) ) { #if Lattice LatticeForm = new LatticeForm( Model , device ); LatticeForm.Show( ); #endif Model.LoadTexture( device ); Axis.LoadTexture( device ); #if Lattice LatticeForm.LoadTexture( device ); #endif #if DEBUGLINE Line.LoadTexture(device); Line.AfterLoaded(); #endif //init frame counter FpsCounter.Reset( ); device.SetBlend( BlendOperation.Add , BlendOption.SourceAlpha , BlendOption.InverseSourceAlpha ); OnResizeForm( ( float )Form.ClientRectangle.Width / Form.ClientRectangle.Height , device ); //main loop RenderLoop.Run( Form , () => OnUpdate( device ) ); //release resource Model.Dispose( ); RefModel?.Dispose( ); Axis.Dispose( ); #if DEBUGLINE Line.Dispose(); #endif } }
private static void OnUpdate( SharpDevice device ) { // ここでしかdevice手に入らない、まだロードが完全でない if ( RefModel != null ) { if ( RefModel.Mesh == null ) { RefModel.LoadTexture( device ); } } //set transformation matrix float ratio = ( float )Form.ClientRectangle.Width / Form.ClientRectangle.Height; //90° degree with 1 ratio Projection = Camera.Projection; //Resizing if ( device.MustResize ) { device.Resize( ); OnResizeForm( ratio , device ); } //apply states device.UpdateAllStates( ); PreViewUpdate( device ); //MATRICES //camera View = Camera.GetView( ); //View = Matrix.LookAtLH(new Vector3(0, 30, 70), new Vector3(0, 0, 0), Vector3.UnitY); Camera.Update( Mouse , FpsCounter.Delta * 0.001f ); Mouse.Update( ); Vector3 from = Camera.Position; if ( !float.IsNaN( from.X ) ) { Debug.vdb_label( "campos" ); Debug.Send( from.DebugStr( ) ); } Matrix world = Matrix.Translation( 0 , 0 , 50 ) * Matrix.RotationY( Environment.TickCount / 1000.0F ); //light direction Vector3 lightDirection = new Vector3( 0.5f , 0 , -1 ); lightDirection.Normalize( ); //RENDERING TO DEVICE //Set original targets device.SetDefaultTargers( ); //clear color device.Clear( Color.Brown ); //apply shader Model.Update( device , View , Projection ); RefModel?.Update( device , View , Projection ); Axis.Update( device , View , Projection ); #if DEBUGLINE Line.Update(device, View , Projection); #endif PostViewUpdate( device ); //present device.Present( ); }