prosperon/source/engine/transform.h

49 lines
1.2 KiB
C
Raw Normal View History

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
2023-11-30 10:47:59 -06:00
typedef struct {
2023-05-24 20:45:50 -05:00
HMM_Vec3 pos;
2023-11-30 10:47:59 -06:00
HMM_Vec3 scale;
2023-05-24 20:45:50 -05:00
HMM_Quat rotation;
2023-11-30 10:47:59 -06:00
} transform3d;
2021-11-30 21:29:18 -06:00
2023-11-30 10:47:59 -06:00
typedef struct {
HMM_Vec2 pos;
HMM_Vec2 scale;
float angle;
} transform2d;
2021-11-30 21:29:18 -06:00
2023-11-30 10:47:59 -06:00
extern const transform2d t2d_unit;
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
2023-11-30 10:47:59 -06:00
HMM_Vec3 trans_forward(const transform3d *const trans);
HMM_Vec3 trans_back(const transform3d *trans);
HMM_Vec3 trans_up(const transform3d *trans);
HMM_Vec3 trans_down(const transform3d *trans);
HMM_Vec3 trans_right(const transform3d *trans);
HMM_Vec3 trans_left(const transform3d *trans);
2021-11-30 21:29:18 -06: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);
HMM_Mat3 transform2d2mat(transform2d t);
2023-12-04 13:38:37 -06:00
transform2d mat2transform2d(HMM_Mat3 m);
2023-11-30 10:47:59 -06:00
HMM_Mat4 transform3d2mat(transform3d t);
2023-12-04 13:38:37 -06:00
transform3d mat2transform3d(HMM_Mat4 m);
2021-11-30 21:29:18 -06:00
#endif