We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

simon • 7 years ago

"int operator==(vec3 rhs);"
should be
"bool operator==(vec3 rhs);" in the header i guess,

also you cannot add/substract a scalar from a Vector, its undefined behavior.
Multiplying and dividing a vector by a vector is also not possible.

Jon • 7 years ago

Thanks for this. It's not every day that I get corrections for a 7 year old blog post. :)

I changed int to bool where you noted that it was incorrect.

I had originally defined addition and subtraction to work on vectors and scalars in the same way as multiplication and division. You're right that this isn't defined mathematically, and I'm not aware of a single real-world use for this, so I've removed it.

Thank you!

simon • 7 years ago

i have to give Thanks...
was searching for a simple Vector lib, but all i could find are tons of libs, with hundreds of header files i don't have use for. luckily i stumbled across this and just stitched my own mini-lib together.

if you are interested, i'll post normalization and projection implementations later on, so you can include that for future souls, too lazy to look up and implement these Vector basics :)

Jon • 7 years ago

I'm glad it was helpful. I probably won't add anything to this, as other more complete libs exist.

I believe that the two methods you mentioned are simple to add as:

v.norm() => v / v.length()
v.proj(rhs) => v ยท rhs.norm()

Sean Vinsick • 9 years ago

This is awesome thank you!

Maya • 11 years ago

What does "rhs" refer to?

Jon • 11 years ago

This refers to the right hand side of the operation.