| 
									
										
										
										
											2018-04-21 21:24:46 +08:00
										 |  |  |  | #include "..\e2dcollider.h"
 | 
					
						
							|  |  |  |  | #include "..\e2dmanager.h"
 | 
					
						
							|  |  |  |  | #include "..\e2dnode.h"
 | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | e2d::Collider::Collider() | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	: _bIsVisiable(true) | 
					
						
							|  |  |  |  | 	, _nColor(Color::RED, 0.7f) | 
					
						
							|  |  |  |  | 	, _pParentNode(nullptr) | 
					
						
							|  |  |  |  | 	, _pTransformedGeometry(nullptr) | 
					
						
							|  |  |  |  | 	, _bEnable(true) | 
					
						
							|  |  |  |  | 	, _bAutoResize(true) | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | e2d::Collider::~Collider() | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	SafeReleaseInterface(&_pTransformedGeometry); | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | e2d::Node * e2d::Collider::getParentNode() const | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	return _pParentNode; | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-22 13:15:57 +08:00
										 |  |  |  | e2d::Color e2d::Collider::getColor() const | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	return _nColor; | 
					
						
							| 
									
										
										
										
											2018-04-22 13:15:57 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-07 15:48:06 +08:00
										 |  |  |  | void e2d::Collider::setEnable(bool enable) | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	_bEnable = enable; | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void e2d::Collider::setVisiable(bool bVisiable) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	_bIsVisiable = bVisiable; | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-22 13:15:57 +08:00
										 |  |  |  | void e2d::Collider::setColor(Color color) | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	_nColor = color; | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-07 15:48:06 +08:00
										 |  |  |  | void e2d::Collider::setAutoResize(bool enable) | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	_bAutoResize = enable; | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void e2d::Collider::_render() | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	if (_pTransformedGeometry && _bEnable) | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-04-03 11:12:30 +08:00
										 |  |  |  | 		// <20><>ȡ<EFBFBD><C8A1>ɫ<EFBFBD><C9AB>ˢ
 | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | 		ID2D1SolidColorBrush * pBrush = Renderer::getSolidColorBrush(); | 
					
						
							| 
									
										
										
										
											2018-04-03 11:12:30 +08:00
										 |  |  |  | 		// <20><><EFBFBD>û<EFBFBD>ˢ<EFBFBD><CBA2>ɫ<EFBFBD><C9AB><EFBFBD><CDB8><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 		pBrush->SetColor(_nColor.toColorF()); | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | 		// <20><><EFBFBD>Ƽ<EFBFBD><C6BC><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2>
 | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 		Renderer::getRenderTarget()->DrawGeometry(_pTransformedGeometry, pBrush); | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-24 21:22:34 +08:00
										 |  |  |  | e2d::Relation e2d::Collider::getRelationWith(Collider * pCollider) const | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	if (_pTransformedGeometry && pCollider->_pTransformedGeometry) | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 		if (_bEnable && pCollider->_bEnable) | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			D2D1_GEOMETRY_RELATION relation; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 			_pTransformedGeometry->CompareWithGeometry( | 
					
						
							|  |  |  |  | 				pCollider->_pTransformedGeometry, | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | 				D2D1::Matrix3x2F::Identity(), | 
					
						
							|  |  |  |  | 				&relation | 
					
						
							|  |  |  |  | 			); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-24 21:22:34 +08:00
										 |  |  |  | 			return Relation(relation); | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	return Relation::UNKNOWN; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void e2d::Collider::_transform() | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 	if (_pParentNode && _bEnable) | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 		if (_bAutoResize) | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			this->_resize(); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20>ͷ<EFBFBD>ԭ<EFBFBD><D4AD>ײ<EFBFBD><D7B2>
 | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 		SafeReleaseInterface(&_pTransformedGeometry); | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD>ݸ<EFBFBD><DDB8>ڵ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
 | 
					
						
							|  |  |  |  | 		Renderer::getID2D1Factory()->CreateTransformedGeometry( | 
					
						
							|  |  |  |  | 			getD2dGeometry(), | 
					
						
							| 
									
										
										
										
											2018-05-08 17:40:36 +08:00
										 |  |  |  | 			_pParentNode->_MatriFinal, | 
					
						
							|  |  |  |  | 			&_pTransformedGeometry | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		ColliderManager::__updateCollider(this); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } |