-
Adding Vectors
I guess this is more conceptual, and not very game programming related, but okay. I have a quantity which is represented by a unit vector in a cvector class, which has an x, y, z, and magnitude values and then can normalize itself. In my situation they represent acceleration due to gravitation. I don't understand how I can add a vector in the form aB + cD = xY with a, b being scaler magnitudes, B and D being directed unit vectors, and xY being sum.
-
a<x,y,z> + b<A,B,C> = <ax,ay,az> + <bA,bB,bC> = <ax +bA, ay + bB, az + bC>
err, is that what you wanted?
-
You need to multiply 2 vectors by 2 sep scalars and then add the results?
To multiply a vector V by a scalar s:
V*s=(V.x*s,V.y*s,V.z*s)
To add two vectors V1 and V2:
V1+V2=(V1.x+V2.x,V1.y+V2.y,V1.z+V2.z)
-
For the original question I suggest you look for tutorials on operator overloading. Most of them use a vector class to teach you the concept. With this you can specify how the class is manipulated when other data types are used with that operator. If you have a Vector3d vec(1,5,3) and then write vec = vec*5, vec will now be 5,25,15.
<off topic> Also what were the C++ people thinking when they named a stl linked list type thing "std::vector" that is just confusing.</off topic>
-
We answered the original question.
-
Okay.
So, if I were to be calculating the acceleration of, for example, the acceleration due to gravity of one object to another, would I use the normalized displacement vector of the one object to the other multiplied by the scaler magnitude of the that acceleration?