bgc-c/docs/vector3/swap-eng.md

1.9 KiB

Swapping of coordinate values

Русская версия / Russian version

The function for BGC_FP32_Vector3:

inline void bgc_fp32_vector3_swap(BGC_FP32_Vector3* const vector1, BGC_FP32_Vector3* const vector2);

The function for BGC_FP64_Vector3:

inline void bgc_fp64_vector3_swap(BGC_FP64_Vector3* const vector1, BGC_FP64_Vector3* const vector2);

These functions allow to swap the values of the coordinates of two vectors of the same type.

Parameters

Parameter Direction Description
vector1 in / out A pointer to a 3D vector where the values of the coordinates of vector2 will be copied
vector2 in / out A pointer to a 3D vector where the values of the coordinates of vector1 will be copied

The vector1 and vector2 parameters must be valid pointers. The NULL (0) value is considered invalid.

The vector1 vector will have the same values of the coordinates as vector2 had before the calling of the function.

And the vector2 vector will have the same values of the coordinates as vector1 had before the calling of the function.

Example

#include <stdio.h>
#include <basic-geometry.h>

int main()
{
    BGC_FP32_Vector3 v1, v2;

    bgc_fp32_vector3_set_values(&v1, -2, 7, 5);
    bgc_fp32_vector3_set_values(&v2, 10, -1, -3);

    bgc_fp32_vector3_swap(&v1, &v2);

    printf("Vector #1: x = %f, y = %f, z = %f\n", v1.x, v1.y, v1.z);
    printf("Vector #2: x = %f, y = %f, z = %f\n", v2.x, v2.y, v2.z);

    return 0;
}

Output:

Vector #1: x = 10.000000, y = -1.000000, z = -3.000000
Vector #2: x = -2.000000, y = 7.000000, z = 5.000000

Documentation / 3D vectors