Beispiel #1
0
void GlCamera::move() {
       if (motionState.getForward()) {
               offsetPosition(0.1f * forward());
       }

       if (motionState.getBackward()) {
               offsetPosition(0.1f * -forward());
       }

       if (motionState.getLeft()) {
               offsetPosition(0.1f * -right());
       }

       if (motionState.getRight()) {
               offsetPosition(0.1f * right());
       }
       offsetOrientation(motionState.getPitch(), motionState.getYaw());
}
Beispiel #2
0
void Camera::move(Direction d, float dt)
{
	// pos = pos + direction * speed * timestep
	//velocity = speed * direction * timestep
	
	float velocity = m_speed * dt;
	if(FRONT == d)
	{
		offsetPosition(velocity*dt*front());
	}
	if(RIGHT == d)
	{
		offsetPosition(velocity*dt*right());
	}
	if(LEFT == d)
	{	
		offsetPosition(velocity*dt*-right());
	}
	if(BACK == d)
	{
		offsetPosition(velocity*dt*-front());
	}
}
Beispiel #3
0
bool retargetLocator::drawArrowPolygon( MMatrix aimMatrix, MColor cuColor,float fillAlpha, float lineAlpha, int index )
{
	MStatus status;
	MFnMesh inputMesh( inputMeshObj[index], &status );
	if( !status )
		return false;

	float indexedSize = size[index];
	float startIndexedSize = startSize[ index ];

	MPointArray* polygonPoints = getPolygonPoints( inputMesh );

	if( indexedSize > 0 )
	{
		glColor4f( cuColor.r, cuColor.g, cuColor.b, lineAlpha );
		for( int polygonId=0; polygonId< polygonNum ; polygonId++ )
		{
			glBegin( GL_LINE_LOOP );
			MPointArray& cuPolygonPoints = polygonPoints[polygonId];
			for( unsigned int i=0; i < cuPolygonPoints.length(); i++ )
			{
				MPoint cuPoint = cuPolygonPoints[i]*indexedSize*aimMatrix;
				bbox.expand( cuPoint );
				glVertex3f( (float)cuPoint.x, (float)cuPoint.y, (float)cuPoint.z );
			}
			glEnd();
		}

		glColor4f( cuColor.r, cuColor.g, cuColor.b, fillAlpha );
		for( int polygonId=0; polygonId< polygonNum ; polygonId++ )
		{
			glBegin( GL_POLYGON );
			MPointArray& cuPolygonPoints = polygonPoints[polygonId];
			for( unsigned int i=0; i< cuPolygonPoints.length(); i++ )
			{
				MPoint cuPoint = cuPolygonPoints[i]*indexedSize*aimMatrix;
				glVertex3f( (float)cuPoint.x, (float)cuPoint.y, (float)cuPoint.z );
			}
			glEnd();
		}
	}

	MVector offsetPosition( offset[index].x, offset[index].y, offset[index].z );

	if( startIndexedSize > 0 )
	{
		glColor4f( cuColor.r, cuColor.g, cuColor.b, lineAlpha );
		for( int polygonId=0; polygonId< polygonNum ; polygonId++ )
		{
			glBegin( GL_LINE_LOOP );
			MPointArray& cuPolygonPoints = polygonPoints[polygonId];
			for( unsigned int i=0; i < cuPolygonPoints.length(); i++ )
			{
				MPoint cuPoint = cuPolygonPoints[i]*startIndexedSize+offsetPosition;
				bbox.expand( cuPoint );

				glVertex3f( (float)cuPoint.x, (float)cuPoint.y, (float)cuPoint.z );
			}
			glEnd();
		}

		glColor4f( cuColor.r, cuColor.g, cuColor.b, fillAlpha );
		for( int polygonId=0; polygonId< polygonNum ; polygonId++ )
		{
			glBegin( GL_POLYGON );
			MPointArray& cuPolygonPoints = polygonPoints[polygonId];
			for( unsigned int i=0; i< cuPolygonPoints.length(); i++ )
			{
				MPoint cuPoint = cuPolygonPoints[i]*startIndexedSize+offsetPosition;
				glVertex3f( (float)cuPoint.x, (float)cuPoint.y, (float)cuPoint.z );
			}
			glEnd();
		}
	}

	delete []polygonPoints;

	return true;
}
Beispiel #4
0
 void Scale9Sprite::createSlicedSprites()
 {
     float w = _originalSize.width;
     float h = _originalSize.height;
     
     Vec2 offsetPosition(ceil(_offset.x + (_originalSize.width - _spriteRect.size.width) / 2), ceil(_offset.y + (_originalSize.height - _spriteRect.size.height) / 2));
     
     // If there is no specified center region
     if ( _capInsetsInternal.equals(Rect::ZERO) )
     {
         // log("... cap insets not specified : using default cap insets ...");
         _capInsetsInternal = Rect(w/3, h/3, w/3, h/3);
     }
     
     Rect originalRect;
     if(_spriteFrameRotated)
         originalRect = Rect(_spriteRect.origin.x - offsetPosition.y, _spriteRect.origin.y - offsetPosition.x, _originalSize.width, _originalSize.height);
     else
         originalRect = Rect(_spriteRect.origin.x - offsetPosition.x, _spriteRect.origin.y - offsetPosition.y, _originalSize.width, _originalSize.height);
     
     float left_w = _capInsetsInternal.origin.x;
     float center_w = _capInsetsInternal.size.width;
     float right_w = originalRect.size.width - (left_w + center_w);
     
     float top_h = _capInsetsInternal.origin.y;
     float center_h = _capInsetsInternal.size.height;
     float bottom_h = originalRect.size.height - (top_h + center_h);
     
     // calculate rects
     
     // ... top row
     float x = 0.0;
     float y = 0.0;
     
     Rect pixelRect = Rect(offsetPosition.x, offsetPosition.y, _spriteRect.size.width, _spriteRect.size.height);
     
     // top left
     Rect lefttopboundsorig = Rect(x, y, left_w, top_h);
     Rect lefttopbounds = lefttopboundsorig;
     
     // top center
     TRANSLATE_X(x, y, left_w);
     Rect centertopbounds = Rect(x, y, center_w, top_h);
     
     // top right
     TRANSLATE_X(x, y, center_w);
     Rect righttopbounds = Rect(x, y, right_w, top_h);
     
     // ... center row
     x = 0.0;
     y = 0.0;
     TRANSLATE_Y(x, y, top_h);
     
     // center left
     Rect leftcenterbounds = Rect(x, y, left_w, center_h);
     
     // center center
     TRANSLATE_X(x, y, left_w);
     Rect centerboundsorig = Rect(x, y, center_w, center_h);
     Rect centerbounds = centerboundsorig;
     
     // center right
     TRANSLATE_X(x, y, center_w);
     Rect rightcenterbounds = Rect(x, y, right_w, center_h);
     
     // ... bottom row
     x = 0.0;
     y = 0.0;
     TRANSLATE_Y(x, y, top_h);
     TRANSLATE_Y(x, y, center_h);
     
     // bottom left
     Rect leftbottombounds = Rect(x, y, left_w, bottom_h);
     
     // bottom center
     TRANSLATE_X(x, y, left_w);
     Rect centerbottombounds = Rect(x, y, center_w, bottom_h);
     
     // bottom right
     TRANSLATE_X(x, y, center_w);
     Rect rightbottomboundsorig = Rect(x, y, right_w, bottom_h);
     Rect rightbottombounds = rightbottomboundsorig;
     
     if((_capInsetsInternal.origin.x + _capInsetsInternal.size.width) <= _originalSize.width
        || (_capInsetsInternal.origin.y + _capInsetsInternal.size.height) <= _originalSize.height)
     //in general case it is error but for legacy support we will check it
     {
         lefttopbounds = intersectRect(lefttopbounds, pixelRect);
         centertopbounds = intersectRect(centertopbounds, pixelRect);
         righttopbounds = intersectRect(righttopbounds, pixelRect);
         leftcenterbounds = intersectRect(leftcenterbounds, pixelRect);
         centerbounds = intersectRect(centerbounds, pixelRect);
         rightcenterbounds = intersectRect(rightcenterbounds, pixelRect);
         leftbottombounds = intersectRect(leftbottombounds, pixelRect);
         centerbottombounds = intersectRect(centerbottombounds, pixelRect);
         rightbottombounds = intersectRect(rightbottombounds, pixelRect);
     }
     else
         //it is error but for legacy turn off clip system
         CCLOG("Scale9Sprite capInsetsInternal > originalSize");
     
     Rect rotatedlefttopboundsorig = lefttopboundsorig;
     Rect rotatedcenterboundsorig = centerboundsorig;
     Rect rotatedrightbottomboundsorig = rightbottomboundsorig;
     
     Rect rotatedcenterbounds = centerbounds;
     Rect rotatedrightbottombounds = rightbottombounds;
     Rect rotatedleftbottombounds = leftbottombounds;
     Rect rotatedrighttopbounds = righttopbounds;
     Rect rotatedlefttopbounds = lefttopbounds;
     Rect rotatedrightcenterbounds = rightcenterbounds;
     Rect rotatedleftcenterbounds = leftcenterbounds;
     Rect rotatedcenterbottombounds = centerbottombounds;
     Rect rotatedcentertopbounds = centertopbounds;
     
     if (!_spriteFrameRotated)
     {
         
         AffineTransform t = AffineTransform::IDENTITY;
         t = AffineTransformTranslate(t, originalRect.origin.x, originalRect.origin.y);
         
         rotatedlefttopboundsorig = RectApplyAffineTransform(rotatedlefttopboundsorig, t);
         rotatedcenterboundsorig = RectApplyAffineTransform(rotatedcenterboundsorig, t);
         rotatedrightbottomboundsorig = RectApplyAffineTransform(rotatedrightbottomboundsorig, t);
         
         rotatedcenterbounds = RectApplyAffineTransform(rotatedcenterbounds, t);
         rotatedrightbottombounds = RectApplyAffineTransform(rotatedrightbottombounds, t);
         rotatedleftbottombounds = RectApplyAffineTransform(rotatedleftbottombounds, t);
         rotatedrighttopbounds = RectApplyAffineTransform(rotatedrighttopbounds, t);
         rotatedlefttopbounds = RectApplyAffineTransform(rotatedlefttopbounds, t);
         rotatedrightcenterbounds = RectApplyAffineTransform(rotatedrightcenterbounds, t);
         rotatedleftcenterbounds = RectApplyAffineTransform(rotatedleftcenterbounds, t);
         rotatedcenterbottombounds = RectApplyAffineTransform(rotatedcenterbottombounds, t);
         rotatedcentertopbounds = RectApplyAffineTransform(rotatedcentertopbounds, t);
         
         
     } else {
         // set up transformation of coordinates
         // to handle the case where the sprite is stored rotated
         // in the spritesheet
         // log("rotated");
         
         AffineTransform t = AffineTransform::IDENTITY;
         
         t = AffineTransformTranslate(t, originalRect.size.height+originalRect.origin.x, originalRect.origin.y);
         t = AffineTransformRotate(t, 1.57079633f);
         
         lefttopboundsorig = RectApplyAffineTransform(lefttopboundsorig, t);
         centerboundsorig = RectApplyAffineTransform(centerboundsorig, t);
         rightbottomboundsorig = RectApplyAffineTransform(rightbottomboundsorig, t);
         
         centerbounds = RectApplyAffineTransform(centerbounds, t);
         rightbottombounds = RectApplyAffineTransform(rightbottombounds, t);
         leftbottombounds = RectApplyAffineTransform(leftbottombounds, t);
         righttopbounds = RectApplyAffineTransform(righttopbounds, t);
         lefttopbounds = RectApplyAffineTransform(lefttopbounds, t);
         rightcenterbounds = RectApplyAffineTransform(rightcenterbounds, t);
         leftcenterbounds = RectApplyAffineTransform(leftcenterbounds, t);
         centerbottombounds = RectApplyAffineTransform(centerbottombounds, t);
         centertopbounds = RectApplyAffineTransform(centertopbounds, t);
         
         rotatedlefttopboundsorig.origin = lefttopboundsorig.origin;
         rotatedcenterboundsorig.origin = centerboundsorig.origin;
         rotatedrightbottomboundsorig.origin = rightbottomboundsorig.origin;
         
         rotatedcenterbounds.origin = centerbounds.origin;
         rotatedrightbottombounds.origin = rightbottombounds.origin;
         rotatedleftbottombounds.origin = leftbottombounds.origin;
         rotatedrighttopbounds.origin = righttopbounds.origin;
         rotatedlefttopbounds.origin = lefttopbounds.origin;
         rotatedrightcenterbounds.origin = rightcenterbounds.origin;
         rotatedleftcenterbounds.origin = leftcenterbounds.origin;
         rotatedcenterbottombounds.origin = centerbottombounds.origin;
         rotatedcentertopbounds.origin = centertopbounds.origin;
         
         
     }
     
     _topLeftSize = rotatedlefttopboundsorig.size;
     _centerSize = rotatedcenterboundsorig.size;
     _bottomRightSize = rotatedrightbottomboundsorig.size;
     
     if(_spriteFrameRotated)
     {
         float offsetx = (rotatedcenterbounds.origin.x + rotatedcenterbounds.size.height/2) - (rotatedcenterboundsorig.origin.x + rotatedcenterboundsorig.size.height/2);
         float offsety = (rotatedcenterboundsorig.origin.y + rotatedcenterboundsorig.size.width/2)- (rotatedcenterbounds.origin.y + rotatedcenterbounds.size.width/2);
         _centerOffset.x = -offsety;
         _centerOffset.y = offsetx;
     }
     else
     {
         float offsetx = (rotatedcenterbounds.origin.x + rotatedcenterbounds.size.width/2) - (rotatedcenterboundsorig.origin.x + rotatedcenterboundsorig.size.width/2);
         float offsety = (rotatedcenterboundsorig.origin.y + rotatedcenterboundsorig.size.height/2)- (rotatedcenterbounds.origin.y + rotatedcenterbounds.size.height/2);
         _centerOffset.x = offsetx;
         _centerOffset.y = offsety;
     }
     
     // Centre
     if(rotatedcenterbounds.size.width > 0 && rotatedcenterbounds.size.height > 0 )
     {
         _centre = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedcenterbounds, _spriteFrameRotated);
         _centre->retain();
         this->addProtectedChild(_centre);
     }
     
     // Top
     if(rotatedcentertopbounds.size.width > 0 && rotatedcentertopbounds.size.height > 0 )
     {
         _top = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedcentertopbounds, _spriteFrameRotated);
         _top->retain();
         this->addProtectedChild(_top);
     }
     
     // Bottom
     if(rotatedcenterbottombounds.size.width > 0 && rotatedcenterbottombounds.size.height > 0 )
     {
         _bottom = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedcenterbottombounds, _spriteFrameRotated);
         _bottom->retain();
         this->addProtectedChild(_bottom);
     }
     
     // Left
     if(rotatedleftcenterbounds.size.width > 0 && rotatedleftcenterbounds.size.height > 0 )
     {
         _left = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedleftcenterbounds, _spriteFrameRotated);
         _left->retain();
         this->addProtectedChild(_left);
     }
     
     // Right
     if(rotatedrightcenterbounds.size.width > 0 && rotatedrightcenterbounds.size.height > 0 )
     {
         _right = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedrightcenterbounds, _spriteFrameRotated);
         _right->retain();
         this->addProtectedChild(_right);
     }
     
     // Top left
     if(rotatedlefttopbounds.size.width > 0 && rotatedlefttopbounds.size.height > 0 )
     {
         _topLeft = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedlefttopbounds, _spriteFrameRotated);
         _topLeft->retain();
         this->addProtectedChild(_topLeft);
     }
     
     // Top right
     if(rotatedrighttopbounds.size.width > 0 && rotatedrighttopbounds.size.height > 0 )
     {
         _topRight = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedrighttopbounds, _spriteFrameRotated);
         _topRight->retain();
         this->addProtectedChild(_topRight);
     }
     
     // Bottom left
     if(rotatedleftbottombounds.size.width > 0 && rotatedleftbottombounds.size.height > 0 )
     {
         _bottomLeft = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedleftbottombounds, _spriteFrameRotated);
         _bottomLeft->retain();
         this->addProtectedChild(_bottomLeft);
     }
     
     // Bottom right
     if(rotatedrightbottombounds.size.width > 0 && rotatedrightbottombounds.size.height > 0 )
     {
         _bottomRight = Sprite::createWithTexture(_scale9Image->getTexture(), rotatedrightbottombounds, _spriteFrameRotated);
         _bottomRight->retain();
         this->addProtectedChild(_bottomRight);
     }
 }
Beispiel #5
0
int main()
{
	RobotArmController robotArmController;

	ComponentLoader leftGripperLoader("GripperComp", "LeftGripperComp.xml");
	ComponentLoader rightGripperLoader("GripperComp", "rightGripperComp.xml");

	ComponentLoader leftIKLoader("KITECH_DampedLeastSquareInverseKinematicsComp", "LeftInverseKinematicsComp.xml");
	ComponentLoader rightIKLoader("KITECH_DampedLeastSquareInverseKinematicsComp", "RightInverseKinematicsComp.xml");

	ComponentLoader trajectoryGenretorLoader("KitechMonotoneCubicTrajectoryGenerationComp");

	//ComponentLoader phantomOmniCompLoader("PhantomOmniComp");

	ComponentLoader centerLoader("Center");

	ComponentLoader joystickCompLoader("JoystickComp");

	ComponentLoader wheelCompLoader("WheelControllerComp");

	//서비스 연결
	leftGripperLoader.Connect("GripperService", static_cast<RequiredServicePort*>(robotArmController.getPort("LeftGripperSerivce")));
	rightGripperLoader.Connect("GripperService", static_cast<RequiredServicePort*>(robotArmController.getPort("RightGripperService")));

	leftIKLoader.Connect("InverseKinematicsService", static_cast<RequiredServicePort*>(robotArmController.getPort("LeftIKService")));
	rightIKLoader.Connect("InverseKinematicsService", static_cast<RequiredServicePort*>(robotArmController.getPort("RightIkService")));

	trajectoryGenretorLoader.Connect("TrajectoryGenerationService", static_cast<RequiredServicePort*>(robotArmController.getPort("TrajectoryGenerationService")));
	
	//phantomOmniCompLoader.Connect("PhantomOmniService", centerLoader.GetRequiredServicePort("PhantomOmniService"));
	centerLoader.GetRequiredServicePort("RobotArmControllerService")->setPeer(static_cast<ServicePort*>(robotArmController.getPort("RobotArmControllerService")));

	JoystickServiceRequired joystickService;
	WheelControllerServiceRequired wheelService;

	joystickCompLoader.Connect("JoystickService", &joystickService);
	wheelCompLoader.Connect("WheelControllerService", &wheelService);

	//컴포넌트 초기화
	robotArmController.initialize();
	leftIKLoader.Initialize();
	rightIKLoader.Initialize();
	leftGripperLoader.Initialize();
	rightGripperLoader.Initialize();
	trajectoryGenretorLoader.Initialize();
	//phantomOmniCompLoader.Initialize();
	centerLoader.Initialize();
	joystickCompLoader.Initialize();
	wheelCompLoader.Initialize();

	//컴포넌트 시작
	leftIKLoader.Start();
	rightIKLoader.Start();
	leftGripperLoader.Start();
	rightGripperLoader.Start();
	trajectoryGenretorLoader.Start();
	robotArmController.start();
	//phantomOmniCompLoader.Start(100);
	joystickCompLoader.Start();
	centerLoader.Start();
	wheelCompLoader.Start();

	//처리

	bool mode = true;
	bool previousButton = false;

	ObjectPosition offsetPosition(0.1, 0.0, 0.3, 90, 0, 90);
	const double scale = 0.01;
	for (;;)
	{
		auto controlData = joystickService.GetJoystickData();

		if (!previousButton && controlData.button[5])
		{
			mode = !mode;
		}

		previousButton = controlData.button[5];


		if (mode)
		{
			const double maxLinearVelocity = 0.2;
			const double maxAngularVelocity = 30;

			wheelService.DriveWheel(maxLinearVelocity * -controlData.y
				, maxAngularVelocity * -controlData.x);
		}
		else
		{

			if (robotArmController.GetManipulateState('L') != 0
				&& robotArmController.GetManipulateState('R') != 0)
			{
				offsetPosition.x += -controlData.y * scale;
				offsetPosition.y += -controlData.x * scale;
				offsetPosition.z += (abs(controlData.z ) < 0.0001 ? 0 : controlData.z) * scale;

				auto endpoint = offsetPosition;

				std::vector<ObjectPosition> leftEndEffoctorPath;
				std::vector<ObjectPosition> rightEndEffoctorPath;

				endpoint.y += 0.1;
				endpoint.roll = 90;
				endpoint.pitch = 0;
				endpoint.yaw = 90;

				leftEndEffoctorPath.push_back(endpoint);

				endpoint.y -= 0.2;
				endpoint.roll = -90;
				endpoint.pitch = 0;
				endpoint.yaw = 90.0;

				rightEndEffoctorPath.push_back(endpoint);

				robotArmController.Manipulate('L', leftEndEffoctorPath);
				robotArmController.Manipulate('R', rightEndEffoctorPath);
			}

			//왼손
			switch(robotArmController.GetGripperState('L'))
			{
			case 1:
				if (!(controlData.button[0]))
					robotArmController.Grab('L', false);
				break;
			case -1:
				if (controlData.button[0])
					robotArmController.Grab('L', true);		
				break;
			}
			//오른손
			switch(robotArmController.GetGripperState('R'))
			{
			case 1:
				if (!(controlData.button[1]))
					robotArmController.Grab('R', false);
				break;
			case -1:
				if (controlData.button[1])
					robotArmController.Grab('R', true);		
				break;
			}
		}

		Sleep(100);
	}

	getchar();
	return 0;
}
void Scale9Sprite::createSlicedSprites()
{
    float width = _originalSize.width;
    float height = _originalSize.height;
    
    Vec2 offsetPosition(ceilf(_offset.x + (_originalSize.width - _spriteRect.size.width) / 2),
                        ceilf(_offset.y + (_originalSize.height - _spriteRect.size.height) / 2));
    
    // If there is no specified center region
    if ( _capInsetsInternal.equals(Rect::ZERO) )
    {
        // log("... cap insets not specified : using default cap insets ...");
        _capInsetsInternal = Rect(width /3, height /3, width /3, height /3);
    }
    
    Rect originalRect=_spriteRect;
    if(_spriteFrameRotated)
        originalRect = Rect(_spriteRect.origin.x - offsetPosition.y,
                            _spriteRect.origin.y - offsetPosition.x,
                            _originalSize.width, _originalSize.height);
    else
        originalRect = Rect(_spriteRect.origin.x - offsetPosition.x,
                            _spriteRect.origin.y - offsetPosition.y,
                            _originalSize.width, _originalSize.height);
    
    float leftWidth = _capInsetsInternal.origin.x;
    float centerWidth = _capInsetsInternal.size.width;
    float rightWidth = originalRect.size.width - (leftWidth + centerWidth);
    
    float topHeight = _capInsetsInternal.origin.y;
    float centerHeight = _capInsetsInternal.size.height;
    float bottomHeight = originalRect.size.height - (topHeight + centerHeight);
    
    // calculate rects
    
    // ... top row
    float x = 0.0;
    float y = 0.0;
    //why do we need pixelRect?
    Rect pixelRect = Rect(offsetPosition.x, offsetPosition.y,
                          _spriteRect.size.width, _spriteRect.size.height);
    
    // top left
    Rect leftTopBoundsOriginal = Rect(x, y, leftWidth, topHeight);
    Rect leftTopBounds = leftTopBoundsOriginal;
    
    // top center
    x += leftWidth;
    Rect centerTopBounds = Rect(x, y, centerWidth, topHeight);
    
    // top right
    x += centerWidth;
    Rect rightTopBounds = Rect(x, y, rightWidth, topHeight);
    
    // ... center row
    x = 0.0;
    y = 0.0;
    y += topHeight;
    
    // center left
    Rect leftCenterBounds = Rect(x, y, leftWidth, centerHeight);
    
    // center center
    x += leftWidth;
    Rect centerBoundsOriginal = Rect(x, y, centerWidth, centerHeight);
    Rect centerBounds = centerBoundsOriginal;
    
    // center right
    x += centerWidth;
    Rect rightCenterBounds = Rect(x, y, rightWidth, centerHeight);
    
    // ... bottom row
    x = 0.0;
    y = 0.0;
    y += topHeight;
    y += centerHeight;
    
    // bottom left
    Rect leftBottomBounds = Rect(x, y, leftWidth, bottomHeight);
    
    // bottom center
    x += leftWidth;
    Rect centerBottomBounds = Rect(x, y, centerWidth, bottomHeight);
    
    // bottom right
    x += centerWidth;
    Rect rightBottomBoundsOriginal = Rect(x, y, rightWidth, bottomHeight);
    Rect rightBottomBounds = rightBottomBoundsOriginal;
    
    if((_capInsetsInternal.origin.x + _capInsetsInternal.size.width) <= _originalSize.width
       || (_capInsetsInternal.origin.y + _capInsetsInternal.size.height) <= _originalSize.height)
        //in general case it is error but for legacy support we will check it
    {
        leftTopBounds = intersectRect(leftTopBounds, pixelRect);
        centerTopBounds = intersectRect(centerTopBounds, pixelRect);
        rightTopBounds = intersectRect(rightTopBounds, pixelRect);
        leftCenterBounds = intersectRect(leftCenterBounds, pixelRect);
        centerBounds = intersectRect(centerBounds, pixelRect);
        rightCenterBounds = intersectRect(rightCenterBounds, pixelRect);
        leftBottomBounds = intersectRect(leftBottomBounds, pixelRect);
        centerBottomBounds = intersectRect(centerBottomBounds, pixelRect);
        rightBottomBounds = intersectRect(rightBottomBounds, pixelRect);
    }
    else
        //it is error but for legacy turn off clip system
        CCLOG("Scale9Sprite capInsetsInternal > originalSize");
    
    Rect rotatedLeftTopBoundsOriginal = leftTopBoundsOriginal;
    Rect rotatedCenterBoundsOriginal = centerBoundsOriginal;
    Rect rotatedRightBottomBoundsOriginal = rightBottomBoundsOriginal;
    
    Rect rotatedCenterBounds = centerBounds;
    Rect rotatedRightBottomBounds = rightBottomBounds;
    Rect rotatedLeftBottomBounds = leftBottomBounds;
    Rect rotatedRightTopBounds = rightTopBounds;
    Rect rotatedLeftTopBounds = leftTopBounds;
    Rect rotatedRightCenterBounds = rightCenterBounds;
    Rect rotatedLeftCenterBounds = leftCenterBounds;
    Rect rotatedCenterBottomBounds = centerBottomBounds;
    Rect rotatedCenterTopBounds = centerTopBounds;
    
    if (!_spriteFrameRotated)
    {
        
        AffineTransform t = AffineTransform::IDENTITY;
        t = AffineTransformTranslate(t, originalRect.origin.x, originalRect.origin.y);
        
        rotatedLeftTopBoundsOriginal = RectApplyAffineTransform(rotatedLeftTopBoundsOriginal, t);
        rotatedCenterBoundsOriginal = RectApplyAffineTransform(rotatedCenterBoundsOriginal, t);
        rotatedRightBottomBoundsOriginal = RectApplyAffineTransform(rotatedRightBottomBoundsOriginal, t);
        
        rotatedCenterBounds = RectApplyAffineTransform(rotatedCenterBounds, t);
        rotatedRightBottomBounds = RectApplyAffineTransform(rotatedRightBottomBounds, t);
        rotatedLeftBottomBounds = RectApplyAffineTransform(rotatedLeftBottomBounds, t);
        rotatedRightTopBounds = RectApplyAffineTransform(rotatedRightTopBounds, t);
        rotatedLeftTopBounds = RectApplyAffineTransform(rotatedLeftTopBounds, t);
        rotatedRightCenterBounds = RectApplyAffineTransform(rotatedRightCenterBounds, t);
        rotatedLeftCenterBounds = RectApplyAffineTransform(rotatedLeftCenterBounds, t);
        rotatedCenterBottomBounds = RectApplyAffineTransform(rotatedCenterBottomBounds, t);
        rotatedCenterTopBounds = RectApplyAffineTransform(rotatedCenterTopBounds, t);
        
        
    }
    else
    {
        // set up transformation of coordinates
        // to handle the case where the sprite is stored rotated
        // in the spritesheet
        // log("rotated");
        
        AffineTransform t = AffineTransform::IDENTITY;
        
        t = AffineTransformTranslate(t, originalRect.size.height+originalRect.origin.x, originalRect.origin.y);
        t = AffineTransformRotate(t, 1.57079633f);
        
        leftTopBoundsOriginal = RectApplyAffineTransform(leftTopBoundsOriginal, t);
        centerBoundsOriginal = RectApplyAffineTransform(centerBoundsOriginal, t);
        rightBottomBoundsOriginal = RectApplyAffineTransform(rightBottomBoundsOriginal, t);
        
        centerBounds = RectApplyAffineTransform(centerBounds, t);
        rightBottomBounds = RectApplyAffineTransform(rightBottomBounds, t);
        leftBottomBounds = RectApplyAffineTransform(leftBottomBounds, t);
        rightTopBounds = RectApplyAffineTransform(rightTopBounds, t);
        leftTopBounds = RectApplyAffineTransform(leftTopBounds, t);
        rightCenterBounds = RectApplyAffineTransform(rightCenterBounds, t);
        leftCenterBounds = RectApplyAffineTransform(leftCenterBounds, t);
        centerBottomBounds = RectApplyAffineTransform(centerBottomBounds, t);
        centerTopBounds = RectApplyAffineTransform(centerTopBounds, t);
        
        rotatedLeftTopBoundsOriginal.origin = leftTopBoundsOriginal.origin;
        rotatedCenterBoundsOriginal.origin = centerBoundsOriginal.origin;
        rotatedRightBottomBoundsOriginal.origin = rightBottomBoundsOriginal.origin;
        
        rotatedCenterBounds.origin = centerBounds.origin;
        rotatedRightBottomBounds.origin = rightBottomBounds.origin;
        rotatedLeftBottomBounds.origin = leftBottomBounds.origin;
        rotatedRightTopBounds.origin = rightTopBounds.origin;
        rotatedLeftTopBounds.origin = leftTopBounds.origin;
        rotatedRightCenterBounds.origin = rightCenterBounds.origin;
        rotatedLeftCenterBounds.origin = leftCenterBounds.origin;
        rotatedCenterBottomBounds.origin = centerBottomBounds.origin;
        rotatedCenterTopBounds.origin = centerTopBounds.origin;
        
        
    }
    
    _topLeftSize = rotatedLeftTopBoundsOriginal.size;
    _centerSize = rotatedCenterBoundsOriginal.size;
    _bottomRightSize = rotatedRightBottomBoundsOriginal.size;
    if(_isPatch9)
    {
        _topLeftSize.width = _topLeftSize.width - 1;
        _topLeftSize.height = _topLeftSize.height - 1;
        _bottomRightSize.width = _bottomRightSize.width - 1;
        _bottomRightSize.height = _bottomRightSize.height - 1;
    }
    
    if(_spriteFrameRotated)
    {
        float offsetX = (rotatedCenterBounds.origin.x + rotatedCenterBounds.size.height/2)
        - (rotatedCenterBoundsOriginal.origin.x + rotatedCenterBoundsOriginal.size.height/2);
        float offsetY = (rotatedCenterBoundsOriginal.origin.y + rotatedCenterBoundsOriginal.size.width/2)
        - (rotatedCenterBounds.origin.y + rotatedCenterBounds.size.width/2);
        _centerOffset.x = -offsetY;
        _centerOffset.y = offsetX;
    }
    else
    {
        float offsetX = (rotatedCenterBounds.origin.x + rotatedCenterBounds.size.width/2)
        - (rotatedCenterBoundsOriginal.origin.x + rotatedCenterBoundsOriginal.size.width/2);
        float offsetY = (rotatedCenterBoundsOriginal.origin.y + rotatedCenterBoundsOriginal.size.height/2)
        - (rotatedCenterBounds.origin.y + rotatedCenterBounds.size.height/2);
        _centerOffset.x = offsetX;
        _centerOffset.y = offsetY;
    }
    
    //shrink the image size when it is 9-patch
    if(_isPatch9)
    {
        float offset = 1.4f;
        //Top left
        if(!_spriteFrameRotated)
        {
            rotatedLeftTopBounds.origin.x+=offset;
            rotatedLeftTopBounds.origin.y+=offset;
            rotatedLeftTopBounds.size.width-=offset;
            rotatedLeftTopBounds.size.height-=offset;
            //Center left
            rotatedLeftCenterBounds.origin.x+=offset;
            rotatedLeftCenterBounds.size.width-=offset;
            //Bottom left
            rotatedLeftBottomBounds.origin.x+=offset;
            rotatedLeftBottomBounds.size.width-=offset;
            rotatedLeftBottomBounds.size.height-=offset;
            //Top center
            rotatedCenterTopBounds.size.height-=offset;
            rotatedCenterTopBounds.origin.y+=offset;
            //Bottom center
            rotatedCenterBottomBounds.size.height-=offset;
            //Top right
            rotatedRightTopBounds.size.width-=offset;
            rotatedRightTopBounds.size.height-=offset;
            rotatedRightTopBounds.origin.y+=offset;
            //Center right
            rotatedRightCenterBounds.size.width-=offset;
            //Bottom right
            rotatedRightBottomBounds.size.width-=offset;
            rotatedRightBottomBounds.size.height-=offset;
        }
        else
        {
            //Top left
            rotatedLeftTopBounds.size.width-=offset;
            rotatedLeftTopBounds.size.height-=offset;
            rotatedLeftTopBounds.origin.y+=offset;
            //Center left
            rotatedLeftCenterBounds.origin.y+=offset;
            rotatedLeftCenterBounds.size.width-=offset;
            //Bottom left
            rotatedLeftBottomBounds.origin.x+=offset;
            rotatedLeftBottomBounds.origin.y+=offset;
            rotatedLeftBottomBounds.size.width-=offset;
            rotatedLeftBottomBounds.size.height-=offset;
            //Top center
            rotatedCenterTopBounds.size.height-=offset;
            //Bottom center
            rotatedCenterBottomBounds.size.height-=offset;
            rotatedCenterBottomBounds.origin.x+=offset;
            //Top right
            rotatedRightTopBounds.size.width-=offset;
            rotatedRightTopBounds.size.height-=offset;
            //Center right
            rotatedRightCenterBounds.size.width-=offset;
            //Bottom right
            rotatedRightBottomBounds.size.width-=offset;
            rotatedRightBottomBounds.size.height-=offset;
            rotatedRightBottomBounds.origin.x+=offset;
        }
    }
    
    // Centre
    if(rotatedCenterBounds.size.width > 0 && rotatedCenterBounds.size.height > 0 )
    {
        _centerSprite = Sprite::createWithTexture(_scale9Image->getTexture(),
                                                  rotatedCenterBounds,
                                                  _spriteFrameRotated);
        _centerSprite->retain();
        this->addProtectedChild(_centerSprite);
    }
    
    // Top
    if(rotatedCenterTopBounds.size.width > 0 && rotatedCenterTopBounds.size.height > 0 )
    {
        _topSprite = Sprite::createWithTexture(_scale9Image->getTexture(),
                                               rotatedCenterTopBounds,
                                               _spriteFrameRotated);
        _topSprite->retain();
        this->addProtectedChild(_topSprite);
    }
    
    // Bottom
    if(rotatedCenterBottomBounds.size.width > 0 && rotatedCenterBottomBounds.size.height > 0 )
    {
        _bottomSprite = Sprite::createWithTexture(_scale9Image->getTexture(),
                                                  rotatedCenterBottomBounds,
                                                  _spriteFrameRotated);
        _bottomSprite->retain();
        this->addProtectedChild(_bottomSprite);
    }
    
    // Left
    if(rotatedLeftCenterBounds.size.width > 0 && rotatedLeftCenterBounds.size.height > 0 )
    {
        _leftSprite = Sprite::createWithTexture(_scale9Image->getTexture(),
                                                rotatedLeftCenterBounds,
                                                _spriteFrameRotated);
        _leftSprite->retain();
        this->addProtectedChild(_leftSprite);
    }
    
    // Right
    if(rotatedRightCenterBounds.size.width > 0 && rotatedRightCenterBounds.size.height > 0 )
    {
        _rightSprite = Sprite::createWithTexture(_scale9Image->getTexture(),
                                                 rotatedRightCenterBounds,
                                                 _spriteFrameRotated);
        _rightSprite->retain();
        this->addProtectedChild(_rightSprite);
    }
    
    // Top left
    if(rotatedLeftTopBounds.size.width > 0 && rotatedLeftTopBounds.size.height > 0 )
    {
        _topLeftSprite = Sprite::createWithTexture(_scale9Image->getTexture(),
                                                   rotatedLeftTopBounds,
                                                   _spriteFrameRotated);
        _topLeftSprite->retain();
        this->addProtectedChild(_topLeftSprite);
    }
    
    // Top right
    if(rotatedRightTopBounds.size.width > 0 && rotatedRightTopBounds.size.height > 0 )
    {
        _topRightSprite = Sprite::createWithTexture(_scale9Image->getTexture(),
                                                    rotatedRightTopBounds,
                                                    _spriteFrameRotated);
        _topRightSprite->retain();
        this->addProtectedChild(_topRightSprite);
    }
    
    // Bottom left
    if(rotatedLeftBottomBounds.size.width > 0 && rotatedLeftBottomBounds.size.height > 0 )
    {
        _bottomLeftSprite = Sprite::createWithTexture(_scale9Image->getTexture(),
                                                      rotatedLeftBottomBounds,
                                                      _spriteFrameRotated);
        _bottomLeftSprite->retain();
        this->addProtectedChild(_bottomLeftSprite);
    }
    
    // Bottom right
    if(rotatedRightBottomBounds.size.width > 0 && rotatedRightBottomBounds.size.height > 0 )
    {
        _bottomRightSprite = Sprite::createWithTexture(_scale9Image->getTexture(),
                                                       rotatedRightBottomBounds,
                                                       _spriteFrameRotated);
        _bottomRightSprite->retain();
        this->addProtectedChild(_bottomRightSprite);
    }
}