Skip to content

Instantly share code, notes, and snippets.

@unbit
Created November 22, 2018 12:22
Show Gist options
  • Save unbit/8bf6ff8a4967eb152a65c929829ee4cc to your computer and use it in GitHub Desktop.
Save unbit/8bf6ff8a4967eb152a65c929829ee4cc to your computer and use it in GitHub Desktop.
#include <stdio.h>
struct vector3 {
float x;
float y;
float z;
};
struct vector3 vector3_add(struct vector3 v0, struct vector3 v1) {
struct vector3 new_vec;
new_vec.x = v0.x + v1.x;
new_vec.y = v0.y + v1.y;
new_vec.z = v0.z + v1.z;
return new_vec;
}
void vector3_init(struct vector3 *v0, float x, float y, float z) {
v0->x = x;
v0->y = y;
v0->z = z;
}
int main(int argc, char **argv) {
struct vector3 va;
struct vector3 vb;
struct vector3 vd;
struct vector3 *vshit = &vd;
vector3_init(&va, 1, 2, 3);
vector3_init(&vb, 4, 5, 6);
vector3_init(vshit, 4, 5, 6);
struct vector3 vc = vector3_add(va, vb);
printf("vector3 %f %f %f\n", vc.x, vc.y, vc.z);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment