-
Notifications
You must be signed in to change notification settings - Fork 20
Update transform system to allow for rotations #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: TonyMax <[email protected]>
Co-authored-by: TonyMax <[email protected]>
Co-authored-by: TonyMax <[email protected]>
Co-authored-by: TonyMax <[email protected]>
Co-authored-by: TonyMax <[email protected]>
Co-authored-by: TonyMax <[email protected]>
Co-authored-by: TonyMax <[email protected]>
Ok, thank you for that brilliant work. Will merge it after finish my refactoring branch where I've reworked authoring components to be more flexible (+ some minor bug fixes). |
Is it problematic to split |
Yes, that is a required component for this way of handling positions. This component gets updates via the transform system and should not be manually updated. Use LocalToWorld2D to update the positions of an entity |
In your use case I think you want seperate components for the L2W? Never really required it to have seperate components myself though |
|
I'm sorry, I was a little bit out of date with current unity's transforms implementation. I've read docs and as I understand both And it also seems like I even see methods like However I see that unity no longer have TRS components and there is solid |
Also as I can see despite we are in 2D space we still use 4x4 matrix passed to shader. And what is optimized is So this is quite the same implementation as a built-in one. Is this right? |
Yes, that is correct. I just copied and pasted unity's version, then making it all 2d, then making it work with NSprites-foundation |
There is some kind of problem with culling process. It seems like sprite gets culled every time it is NOT fully on screen. Also I doubt 2D rectangle bounds still can fully work because now we have full 3D transform matrix. |
Wow it was hard! There was a bunch of problems I believe I've solved:
So public static Bounds2D From(in LocalToWorld2D ltw, in Scale2D size, in Pivot pivot)
{
var rotation = MathHelper.euler(ltw.Rotation).z;
var scale = ltw.Scale * size.value;
var localCenter= -scale * pivot.value + scale * .5f;
var sin = math.sin(rotation);
var cos = math.cos(rotation);
static float2 RotateScale2D(in float sin, in float cos, in float2 v)
{
var abssin = math.abs(sin);
var abscos = math.abs(cos);
return new float2(v.x * abscos + v.y * abssin, v.x * abssin + v.y * abscos);
}
static float2 RotateFloat2(in float sin, in float cos, in float2 v)
=> new(v.x * cos - v.y * sin, v.x * sin + v.y * cos);
var adjustedScale = RotateScale2D(sin, cos, scale);
var position = ltw.Position + RotateFloat2(sin, cos, localCenter);
return new Bounds2D(position, adjustedScale);
} |
Uh oh!
There was an error while loading. Please reload this page.