Skip to content

Commit ad45040

Browse files
committed
Add missing functions that take pointers
1 parent 58e4c1b commit ad45040

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

mathc.c

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,18 @@ float to_degrees(float radians)
7474
}
7575

7676
/* Vector 2D */
77-
struct vec to_vector2(float x, float y)
77+
void to_pvector2(float x, float y, struct vec *result)
78+
{
79+
result->x = x;
80+
result->y = y;
81+
result->z = 0.0f;
82+
result->w = 1.0f;
83+
}
84+
85+
MATHC_EXTERN_INLINE struct vec to_vector2(float x, float y)
7886
{
7987
struct vec result;
80-
result.x = x;
81-
result.y = y;
82-
result.z = 0.0f;
83-
result.w = 1.0f;
88+
to_pvector2(x, y, &result);
8489
return result;
8590
}
8691

@@ -411,13 +416,18 @@ MATHC_EXTERN_INLINE struct vec vector2_linear_interpolation(struct vec a, struct
411416
}
412417

413418
/* Vector 3D */
414-
struct vec to_vector3(float x, float y, float z)
419+
void to_pvector3(float x, float y, float z, struct vec *result)
420+
{
421+
result->x = x;
422+
result->y = y;
423+
result->z = z;
424+
result->w = 1.0f;
425+
}
426+
427+
MATHC_EXTERN_INLINE struct vec to_vector3(float x, float y, float z)
415428
{
416429
struct vec result;
417-
result.x = x;
418-
result.y = y;
419-
result.z = z;
420-
result.w = 1.0f;
430+
to_pvector3(x, y, z, &result);
421431
return result;
422432
}
423433

@@ -746,13 +756,18 @@ MATHC_EXTERN_INLINE struct vec vector3_linear_interpolation(struct vec a, struct
746756
}
747757

748758
/* Quaternion */
759+
void to_pquaternion(float x, float y, float z, float w, struct vec *result)
760+
{
761+
result->x = x;
762+
result->y = y;
763+
result->z = z;
764+
result->w = w;
765+
}
766+
749767
struct vec to_quaternion(float x, float y, float z, float w)
750768
{
751769
struct vec result;
752-
result.x = x;
753-
result.y = y;
754-
result.z = z;
755-
result.w = w;
770+
to_pquaternion(x, y, z, w, &result);
756771
return result;
757772
}
758773

mathc.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ float to_radians(float degrees);
5757
float to_degrees(float radians);
5858

5959
/* Vector 2D */
60-
struct vec to_vector2(float x, float y);
60+
void to_pvector2(float x, float y, struct vec *result);
6161
void pvector2_add(struct vec *a, struct vec *b, struct vec *result);
6262
void pvector2_subtract(struct vec *a, struct vec *b, struct vec *result);
6363
void pvector2_scale(struct vec *a, float scale, struct vec *result);
@@ -84,6 +84,7 @@ float pvector2_distance_to(struct vec *a, struct vec *b);
8484
float pvector2_distance_squared_to(struct vec *a, struct vec *b);
8585
void pvector2_linear_interpolation(struct vec *a, struct vec *b, float p, struct vec *result);
8686

87+
struct vec to_vector2(float x, float y);
8788
struct vec vector2_add(struct vec a, struct vec b);
8889
struct vec vector2_subtract(struct vec a, struct vec b);
8990
struct vec vector2_scale(struct vec a, float scale);
@@ -111,7 +112,7 @@ float vector2_distance_squared_to(struct vec a, struct vec b);
111112
struct vec vector2_linear_interpolation(struct vec a, struct vec b, float p);
112113

113114
/* Vector 3D */
114-
struct vec to_vector3(float x, float y, float z);
115+
void to_pvector3(float x, float y, float z, struct vec *result);
115116
void pvector3_add(struct vec *a, struct vec *b, struct vec *result);
116117
void pvector3_subtract(struct vec *a, struct vec *b, struct vec *result);
117118
void pvector3_scale(struct vec *a, float scale, struct vec *result);
@@ -136,6 +137,7 @@ float pvector3_distance_to(struct vec *a, struct vec *b);
136137
float pvector3_distance_squared_to(struct vec *a, struct vec *b);
137138
void pvector3_linear_interpolation(struct vec *a, struct vec *b, float p, struct vec *result);
138139

140+
struct vec to_vector3(float x, float y, float z);
139141
struct vec vector3_add(struct vec a, struct vec b);
140142
struct vec vector3_subtract(struct vec a, struct vec b);
141143
struct vec vector3_scale(struct vec a, float scale);
@@ -161,7 +163,7 @@ float vector3_distance_squared_to(struct vec a, struct vec b);
161163
struct vec vector3_linear_interpolation(struct vec a, struct vec b, float p);
162164

163165
/* Quaternion */
164-
struct vec to_quaternion(float x, float y, float z, float w);
166+
void to_pquaternion(float x, float y, float z, float w, struct vec *result);
165167
void pquaternion_add(struct vec *a, struct vec *b, struct vec *result);
166168
void pquaternion_subtract(struct vec *a, struct vec *b, struct vec *result);
167169
void pquaternion_scale(struct vec *a, float scale, struct vec *result);
@@ -189,6 +191,7 @@ void pquaternion_yaw_pitch_roll(float yaw, float pitch, float roll, struct vec *
189191
void pquaternion_linear_interpolation(struct vec *a, struct vec *b, float p, struct vec *result);
190192
void pquaternion_spherical_linear_interpolation(struct vec *a, struct vec *b, float p, struct vec *result);
191193

194+
struct vec to_quaternion(float x, float y, float z, float w);
192195
struct vec quaternion_add(struct vec a, struct vec b);
193196
struct vec quaternion_subtract(struct vec a, struct vec b);
194197
struct vec quaternion_scale(struct vec a, float scale);

0 commit comments

Comments
 (0)