Collider::Type改为Collider::Shape;增加节点变化差值。
This commit is contained in:
		
							parent
							
								
									0c6044491e
								
							
						
					
					
						commit
						2ac7ac6591
					
				|  | @ -8,9 +8,9 @@ e2d::Collider::Collider(Node * parent) | |||
| 	, _parentNode(parent) | ||||
| 	, _geometry(nullptr) | ||||
| 	, _enabled(true) | ||||
| 	, _type(Collider::Type::None) | ||||
| 	, _shape(Collider::Shape::None) | ||||
| { | ||||
| 	_type = Game::getInstance()->getConfig()->getDefaultColliderType(); | ||||
| 	_shape = Game::getInstance()->getConfig()->getDefaultColliderShape(); | ||||
| } | ||||
| 
 | ||||
| e2d::Collider::~Collider() | ||||
|  | @ -23,11 +23,22 @@ e2d::Color e2d::Collider::getColor() const | |||
| 	return _color; | ||||
| } | ||||
| 
 | ||||
| e2d::Collider::Shape e2d::Collider::getShape() const | ||||
| { | ||||
| 	return _shape; | ||||
| } | ||||
| 
 | ||||
| ID2D1Geometry * e2d::Collider::getGeometry() const | ||||
| { | ||||
| 	return _geometry; | ||||
| } | ||||
| 
 | ||||
| void e2d::Collider::setShape(Shape shape) | ||||
| { | ||||
| 	_shape = shape; | ||||
| 	this->_recreate(); | ||||
| } | ||||
| 
 | ||||
| void e2d::Collider::setEnabled(bool enabled) | ||||
| { | ||||
| 	_enabled = enabled; | ||||
|  | @ -81,12 +92,12 @@ void e2d::Collider::_recreate() | |||
| { | ||||
| 	SafeRelease(_geometry); | ||||
| 
 | ||||
| 	if (_type == Type::None) | ||||
| 	if (!_enabled || _shape == Shape::None) | ||||
| 		return; | ||||
| 
 | ||||
| 	switch (_type) | ||||
| 	switch (_shape) | ||||
| 	{ | ||||
| 	case Type::Rect: | ||||
| 	case Shape::Rect: | ||||
| 	{ | ||||
| 		ID2D1RectangleGeometry* rectangle = nullptr; | ||||
| 		Renderer::getFactory()->CreateRectangleGeometry( | ||||
|  | @ -101,7 +112,7 @@ void e2d::Collider::_recreate() | |||
| 	} | ||||
| 	break; | ||||
| 
 | ||||
| 	case Type::Circle: | ||||
| 	case Shape::Circle: | ||||
| 	{ | ||||
| 		double minSide = std::min(_parentNode->getRealWidth(), _parentNode->getRealHeight()); | ||||
| 
 | ||||
|  | @ -121,7 +132,7 @@ void e2d::Collider::_recreate() | |||
| 	} | ||||
| 	break; | ||||
| 
 | ||||
| 	case Type::Ellipse: | ||||
| 	case Shape::Ellipse: | ||||
| 	{ | ||||
| 		float halfWidth = float(_parentNode->getWidth() / 2), | ||||
| 			halfHeight = float(_parentNode->getHeight() / 2); | ||||
|  |  | |||
|  | @ -3,12 +3,12 @@ | |||
| 
 | ||||
| e2d::Config::Config() | ||||
| 	: _gameName() | ||||
| 	, _nodeDefPivot() | ||||
| 	, _defaultNodePivot() | ||||
| 	, _soundEnabled(true) | ||||
| 	, _outlineVisible(false) | ||||
| 	, _collisionEnabled(false) | ||||
| 	, _colliderVisible(false) | ||||
| 	, _nodeDefColliderType(Collider::Type::None) | ||||
| 	, _defaultColliderShape(Collider::Shape::None) | ||||
| 	, _unconfigured(true) | ||||
| { | ||||
| } | ||||
|  | @ -43,15 +43,15 @@ void e2d::Config::setCollisionEnabled(bool enabled) | |||
| 
 | ||||
| void e2d::Config::setNodeDefaultPivot(Point pivot) | ||||
| { | ||||
| 	_nodeDefPivot = Point( | ||||
| 	_defaultNodePivot = Point( | ||||
| 		std::min(std::max(pivot.x, 0.0), 1.0), | ||||
| 		std::min(std::max(pivot.y, 0.0), 1.0) | ||||
| 	); | ||||
| } | ||||
| 
 | ||||
| void e2d::Config::setDefaultColliderType(Collider::Type type) | ||||
| void e2d::Config::setDefaultColliderShape(Collider::Shape shape) | ||||
| { | ||||
| 	_nodeDefColliderType = type; | ||||
| 	_defaultColliderShape = shape; | ||||
| } | ||||
| 
 | ||||
| void e2d::Config::setColliderVisible(bool visible) | ||||
|  | @ -81,12 +81,12 @@ bool e2d::Config::isCollisionEnabled() const | |||
| 
 | ||||
| e2d::Point e2d::Config::getNodeDefaultPivot() const | ||||
| { | ||||
| 	return _nodeDefPivot; | ||||
| 	return _defaultNodePivot; | ||||
| } | ||||
| 
 | ||||
| e2d::Collider::Type e2d::Config::getDefaultColliderType() const | ||||
| e2d::Collider::Shape e2d::Config::getDefaultColliderShape() const | ||||
| { | ||||
| 	return _nodeDefColliderType; | ||||
| 	return _defaultColliderShape; | ||||
| } | ||||
| 
 | ||||
| bool e2d::Config::isColliderVisible() const | ||||
|  |  | |||
|  | @ -47,7 +47,7 @@ void e2d::CollisionManager::updateCollider(Node * node) | |||
| { | ||||
| 	if (node) | ||||
| 	{ | ||||
| 		if (node->getCollider()->_type != Collider::Type::None) | ||||
| 		if (node->getCollider()->_shape != Collider::Shape::None) | ||||
| 		{ | ||||
| 			node->getCollider()->_recreate(); | ||||
| 			_collisionNodes.insert(node); | ||||
|  |  | |||
|  | @ -3,9 +3,45 @@ | |||
| #include "..\e2daction.h" | ||||
| #include <algorithm> | ||||
| 
 | ||||
| const e2d::Node::Property e2d::Node::Property::Origin = { 0 }; | ||||
| 
 | ||||
| e2d::Node::Property e2d::Node::Property::operator+(Property const & prop) const | ||||
| { | ||||
| 	Property result; | ||||
| 	result.posX = this->posX + prop.posX; | ||||
| 	result.posY = this->posY + prop.posY; | ||||
| 	result.width = this->width + prop.width; | ||||
| 	result.height = this->height + prop.height; | ||||
| 	result.pivotX = this->pivotX + prop.pivotX; | ||||
| 	result.pivotY = this->pivotY + prop.pivotY; | ||||
| 	result.scaleX = this->scaleX + prop.scaleX; | ||||
| 	result.scaleY = this->scaleY + prop.scaleY; | ||||
| 	result.rotation = this->rotation + prop.rotation; | ||||
| 	result.skewAngleX = this->skewAngleX + prop.skewAngleX; | ||||
| 	result.skewAngleY = this->skewAngleY + prop.skewAngleY; | ||||
| 	return std::move(result); | ||||
| } | ||||
| 
 | ||||
| e2d::Node::Property e2d::Node::Property::operator-(Property const & prop) const | ||||
| { | ||||
| 	Property result; | ||||
| 	result.posX = this->posX - prop.posX; | ||||
| 	result.posY = this->posY - prop.posY; | ||||
| 	result.width = this->width - prop.width; | ||||
| 	result.height = this->height - prop.height; | ||||
| 	result.pivotX = this->pivotX - prop.pivotX; | ||||
| 	result.pivotY = this->pivotY - prop.pivotY; | ||||
| 	result.scaleX = this->scaleX - prop.scaleX; | ||||
| 	result.scaleY = this->scaleY - prop.scaleY; | ||||
| 	result.rotation = this->rotation - prop.rotation; | ||||
| 	result.skewAngleX = this->skewAngleX - prop.skewAngleX; | ||||
| 	result.skewAngleY = this->skewAngleY - prop.skewAngleY; | ||||
| 	return std::move(result); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| e2d::Node::Node() | ||||
| 	: _nOrder(0) | ||||
| 	: _order(0) | ||||
| 	, _posX(0) | ||||
| 	, _posY(0) | ||||
| 	, _width(0) | ||||
|  | @ -31,6 +67,7 @@ e2d::Node::Node() | |||
| 	, _positionFixed(false) | ||||
| 	, _outline(nullptr) | ||||
| 	, _collider(this) | ||||
| 	, _extrapolate(Property::Origin) | ||||
| { | ||||
| 	// ÉèÖÃĬÈÏÖÐÐĵãλÖÃ
 | ||||
| 	Point defPivot = Game::getInstance()->getConfig()->getNodeDefaultPivot(); | ||||
|  | @ -374,12 +411,10 @@ double e2d::Node::getOpacity() const | |||
| e2d::Node::Property e2d::Node::getProperty() const | ||||
| { | ||||
| 	Property prop; | ||||
| 	prop.visible = _visible; | ||||
| 	prop.posX = _posX; | ||||
| 	prop.posY = _posY; | ||||
| 	prop.width = _width; | ||||
| 	prop.height = _height; | ||||
| 	prop.opacity = _realOpacity; | ||||
| 	prop.pivotX = _pivotX; | ||||
| 	prop.pivotY = _pivotY; | ||||
| 	prop.scaleX = _scaleX; | ||||
|  | @ -387,7 +422,7 @@ e2d::Node::Property e2d::Node::getProperty() const | |||
| 	prop.rotation = _rotation; | ||||
| 	prop.skewAngleX = _skewAngleX; | ||||
| 	prop.skewAngleY = _skewAngleY; | ||||
| 	return prop; | ||||
| 	return std::move(prop); | ||||
| } | ||||
| 
 | ||||
| e2d::Collider* e2d::Node::getCollider() | ||||
|  | @ -397,12 +432,12 @@ e2d::Collider* e2d::Node::getCollider() | |||
| 
 | ||||
| int e2d::Node::getOrder() const | ||||
| { | ||||
| 	return _nOrder; | ||||
| 	return _order; | ||||
| } | ||||
| 
 | ||||
| void e2d::Node::setOrder(int order) | ||||
| { | ||||
| 	_nOrder = order; | ||||
| 	_order = order; | ||||
| } | ||||
| 
 | ||||
| void e2d::Node::setPosX(double x) | ||||
|  | @ -427,6 +462,8 @@ void e2d::Node::setPos(double x, double y) | |||
| 
 | ||||
| 	_posX = float(x); | ||||
| 	_posY = float(y); | ||||
| 	_extrapolate.posX += x; | ||||
| 	_extrapolate.posY += y; | ||||
| 	_needTransform = true; | ||||
| } | ||||
| 
 | ||||
|  | @ -481,6 +518,8 @@ void e2d::Node::setScale(double scaleX, double scaleY) | |||
| 
 | ||||
| 	_scaleX = float(scaleX); | ||||
| 	_scaleY = float(scaleY); | ||||
| 	_extrapolate.scaleX += scaleX; | ||||
| 	_extrapolate.scaleY += scaleY; | ||||
| 	_needTransform = true; | ||||
| } | ||||
| 
 | ||||
|  | @ -501,6 +540,8 @@ void e2d::Node::setSkew(double angleX, double angleY) | |||
| 
 | ||||
| 	_skewAngleX = float(angleX); | ||||
| 	_skewAngleY = float(angleY); | ||||
| 	_extrapolate.skewAngleX += angleX; | ||||
| 	_extrapolate.skewAngleY += angleY; | ||||
| 	_needTransform = true; | ||||
| } | ||||
| 
 | ||||
|  | @ -510,6 +551,7 @@ void e2d::Node::setRotation(double angle) | |||
| 		return; | ||||
| 
 | ||||
| 	_rotation = float(angle); | ||||
| 	_extrapolate.rotation += angle; | ||||
| 	_needTransform = true; | ||||
| } | ||||
| 
 | ||||
|  | @ -540,6 +582,8 @@ void e2d::Node::setPivot(double pivotX, double pivotY) | |||
| 
 | ||||
| 	_pivotX = std::min(std::max(float(pivotX), 0.f), 1.f); | ||||
| 	_pivotY = std::min(std::max(float(pivotY), 0.f), 1.f); | ||||
| 	_extrapolate.pivotX += pivotX; | ||||
| 	_extrapolate.pivotY += pivotY; | ||||
| 	_needTransform = true; | ||||
| } | ||||
| 
 | ||||
|  | @ -560,6 +604,8 @@ void e2d::Node::setSize(double width, double height) | |||
| 
 | ||||
| 	_width = float(width); | ||||
| 	_height = float(height); | ||||
| 	_extrapolate.width += width; | ||||
| 	_extrapolate.height += height; | ||||
| 	_needTransform = true; | ||||
| } | ||||
| 
 | ||||
|  | @ -570,25 +616,14 @@ void e2d::Node::setSize(Size size) | |||
| 
 | ||||
| void e2d::Node::setProperty(Property prop) | ||||
| { | ||||
| 	this->setVisible(prop.visible); | ||||
| 	this->setPos(prop.posX, prop.posY); | ||||
| 	this->setSize(prop.width, prop.height); | ||||
| 	this->setOpacity(prop.opacity); | ||||
| 	this->setPivot(prop.pivotX, prop.pivotY); | ||||
| 	this->setScale(prop.scaleX, prop.scaleY); | ||||
| 	this->setRotation(prop.rotation); | ||||
| 	this->setSkew(prop.skewAngleX, prop.skewAngleY); | ||||
| } | ||||
| 
 | ||||
| void e2d::Node::setColliderType(Collider::Type type) | ||||
| { | ||||
| 	if (_collider._type != type) | ||||
| 	{ | ||||
| 		_collider._type = type; | ||||
| 		_needTransform = true; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void e2d::Node::addChild(Node * child, int order  /* = 0 */) | ||||
| { | ||||
| 	WARN_IF(child == nullptr, "Node::addChild NULL pointer exception."); | ||||
|  |  | |||
|  | @ -450,8 +450,8 @@ class Collider | |||
| 	friend class CollisionManager; | ||||
| 
 | ||||
| public: | ||||
| 	// 碰撞体类别
 | ||||
| 	enum class Type | ||||
| 	// 碰撞体形状
 | ||||
| 	enum class Shape | ||||
| 	{ | ||||
| 		None,		/* 无 */ | ||||
| 		Rect,		/* 矩形 */ | ||||
|  | @ -470,6 +470,11 @@ public: | |||
| 	}; | ||||
| 
 | ||||
| public: | ||||
| 	// 设置碰撞体形状
 | ||||
| 	virtual void setShape( | ||||
| 		Shape shape | ||||
| 	); | ||||
| 
 | ||||
| 	// 启用或关闭该碰撞体
 | ||||
| 	virtual void setEnabled( | ||||
| 		bool enabled | ||||
|  | @ -493,6 +498,9 @@ public: | |||
| 	// 获取绘制颜色
 | ||||
| 	Color getColor() const; | ||||
| 
 | ||||
| 	// 获取形状
 | ||||
| 	Shape getShape() const; | ||||
| 
 | ||||
| 	// 获取 ID2D1Geometry* 对象
 | ||||
| 	ID2D1Geometry* getGeometry() const; | ||||
| 
 | ||||
|  | @ -516,7 +524,7 @@ protected: | |||
| 	bool	_visible; | ||||
| 	Color	_color; | ||||
| 	Node *	_parentNode; | ||||
| 	Type	_type; | ||||
| 	Shape	_shape; | ||||
| 	ID2D1Geometry* _geometry; | ||||
| }; | ||||
| 
 | ||||
|  | @ -797,10 +805,10 @@ public: | |||
| 		Point pivot | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置节点的默认碰撞体类型
 | ||||
| 	// 默认:Collider::Type::None
 | ||||
| 	void setDefaultColliderType( | ||||
| 		Collider::Type type | ||||
| 	// 设置节点的默认碰撞体形状
 | ||||
| 	// 默认:Collider::Shape::None
 | ||||
| 	void setDefaultColliderShape( | ||||
| 		Collider::Shape shape | ||||
| 	); | ||||
| 
 | ||||
| 	// 打开或关闭碰撞体可视化
 | ||||
|  | @ -825,7 +833,7 @@ public: | |||
| 	Point getNodeDefaultPivot() const; | ||||
| 
 | ||||
| 	// 获取节点的默认碰撞体类型
 | ||||
| 	Collider::Type getDefaultColliderType() const; | ||||
| 	Collider::Shape getDefaultColliderShape() const; | ||||
| 
 | ||||
| 	// 获取碰撞体可视化状态
 | ||||
| 	bool isColliderVisible() const; | ||||
|  | @ -840,8 +848,8 @@ protected: | |||
| 	bool			_collisionEnabled; | ||||
| 	bool			_colliderVisible; | ||||
| 	String			_gameName; | ||||
| 	Point			_nodeDefPivot; | ||||
| 	Collider::Type	_nodeDefColliderType; | ||||
| 	Point			_defaultNodePivot; | ||||
| 	Collider::Shape	_defaultColliderShape; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -19,12 +19,10 @@ public: | |||
| 	// 节点属性
 | ||||
| 	struct Property | ||||
| 	{ | ||||
| 		bool visible;		// 可见性
 | ||||
| 		double posX;		// X 坐标
 | ||||
| 		double posY;		// Y 坐标
 | ||||
| 		double width;		// 宽度
 | ||||
| 		double height;		// 高度
 | ||||
| 		double opacity;		// 透明度
 | ||||
| 		double pivotX;		// 中心点 X 坐标
 | ||||
| 		double pivotY;		// 中心点 Y 坐标
 | ||||
| 		double scaleX;		// 横向缩放
 | ||||
|  | @ -32,6 +30,11 @@ public: | |||
| 		double rotation;	// 旋转角度
 | ||||
| 		double skewAngleX;	// 横向倾斜角度
 | ||||
| 		double skewAngleY;	// 纵向倾斜角度
 | ||||
| 
 | ||||
| 		Property operator+ (Property const & prop) const; | ||||
| 		Property operator- (Property const & prop) const; | ||||
| 
 | ||||
| 		static const Property Origin; | ||||
| 	}; | ||||
| 
 | ||||
| public: | ||||
|  | @ -331,11 +334,6 @@ public: | |||
| 		Property prop | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置碰撞体类型
 | ||||
| 	virtual void setColliderType( | ||||
| 		Collider::Type type | ||||
| 	); | ||||
| 
 | ||||
| 	// 添加子节点
 | ||||
| 	virtual void addChild( | ||||
| 		Node * child, | ||||
|  | @ -425,7 +423,7 @@ protected: | |||
| 	float		_realOpacity; | ||||
| 	float		_pivotX; | ||||
| 	float		_pivotY; | ||||
| 	int			_nOrder; | ||||
| 	int			_order; | ||||
| 	bool		_visible; | ||||
| 	bool		_autoUpdate; | ||||
| 	bool		_needSort; | ||||
|  | @ -434,6 +432,7 @@ protected: | |||
| 	Collider	_collider; | ||||
| 	Scene *		_parentScene; | ||||
| 	Node *		_parent; | ||||
| 	Property	_extrapolate; | ||||
| 	ID2D1Geometry*		_outline; | ||||
| 	D2D1::Matrix3x2F	_initialMatri; | ||||
| 	D2D1::Matrix3x2F	_finalMatri; | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue