p = tdu.Position()

p1 = tdu.Position()

p = p + p1

// result

td.Error: Addition between a Position and a Position is undefined.

I get the docs doesn’t specify this, and specifies subtraction returns a vector. But this should be allowed.

A bit annoying as I have to change to vectors to do addition

2020 23680

It’s tricky. The reason I’ve designed it this way is to ensure that the operations stay correct for matrix multiplication. For a 4x4 matrix to be properly applied to a vector or a position it’s critical that the W value is correct. If W = 1 then it’s a position, if W = 0 then it’s a vector. If it’s anything else the operation is incorrect. If you have the wrong W value then your value (vector or position) will be improperly transformed by the 4x4 matrix.

Any operation needs to result in either W = 0 or W = 1.

Position - Position works because W=1 - W=1 = W=0 (a vector)

However Position + Position means W=1 + W=1 = W=2, which is meaningless.

It may be annoying but it greatly helps avoiding common pitfalls I’ve seen when people are writing GLSL code, where they end up with incorrect W value for their vec4s due to adding positions together.

1 Like