2016-11-24 17 views
0

これは初めて私がurhosharpを使用していて、何か問題があります。私はいくつかのサンプルのサンプルを試してみましたが、私のアプリはクラッシュしています。 Xamarinフォーム - Urho - ページの作成シーン

私はnugetパッケージUrhoSharp.Forms

私はちょうど私が360度回転することができます真ん中のカメラでシーンを作成したい

を設置しました。

これは私のページです:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 

using Urho; 
using Urho.Forms; 

using Urho.Resources; 
using Urho.Gui; 

using Xamarin.Forms; 

namespace testApp.Pages.Urho 
{ 
    public partial class urhoPage : ContentPage 
    { 

     Scene scene; 
     Camera camera; 

     protected Node CameraNode { get; set; } 


     public urhoPage() 
     { 
      InitializeComponent(); 

      scene = new Scene(); 

      scene.CreateComponent<Octree>(); 
      scene.CreateComponent<DebugRenderer>(); 

      var planeNode = scene.CreateChild("Plane"); 
      planeNode.Scale = new Vector3(100, 1, 100); 
      var planeObject = planeNode.CreateComponent<StaticModel>(); 

      // Create a Zone component for ambient lighting & fog control 
      var zoneNode = scene.CreateChild("Zone"); 
      var zone = zoneNode.CreateComponent<Zone>(); 

      // Set same volume as the Octree, set a close bluish fog and some ambient light 
      zone.SetBoundingBox(new BoundingBox(-1000.0f, 1000.0f)); 
      zone.AmbientColor = new Urho.Color(0.15f, 0.15f, 0.15f); 
      zone.FogColor = new Urho.Color(0.5f, 0.5f, 0.7f); 
      zone.FogStart = 100; 
      zone.FogEnd = 300; 

      // Create the camera. Limit far clip distance to match the fog 
      CameraNode = scene.CreateChild("Camera"); 
      camera = CameraNode.CreateComponent<Camera>(); 
      camera.FarClip = 300; 

      // Set an initial position for the camera scene node above the plane 
      CameraNode.Position = new Vector3(0.0f, 5.0f, 0.0f); 

      // var renderer = Renderer; 
      //renderer.SetViewport(0, new Viewport(Context, scene, camera, null)); 


     } 
    } 
} 

私はエラーを取得したとして、これらの2行を削除する必要がありました。レンダラーとコンテキストが設定されていませんでした。私はページを使用していないフィーチャサンプルからそれを得た

// var renderer =レンダラー; //renderer.SetViewport(0、新しいビューポート(コンテキスト、シーン、カメラ、null));あなたの飛行機のノード規模のため

答えて

0
  1. 山車のVector3()、FogStart、FogEndとFarClipは山車にする必要があります。

  2. ビューポートのコンテキストがわからない場合は、Urhoが確実にクラッシュします。

  3. 'var'をtypename:Node、Component、Rendererに置き換えて、アプリの安定性を向上させました。

    using Xamarin.Forms; 
    namespace testApp.Pages.Urho 
    { 
    public partial class urhoPage : ContentPage 
    { 
    Scene scene; 
    Camera camera; 
    
    protected Node CameraNode { get; set; } 
    
    
    public urhoPage() 
    { 
        InitializeComponent(); 
    
        scene = new Scene(); 
    
        scene.CreateComponent<Octree>(); 
        scene.CreateComponent<DebugRenderer>(); 
    
        var planeNode = scene.CreateChild("Plane"); 
        planeNode.Scale = new Vector3(100f, 1f, 100f); 
        var planeObject = planeNode.CreateComponent<StaticModel>(); 
    
        // Create a Zone component for ambient lighting & fog control 
        var zoneNode = scene.CreateChild("Zone"); 
        var zone = zoneNode.CreateComponent<Zone>(); 
    
        // Set same volume as the Octree, set a close bluish fog and some ambient light 
        zone.SetBoundingBox(new BoundingBox(-1000.0f, 1000.0f)); 
        zone.AmbientColor = new Urho.Color(0.15f, 0.15f, 0.15f); 
        zone.FogColor = new Urho.Color(0.5f, 0.5f, 0.7f); 
        zone.FogStart = 100f; 
        zone.FogEnd = 300f; 
    
        // Create the camera. Limit far clip distance to match the fog 
        CameraNode = new Node(); 
        Camera camera = CameraNode.CreateComponent<Camera>(); 
        camera.FarClip = 300.0f; 
    
        // Set an initial position for the camera scene node above the plane 
        CameraNode.Position = new Vector3(0.0f, 5.0f, 0.0f); 
    
        var renderer = Application.Current.Renderer; 
        renderer.SetViewport(0, new Viewport(Application.CurrentContext, scene, CameraNode.GetComponent<Camera>(), null)); 
    } 
    
    }} 
    
関連する問題