Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Engine/Collection/DrawnCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal void Register(IDrawn node)

for (int i = 0; i < Engine.MaxCameraGroupCount; i++)
{
var mask = 1u << i;
var mask = 1ul << i;
if (!HasBit(node.CameraGroup, mask)) continue;

var group = _Sorted[i];
Expand All @@ -49,7 +49,7 @@ internal void Unregister(IDrawn node)

for (int i = 0; i < Engine.MaxCameraGroupCount; i++)
{
var mask = 1u << i;
var mask = 1ul << i;
if (!HasBit(node.CameraGroup, mask)) continue;

var group = _Sorted[i];
Expand All @@ -63,7 +63,7 @@ internal void UpdateCameraGroup(IDrawn node, ulong old)

for (int i = 0; i < Engine.MaxCameraGroupCount; i++)
{
var mask = 1u << i;
var mask = 1ul << i;

if (HasBit(old, mask) && !HasBit(node.CameraGroup, mask))
{
Expand Down Expand Up @@ -99,7 +99,7 @@ internal void UpdateZOrder(IDrawn node, int old)

for (int i = 0; i < Engine.MaxCameraGroupCount; i++)
{
var mask = 1u << i;
var mask = 1ul << i;

if (!HasBit(node.CameraGroup, mask)) continue;

Expand All @@ -117,7 +117,7 @@ internal void UpdateZOrder(IDrawn node, int old)
internal SortedDictionary<int, HashSet<IDrawn>> GetDrawns() => _Drawns;
internal SortedDictionary<int, HashSet<IDrawn>> this[int cameraGroup] => _Sorted[cameraGroup];

private bool HasBit(ulong value, uint mask) => (value & mask) != 0;
private bool HasBit(ulong value, ulong mask) => (value & mask) != 0;
}

internal class CameraNodeCollection
Expand All @@ -138,7 +138,7 @@ internal void AddCamera(CameraNode node)
{
for (int i = 0; i < Engine.MaxCameraGroupCount; i++)
{
var mask = 1u << i;
var mask = 1ul << i;
if (HasBit(node.Group, mask))
{
_Lists[i].Add(node);
Expand All @@ -151,7 +151,7 @@ internal void RemoveCamera(CameraNode node)
{
for (int i = 0; i < Engine.MaxCameraGroupCount; i++)
{
var mask = 1u << i;
var mask = 1ul << i;
if (HasBit(node.Group, mask))
{
_Lists[i].Remove(node);
Expand All @@ -164,7 +164,7 @@ internal void UpdateGroup(CameraNode node, ulong oldGroup)
{
for (int i = 0; i < Engine.MaxCameraGroupCount; i++)
{
var mask = 1u << i;
var mask = 1ul << i;
if (HasBit(oldGroup, mask) && !HasBit(node.Group, mask))
{
_Lists[i].Remove(node);
Expand All @@ -178,6 +178,6 @@ internal void UpdateGroup(CameraNode node, ulong oldGroup)

internal List<CameraNode> this[int index] => _Lists[index];

private bool HasBit(ulong value, uint mask) => (value & mask) != 0;
private bool HasBit(ulong value, ulong mask) => (value & mask) != 0;
}
}
29 changes: 18 additions & 11 deletions Engine/Node/CameraNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,28 @@ public RenderTexture TargetTexture

internal override void Update()
{
if (_RequireCalcTransform || _TargetSize != (TargetTexture?.Size ?? Engine.WindowSize))
base.Update();

if (_TargetSize != (TargetTexture?.Size ?? Engine.WindowSize))
{
_TargetSize = (TargetTexture?.Size ?? Engine.WindowSize);
CalcTransform();
}
}

RenderedCamera.ViewMatrix =
Matrix44F.GetTranslation2D(CenterPosition - _TargetSize / 2)
* Matrix44F.GetScale2D(new Vector2F(1f, 1f) / Scale)
* Matrix44F.GetRotationZ(MathHelper.DegreeToRadian(-Angle))
* Matrix44F.GetTranslation2D(-Position);
// NOTE: DrawnNodeのTransformとは逆
private protected override void CalcTransform()
{
_TargetSize = (TargetTexture?.Size ?? Engine.WindowSize);

_RequireCalcTransform = false;
}
RenderedCamera.ViewMatrix =
Matrix44F.GetTranslation2D(CenterPosition - _TargetSize / 2)
* Matrix44F.GetScale2D(new Vector2F(1f, 1f) / Scale)
* Matrix44F.GetRotationZ(MathHelper.DegreeToRadian(-Angle))
* Matrix44F.GetTranslation2D(-Position);
// NOTE: DrawnNodeのTransformとは逆

base.Update();
_RequireCalcTransform = false;

base.CalcTransform();
}

#region Node
Expand Down
4 changes: 2 additions & 2 deletions Engine/Node/TransformNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ internal override void Registered()

internal override void Update()
{
base.Update();

if (_RequireCalcTransform || (Transfomer?.RequireCalcTransform ?? false))
UpdateTransform();

base.Update();
}

/// <summary>
Expand Down
30 changes: 30 additions & 0 deletions Test/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,36 @@ public void NoRenderTexture()
tc.End();
}

[Test, Apartment(ApartmentState.STA)]
public void CameraGroup()
{
var tc = new TestCore();
tc.Init();

var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");
Assert.NotNull(texture);

var node = new SpriteNode();
node.Texture = texture;
node.CenterPosition = texture.Size / 2;
node.CameraGroup = 0b1L << 40;
Engine.AddNode(node);

var camera = new CameraNode();
camera.Position = new Vector2F(100, 0);
camera.Scale = new Vector2F(2, 2);
camera.Group = 0b1L << 40;
Engine.AddNode(camera);

tc.LoopBody(c =>
{
node.Angle++;
}
, null);

tc.End();
}

[Test, Apartment(ApartmentState.STA)]
public void _RenderTexture()
{
Expand Down