| 
									
										
										
										
											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-09 00:34:15 +08:00
										 |  |  |  | 	: _visiable(true) | 
					
						
							| 
									
										
										
										
											2018-05-24 20:37:34 +08:00
										 |  |  |  | 	, _color(Color::Red, 0.7) | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	, _parentNode(nullptr) | 
					
						
							|  |  |  |  | 	, _transformed(nullptr) | 
					
						
							| 
									
										
										
										
											2018-07-04 17:23:47 +08:00
										 |  |  |  | 	, _geometry(nullptr) | 
					
						
							| 
									
										
										
										
											2018-07-04 17:00:21 +08:00
										 |  |  |  | 	, _enabled(true) | 
					
						
							| 
									
										
										
										
											2018-05-17 12:22:52 +08:00
										 |  |  |  | 	, _autoResize(false) | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | e2d::Collider::~Collider() | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-22 12:24:43 +08:00
										 |  |  |  | 	SafeRelease(_transformed); | 
					
						
							| 
									
										
										
										
											2018-07-04 17:23:47 +08:00
										 |  |  |  | 	SafeRelease(_geometry); | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | e2d::Node * e2d::Collider::getParentNode() const | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	return _parentNode; | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-22 13:15:57 +08:00
										 |  |  |  | e2d::Color e2d::Collider::getColor() const | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	return _color; | 
					
						
							| 
									
										
										
										
											2018-04-22 13:15:57 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-04 17:00:21 +08:00
										 |  |  |  | void e2d::Collider::setEnabled(bool enabled) | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-04 17:00:21 +08:00
										 |  |  |  | 	_enabled = enabled; | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void e2d::Collider::setVisiable(bool bVisiable) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	_visiable = 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-09 00:34:15 +08:00
										 |  |  |  | 	_color = color; | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-04 17:00:21 +08:00
										 |  |  |  | void e2d::Collider::setAutoResize(bool enabled) | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-04 17:00:21 +08:00
										 |  |  |  | 	_autoResize = enabled; | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void e2d::Collider::_render() | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-04 17:00:21 +08:00
										 |  |  |  | 	if (_transformed && _enabled) | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 		auto renderer = Renderer::getInstance(); | 
					
						
							| 
									
										
										
										
											2018-04-03 11:12:30 +08:00
										 |  |  |  | 		// <20><>ȡ<EFBFBD><C8A1>ɫ<EFBFBD><C9AB>ˢ
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +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-17 15:22:14 +08:00
										 |  |  |  | 		pBrush->SetColor(_color.toD2DColorF()); | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | 		// <20><><EFBFBD>Ƽ<EFBFBD><C6BC><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2>
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 		renderer->getRenderTarget()->DrawGeometry(_transformed, pBrush); | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:22:14 +08:00
										 |  |  |  | e2d::Collider::Relation e2d::Collider::getRelationWith(Collider * pCollider) const | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	if (_transformed && pCollider->_transformed) | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-07-04 17:00:21 +08:00
										 |  |  |  | 		if (_enabled && pCollider->_enabled) | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			D2D1_GEOMETRY_RELATION relation; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 			_transformed->CompareWithGeometry( | 
					
						
							|  |  |  |  | 				pCollider->_transformed, | 
					
						
							| 
									
										
										
										
											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
										 |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-24 20:37:34 +08:00
										 |  |  |  | 	return Relation::Unknown; | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void e2d::Collider::_transform() | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-04 17:23:47 +08:00
										 |  |  |  | 	if (_parentNode && _enabled && _geometry) | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 		if (_autoResize) | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			this->_resize(); | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20>ͷ<EFBFBD>ԭ<EFBFBD><D4AD>ײ<EFBFBD><D7B2>
 | 
					
						
							| 
									
										
										
										
											2018-05-22 12:24:43 +08:00
										 |  |  |  | 		SafeRelease(_transformed); | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD>ݸ<EFBFBD><DDB8>ڵ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 		Renderer::getFactory()->CreateTransformedGeometry( | 
					
						
							| 
									
										
										
										
											2018-07-04 17:23:47 +08:00
										 |  |  |  | 			_geometry, | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 			_parentNode->_finalMatri, | 
					
						
							|  |  |  |  | 			&_transformed | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		ColliderManager::__updateCollider(this); | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-04 17:23:47 +08:00
										 |  |  |  | 	else | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		SafeRelease(_transformed); | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-02 23:01:38 +08:00
										 |  |  |  | } |