52 lines
1.2 KiB
Markdown
52 lines
1.2 KiB
Markdown
# Setting the coordinates of a two-dimensional vector
|
|
|
|
[Русская версия / Russian version](set-values-rus.md)
|
|
|
|
You can set the coordinates of vectors either directly or using functions.
|
|
The functions for setting coordinate values allow you to do this in one line.
|
|
|
|
Function for **BGC_FP32_Vector2**:
|
|
|
|
```c
|
|
inline void bgc_fp32_vector2_set_values(BGC_FP32_Vector2* const destination, const float x, const float y);
|
|
```
|
|
|
|
Function for **BGC_FP64_Vector2**:
|
|
|
|
```c
|
|
inline void bgc_fp64_vector2_set_values(BGC_FP64_Vector2* const destination, const double x, const double y);
|
|
```
|
|
|
|
Each of these functions is equivalent to the following lines of code:
|
|
|
|
```c
|
|
destination->x = x;
|
|
destination->y = y;
|
|
```
|
|
|
|
Valid pointers should pass in the **destination** parameter.
|
|
The NULL (0) value is considered invalid.
|
|
|
|
This function is good for setting up the initial values of coordinates with
|
|
one-line especially when the values are fixed constants like in the example
|
|
below.
|
|
|
|
Example of use:
|
|
|
|
```c
|
|
#include <stdio.h>
|
|
#include <basic-geometry.h>
|
|
|
|
int main()
|
|
{
|
|
BGC_FP32_Vector2 v;
|
|
|
|
bgc_fp32_vector2_set_values(&v, -2.2f, 7.1f);
|
|
|
|
printf("x = %f, y = %f\n", v.x, v.y);
|
|
|
|
return 0;
|
|
}
|
|
```
|
|
|
|
[Documentation](../intro-eng.md) / [2D vectors](../vector2-eng.md)
|