I'm looking for what exactly is a Vector3 (or any Vector for that matter) and also what a Quaternion is in code?
What are the variables types? Should you have multiple classes for each type?
Thanks!
I'm looking for what exactly is a Vector3 (or any Vector for that matter) and also what a Quaternion is in code?
What are the variables types? Should you have multiple classes for each type?
Thanks!
I'm looking for what exactly is a Vector3 (or any Vector for that matter) and also what a Quaternion is in code? What are the variables types? Should you have multiple classes for each type?
Depends on the language you're using, and even then, there are multiple ways to represent vectors and quaternions.
Vectors in R3 can be simple structures with x, y, and z members, or you can use an array-like member to hold those values instead. You'll need arrays (or equivalent) to represent generic vectors in Rn though. If you're going to be working with matrices, you might also consider using a 1xn or nx1 matrix for your vectors.
The actual member type will be something "close enough" to a real number. For practical purposes, this is usually a single- or double-precision floating point value, unless you're doing something special, which is an entirely different conversation.
Then there are vector operations--some are only defined for vectors of certain sizes, and others, while they can be written generically for any size vector, have alternate implementations that are smaller and/or faster for certain sizes. Depending on your language, you may be able to take advantage of inheritance and/or templates to avoid writing duplicate code.
The quaternions (denoted H) are equivalent to vectors in R4, just with special operations.
As you don't exactly state the exact programming language you're working in, you will find on this Rosetta site some code for quaternions.