public Matrix2x3 inverse( Matrix2x3 other ) { double invdet = 1.0 / (r1c1*r2c2 - r1c2*r2c1); Matrix2x3 result; result.r1c1 = r2c2 * invdet; result.r1c2 = -r1c2 * invdet; result.r1c3 = (r1c2*r2c3 - r1c3*r2c2) * invdet; result.r2c1 = -r2c1 * invdet; result.r2c2 = r1c1 * invdet; result.r2c3 = (r1c3*r2c1 - r1c1*r2c3) * invdet; return result; }
public Matrix2x3 times( Matrix2x3 other ) { /* a b c * g h i d e f j k l 0 0 1 0 0 1 = ag+bj ah+bk ai+bl+c dg+ej dh+ek di+el+f */ return new Matrix2x3( r1c1*other.r1c1+r1c2*other.r2c1, r1c1*other.r1c2+r1c2*other.r2c2, r1c1*other.r1c3+r1c2*other.r2c3 + r1c3, r2c1*other.r1c1+r2c2*other.r2c1, r2c1*other.r1c2+r2c2*other.r2c2, r2c1*other.r1c3+r2c2*other.r2c3 + r2c3 ); }
public static void push_object_transform( ClassTransformManager obj, CompoundTransform transform) { if (object_transform_stack_count < TRANSFORM_STACK_SIZE) { CompoundTransformRow r0 = transform.property_r0; CompoundTransformRow r1 = transform.property_r1; object_transform_stack[object_transform_stack_count++] = new Matrix2x3( r0.property_c0, r0.property_c1, r0.property_c2, r1.property_c0, r1.property_c1, r1.property_c2 ); object_transform_stack_modified = true; } }
public static void update() { bool modified = false; int camera_count = camera_transform_stack_count; if (camera_transform_stack_modified) { modified = true; camera_transform_stack_modified = false; if (camera_count > 0) { int mpos = 0; camera_transform = camera_transform_stack[0]; while (--camera_count > 0) { camera_transform = camera_transform.times(camera_transform_stack[++mpos]); } } else { camera_transform = new Matrix2x3(1,0,0,0,1,0); } } int object_count = object_transform_stack_count; if (object_transform_stack_modified) { modified = true; object_transform_stack_modified = false; if (object_count > 0) { int mpos = object_count; object_transform = object_transform_stack[--mpos]; while (--object_count > 0) { object_transform = object_transform.times( object_transform_stack[--mpos] ); } } else { object_transform = new Matrix2x3(1,0,0,0,1,0); } } if (modified) transform = camera_transform.times( object_transform ); }
public static CompoundTransform create_from( ClassTransformManager obj, CompoundVector2 size, CompoundVector2 handle, CompoundRadians angle, CompoundVector2 scale, CompoundVector2 position, bool hflip, bool vflip) { double handle_x = handle.property_x; double handle_y = handle.property_y; double size_x = size.property_x; double size_y = size.property_y; double scale_x = scale.property_x; double scale_y = scale.property_y; if (hflip || vflip) { handle_x -= size_x / 2.0; handle_y -= size_y / 2.0; } double cost = Math.Cos(angle.property_value); double sint = Math.Sin(angle.property_value); double r1c1 = cost*scale_x; double r1c2 = -sint*scale_y; double r1c3 = position.property_x - scale_x*handle_x*cost + sint*scale_y*handle_y; double r2c1 = sint*scale_x; double r2c2 = cost*scale_y; double r2c3 = position.property_y - scale_x*handle_x*sint - cost*scale_y*handle_y; Matrix2x3 m = new Matrix2x3(r1c1,r1c2,r1c3,r2c1,r2c2,r2c3); if (hflip || vflip) { if (hflip) { if (vflip) { m = m.times( new Matrix2x3(-1,0,0,0,-1,0) ); } else { m = m.times( new Matrix2x3(-1,0,0,0,1,0) ); } } else { m = m.times( new Matrix2x3(1,0,0,0,-1,0) ); } // translate by -size/2 m = m.times( new Matrix2x3(1,0,-size_x/2.0,0,1,-size_y/2.0) ); } return new CompoundTransform( new CompoundTransformRow(m.r1c1,m.r1c2,m.r1c3), new CompoundTransformRow(m.r2c1,m.r2c2,m.r2c3) ); }