if (regMatters) [matrix translateXBy:mRegX yBy:mRegY];
[matrix rotateBy:mRotationZ];
if (regMatters) [matrix translateXBy:-mRegX yBy:-mRegY];
+
+ // if (mRegX != 0.0f || mRegY != 0.0f) {
+ // [matrix translateXBy:mRegX yBy:mRegY];
+ // SPMatrix* origin = [SPMatrix matrixWithRotation:mRotationZ];
+ // SPPoint* reg = [origin transformPoint:[SPPoint pointWithX:-mRegX y:-mRegY]];
+ // [matrix rotateBy:mRotationZ];
+ // [matrix translateXBy:reg.x yBy:reg.y];
+ // } else
+ // [matrix rotateBy:mRotationZ];
}
if (mScaleX != 1.0f || mScaleY != 1.0f) [matrix scaleXBy:mScaleX yBy:mScaleY];
}
- (NSString*) description {
- return [NSString stringWithFormat:@"[%@ pos=(%f,%f), rotation=%f @ (%f,%f), scale=(%f,%f)]",
- [super description], self.x,self.y, self.rotation, self.registrationX,self.registrationY, self.scaleX,self.scaleY];
+ SPDisplayObjectContainer* parent = self.parent;
+ return [NSString stringWithFormat:@"<%@: %p> {name=%@, global=%@, local=(%.3f,%.3f), scale=(%.3f,%.3f), rotation=%.3f @ (%.3f,%.3f), visible=%s @ %.3f, touchable=%s, parent=<%@: %p>}",
+ [self class], self, self.name,
+ self.bounds, self.x,self.y, self.scaleX,self.scaleY,
+ self.rotation, self.registrationX,self.registrationY,
+ SP_B2S(self.visible), self.alpha, SP_B2S(self.touchable),
+ (parent ? [parent class] : NULL), parent
+ ];
}
#define SP_COLOR_PART_GREEN(color) (((color) >> 8) & 0xff)
#define SP_COLOR_PART_BLUE(color) ( (color) & 0xff)
-#define SP_COLOR(r, g, b) (((r) << 16) | ((g) << 8) | (b))
+#define SP_COLOR(r, g, b) (((r) << 16) | ((g) << 8) | (b))
#define SP_IS_FLOAT_EQUAL(f1, f2) (fabsf((f1)-(f2)) < SP_FLOAT_EPSILON)
-
+#define SP_B2S(__val) ((__val)?("YES"):("NO"))
/// Factory method.
+ (SPMatrix*)matrixWithIdentity;
++ (SPMatrix*) matrixWithRotation:(float)angle;
+
/// -------------
/// @name Methods
/// -------------
- (void)translateXBy:(float)dx yBy:(float)dy
{
mTx += dx;
- mTy += dy;
+ mTy += dy;
}
- (void)scaleXBy:(float)sx yBy:(float)sy
SPMatrix *rotMatrix = [[SPMatrix alloc] initWithA:cosf(angle) b:sinf(angle)
c:-sinf(angle) d:cosf(angle) tx:0 ty:0];
[self concatMatrix:rotMatrix];
- [rotMatrix release];
+ [rotMatrix release];
}
- (void)identity
- (void)invert
{
float det = self.determinant;
+ // XXX: isn't this wrong? shouldn't it be...
+ // setValues(self, mD/det, -mC/det, -mB/det, mA/det, (mC*mTy-mD*mTx)/det, (mB*mTx-mA*mTy)/det);
+ // not...
setValues(self, mD/det, -mB/det, -mC/det, mA/det, (mC*mTy-mD*mTx)/det, (mB*mTx-mA*mTy)/det);
}
return [[[SPMatrix alloc] init] autorelease];
}
++ (SPMatrix*) matrixWithRotation:(float)angle {
+ return [[[SPMatrix alloc] initWithA:cosf(angle) b:sinf(angle) c:-sinf(angle) d:cosf(angle) tx:0 ty:0] autorelease];
+}
+
#pragma mark NSCopying
- (id)copyWithZone:(NSZone*)zone;
return [self initWithWidth:width height:height color:SP_WHITE];
}
-- (id)init
-{
- return [self initWithWidth:32 height:32];
-}
- (SPRectangle*)boundsInSpace:(SPDisplayObject*)targetCoordinateSpace
{
- (NSString*)description
{
- return [NSString stringWithFormat:@"(x: %f, y: %f, width: %f, height: %f)", mX, mY, mWidth, mHeight];
+ return [NSString stringWithFormat:@"[SPRect (%.3f,%.3f) w=%f, h=%f]", mX, mY, mWidth, mHeight];
}
+ (SPRectangle*)rectangleWithX:(float)x y:(float)y width:(float)width height:(float)height
[super dealloc];
}
+- (NSString*) description {
+ return [NSString stringWithFormat:@"<%@: %p> {pos=(%.3f,%.3f), width=%.3f, height=%.3f}",
+ [self class], self, self.x,self.y, self.width, self.height];
+}
+
+
@end
// -------------------------------------------------------------------------------------------------
}
}
+- (NSString*) description {
+ return [NSString stringWithFormat:@"<%@: %p> {global=(%.3f,%.3f), tapCount=%i, timestamp=%f, target=%@}",
+ [self class], self, self.globalX,self.globalY, self.tapCount, self.timestamp, self.target];
+}
+
+
+ (SPTouch*)touch
{
return [[[SPTouch alloc] init] autorelease];
return [[[SPTouchEvent alloc] initWithType:type touches:touches] autorelease];
}
+- (NSString*) description {
+ return [NSString stringWithFormat:@"<%@: %p> {touches=%@}",
+ [self class], self, self.touches];
+}
+
+
@end