Saturday, June 3, 2023
HomeGame Developmentunity - Discover coordinates in a single house from one other

unity – Discover coordinates in a single house from one other


I am making an attempt to find out what coordinates are in a single house when given a degree in one other house.

For instance, I’ve bought a Matrix4x4 that I can use to transform a degree in unity’s world house to a skewed house outlined by that matrix.

The inverse of this matrix returns me to the unique world house.

non-public float HALF_SQRT_3 = Mathf.Sqrt(3) / 2;

non-public Matrix4x4 mWorldToSkewGrid = new Matrix4x4(
    new Vector4(HALF_SQRT_3, 0, 0, 0),
    new Vector4(0, 1, 0, 0),
    new Vector4(Mathf.Cos(Mathf.PI / 3) * HALF_SQRT_3, 0, Mathf.Sin(Mathf.PI / 3) * HALF_SQRT_3, 0),
    new Vector4(0, 0, 0, 1)
);

non-public Matrix4x4 mSkewGridToWorld = mWorldToSkewGrid.inverse;

I am trying to determine how I can go about getting the coordinates of the skewed house AT the default world house moderately than remodeling a degree in default house to the skewed house.

I assumed it was one thing just like how unity converts a display screen level right into a world level.
One thing like this:

Vector4 p = mSkewGridToWorld * new Vector4(defaultWorldPos.x, defaultWorldPos.y, defaultWorldPos.z, 1.0f);
p.w = 1.0f / p.w;
p.x *= p.w;
p.y *= p.w;
p.z *= p.w;

The place p is meant to carry the place of defaultWorldPos however within the skewed coordinates the place it might overlap within the skewed house.

Edit: Under is an instance of the “default world house” in inexperienced being reworked into the “skewed house” in pink, represented by a 10×10 grid. Reasonably than remodeling say the grid cell 5×5 to the opposite house ensuing within the level shifting and being nonetheless at 5×5 within the skewed house, I need to know what skewed level is beneath 5×5, on this instance it might be one thing like 2×6 within the skewed house.
Example image showing the default world space in a green grid being transformed to the skewed space in a red grid.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments