Day 50: Very confused about TestWall's linear blend

6 months, 3 weeks ago
Edited by
panthalassadigital
on April 10, 2020, 9:31 a.m.
Hi folks,

I'm very confused about an aspect of the collision detection algorithm used in Day 50 and some episodes prior. My confusion is not so much regarding linear blending as a concept, but more on the particular implementation of that blend in the TestWallfunction.

It seems like there are three quantities at play here:

WallX: the X component of the wall we're testing, relative to the center of the test tile

RelX/Y: the distance to the player's current position, relative to the center of the test tile

PlayerDeltaX/Y: the computed end position of the player, relative to the player's current position

What confuses the hell outta me is that the end of the above lines differ in that final remark, i.e. WallX and RelX/Y are relative*to center of the test tile* TestTileP, but the 3rd is *relative to the player's starting position* Entity->P.

This kinda stumps my intuition somewhat - don't all of these quantities need to "agree" on a common 0,0 origin in order for the math to work? I don't understand how linearly blending between RelX/Y and PlayerDeltaX/Y up to point WallX gives us the correct result, given the above. What am I missing here?

Any help would be massively appreciated!

Thanks,

- Jonny

I'm very confused about an aspect of the collision detection algorithm used in Day 50 and some episodes prior. My confusion is not so much regarding linear blending as a concept, but more on the particular implementation of that blend in the TestWallfunction.

It seems like there are three quantities at play here:

WallX: the X component of the wall we're testing, relative to the center of the test tile

RelX/Y: the distance to the player's current position, relative to the center of the test tile

PlayerDeltaX/Y: the computed end position of the player, relative to the player's current position

What confuses the hell outta me is that the end of the above lines differ in that final remark, i.e. WallX and RelX/Y are relative

This kinda stumps my intuition somewhat - don't all of these quantities need to "agree" on a common 0,0 origin in order for the math to work? I don't understand how linearly blending between RelX/Y and PlayerDeltaX/Y up to point WallX gives us the correct result, given the above. What am I missing here?

Any help would be massively appreciated!

Thanks,

- Jonny

Day 50: Very confused about TestWall's linear blend

6 months, 3 weeks ago
Do you have a timestamp in the episode ? Or some code with context ?

Day 50: Very confused about TestWall's linear blend

6 months, 3 weeks ago
Edited by
panthalassadigital
on April 14, 2020, 2:08 p.m.
Hi again Simon! Yes absolutely I can give code with context - the code I'm using as reference is from the end of day 50.

So, this is how the values in question are computed:

and the linear blend equation in the TestWall function looks like this:

Hopefully that makes it clearer what I'm trying to say - MaxCorner and Relare computed as quantities relative to the center of the test tile, but PlayerDelta is computed as a quantity relative to the Player Entity's current position.

It was my understanding that all the vectors needed to agree on a common "origin", or the math wouldn't work. Am I misunderstanding something? Appreciate the help!

- Jonny

[EDIT]: Here's a little sketch with what I'm describing, in case that makes it any easier to understand. Thanks!

So, this is how the values in question are computed:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // Vector containing WallX (in this example case) // computed as the vector from the center of the test tile to the wall we're testing real32 DiameterW = TileMap->TileSideInMeters + Entity->Width; real32 DiameterH = TileMap->TileSideInMeters + Entity->Height; v2 MaxCorner = 0.5f*v2{DiameterW, DiameterH}; // Vector containing RelX // computed from the center of the test tile to the Entity's current position tile_map_difference RelOldPlayerP = Subtract(TileMap, &Entity->P, &TestTileP); v2 Rel = RelOldPlayerP.dXY; // Vector containing PlayerDeltaX // computed as the position delta from the entity's current position v2 PlayerDelta = (0.5f*ddP*Square(dt) + Entity->dP*dt); |

and the linear blend equation in the TestWall function looks like this:

1 | real32 tResult = (WallX - RelX) / PlayerDeltaX; |

Hopefully that makes it clearer what I'm trying to say - MaxCorner and Relare computed as quantities relative to the center of the test tile, but PlayerDelta is computed as a quantity relative to the Player Entity's current position.

It was my understanding that all the vectors needed to agree on a common "origin", or the math wouldn't work. Am I misunderstanding something? Appreciate the help!

- Jonny

[EDIT]: Here's a little sketch with what I'm describing, in case that makes it any easier to understand. Thanks!

Day 50: Very confused about TestWall's linear blend

6 months, 3 weeks ago
Vectors are a direction and magnitude (length), they don't have a position or origin.

If you have two points and subtract them you have the vector that represent the "movement" to do to go from one point to the other. For example to go from point A (2, 4) to point B (4, 7) you have a to move (4-2, 7-4) = (2, 3). If you use A (3, 2) and B (5, 5) you will get the same vector. There is an infinity of point you can use to get the same vector.

The important part is that the points used to find the vectors, need to be in the same coordinate space.

If you have two points and subtract them you have the vector that represent the "movement" to do to go from one point to the other. For example to go from point A (2, 4) to point B (4, 7) you have a to move (4-2, 7-4) = (2, 3). If you use A (3, 2) and B (5, 5) you will get the same vector. There is an infinity of point you can use to get the same vector.

The important part is that the points used to find the vectors, need to be in the same coordinate space.