22 #ifndef CHIPMUNK_TRANSFORM_H
23 #define CHIPMUNK_TRANSFORM_H
25 #include "chipmunk_types.h"
30 static const cpTransform cpTransformIdentity = {1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f};
55 cpFloat inv_det = 1.0/(t.a*t.d - t.c*t.b);
56 return cpTransformNewTranspose(
57 t.d*inv_det, -t.c*inv_det, (t.c*t.ty - t.tx*t.d)*inv_det,
58 -t.b*inv_det, t.a*inv_det, (t.tx*t.b - t.a*t.ty)*inv_det
66 return cpTransformNewTranspose(
67 t1.a*t2.a + t1.c*t2.b, t1.a*t2.c + t1.c*t2.d, t1.a*t2.tx + t1.c*t2.ty + t1.tx,
68 t1.b*t2.a + t1.d*t2.b, t1.b*t2.c + t1.d*t2.d, t1.b*t2.tx + t1.d*t2.ty + t1.ty
76 return cpv(t.a*p.x + t.c*p.y + t.tx, t.b*p.x + t.d*p.y + t.ty);
83 return cpv(t.a*v.x + t.c*v.y, t.b*v.x + t.d*v.y);
94 cpFloat a = t.a*hw, b = t.c*hh, d = t.b*hw, e = t.d*hh;
102 cpTransformTranslate(
cpVect translate)
104 return cpTransformNewTranspose(
105 1.0, 0.0, translate.x,
106 0.0, 1.0, translate.y
114 return cpTransformNewTranspose(
122 cpTransformRotate(
cpFloat radians)
125 return cpTransformNewTranspose(
136 return cpTransformNewTranspose(
137 rot.x, -rot.y, translate.x,
138 rot.y, rot.x, translate.y
146 return cpTransformNewTranspose(
147 t.d, -t.c, (t.c*t.ty - t.tx*t.d),
148 -t.b, t.a, (t.tx*t.b - t.a*t.ty)
158 return cpTransformMult(cpTransformInverse(outer), cpTransformMult(inner, outer));
164 return cpTransformMult(outer, cpTransformMult(inner, cpTransformInverse(outer)));
168 cpTransformOrtho(
cpBB bb)
170 return cpTransformNewTranspose(
171 2.0/(bb.r - bb.l), 0.0, -(bb.r + bb.l)/(bb.r - bb.l),
172 0.0, 2.0/(bb.t - bb.b), -(bb.t + bb.b)/(bb.t - bb.b)
180 return cpTransformNewTranspose(
189 cpFloat A = axis.x*axis.y*(scale - 1.0);
192 return cpTransformNewTranspose(
193 scale*axis.x*axis.x + axis.y*axis.y, A, axis.x*B,
194 A, axis.x*axis.x + scale*axis.y*axis.y, axis.y*B