Tuesday, September 26, 2023
HomeGame DevelopmentDiscover coordinates in a single house from one other C#/Unity

Discover coordinates in a single house from one other C#/Unity

I am attempting to find out what coordinates are in a single house when given some extent in one other house.

For instance, I’ve received a Matrix4x4 that I can use to transform some extent 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 making an attempt to determine how I can go about getting the coordinates of the skewed house AT the default world house slightly than reworking some extent 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 could overlap within the skewed house.

Edit: Under is an instance of the “default world house” in inexperienced being reworked into the “skewed house” in purple, represented by a 10×10 grid. Slightly than reworking 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 underneath 5×5, on this instance it could 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.



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments

Arnavsijapati on Planet of Lana – Beta Demo
Jai Kishor Upadhyay on Planet of Lana – Beta Demo