4D matrix / vector addition?

Started by
0 comments, last by Zakwayda 16 years, 10 months ago
I'm trying to write a basic math library for use in games. I'm writing support for 4D matrices and vectors because I want to be able to use a single matrix to describe both rotations and translations. But I don't know of a clean way to handle addition between two 4D matrices or two 4D vectors. For example, if I want to sum up a bunch of vectors and then transform the sum by some matrix, I'll probably want the w coordinate of the sum vector to be 1, but if I just do straight vector addition it will end up being more than 1. I could just ignore the fourth dimension when performing addition, but this seems like an ugly hack. This seems like it would be a fairly common problem, so I'm just wondering if there is some sort of convention on how to perform addition.
Advertisement
Can you give an example of a case where you would want to add 4x4 matrices, or add 3D points (represented by 4D vectors) and then transform the result?

Also, I'll give some advice that's often repeated around here: if your goal is to make games (rather than, say, exercise your programming skills or build basic math knowledge), use a pre-existing math library rather than writing your own. In other words, don't write a math library just because you need a math library (that work has already been done many times over by others).

If you do want to look into existing math libraries, options that come to mind include WildMagic, SVL, and the CML (the latter of which I am co-author).

This topic is closed to new replies.

Advertisement