PDA

View Full Version : Vector representation



Michael Steinberg
09-07-2008, 04:53 AM
Hello there!
Ever since, I used C-Funtions for my vector/vertex manipulation-code. I now decided to wrap my vectors up in C++ classes and ran across the problem of properly handling homogenous vectors. As the packing of vectors and vertices in 4-float manner is ideal, you essentially get a 4th component for free. In your math libraries, do you handle the 4th component (commonly named w) at all? I mean, the difference of two vertices (with w=1 per definition) yields a vector (w=0), which makes perfect sense, but how often would one really need this distinction in-data? You see, I want to handle things nice and correctly, but implementing the dot-product for four dimensions for example breaks nice packing for plane representations or I cannot use the standard operations in derived types. Did you ever come across occasions, which led you to set w to anything but 0 or 1, meaning you need mathematically correct handling of homogenous vectors?

I hope I explained my concerns understandably.

Best regards,
Michael

dletozeun
09-07-2008, 06:09 AM
but implementing the dot-product for four dimensions for example breaks nice packing for plane representations or I cannot use the standard operations in derived types


I don't understand you here, can you explain explicate a bit more?

Michael Steinberg
09-07-2008, 06:30 AM
Hey.
I specifically meant Packing of Normal and distance (Hesse-Form) of the plane into a 4d vector. If that vector implements its operations in 4D, the plane class would have to reimplement all needed operations on vectors.
After all, my concerns here are all about style.

dletozeun
09-07-2008, 06:38 AM
Yes you would have to overload functions like cross product, addition,... for a plane or don't make a distinction between points vectors and planes as w is always 0 for a vector, this would not cause problems.

Michael Steinberg
09-07-2008, 08:49 AM
Yes, now that I thought about using SSE extensions eventually, i will have to implement that plane packing distinctly anyways, since those SSE operations always work on 1 or all 4 components, if I understand that correctly. So I'll probably ignore w or will do it correctly when it comes for free and add special code for planes.