-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathScene.uno
137 lines (111 loc) · 3.14 KB
/
Scene.uno
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using Uno;
namespace Fuse.Entities
{
public class Scene : RenderNode, IViewport, IRenderViewport
{
extern (MOBILE) public event Uno.EventHandler WindowResized
{
add { Fuse.Platform.SystemUI.FrameChanged += value; }
remove { Fuse.Platform.SystemUI.FrameChanged -= value; }
}
extern (!MOBILE) public event Uno.EventHandler WindowResized
{
add { Uno.Application.Current.Window.Resized += value; }
remove { Uno.Application.Current.Window.Resized -= value; }
}
public Entity Camera { get; set; }
public bool AlwaysUseOwnCamera { get; set; }
public bool AlwaysClear { get; set; }
public float4 ClearColor { get; set; }
public Scene()
{
ClearColor = float4(1);
}
bool HasCamera { get { return Camera != null && Camera.FrustumComponent != null; } }
protected override void OnDraw(DrawContext dc)
{
if (AlwaysClear)
dc.Clear(ClearColor, 1);
if (HasCamera)
dc.PushViewport(this);
base.OnDraw(dc);
if (HasCamera)
dc.PopViewport();
}
protected override void OnHitTest(HitTestContext args)
{
var w = Viewport;
if (w == null)
return;
var ray = PointToWorldRay(args.WindowPoint);
var oldRay = args.PushWorldRay(ray);
base.OnHitTest(args);
args.PopWorldRay(oldRay);
}
/*public override VisualBounds HitTestBounds
{
get { return VisualBounds.Infinite; }
}*/
public float2 Size { get { return Parent.Viewport.Size; } }
public float2 PixelSize { get { return Parent.Viewport.PixelSize; } }
public float PixelsPerPoint { get { return Parent.Viewport.PixelsPerPoint; } }
public float4x4 ProjectionTransform
{
get
{
float4x4 result;
if (Camera.FrustumComponent.TryGetProjectionTransform(this, out result))
return result;
else
return float4x4.Identity;
}
}
float4x4 ProjectionTransformInverse
{
get
{
float4x4 result;
if (Camera.FrustumComponent.TryGetProjectionTransformInverse(this, out result))
return result;
else
return float4x4.Identity;
}
}
public float4x4 ViewProjectionTransform
{
get { return Matrix.Mul(ViewTransform,ProjectionTransform); }
}
float4x4 ViewProjectionTransformInverse
{
get { return Matrix.Mul(ProjectionTransformInverse,ViewTransformInverse); }
}
public float4x4 ViewTransform
{
get { return Camera.FrustumComponent.GetViewTransform(this); }
}
float4x4 ViewTransformInverse
{
get { return Camera.FrustumComponent.GetViewTransformInverse(this); }
}
public Ray PointToWorldRay(float2 pointPos)
{
var pr = Parent.Viewport.PointToWorldRay(pointPos);
var local = Parent.Viewport.WorldToLocalRay(Parent.Viewport, pr, this);
pointPos = ViewportHelpers.LocalPlaneIntersection(local);
var r = ViewportHelpers.PointToWorldRay(this, ViewProjectionTransformInverse, pointPos);
return r;
}
public Ray WorldToLocalRay(IViewport world, Ray worldRay, Visual where)
{
return ViewportHelpers.WorldToLocalRay(this, world, worldRay, where);
}
public float3 ViewOrigin
{
get { return Camera.FrustumComponent.GetWorldPosition(this); }
}
public float2 ViewRange
{
get { return Camera.FrustumComponent.GetDepthRange(this); }
}
}
}