I'm showing UrhoSurface in ContentView and trying to get it working.
However, the cube of EnterButton becomes null.
Why?
public partial class Test3D : ContentView
{
Cube cube;
public Test3D()
{
InitializeComponent();
test();
}
public async void test()
{
cube = await urhoSurface.Show<Cube>(new ApplicationOptions("Data"));
}
public async void EnterButton(object sender, EventArgs args)
{
cube.Rotate();
}
}
Postscript
public class Cube : Urho.Application
{
Node CubeNode;
StaticModel model;
Node cameraNode;
public Cube(ApplicationOptions options) : base(options) { }
protected override async void Start()
{
base.Start();
await Create3DObject();
}
protected override void OnUpdate(float timeStep)
{
base.OnUpdate(timeStep);
}
protected override void OnDeleted()
{
base.OnDeleted();
}
public void Rotate()
{
CubeNode.Rotation *= new Quaternion(0.0f, 1.0f, 0.0f);
}
private async Task Create3DObject()
{
Scene scene = new Scene();
scene.CreateComponent<Octree>();
CubeNode = scene.CreateChild();
CubeNode.Position = new Vector3(0, 0, 0);
CubeNode.Rotation = new Quaternion(0, 0, 0);
CubeNode.SetScale(15.0f);
model = CubeNode.CreateComponent<StaticModel>();
model.Model = ResourceCache.GetModel("Models/cube.mdl");
Node lightNode = scene.CreateChild(name: "light");
lightNode.SetDirection(new Vector3(0, 0, 0));
lightNode.Rotate(new Quaternion(20.0f, 0.0f, 0.0f));
Light light = lightNode.CreateComponent<Light>();
light.Color = new Urho.Color(0.525f, 0.525f, 0.525f);
light.LightType = LightType.Directional;
light.Brightness = 0.8f;
Node zoneNode = scene.CreateChild(name: "Zone");
Zone zone = zoneNode.CreateComponent<Zone>();
zone.SetBoundingBox(new BoundingBox(-10000.0f, 10000.0f));
zone.AmbientColor = new Urho.Color(0.6f, 0.6f, 0.6f);
cameraNode = scene.CreateChild(name: "camera");
cameraNode.Position = new Vector3(0, 0, -5.0f);
cameraNode.SetDirection(new Vector3(0, 0, 0) - cameraNode.Position);
Camera camera = cameraNode.CreateComponent<Camera>();
var viewport = new Viewport(Context, scene, camera, null);
viewport.SetClearColor(Urho.Color.White);
Renderer.SetViewport(0, viewport);
}
}