transforms
This commit is contained in:
parent
6b28e60e3a
commit
de8c8c9168
2
Makefile
2
Makefile
|
@ -76,7 +76,7 @@ else
|
|||
endif
|
||||
endif
|
||||
|
||||
CPPFLAGS += -DHAVE_CEIL -DCP_USE_CGTYPES=0 -DCP_USE_DOUBLES=0 -DTINYSPLINE_FLOAT_PRECISION -DHAVE_FLOOR -DHAVE_FMOD -DHAVE_LRINT -DHAVE_LRINTF $(includeflag) -MD $(WARNING_FLAGS) -I. -DVER=\"$(VER)\" -DINFO=\"$(INFO)\" -DENABLE_SINC_MEDIUM_CONVERTER -DENABLE_SINC_FAST_CONVERTER
|
||||
CPPFLAGS += -DHAVE_CEIL -DCP_USE_CGTYPES=0 -DCP_USE_DOUBLES=0 -DTINYSPLINE_FLOAT_PRECISION -DHAVE_FLOOR -DHAVE_FMOD -DHAVE_LRINT -DHAVE_LRINTF $(includeflag) -MD $(WARNING_FLAGS) -I. -DVER=\"$(VER)\" -DINFO=\"$(INFO)\" #-DENABLE_SINC_MEDIUM_CONVERTER -DENABLE_SINC_FAST_CONVERTER
|
||||
|
||||
# ENABLE_SINC_[BEST|FAST|MEDIUM]_CONVERTER
|
||||
# default, fast and medium available in game at runtime; best available in editor
|
||||
|
|
|
@ -141,7 +141,8 @@ var gameobject = {
|
|||
this.set_worldpos(this.level.this2world(x));
|
||||
},
|
||||
|
||||
get pos() {
|
||||
get pos() { return cmd
|
||||
|
||||
if (!this.level) return this.worldpos();
|
||||
return this.level.world2this(this.worldpos());
|
||||
},
|
||||
|
|
|
@ -44,24 +44,35 @@ struct gameobject *shape2go(cpShape *shape)
|
|||
return id2go(shape2gameobject(shape));
|
||||
}
|
||||
|
||||
HMM_Vec2 go2pos(struct gameobject *go)
|
||||
HMM_Vec2 go_pos(struct gameobject *go)
|
||||
{
|
||||
cpVect p = cpBodyGetPosition(go->body);
|
||||
return (HMM_Vec2){p.x, p.y};
|
||||
}
|
||||
|
||||
HMM_Vec2 go_worldpos(struct gameobject *go)
|
||||
{
|
||||
HMM_Vec2 ret;
|
||||
ret.cp = cpBodyGetPosition(go->body);
|
||||
return ret;
|
||||
}
|
||||
|
||||
float go_angle(struct gameobject *go) { return go_worldangle(go); }
|
||||
|
||||
float go_worldangle(struct gameobject *go) { return cpBodyGetAngle(go->body); }
|
||||
|
||||
float go2angle(struct gameobject *go) { return cpBodyGetAngle(go->body); }
|
||||
|
||||
transform3d go2t3(gameobject *go)
|
||||
{
|
||||
transform3d t;
|
||||
HMM_Vec2 p = go2pos(go);
|
||||
HMM_Vec2 p = go_pos(go);
|
||||
t.pos.X = p.X;
|
||||
t.pos.Y = p.Y;
|
||||
t.pos.Z = go->drawlayer;
|
||||
t.scale = go->scale;
|
||||
t.scale.Z = go->scale.X;
|
||||
t.rotation = HMM_QFromAxisAngle_RH(vFWD, go2angle(go));
|
||||
t.rotation = HMM_QFromAxisAngle_RH(vFWD, go_angle(go));
|
||||
t.rotation = HMM_MulQ(HMM_QFromAxisAngle_RH(vRIGHT, -t.pos.Y/100), t.rotation);
|
||||
t.rotation = HMM_MulQ(HMM_QFromAxisAngle_RH(vUP, t.pos.X/100), t.rotation);
|
||||
return t;
|
||||
|
|
|
@ -35,8 +35,9 @@ struct component;
|
|||
|
||||
typedef struct gameobject {
|
||||
cpBodyType bodytype;
|
||||
int next;
|
||||
cpBody *body; /* NULL if this object is dead; has 2d position and rotation, relative to global 0 */
|
||||
HMM_Vec3 scale; /* local */
|
||||
int next;
|
||||
float mass;
|
||||
float f; /* friction */
|
||||
float e; /* elasticity */
|
||||
|
@ -48,7 +49,6 @@ typedef struct gameobject {
|
|||
float damping;
|
||||
unsigned int layer;
|
||||
cpShapeFilter filter;
|
||||
cpBody *body; /* NULL if this object is dead */
|
||||
int id;
|
||||
struct phys_cbs cbs;
|
||||
struct shape_cb *shape_cbs;
|
||||
|
@ -82,7 +82,11 @@ HMM_Mat3 t_world2go(struct gameobject *go);
|
|||
HMM_Mat4 t3d_go2world(struct gameobject *go);
|
||||
HMM_Mat4 t3d_world2go(struct gameobject *go);
|
||||
|
||||
HMM_Vec2 go2pos(struct gameobject *go);
|
||||
HMM_Vec2 go_pos(struct gameobject *go);
|
||||
HMM_Vec2 go_worldpos(struct gameobject *go);
|
||||
//float go_angle(struct gameobject *go);
|
||||
float go_worldangle(struct gameobject *go);
|
||||
|
||||
float go2angle(struct gameobject *go);
|
||||
|
||||
HMM_Vec2 goscale(struct gameobject *go, HMM_Vec2 pos);
|
||||
|
|
|
@ -7,40 +7,14 @@ const transform2d t2d_unit = {
|
|||
.angle = 0
|
||||
};
|
||||
|
||||
HMM_Vec3 trans_forward(const transform3d *const trans)
|
||||
{
|
||||
return HMM_QVRot(vFWD, trans->rotation);
|
||||
}
|
||||
HMM_Vec3 trans_forward(const transform3d *const trans) { return HMM_QVRot(vFWD, trans->rotation); }
|
||||
HMM_Vec3 trans_back(const transform3d *trans) { return HMM_QVRot(vBKWD, trans->rotation); }
|
||||
HMM_Vec3 trans_up(const transform3d *trans) { return HMM_QVRot(vUP, trans->rotation); }
|
||||
HMM_Vec3 trans_down(const transform3d *trans) { return HMM_QVRot(vDOWN, trans->rotation); }
|
||||
HMM_Vec3 trans_right(const transform3d *trans) { return HMM_QVRot(vRIGHT, trans->rotation); }
|
||||
HMM_Vec3 trans_left(const transform3d *trans) { return HMM_QVRot(vLEFT, trans->rotation); }
|
||||
|
||||
HMM_Vec3 trans_back(const transform3d *trans)
|
||||
{
|
||||
return HMM_QVRot(vBKWD, trans->rotation);
|
||||
}
|
||||
|
||||
HMM_Vec3 trans_up(const transform3d *trans)
|
||||
{
|
||||
return HMM_QVRot(vUP, trans->rotation);
|
||||
}
|
||||
|
||||
HMM_Vec3 trans_down(const transform3d *trans)
|
||||
{
|
||||
return HMM_QVRot(vDOWN, trans->rotation);
|
||||
}
|
||||
|
||||
HMM_Vec3 trans_right(const transform3d *trans)
|
||||
{
|
||||
return HMM_QVRot(vRIGHT, trans->rotation);
|
||||
}
|
||||
|
||||
HMM_Vec3 trans_left(const transform3d *trans)
|
||||
{
|
||||
return HMM_QVRot(vLEFT, trans->rotation);
|
||||
}
|
||||
|
||||
HMM_Vec2 mat_t_pos(HMM_Mat3 m, HMM_Vec2 pos)
|
||||
{
|
||||
return HMM_MulM3V3(m, (HMM_Vec3){pos.x, pos.y, 0}).XY;
|
||||
}
|
||||
HMM_Vec2 mat_t_pos(HMM_Mat3 m, HMM_Vec2 pos) { return HMM_MulM3V3(m, (HMM_Vec3){pos.x, pos.y, 0}).XY; }
|
||||
|
||||
HMM_Vec2 mat_t_dir(HMM_Mat3 m, HMM_Vec2 dir)
|
||||
{
|
||||
|
@ -48,10 +22,13 @@ HMM_Vec2 mat_t_dir(HMM_Mat3 m, HMM_Vec2 dir)
|
|||
return HMM_MulM3V3(m, (HMM_Vec3){dir.x, dir.y, 1}).XY;
|
||||
}
|
||||
|
||||
HMM_Vec3 mat3_t_pos(HMM_Mat4 m, HMM_Vec3 pos)
|
||||
{
|
||||
return HMM_MulM4V4(m, (HMM_Vec4){pos.X, pos.Y, pos.Z, 1}).XYZ;
|
||||
}
|
||||
HMM_Vec2 mat_up(HMM_Mat3 m) { return HMM_NormV2(m.Columns[1].XY); }
|
||||
HMM_Vec2 mat_right(HMM_Mat3 m) { return HMM_NormV2(m.Columns[0].XY); }
|
||||
float vec_angle(HMM_Vec2 a, HMM_Vec2 b) { return acos(HMM_DotV2(a,b)/(HMM_LenV2(a)*HMM_LenV2(b))); }
|
||||
float vec_dirangle(HMM_Vec2 a, HMM_Vec2 b) { return atan2(b.x, b.y) - atan2(a.x, a.y); }
|
||||
|
||||
|
||||
HMM_Vec3 mat3_t_pos(HMM_Mat4 m, HMM_Vec3 pos) { return HMM_MulM4V4(m, (HMM_Vec4){pos.X, pos.Y, pos.Z, 1}).XYZ; }
|
||||
|
||||
HMM_Vec3 mat3_t_dir(HMM_Mat4 m, HMM_Vec3 dir)
|
||||
{
|
||||
|
|
|
@ -29,6 +29,11 @@ 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);
|
||||
|
||||
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);
|
||||
|
||||
HMM_Vec3 mat3_t_pos(HMM_Mat4 m, HMM_Vec3 pos);
|
||||
HMM_Vec3 mat3_t_dir(HMM_Mat4 m, HMM_Vec3 dir);
|
||||
|
||||
|
|
Loading…
Reference in a new issue