next up previous contents
Next: Fixed size vector subtraction Up: Fixed size vectors Previous: Creating and accessing fixed   Contents

Fixed size vector addition

To add two 3-vectors use either the macro
      Gan_Vector3 v3z;

      gan_vec3_add_q ( &v3x, &v3y, &v3z ); /* macro */
or the function
      v3z = gan_vec3_add_s ( &v3x, &v3y ); /* function call */
See the discussion of ``quick'' and ``slow'' versions of the same operation, identified by the ..._q and ..._s suffices, in Section 1.1. In this case, the ``slow'' version gan_vec3_add_s() has the overhead of a function call relative to the ``quick'' version gan_vec3_add_q(), so the latter should be used unless the input vectors are not simple variables (i.e. they might be elements of arrays), in which case the repeated evaluation required by the macro version might be slower.

There are also in-place versions of the add operation, which overwrite one of the input vectors with the result. The macro operations

      gan_vec3_add_i1 ( &v3x, &v3y ); /* result in-place in v3x */
and
      gan_vec3_add_i2 ( &v3x, &v3y ); /* result in-place in v3y */
produce the same result but overwrite respectively the first v3x and the second v3y argument with the result. There is also a more explicit macro
      gan_vec3_increment ( &v3x, &v3y ); /* result in-place in v3x */
which increments v3x by v3y, i.e. identical to gan_vec3_add_i1(). Note that if one of the input arguments is a non-trivial expression, and the result is being overwritten on the other, use the function gan_vec3_add_s(), as in
      Gan_Vector3 av3x[100];

      /* ... fill av3x array ... */
      v3x = gan_vec3_add_s ( &v3x, &av3x[33] );


next up previous contents
Next: Fixed size vector subtraction Up: Fixed size vectors Previous: Creating and accessing fixed   Contents
2006-03-17