2021-11-30 21:29:18 -06:00
|
|
|
#ifndef TRANSFORM_H
|
|
|
|
#define TRANSFORM_H
|
|
|
|
|
2023-05-24 20:45:50 -05:00
|
|
|
#include "HandmadeMath.h"
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2024-05-12 18:36:14 -05:00
|
|
|
typedef struct transform {
|
2024-05-14 15:22:24 -05:00
|
|
|
HMM_Vec3 pos;
|
|
|
|
HMM_Vec3 scale;
|
|
|
|
HMM_Quat rotation;
|
|
|
|
HMM_Mat4 cache;
|
|
|
|
int dirty;
|
2024-05-12 18:36:14 -05:00
|
|
|
} transform;
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2024-05-12 18:36:14 -05:00
|
|
|
transform *make_transform();
|
2024-07-23 14:30:41 -05:00
|
|
|
void transform_apply(transform *t);
|
2024-05-12 18:36:14 -05:00
|
|
|
void transform_free(transform *t);
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2023-12-04 13:38:37 -06:00
|
|
|
#define VEC2_FMT "[%g,%g]"
|
|
|
|
#define VEC2_MEMS(s) (s).x, (s).y
|
|
|
|
|
2024-09-29 06:10:42 -05:00
|
|
|
#define TR_FMT "(pos) " HMMFMT_VEC3 " scale " HMMFMT_VEC3
|
|
|
|
#define TR_PRINT(tr) HMMPRINT_VEC3(tr->pos), HMMPRINT_VEC3(tr->scale)
|
|
|
|
|
2024-05-15 07:54:19 -05:00
|
|
|
void transform_move(transform *t, HMM_Vec3 v);
|
|
|
|
HMM_Vec3 transform_direction(transform *t, HMM_Vec3 dir);
|
2024-04-23 15:58:08 -05:00
|
|
|
|
2023-11-30 10:47:59 -06:00
|
|
|
/* Transform a position via the matrix */
|
|
|
|
HMM_Vec2 mat_t_pos(HMM_Mat3 m, HMM_Vec2 pos);
|
|
|
|
/* Transform a direction via the matrix - does not take into account translation of matrix */
|
|
|
|
HMM_Vec2 mat_t_dir(HMM_Mat3 m, HMM_Vec2 dir);
|
|
|
|
|
2023-11-30 16:24:26 -06:00
|
|
|
HMM_Vec2 mat_up(HMM_Mat3 m);
|
|
|
|
HMM_Vec2 mat_right(HMM_Mat3 m);
|
|
|
|
float vec_angle(HMM_Vec2 a, HMM_Vec2 b);
|
|
|
|
float vec_dirangle(HMM_Vec2 a, HMM_Vec2 b);
|
|
|
|
|
2023-11-30 10:47:59 -06:00
|
|
|
HMM_Vec3 mat3_t_pos(HMM_Mat4 m, HMM_Vec3 pos);
|
|
|
|
HMM_Vec3 mat3_t_dir(HMM_Mat4 m, HMM_Vec3 dir);
|
|
|
|
|
2024-07-23 14:30:41 -05:00
|
|
|
HMM_Mat4 transform2mat(transform *t);
|
2024-05-12 18:36:14 -05:00
|
|
|
transform mat2transform(HMM_Mat4 m);
|
|
|
|
|
|
|
|
HMM_Quat angle2rotation(float angle);
|
2021-11-30 21:29:18 -06:00
|
|
|
|
|
|
|
#endif
|