This commit is contained in:
XiaoFeng 2015-04-20 10:13:18 +08:00
commit 93e36001a6
58 changed files with 450 additions and 372 deletions

View File

@ -1106,6 +1106,9 @@ Developers:
milos1290 milos1290
Added Lerp for Vec3 Added Lerp for Vec3
perminovVS
Optimize Vec3 and Vec2
Retired Core Developers: Retired Core Developers:
WenSheng Yang WenSheng Yang

View File

@ -3,6 +3,7 @@ cocos2d-x-3.6 ??
[NEW] 3rd: update freetype to v 2.5.5 on Windows 8.1 Universal App [NEW] 3rd: update freetype to v 2.5.5 on Windows 8.1 Universal App
[NEW] Label: added LabelEffect::ALL which can be used in disableEffect(LabelEffect) to disable all effects [NEW] Label: added LabelEffect::ALL which can be used in disableEffect(LabelEffect) to disable all effects
[NEW] MathUtil: added `MathUtil::lerp()` [NEW] MathUtil: added `MathUtil::lerp()`
[NEW] Vec2: added `Vec2::setZero()`
[NEW] Vec3: added `Vec3::lerp()` [NEW] Vec3: added `Vec3::lerp()`
[NEW] WP8: remove WP8 support because Angle don't support WP8 any more [NEW] WP8: remove WP8 support because Angle don't support WP8 any more

View File

@ -206,7 +206,7 @@ bool Follow::initWithTarget(Node *followedNode, const Rect& rect/* = Rect::ZERO*
_boundaryFullyCovered = false; _boundaryFullyCovered = false;
Size winSize = Director::getInstance()->getWinSize(); Size winSize = Director::getInstance()->getWinSize();
_fullScreenSize = Vec2(winSize.width, winSize.height); _fullScreenSize.set(winSize.width, winSize.height);
_halfScreenSize = _fullScreenSize * 0.5f; _halfScreenSize = _fullScreenSize * 0.5f;
if (_boundarySet) if (_boundarySet)

View File

@ -96,7 +96,7 @@ void ActionCamera::updateTransform()
Vec2 anchorPoint = _target->getAnchorPointInPoints(); Vec2 anchorPoint = _target->getAnchorPointInPoints();
bool needsTranslation = !anchorPoint.equals(Vec2::ZERO); bool needsTranslation = !anchorPoint.isZero();
Mat4 mv = Mat4::IDENTITY; Mat4 mv = Mat4::IDENTITY;

View File

@ -274,7 +274,7 @@ void CardinalSplineTo::startWithTarget(cocos2d::Node *target)
_deltaT = (float) 1 / (_points->count() - 1); _deltaT = (float) 1 / (_points->count() - 1);
_previousPosition = target->getPosition(); _previousPosition = target->getPosition();
_accumulatedDiff = Vec2::ZERO; _accumulatedDiff.setZero();
} }
CardinalSplineTo* CardinalSplineTo::clone() const CardinalSplineTo* CardinalSplineTo::clone() const

View File

@ -143,8 +143,8 @@ void FlipX3D::update(float time)
Vec3 v0, v1, v, diff; Vec3 v0, v1, v, diff;
v0 = getOriginalVertex(Vec2(1, 1)); v0 = getOriginalVertex(Vec2(1.0f, 1.0f));
v1 = getOriginalVertex(Vec2(0, 0)); v1 = getOriginalVertex(Vec2());
float x0 = v0.x; float x0 = v0.x;
float x1 = v1.x; float x1 = v1.x;
@ -154,19 +154,19 @@ void FlipX3D::update(float time)
if ( x0 > x1 ) if ( x0 > x1 )
{ {
// Normal Grid // Normal Grid
a = Vec2(0,0); a.setZero();
b = Vec2(0,1); b.set(0.0f, 1.0f);
c = Vec2(1,0); c.set(1.0f, 0.0f);
d = Vec2(1,1); d.set(1.0f, 1.0f);
x = x0; x = x0;
} }
else else
{ {
// Reversed Grid // Reversed Grid
c = Vec2(0,0); c.setZero();
d = Vec2(0,1); d.set(0.0f, 1.0f);
a = Vec2(1,0); a.set(1.0f, 0.0f);
b = Vec2(1,1); b.set(1.0f, 1.0f);
x = x1; x = x1;
} }
@ -237,8 +237,8 @@ void FlipY3D::update(float time)
Vec3 v0, v1, v, diff; Vec3 v0, v1, v, diff;
v0 = getOriginalVertex(Vec2(1, 1)); v0 = getOriginalVertex(Vec2(1.0f, 1.0f));
v1 = getOriginalVertex(Vec2(0, 0)); v1 = getOriginalVertex(Vec2());
float y0 = v0.y; float y0 = v0.y;
float y1 = v1.y; float y1 = v1.y;
@ -248,19 +248,19 @@ void FlipY3D::update(float time)
if (y0 > y1) if (y0 > y1)
{ {
// Normal Grid // Normal Grid
a = Vec2(0,0); a.setZero();
b = Vec2(0,1); b.set(0.0f, 1.0f);
c = Vec2(1,0); c.set(1.0f, 0.0f);
d = Vec2(1,1); d.set(1.0f, 1.0f);
y = y0; y = y0;
} }
else else
{ {
// Reversed Grid // Reversed Grid
b = Vec2(0,0); b.setZero();
a = Vec2(0,1); a.set(0.0f, 1.0f);
d = Vec2(1,0); d.set(1.0f, 0.0f);
c = Vec2(1,1); c.set(1.0f, 1.0f);
y = y1; y = y1;
} }
@ -318,7 +318,7 @@ bool Lens3D::initWithDuration(float duration, const Size& gridSize, const Vec2&
{ {
if (Grid3DAction::initWithDuration(duration, gridSize)) if (Grid3DAction::initWithDuration(duration, gridSize))
{ {
_position = Vec2(-1, -1); _position.set(-1.0f, -1.0f);
setPosition(position); setPosition(position);
_radius = radius; _radius = radius;
_lensEffect = 0.7f; _lensEffect = 0.7f;
@ -725,13 +725,13 @@ void Twirl::update(float time)
{ {
Vec3 v = getOriginalVertex(Vec2(i ,j)); Vec3 v = getOriginalVertex(Vec2(i ,j));
Vec2 avg = Vec2(i-(_gridSize.width/2.0f), j-(_gridSize.height/2.0f)); Vec2 avg(i-(_gridSize.width/2.0f), j-(_gridSize.height/2.0f));
float r = avg.getLength(); float r = avg.getLength();
float amp = 0.1f * _amplitude * _amplitudeRate; float amp = 0.1f * _amplitude * _amplitudeRate;
float a = r * cosf( (float)M_PI/2.0f + time * (float)M_PI * _twirls * 2 ) * amp; float a = r * cosf( (float)M_PI/2.0f + time * (float)M_PI * _twirls * 2 ) * amp;
Vec2 d = Vec2( Vec2 d(
sinf(a) * (v.y-c.y) + cosf(a) * (v.x-c.x), sinf(a) * (v.y-c.y) + cosf(a) * (v.x-c.x),
cosf(a) * (v.y-c.y) - sinf(a) * (v.x-c.x)); cosf(a) * (v.y-c.y) - sinf(a) * (v.x-c.x));

View File

@ -1478,7 +1478,7 @@ JumpTo* JumpTo::reverse() const
void JumpTo::startWithTarget(Node *target) void JumpTo::startWithTarget(Node *target)
{ {
JumpBy::startWithTarget(target); JumpBy::startWithTarget(target);
_delta = Vec2(_endPosition.x - _startPosition.x, _endPosition.y - _startPosition.y); _delta.set(_endPosition.x - _startPosition.x, _endPosition.y - _startPosition.y);
} }
// Bezier cubic formula: // Bezier cubic formula:

View File

@ -325,8 +325,8 @@ void ShuffleTiles::startWithTarget(Node *target)
{ {
for ( int j = 0; j < _gridSize.height; ++j) for ( int j = 0; j < _gridSize.height; ++j)
{ {
tileArray->position = Vec2((float)i, (float)j); tileArray->position.set((float)i, (float)j);
tileArray->startPosition = Vec2((float)i, (float)j); tileArray->startPosition.set((float)i, (float)j);
tileArray->delta = getDelta(Size(i, j)); tileArray->delta = getDelta(Size(i, j));
++tileArray; ++tileArray;
} }
@ -694,7 +694,7 @@ void TurnOffTiles::update(float time)
for (unsigned int i = 0; i < _tilesCount; i++ ) for (unsigned int i = 0; i < _tilesCount; i++ )
{ {
t = _tilesOrder[i]; t = _tilesOrder[i];
Vec2 tilePos = Vec2( (unsigned int)(t / _gridSize.height), t % (unsigned int)_gridSize.height ); Vec2 tilePos( (unsigned int)(t / _gridSize.height), t % (unsigned int)_gridSize.height );
if ( i < l ) if ( i < l )
{ {

View File

@ -202,10 +202,10 @@ void ClippingNode::drawFullScreenQuadClearStencil()
director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
Vec2 vertices[] = { Vec2 vertices[] = {
Vec2(-1, -1), Vec2(-1.0f, -1.0f),
Vec2(1, -1), Vec2(1.0f, -1.0f),
Vec2(1, 1), Vec2(1.0f, 1.0f),
Vec2(-1, 1) Vec2(-1.0f, 1.0f)
}; };
auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_U_COLOR); auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_U_COLOR);

View File

@ -328,7 +328,7 @@ void drawSolidPoly(const Vec2 *poli, unsigned int numberOfPoints, Color4F color)
// Mac on 64-bit // Mac on 64-bit
for(unsigned int i = 0; i < numberOfPoints; i++) for(unsigned int i = 0; i < numberOfPoints; i++)
{ {
newPoli[i] = Vec2( poli[i].x, poli[i].y ); newPoli[i].set(poli[i].x, poli[i].y);
} }
#ifdef EMSCRIPTEN #ifdef EMSCRIPTEN
setGLBufferData(newPoli, numberOfPoints * sizeof(Vec2)); setGLBufferData(newPoli, numberOfPoints * sizeof(Vec2));

View File

@ -740,19 +740,19 @@ void TMXLayer::parseInternalProperties()
//CCTMXLayer2 - obtaining positions, offset //CCTMXLayer2 - obtaining positions, offset
Vec2 TMXLayer::calculateLayerOffset(const Vec2& pos) Vec2 TMXLayer::calculateLayerOffset(const Vec2& pos)
{ {
Vec2 ret = Vec2::ZERO; Vec2 ret;
switch (_layerOrientation) switch (_layerOrientation)
{ {
case FAST_TMX_ORIENTATION_ORTHO: case FAST_TMX_ORIENTATION_ORTHO:
ret = Vec2( pos.x * _mapTileSize.width, -pos.y *_mapTileSize.height); ret.set( pos.x * _mapTileSize.width, -pos.y *_mapTileSize.height);
break; break;
case FAST_TMX_ORIENTATION_ISO: case FAST_TMX_ORIENTATION_ISO:
ret = Vec2((_mapTileSize.width /2) * (pos.x - pos.y), ret.set((_mapTileSize.width /2) * (pos.x - pos.y),
(_mapTileSize.height /2 ) * (-pos.x - pos.y)); (_mapTileSize.height /2 ) * (-pos.x - pos.y));
break; break;
case FAST_TMX_ORIENTATION_HEX: case FAST_TMX_ORIENTATION_HEX:
default: default:
CCASSERT(pos.equals(Vec2::ZERO), "offset for this map not implemented yet"); CCASSERT(pos.isZero(), "offset for this map not implemented yet");
break; break;
} }
return ret; return ret;

View File

@ -714,7 +714,7 @@ void LayerGradient::updateColor()
return; return;
float c = sqrtf(2.0f); float c = sqrtf(2.0f);
Vec2 u = Vec2(_alongVector.x / h, _alongVector.y / h); Vec2 u(_alongVector.x / h, _alongVector.y / h);
// Compressed Interpolation mode // Compressed Interpolation mode
if (_compressedInterpolation) if (_compressedInterpolation)

View File

@ -549,7 +549,7 @@ MenuItem* Menu::getItemForTouch(Touch *touch)
{ {
Vec2 local = child->convertToNodeSpace(touchLocation); Vec2 local = child->convertToNodeSpace(touchLocation);
Rect r = child->rect(); Rect r = child->rect();
r.origin = Vec2::ZERO; r.origin.setZero();
if (r.containsPoint(local)) if (r.containsPoint(local))
{ {

View File

@ -40,7 +40,6 @@ MotionStreak::MotionStreak()
, _startingPositionInitialized(false) , _startingPositionInitialized(false)
, _texture(nullptr) , _texture(nullptr)
, _blendFunc(BlendFunc::ALPHA_NON_PREMULTIPLIED) , _blendFunc(BlendFunc::ALPHA_NON_PREMULTIPLIED)
, _positionR(Vec2::ZERO)
, _stroke(0.0f) , _stroke(0.0f)
, _fadeDelta(0.0f) , _fadeDelta(0.0f)
, _minSeg(0.0f) , _minSeg(0.0f)
@ -106,7 +105,7 @@ bool MotionStreak::initWithFade(float fade, float minSeg, float stroke, const Co
ignoreAnchorPointForPosition(true); ignoreAnchorPointForPosition(true);
_startingPositionInitialized = false; _startingPositionInitialized = false;
_positionR = Vec2::ZERO; _positionR.setZero();
_fastMode = true; _fastMode = true;
_minSeg = (minSeg == -1.0f) ? stroke/5.0f : minSeg; _minSeg = (minSeg == -1.0f) ? stroke/5.0f : minSeg;
_minSeg *= _minSeg; _minSeg *= _minSeg;

View File

@ -83,14 +83,11 @@ Node::Node(void)
, _scaleX(1.0f) , _scaleX(1.0f)
, _scaleY(1.0f) , _scaleY(1.0f)
, _scaleZ(1.0f) , _scaleZ(1.0f)
, _position(Vec2::ZERO)
, _positionZ(0.0f) , _positionZ(0.0f)
, _usingNormalizedPosition(false) , _usingNormalizedPosition(false)
, _normalizedPositionDirty(false) , _normalizedPositionDirty(false)
, _skewX(0.0f) , _skewX(0.0f)
, _skewY(0.0f) , _skewY(0.0f)
, _anchorPointInPoints(Vec2::ZERO)
, _anchorPoint(Vec2::ZERO)
, _contentSize(Size::ZERO) , _contentSize(Size::ZERO)
, _contentSizeDirty(true) , _contentSizeDirty(true)
, _transformDirty(true) , _transformDirty(true)
@ -723,7 +720,7 @@ void Node::setAnchorPoint(const Vec2& point)
if (! point.equals(_anchorPoint)) if (! point.equals(_anchorPoint))
{ {
_anchorPoint = point; _anchorPoint = point;
_anchorPointInPoints = Vec2(_contentSize.width * _anchorPoint.x, _contentSize.height * _anchorPoint.y); _anchorPointInPoints.set(_contentSize.width * _anchorPoint.x, _contentSize.height * _anchorPoint.y);
_transformUpdated = _transformDirty = _inverseDirty = true; _transformUpdated = _transformDirty = _inverseDirty = true;
} }
} }
@ -740,7 +737,7 @@ void Node::setContentSize(const Size & size)
{ {
_contentSize = size; _contentSize = size;
_anchorPointInPoints = Vec2(_contentSize.width * _anchorPoint.x, _contentSize.height * _anchorPoint.y); _anchorPointInPoints.set(_contentSize.width * _anchorPoint.x, _contentSize.height * _anchorPoint.y);
_transformUpdated = _transformDirty = _inverseDirty = _contentSizeDirty = true; _transformUpdated = _transformDirty = _inverseDirty = _contentSizeDirty = true;
} }
} }
@ -1768,7 +1765,7 @@ const Mat4& Node::getNodeToParentTransform() const
Vec2 anchorPoint(_anchorPointInPoints.x * _scaleX, _anchorPointInPoints.y * _scaleY); Vec2 anchorPoint(_anchorPointInPoints.x * _scaleX, _anchorPointInPoints.y * _scaleY);
// caculate real position // caculate real position
if (! needsSkewMatrix && !_anchorPointInPoints.equals(Vec2::ZERO)) if (! needsSkewMatrix && !_anchorPointInPoints.isZero())
{ {
x += -anchorPoint.x; x += -anchorPoint.x;
y += -anchorPoint.y; y += -anchorPoint.y;
@ -1831,7 +1828,7 @@ const Mat4& Node::getNodeToParentTransform() const
_transform = _transform * skewMatrix; _transform = _transform * skewMatrix;
// adjust anchor point // adjust anchor point
if (!_anchorPointInPoints.equals(Vec2::ZERO)) if (!_anchorPointInPoints.isZero())
{ {
// FIXME:: Argh, Mat4 needs a "translate" method. // FIXME:: Argh, Mat4 needs a "translate" method.
// FIXME:: Although this is faster than multiplying a vec4 * mat4 // FIXME:: Although this is faster than multiplying a vec4 * mat4

View File

@ -66,7 +66,7 @@ private:
ParallaxNode::ParallaxNode() ParallaxNode::ParallaxNode()
{ {
_parallaxArray = ccArrayNew(5); _parallaxArray = ccArrayNew(5);
_lastPosition = Vec2(-100,-100); _lastPosition.set(-100.0f, -100.0f);
} }
ParallaxNode::~ParallaxNode() ParallaxNode::~ParallaxNode()

View File

@ -98,7 +98,7 @@ bool ParticleFire::initWithTotalParticles(int numberOfParticles)
this->_emitterMode = Mode::GRAVITY; this->_emitterMode = Mode::GRAVITY;
// Gravity Mode: gravity // Gravity Mode: gravity
this->modeA.gravity = Vec2(0,0); this->modeA.gravity.setZero();
// Gravity Mode: radial acceleration // Gravity Mode: radial acceleration
this->modeA.radialAccel = 0; this->modeA.radialAccel = 0;
@ -114,8 +114,8 @@ bool ParticleFire::initWithTotalParticles(int numberOfParticles)
// emitter position // emitter position
Size winSize = Director::getInstance()->getWinSize(); Size winSize = Director::getInstance()->getWinSize();
this->setPosition(winSize.width/2, 60); this->setPosition(winSize.width/2.0f, 60.0f);
this->_posVar = Vec2(40, 20); this->_posVar.set(40.0f, 20.0f);
// life of particles // life of particles
_life = 3; _life = 3;
@ -203,27 +203,27 @@ bool ParticleFireworks::initWithTotalParticles(int numberOfParticles)
this->_emitterMode = Mode::GRAVITY; this->_emitterMode = Mode::GRAVITY;
// Gravity Mode: gravity // Gravity Mode: gravity
this->modeA.gravity = Vec2(0,-90); this->modeA.gravity.set(0.0f, -90.0f);
// Gravity Mode: radial // Gravity Mode: radial
this->modeA.radialAccel = 0; this->modeA.radialAccel = 0.0f;
this->modeA.radialAccelVar = 0; this->modeA.radialAccelVar = 0.0f;
// Gravity Mode: speed of particles // Gravity Mode: speed of particles
this->modeA.speed = 180; this->modeA.speed = 180.0f;
this->modeA.speedVar = 50; this->modeA.speedVar = 50.0f;
// emitter position // emitter position
Size winSize = Director::getInstance()->getWinSize(); Size winSize = Director::getInstance()->getWinSize();
this->setPosition(winSize.width/2, winSize.height/2); this->setPosition(winSize.width/2, winSize.height/2);
// angle // angle
this->_angle= 90; this->_angle= 90.0f;
this->_angleVar = 20; this->_angleVar = 20.0f;
// life of particles // life of particles
this->_life = 3.5f; this->_life = 3.5f;
this->_lifeVar = 1; this->_lifeVar = 1.0f;
// emits per frame // emits per frame
this->_emissionRate = _totalParticles/_life; this->_emissionRate = _totalParticles/_life;

View File

@ -93,8 +93,6 @@ ParticleSystem::ParticleSystem()
, _isActive(true) , _isActive(true)
, _particleCount(0) , _particleCount(0)
, _duration(0) , _duration(0)
, _sourcePosition(Vec2::ZERO)
, _posVar(Vec2::ZERO)
, _life(0) , _life(0)
, _lifeVar(0) , _lifeVar(0)
, _angle(0) , _angle(0)
@ -116,7 +114,7 @@ ParticleSystem::ParticleSystem()
, _yCoordFlipped(1) , _yCoordFlipped(1)
, _positionType(PositionType::FREE) , _positionType(PositionType::FREE)
{ {
modeA.gravity = Vec2::ZERO; modeA.gravity.setZero();
modeA.speed = 0; modeA.speed = 0;
modeA.speedVar = 0; modeA.speedVar = 0;
modeA.tangentialAccel = 0; modeA.tangentialAccel = 0;
@ -683,7 +681,7 @@ void ParticleSystem::update(float dt)
_particleIdx = 0; _particleIdx = 0;
Vec2 currentPosition = Vec2::ZERO; Vec2 currentPosition;
if (_positionType == PositionType::FREE) if (_positionType == PositionType::FREE)
{ {
currentPosition = this->convertToWorldSpace(Vec2::ZERO); currentPosition = this->convertToWorldSpace(Vec2::ZERO);
@ -710,7 +708,6 @@ void ParticleSystem::update(float dt)
{ {
Vec2 tmp, radial, tangential; Vec2 tmp, radial, tangential;
radial = Vec2::ZERO;
// radial acceleration // radial acceleration
if (p->pos.x || p->pos.y) if (p->pos.x || p->pos.y)
{ {

View File

@ -237,7 +237,7 @@ void ParticleSystemQuad::setTexture(Texture2D* texture)
void ParticleSystemQuad::setDisplayFrame(SpriteFrame *spriteFrame) void ParticleSystemQuad::setDisplayFrame(SpriteFrame *spriteFrame)
{ {
CCASSERT(spriteFrame->getOffsetInPixels().equals(Vec2::ZERO), CCASSERT(spriteFrame->getOffsetInPixels().isZero(),
"QuadParticle only supports SpriteFrames with no offsets"); "QuadParticle only supports SpriteFrames with no offsets");
// update texture before updating texture rect // update texture before updating texture rect

View File

@ -157,8 +157,8 @@ Tex2F ProgressTimer::textureCoordFromAlphaPoint(Vec2 alpha)
return ret; return ret;
} }
V3F_C4B_T2F_Quad quad = _sprite->getQuad(); V3F_C4B_T2F_Quad quad = _sprite->getQuad();
Vec2 min = Vec2(quad.bl.texCoords.u,quad.bl.texCoords.v); Vec2 min(quad.bl.texCoords.u,quad.bl.texCoords.v);
Vec2 max = Vec2(quad.tr.texCoords.u,quad.tr.texCoords.v); Vec2 max(quad.tr.texCoords.u,quad.tr.texCoords.v);
// Fix bug #1303 so that progress timer handles sprite frame texture rotation // Fix bug #1303 so that progress timer handles sprite frame texture rotation
if (_sprite->isTextureRectRotated()) { if (_sprite->isTextureRectRotated()) {
std::swap(alpha.x, alpha.y); std::swap(alpha.x, alpha.y);
@ -173,8 +173,8 @@ Vec2 ProgressTimer::vertexFromAlphaPoint(Vec2 alpha)
return ret; return ret;
} }
V3F_C4B_T2F_Quad quad = _sprite->getQuad(); V3F_C4B_T2F_Quad quad = _sprite->getQuad();
Vec2 min = Vec2(quad.bl.vertices.x,quad.bl.vertices.y); Vec2 min(quad.bl.vertices.x,quad.bl.vertices.y);
Vec2 max = Vec2(quad.tr.vertices.x,quad.tr.vertices.y); Vec2 max(quad.tr.vertices.x,quad.tr.vertices.y);
ret.x = min.x * (1.f - alpha.x) + max.x * alpha.x; ret.x = min.x * (1.f - alpha.x) + max.x * alpha.x;
ret.y = min.y * (1.f - alpha.y) + max.y * alpha.y; ret.y = min.y * (1.f - alpha.y) + max.y * alpha.y;
return ret; return ret;
@ -269,12 +269,12 @@ void ProgressTimer::updateRadial(void)
// We find the vector to do a hit detection based on the percentage // We find the vector to do a hit detection based on the percentage
// We know the first vector is the one @ 12 o'clock (top,mid) so we rotate // We know the first vector is the one @ 12 o'clock (top,mid) so we rotate
// from that by the progress angle around the _midpoint pivot // from that by the progress angle around the _midpoint pivot
Vec2 topMid = Vec2(_midpoint.x, 1.f); Vec2 topMid(_midpoint.x, 1.f);
Vec2 percentagePt = topMid.rotateByAngle(_midpoint, angle); Vec2 percentagePt = topMid.rotateByAngle(_midpoint, angle);
int index = 0; int index = 0;
Vec2 hit = Vec2::ZERO; Vec2 hit;
if (alpha == 0.f) { if (alpha == 0.f) {
// More efficient since we don't always need to check intersection // More efficient since we don't always need to check intersection

View File

@ -228,7 +228,7 @@ bool Sprite::initWithTexture(Texture2D *texture, const Rect& rect, bool rotated)
setAnchorPoint(Vec2(0.5f, 0.5f)); setAnchorPoint(Vec2(0.5f, 0.5f));
// zwoptex default values // zwoptex default values
_offsetPosition = Vec2::ZERO; _offsetPosition.setZero();
// clean the Quad // clean the Quad
memset(&_quad, 0, sizeof(_quad)); memset(&_quad, 0, sizeof(_quad));

View File

@ -605,18 +605,18 @@ void TMXLayer::removeTileAt(const Vec2& pos)
//CCTMXLayer - obtaining positions, offset //CCTMXLayer - obtaining positions, offset
Vec2 TMXLayer::calculateLayerOffset(const Vec2& pos) Vec2 TMXLayer::calculateLayerOffset(const Vec2& pos)
{ {
Vec2 ret = Vec2::ZERO; Vec2 ret;
switch (_layerOrientation) switch (_layerOrientation)
{ {
case TMXOrientationOrtho: case TMXOrientationOrtho:
ret = Vec2( pos.x * _mapTileSize.width, -pos.y *_mapTileSize.height); ret.set( pos.x * _mapTileSize.width, -pos.y *_mapTileSize.height);
break; break;
case TMXOrientationIso: case TMXOrientationIso:
ret = Vec2((_mapTileSize.width /2) * (pos.x - pos.y), ret.set((_mapTileSize.width /2) * (pos.x - pos.y),
(_mapTileSize.height /2 ) * (-pos.x - pos.y)); (_mapTileSize.height /2 ) * (-pos.x - pos.y));
break; break;
case TMXOrientationHex: case TMXOrientationHex:
CCASSERT(pos.equals(Vec2::ZERO), "offset for hexagonal map not implemented yet"); CCASSERT(pos.isZero(), "offset for hexagonal map not implemented yet");
break; break;
case TMXOrientationStaggered: case TMXOrientationStaggered:
{ {
@ -625,7 +625,7 @@ Vec2 TMXLayer::calculateLayerOffset(const Vec2& pos)
{ {
diffX = _mapTileSize.width/2; diffX = _mapTileSize.width/2;
} }
ret = Vec2(pos.x * _mapTileSize.width + diffX, ret.set(pos.x * _mapTileSize.width + diffX,
(-pos.y) * _mapTileSize.height/2); (-pos.y) * _mapTileSize.height/2);
} }
break; break;
@ -635,7 +635,7 @@ Vec2 TMXLayer::calculateLayerOffset(const Vec2& pos)
Vec2 TMXLayer::getPositionAt(const Vec2& pos) Vec2 TMXLayer::getPositionAt(const Vec2& pos)
{ {
Vec2 ret = Vec2::ZERO; Vec2 ret;
switch (_layerOrientation) switch (_layerOrientation)
{ {
case TMXOrientationOrtho: case TMXOrientationOrtho:
@ -675,7 +675,8 @@ Vec2 TMXLayer::getPositionForHexAt(const Vec2& pos)
diffY = -_mapTileSize.height/2 ; diffY = -_mapTileSize.height/2 ;
} }
Vec2 xy = Vec2(pos.x * _mapTileSize.width*3/4, Vec2 xy(
pos.x * _mapTileSize.width*3/4,
(_layerSize.height - pos.y - 1) * _mapTileSize.height + diffY); (_layerSize.height - pos.y - 1) * _mapTileSize.height + diffY);
return xy; return xy;
} }

View File

@ -34,7 +34,6 @@ NS_CC_BEGIN
TMXObjectGroup::TMXObjectGroup() TMXObjectGroup::TMXObjectGroup()
: _groupName("") : _groupName("")
, _positionOffset(Vec2::ZERO)
{ {
} }

View File

@ -44,7 +44,6 @@ TMXLayerInfo::TMXLayerInfo()
: _name("") : _name("")
, _tiles(nullptr) , _tiles(nullptr)
, _ownTiles(true) , _ownTiles(true)
, _offset(Vec2::ZERO)
{ {
} }
@ -355,7 +354,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
float x = attributeDict["x"].asFloat(); float x = attributeDict["x"].asFloat();
float y = attributeDict["y"].asFloat(); float y = attributeDict["y"].asFloat();
layer->_offset = Vec2(x,y); layer->_offset.set(x, y);
tmxMapInfo->getLayers().pushBack(layer); tmxMapInfo->getLayers().pushBack(layer);
layer->release(); layer->release();

View File

@ -297,19 +297,19 @@ void Terrain::setChunksLOD(Vec3 cameraPos)
float Terrain::getHeight(float x, float z, Vec3 * normal) float Terrain::getHeight(float x, float z, Vec3 * normal)
{ {
Vec2 pos = Vec2(x,z); Vec2 pos(x,z);
//top-left //top-left
Vec2 tl = Vec2(-1*_terrainData._mapScale*_imageWidth/2,-1*_terrainData._mapScale*_imageHeight/2); Vec2 tl(-1*_terrainData._mapScale*_imageWidth/2,-1*_terrainData._mapScale*_imageHeight/2);
auto result = getNodeToWorldTransform()*Vec4(tl.x,0.0f,tl.y,1.0f); auto result = getNodeToWorldTransform()*Vec4(tl.x,0.0f,tl.y,1.0f);
tl = Vec2(result.x,result.z); tl.set(result.x, result.z);
Vec2 to_tl = pos - tl; Vec2 to_tl = pos - tl;
//real size //real size
Vec2 size = Vec2(_imageWidth*_terrainData._mapScale,_imageHeight*_terrainData._mapScale); Vec2 size(_imageWidth*_terrainData._mapScale,_imageHeight*_terrainData._mapScale);
result = getNodeToWorldTransform()*Vec4(size.x,0.0f,size.y,0.0f); result = getNodeToWorldTransform()*Vec4(size.x,0.0f,size.y,0.0f);
size = Vec2(result.x,result.z); size.set(result.x, result.z);
float width_ratio = to_tl.x/size.x; float width_ratio = to_tl.x/size.x;
float height_ratio = to_tl.y/size.y; float height_ratio = to_tl.y/size.y;
@ -543,19 +543,19 @@ void Terrain::setMaxDetailMapAmount(int max_value)
cocos2d::Vec2 Terrain::convertToTerrainSpace(Vec2 worldSpaceXZ) cocos2d::Vec2 Terrain::convertToTerrainSpace(Vec2 worldSpaceXZ)
{ {
Vec2 pos = Vec2(worldSpaceXZ.x,worldSpaceXZ.y); Vec2 pos(worldSpaceXZ.x,worldSpaceXZ.y);
//top-left //top-left
Vec2 tl = Vec2(-1*_terrainData._mapScale*_imageWidth/2,-1*_terrainData._mapScale*_imageHeight/2); Vec2 tl(-1*_terrainData._mapScale*_imageWidth/2,-1*_terrainData._mapScale*_imageHeight/2);
auto result = getNodeToWorldTransform()*Vec4(tl.x,0.0f,tl.y,1.0f); auto result = getNodeToWorldTransform()*Vec4(tl.x,0.0f,tl.y,1.0f);
tl = Vec2(result.x,result.z); tl.set(result.x, result.z);
Vec2 to_tl = pos - tl; Vec2 to_tl = pos - tl;
//real size //real size
Vec2 size = Vec2(_imageWidth*_terrainData._mapScale,_imageHeight*_terrainData._mapScale); Vec2 size(_imageWidth*_terrainData._mapScale,_imageHeight*_terrainData._mapScale);
result = getNodeToWorldTransform()*Vec4(size.x,0.0f,size.y,0.0f); result = getNodeToWorldTransform()*Vec4(size.x,0.0f,size.y,0.0f);
size = Vec2(result.x,result.z); size.set(result.x, result.z);
float width_ratio = to_tl.x/size.x; float width_ratio = to_tl.x/size.x;
float height_ratio = to_tl.y/size.y; float height_ratio = to_tl.y/size.y;
@ -1206,8 +1206,8 @@ void Terrain::Chunk::calculateSlope()
highest = _originalVertices[i]._position; highest = _originalVertices[i]._position;
} }
} }
auto a = Vec2(lowest.x,lowest.z); Vec2 a(lowest.x,lowest.z);
auto b = Vec2(highest.x,highest.z); Vec2 b(highest.x,highest.z);
float dist = a.distance(b); float dist = a.distance(b);
_slope = (highest.y - lowest.y)/dist; _slope = (highest.y - lowest.y)/dist;
} }

View File

@ -148,7 +148,7 @@ Rect RectFromString(const std::string& str)
Vec2 PointFromString(const std::string& str) Vec2 PointFromString(const std::string& str)
{ {
Vec2 ret = Vec2::ZERO; Vec2 ret;
do do
{ {
@ -158,7 +158,7 @@ Vec2 PointFromString(const std::string& str)
float x = (float) utils::atof(strs[0].c_str()); float x = (float) utils::atof(strs[0].c_str());
float y = (float) utils::atof(strs[1].c_str()); float y = (float) utils::atof(strs[1].c_str());
ret = Vec2(x, y); ret.set(x, y);
} while (0); } while (0);
return ret; return ret;

View File

@ -34,7 +34,7 @@
NS_CC_BEGIN NS_CC_BEGIN
const Vec2 CCPointZero = Vec2::ZERO; const Vec2 CCPointZero;
/* The "zero" size -- equivalent to Size(0, 0). */ /* The "zero" size -- equivalent to Size(0, 0). */
const Size CCSizeZero = Size::ZERO; const Size CCSizeZero = Size::ZERO;

View File

@ -7,7 +7,7 @@ namespace cocosbuilder {
CC_DLL Vec2 getAbsolutePosition(const Vec2 &pt, CCBReader::PositionType type, const Size &containerSize, const std::string& propName) CC_DLL Vec2 getAbsolutePosition(const Vec2 &pt, CCBReader::PositionType type, const Size &containerSize, const std::string& propName)
{ {
Vec2 absPt = Vec2(0,0); Vec2 absPt;
if (type == CCBReader::PositionType::RELATIVE_BOTTOM_LEFT) if (type == CCBReader::PositionType::RELATIVE_BOTTOM_LEFT)
{ {
absPt = pt; absPt = pt;

View File

@ -329,7 +329,7 @@ void Armature::updateOffsetPoint()
// Set contentsize and Calculate anchor point. // Set contentsize and Calculate anchor point.
Rect rect = getBoundingBox(); Rect rect = getBoundingBox();
setContentSize(rect.size); setContentSize(rect.size);
_offsetPoint = Vec2(-rect.origin.x, -rect.origin.y); _offsetPoint.set(-rect.origin.x, -rect.origin.y);
if (rect.size.width != 0 && rect.size.height != 0) if (rect.size.width != 0 && rect.size.height != 0)
{ {
setAnchorPoint(Vec2(_offsetPoint.x / rect.size.width, _offsetPoint.y / rect.size.height)); setAnchorPoint(Vec2(_offsetPoint.x / rect.size.width, _offsetPoint.y / rect.size.height));
@ -341,8 +341,8 @@ void Armature::setAnchorPoint(const Vec2& point)
if( ! point.equals(_anchorPoint)) if( ! point.equals(_anchorPoint))
{ {
_anchorPoint = point; _anchorPoint = point;
_anchorPointInPoints = Vec2(_contentSize.width * _anchorPoint.x - _offsetPoint.x, _contentSize.height * _anchorPoint.y - _offsetPoint.y); _anchorPointInPoints.set(_contentSize.width * _anchorPoint.x - _offsetPoint.x, _contentSize.height * _anchorPoint.y - _offsetPoint.y);
_realAnchorPointInPoints = Vec2(_contentSize.width * _anchorPoint.x, _contentSize.height * _anchorPoint.y); _realAnchorPointInPoints.set(_contentSize.width * _anchorPoint.x, _contentSize.height * _anchorPoint.y);
_transformDirty = _inverseDirty = true; _transformDirty = _inverseDirty = true;
} }
} }

View File

@ -380,7 +380,7 @@ bool DisplayManager::containPoint(Vec2 &point)
* *
*/ */
Vec2 outPoint = Vec2(0, 0); Vec2 outPoint;
Sprite *sprite = (Sprite *)_currentDecoDisplay->getDisplay(); Sprite *sprite = (Sprite *)_currentDecoDisplay->getDisplay();
sprite = (Sprite *)sprite->getChildByTag(0); sprite = (Sprite *)sprite->getChildByTag(0);
@ -398,7 +398,7 @@ bool DisplayManager::containPoint(Vec2 &point)
bool DisplayManager::containPoint(float x, float y) bool DisplayManager::containPoint(float x, float y)
{ {
Vec2 p = Vec2(x, y); Vec2 p(x, y);
return containPoint(p); return containPoint(p);
} }

View File

@ -41,7 +41,7 @@ bool isSpriteContainPoint(Sprite *sprite, Vec2 point, Vec2 &outPoint)
bool isSpriteContainPoint(Sprite *sprite, Vec2 point) bool isSpriteContainPoint(Sprite *sprite, Vec2 point)
{ {
Vec2 p = Vec2(0, 0); Vec2 p;
return isSpriteContainPoint(sprite, point, p); return isSpriteContainPoint(sprite, point, p);
} }

View File

@ -1173,7 +1173,7 @@ flatbuffers::Offset<flatbuffers::EasingData> FlatBuffersSerialize::createEasingD
const tinyxml2::XMLElement* PointF = Points->FirstChildElement(); const tinyxml2::XMLElement* PointF = Points->FirstChildElement();
while (PointF) while (PointF)
{ {
Vec2 pointF = Vec2::ZERO; Vec2 pointF;
attribute = PointF->FirstAttribute(); attribute = PointF->FirstAttribute();

View File

@ -89,17 +89,17 @@ namespace cocostudio
{ {
std::string name = ""; std::string name = "";
long actionTag = 0; long actionTag = 0;
Vec2 rotationSkew = Vec2::ZERO; Vec2 rotationSkew;
int zOrder = 0; int zOrder = 0;
bool visible = true; bool visible = true;
GLubyte alpha = 255; GLubyte alpha = 255;
int tag = 0; int tag = 0;
Vec2 position = Vec2::ZERO; Vec2 position;
Vec2 scale = Vec2(1.0f, 1.0f); Vec2 scale(1.0f, 1.0f);
Vec2 anchorPoint = Vec2::ZERO; Vec2 anchorPoint;
Color4B color(255, 255, 255, 255); Color4B color(255, 255, 255, 255);
Vec2 size = Vec2::ZERO; Vec2 size;
bool flipX = false; bool flipX = false;
bool flipY = false; bool flipY = false;
bool ignoreSize = false; bool ignoreSize = false;

View File

@ -77,7 +77,7 @@ namespace cocostudio
if(!attribute) if(!attribute)
return Vec2::ZERO; return Vec2::ZERO;
Vec2 ret(Vec2::ZERO); Vec2 ret;
std::string attriname; std::string attriname;
while (attribute) while (attribute)

View File

@ -76,7 +76,7 @@ namespace cocostudio
if(!attribute) if(!attribute)
return Vec2::ZERO; return Vec2::ZERO;
Vec2 ret(Vec2::ZERO); Vec2 ret;
std::string attriname; std::string attriname;
while (attribute) while (attribute)

View File

@ -391,16 +391,16 @@ namespace cocostudio
{ {
std::string name = ""; std::string name = "";
long actionTag = 0; long actionTag = 0;
Vec2 rotationSkew = Vec2::ZERO; Vec2 rotationSkew;
int zOrder = 0; int zOrder = 0;
bool visible = true; bool visible = true;
GLubyte alpha = 255; GLubyte alpha = 255;
int tag = 0; int tag = 0;
Vec2 position = Vec2::ZERO; Vec2 position;
Vec2 scale = Vec2(1.0f, 1.0f); Vec2 scale(1.0f, 1.0f);
Vec2 anchorPoint = Vec2::ZERO; Vec2 anchorPoint;
Color4B color(255, 255, 255, 255); Color4B color(255, 255, 255, 255);
Vec2 size = Vec2::ZERO; Vec2 size;
bool flipX = false; bool flipX = false;
bool flipY = false; bool flipY = false;
bool ignoreSize = false; bool ignoreSize = false;

View File

@ -69,8 +69,8 @@ void ccVertexLineToPolygon(Vec2 *points, float stroke, Vec2 *vertices, unsigned
} }
perpVector = perpVector * stroke; perpVector = perpVector * stroke;
vertices[idx] = Vec2(p1.x+perpVector.x, p1.y+perpVector.y); vertices[idx].set(p1.x + perpVector.x, p1.y + perpVector.y);
vertices[idx+1] = Vec2(p1.x-perpVector.x, p1.y-perpVector.y); vertices[idx + 1].set(p1.x - perpVector.x, p1.y - perpVector.y);
} }

View File

@ -67,57 +67,12 @@ float crossProduct2Vector(const Vec2& A, const Vec2& B, const Vec2& C, const Vec
return (D.y - C.y) * (B.x - A.x) - (D.x - C.x) * (B.y - A.y); return (D.y - C.y) * (B.x - A.x) - (D.x - C.x) * (B.y - A.y);
} }
Vec2::Vec2()
: x(0.0f), y(0.0f)
{
}
Vec2::Vec2(float xx, float yy)
: x(xx), y(yy)
{
}
Vec2::Vec2(const float* array)
{
set(array);
}
Vec2::Vec2(const Vec2& p1, const Vec2& p2)
{
set(p1, p2);
}
Vec2::Vec2(const Vec2& copy)
{
set(copy);
}
Vec2::~Vec2()
{
}
bool Vec2::isZero() const
{
return x == 0.0f && y == 0.0f;
}
bool Vec2::isOne() const
{
return x == 1.0f && y == 1.0f;
}
float Vec2::angle(const Vec2& v1, const Vec2& v2) float Vec2::angle(const Vec2& v1, const Vec2& v2)
{ {
float dz = v1.x * v2.y - v1.y * v2.x; float dz = v1.x * v2.y - v1.y * v2.x;
return atan2f(fabsf(dz) + MATH_FLOAT_SMALL, dot(v1, v2)); return atan2f(fabsf(dz) + MATH_FLOAT_SMALL, dot(v1, v2));
} }
void Vec2::add(const Vec2& v)
{
x += v.x;
y += v.y;
}
void Vec2::add(const Vec2& v1, const Vec2& v2, Vec2* dst) void Vec2::add(const Vec2& v1, const Vec2& v2, Vec2* dst)
{ {
GP_ASSERT(dst); GP_ASSERT(dst);
@ -171,18 +126,6 @@ float Vec2::distance(const Vec2& v) const
return sqrt(dx * dx + dy * dy); return sqrt(dx * dx + dy * dy);
} }
float Vec2::distanceSquared(const Vec2& v) const
{
float dx = v.x - x;
float dy = v.y - y;
return (dx * dx + dy * dy);
}
float Vec2::dot(const Vec2& v) const
{
return (x * v.x + y * v.y);
}
float Vec2::dot(const Vec2& v1, const Vec2& v2) float Vec2::dot(const Vec2& v1, const Vec2& v2)
{ {
return (v1.x * v2.x + v1.y * v2.y); return (v1.x * v2.x + v1.y * v2.y);
@ -193,17 +136,6 @@ float Vec2::length() const
return sqrt(x * x + y * y); return sqrt(x * x + y * y);
} }
float Vec2::lengthSquared() const
{
return (x * x + y * y);
}
void Vec2::negate()
{
x = -x;
y = -y;
}
void Vec2::normalize() void Vec2::normalize()
{ {
float n = x * x + y * y; float n = x * x + y * y;
@ -228,18 +160,6 @@ Vec2 Vec2::getNormalized() const
return v; return v;
} }
void Vec2::scale(float scalar)
{
x *= scalar;
y *= scalar;
}
void Vec2::scale(const Vec2& scale)
{
x *= scale.x;
y *= scale.y;
}
void Vec2::rotate(const Vec2& point, float angle) void Vec2::rotate(const Vec2& point, float angle)
{ {
double sinAngle = sin(angle); double sinAngle = sin(angle);
@ -261,12 +181,6 @@ void Vec2::rotate(const Vec2& point, float angle)
} }
} }
void Vec2::set(float xx, float yy)
{
this->x = xx;
this->y = yy;
}
void Vec2::set(const float* array) void Vec2::set(const float* array)
{ {
GP_ASSERT(array); GP_ASSERT(array);
@ -275,24 +189,6 @@ void Vec2::set(const float* array)
y = array[1]; y = array[1];
} }
void Vec2::set(const Vec2& v)
{
this->x = v.x;
this->y = v.y;
}
void Vec2::set(const Vec2& p1, const Vec2& p2)
{
x = p2.x - p1.x;
y = p2.y - p1.y;
}
void Vec2::subtract(const Vec2& v)
{
x -= v.x;
y -= v.y;
}
void Vec2::subtract(const Vec2& v1, const Vec2& v2, Vec2* dst) void Vec2::subtract(const Vec2& v1, const Vec2& v2, Vec2* dst)
{ {
GP_ASSERT(dst); GP_ASSERT(dst);
@ -301,20 +197,6 @@ void Vec2::subtract(const Vec2& v1, const Vec2& v2, Vec2* dst)
dst->y = v1.y - v2.y; dst->y = v1.y - v2.y;
} }
void Vec2::smooth(const Vec2& target, float elapsedTime, float responseTime)
{
if (elapsedTime > 0)
{
*this += (target - *this) * (elapsedTime / (elapsedTime + responseTime));
}
}
void Vec2::setPoint(float xx, float yy)
{
this->x = xx;
this->y = yy;
}
bool Vec2::equals(const Vec2& target) const bool Vec2::equals(const Vec2& target) const
{ {
return (fabs(this->x - target.x) < FLT_EPSILON) return (fabs(this->x - target.x) < FLT_EPSILON)
@ -449,18 +331,18 @@ Vec2 Vec2::getIntersectPoint(const Vec2& A, const Vec2& B, const Vec2& C, const
return Vec2::ZERO; return Vec2::ZERO;
} }
const Vec2 Vec2::ZERO = Vec2(0.0f, 0.0f); const Vec2 Vec2::ZERO(0.0f, 0.0f);
const Vec2 Vec2::ONE = Vec2(1.0f, 1.0f); const Vec2 Vec2::ONE(1.0f, 1.0f);
const Vec2 Vec2::UNIT_X = Vec2(1.0f, 0.0f); const Vec2 Vec2::UNIT_X(1.0f, 0.0f);
const Vec2 Vec2::UNIT_Y = Vec2(0.0f, 1.0f); const Vec2 Vec2::UNIT_Y(0.0f, 1.0f);
const Vec2 Vec2::ANCHOR_MIDDLE = Vec2(0.5f, 0.5f); const Vec2 Vec2::ANCHOR_MIDDLE(0.5f, 0.5f);
const Vec2 Vec2::ANCHOR_BOTTOM_LEFT = Vec2(0.0f, 0.0f); const Vec2 Vec2::ANCHOR_BOTTOM_LEFT(0.0f, 0.0f);
const Vec2 Vec2::ANCHOR_TOP_LEFT = Vec2(0.0f, 1.0f); const Vec2 Vec2::ANCHOR_TOP_LEFT(0.0f, 1.0f);
const Vec2 Vec2::ANCHOR_BOTTOM_RIGHT = Vec2(1.0f, 0.0f); const Vec2 Vec2::ANCHOR_BOTTOM_RIGHT(1.0f, 0.0f);
const Vec2 Vec2::ANCHOR_TOP_RIGHT = Vec2(1.0f, 1.0f); const Vec2 Vec2::ANCHOR_TOP_RIGHT(1.0f, 1.0f);
const Vec2 Vec2::ANCHOR_MIDDLE_RIGHT = Vec2(1.0f, 0.5f); const Vec2 Vec2::ANCHOR_MIDDLE_RIGHT(1.0f, 0.5f);
const Vec2 Vec2::ANCHOR_MIDDLE_LEFT = Vec2(0.0f, 0.5f); const Vec2 Vec2::ANCHOR_MIDDLE_LEFT(0.0f, 0.5f);
const Vec2 Vec2::ANCHOR_MIDDLE_TOP = Vec2(0.5f, 1.0f); const Vec2 Vec2::ANCHOR_MIDDLE_TOP(0.5f, 1.0f);
const Vec2 Vec2::ANCHOR_MIDDLE_BOTTOM = Vec2(0.5f, 0.0f); const Vec2 Vec2::ANCHOR_MIDDLE_BOTTOM(0.5f, 0.0f);
NS_CC_MATH_END NS_CC_MATH_END

View File

@ -109,14 +109,14 @@ public:
* *
* @return true if this vector contains all zeros, false otherwise. * @return true if this vector contains all zeros, false otherwise.
*/ */
bool isZero() const; inline bool isZero() const;
/** /**
* Indicates whether this vector contains all ones. * Indicates whether this vector contains all ones.
* *
* @return true if this vector contains all ones, false otherwise. * @return true if this vector contains all ones, false otherwise.
*/ */
bool isOne() const; inline bool isOne() const;
/** /**
* Returns the angle (in radians) between the specified vectors. * Returns the angle (in radians) between the specified vectors.
@ -133,7 +133,7 @@ public:
* *
* @param v The vector to add. * @param v The vector to add.
*/ */
void add(const Vec2& v); inline void add(const Vec2& v);
/** /**
* Adds the specified vectors and stores the result in dst. * Adds the specified vectors and stores the result in dst.
@ -187,7 +187,7 @@ public:
* *
* @see distance * @see distance
*/ */
float distanceSquared(const Vec2& v) const; inline float distanceSquared(const Vec2& v) const;
/** /**
* Returns the dot product of this vector and the specified vector. * Returns the dot product of this vector and the specified vector.
@ -196,7 +196,7 @@ public:
* *
* @return The dot product. * @return The dot product.
*/ */
float dot(const Vec2& v) const; inline float dot(const Vec2& v) const;
/** /**
* Returns the dot product between the specified vectors. * Returns the dot product between the specified vectors.
@ -229,12 +229,12 @@ public:
* *
* @see length * @see length
*/ */
float lengthSquared() const; inline float lengthSquared() const;
/** /**
* Negates this vector. * Negates this vector.
*/ */
void negate(); inline void negate();
/** /**
* Normalizes this vector. * Normalizes this vector.
@ -259,14 +259,14 @@ public:
* *
* @param scalar The scalar value. * @param scalar The scalar value.
*/ */
void scale(float scalar); inline void scale(float scalar);
/** /**
* Scales each element of this vector by the matching component of scale. * Scales each element of this vector by the matching component of scale.
* *
* @param scale The vector to scale by. * @param scale The vector to scale by.
*/ */
void scale(const Vec2& scale); inline void scale(const Vec2& scale);
/** /**
* Rotates this vector by angle (specified in radians) around the given point. * Rotates this vector by angle (specified in radians) around the given point.
@ -282,7 +282,7 @@ public:
* @param xx The new x coordinate. * @param xx The new x coordinate.
* @param yy The new y coordinate. * @param yy The new y coordinate.
*/ */
void set(float xx, float yy); inline void set(float xx, float yy);
/** /**
* Sets the elements of this vector from the values in the specified array. * Sets the elements of this vector from the values in the specified array.
@ -296,7 +296,7 @@ public:
* *
* @param v The vector to copy. * @param v The vector to copy.
*/ */
void set(const Vec2& v); inline void set(const Vec2& v);
/** /**
* Sets this vector to the directional vector between the specified points. * Sets this vector to the directional vector between the specified points.
@ -304,7 +304,12 @@ public:
* @param p1 The first point. * @param p1 The first point.
* @param p2 The second point. * @param p2 The second point.
*/ */
void set(const Vec2& p1, const Vec2& p2); inline void set(const Vec2& p1, const Vec2& p2);
/**
* Sets the elements of this vector to zero.
*/
inline void setZero();
/** /**
* Subtracts this vector and the specified vector as (this - v) * Subtracts this vector and the specified vector as (this - v)
@ -312,7 +317,7 @@ public:
* *
* @param v The vector to subtract. * @param v The vector to subtract.
*/ */
void subtract(const Vec2& v); inline void subtract(const Vec2& v);
/** /**
* Subtracts the specified vectors and stores the result in dst. * Subtracts the specified vectors and stores the result in dst.
@ -335,7 +340,7 @@ public:
* @param elapsedTime elapsed time between calls. * @param elapsedTime elapsed time between calls.
* @param responseTime response time (in the same units as elapsedTime). * @param responseTime response time (in the same units as elapsedTime).
*/ */
void smooth(const Vec2& target, float elapsedTime, float responseTime); inline void smooth(const Vec2& target, float elapsedTime, float responseTime);
/** /**
* Calculates the sum of this vector with the given vector. * Calculates the sum of this vector with the given vector.
@ -452,7 +457,7 @@ public:
* @js NA * @js NA
* @lua NA * @lua NA
*/ */
void setPoint(float xx, float yy); inline void setPoint(float xx, float yy);
/** /**
* @js NA * @js NA
*/ */

View File

@ -22,6 +22,123 @@
NS_CC_MATH_BEGIN NS_CC_MATH_BEGIN
inline Vec2::Vec2()
: x(0.0f), y(0.0f)
{
}
inline Vec2::Vec2(float xx, float yy)
: x(xx), y(yy)
{
}
inline Vec2::Vec2(const float* array)
{
set(array);
}
inline Vec2::Vec2(const Vec2& p1, const Vec2& p2)
{
set(p1, p2);
}
inline Vec2::Vec2(const Vec2& copy)
{
set(copy);
}
inline Vec2::~Vec2()
{
}
inline bool Vec2::isZero() const
{
return x == 0.0f && y == 0.0f;
}
bool Vec2::isOne() const
{
return x == 1.0f && y == 1.0f;
}
inline void Vec2::add(const Vec2& v)
{
x += v.x;
y += v.y;
}
inline float Vec2::distanceSquared(const Vec2& v) const
{
float dx = v.x - x;
float dy = v.y - y;
return (dx * dx + dy * dy);
}
inline float Vec2::dot(const Vec2& v) const
{
return (x * v.x + y * v.y);
}
inline float Vec2::lengthSquared() const
{
return (x * x + y * y);
}
inline void Vec2::negate()
{
x = -x;
y = -y;
}
inline void Vec2::scale(float scalar)
{
x *= scalar;
y *= scalar;
}
inline void Vec2::scale(const Vec2& scale)
{
x *= scale.x;
y *= scale.y;
}
inline void Vec2::set(float xx, float yy)
{
this->x = xx;
this->y = yy;
}
inline void Vec2::set(const Vec2& v)
{
this->x = v.x;
this->y = v.y;
}
inline void Vec2::set(const Vec2& p1, const Vec2& p2)
{
x = p2.x - p1.x;
y = p2.y - p1.y;
}
void Vec2::setZero()
{
x = y = 0.0f;
}
inline void Vec2::subtract(const Vec2& v)
{
x -= v.x;
y -= v.y;
}
inline void Vec2::smooth(const Vec2& target, float elapsedTime, float responseTime)
{
if (elapsedTime > 0)
{
*this += (target - *this) * (elapsedTime / (elapsedTime + responseTime));
}
}
inline const Vec2 Vec2::operator+(const Vec2& v) const inline const Vec2 Vec2::operator+(const Vec2& v) const
{ {
Vec2 result(*this); Vec2 result(*this);
@ -108,4 +225,10 @@ inline const Vec2 operator*(float x, const Vec2& v)
return result; return result;
} }
void Vec2::setPoint(float xx, float yy)
{
this->x = xx;
this->y = yy;
}
NS_CC_MATH_END NS_CC_MATH_END

View File

@ -69,7 +69,6 @@ PhysicsBody::PhysicsBody()
, _angularDamping(0.0f) , _angularDamping(0.0f)
, _tag(0) , _tag(0)
, _positionInitDirty(true) , _positionInitDirty(true)
, _recordedPosition(Vec2::ZERO)
, _rotationOffset(0) , _rotationOffset(0)
, _recordedRotation(0.0f) , _recordedRotation(0.0f)
, _recordedAngle(0.0) , _recordedAngle(0.0)

View File

@ -880,12 +880,45 @@ bool Image::decodeWithWIC(const unsigned char *data, ssize_t dataLen)
bool Image::encodeWithWIC(const std::string& filePath, bool isToRGB, GUID containerFormat) bool Image::encodeWithWIC(const std::string& filePath, bool isToRGB, GUID containerFormat)
{ {
WICPixelFormatGUID format = isToRGB ? GUID_WICPixelFormat24bppRGB : GUID_WICPixelFormat32bppRGBA; // Save formats supported by WIC
WICPixelFormatGUID targetFormat = isToRGB ? GUID_WICPixelFormat24bppBGR : GUID_WICPixelFormat32bppBGRA;
unsigned char *pSaveData = nullptr;
int saveLen = _dataLen;
int bpp = 4;
WICImageLoader img; if (targetFormat == GUID_WICPixelFormat24bppBGR && _renderFormat == Texture2D::PixelFormat::RGBA8888)
return img.encodeImageData(filePath, _data, _dataLen, format, _width, _height, containerFormat); {
bpp = 3;
saveLen = _width * _height * bpp;
pSaveData = new unsigned char[saveLen];
int indL = 0, indR = 0;
while (indL < saveLen && indR < _dataLen)
{
memcpy(&pSaveData[indL], &_data[indR], 3);
indL += 3;
indR += 4;
}
}
else
{
pSaveData = new unsigned char[saveLen];
memcpy(pSaveData, _data, saveLen);
}
for (int ind = 2; ind < saveLen; ind += bpp) {
std::swap(pSaveData[ind - 2], pSaveData[ind]);
}
bool bRet = false;
WICImageLoader img;
bRet = img.encodeImageData(filePath, pSaveData, saveLen, targetFormat, _width, _height, containerFormat);
delete[] pSaveData;
return bRet;
} }
#endif //CC_USE_WIC #endif //CC_USE_WIC
bool Image::initWithJpgData(const unsigned char * data, ssize_t dataLen) bool Image::initWithJpgData(const unsigned char * data, ssize_t dataLen)

View File

@ -36,6 +36,10 @@ using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media; using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation; using namespace Windows::UI::Xaml::Navigation;
#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
using namespace Windows::Phone::UI::Input;
#endif
OpenGLESPage::OpenGLESPage() : OpenGLESPage::OpenGLESPage() :
OpenGLESPage(nullptr) OpenGLESPage(nullptr)
{ {
@ -76,6 +80,7 @@ OpenGLESPage::OpenGLESPage(OpenGLES* openGLES) :
#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) #if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
Windows::UI::ViewManagement::StatusBar::GetForCurrentView()->HideAsync(); Windows::UI::ViewManagement::StatusBar::GetForCurrentView()->HideAsync();
HardwareButtons::BackPressed += ref new EventHandler<BackPressedEventArgs^>(this, &OpenGLESPage::OnBackButtonPressed);
#else #else
// Disable all pointer visual feedback for better performance when touching. // Disable all pointer visual feedback for better performance when touching.
// This is not supported on Windows Phone applications. // This is not supported on Windows Phone applications.
@ -163,6 +168,21 @@ void OpenGLESPage::OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Wi
} }
} }
#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
void OpenGLESPage::OnBackButtonPressed(Object^ sender, BackPressedEventArgs^ args)
{
bool myAppCanNavigate = false;
if (myAppCanNavigate)
{
args->Handled = true;
}
else {
// Do nothing. Leave args->Handled set to the current value, false.
}
}
#endif
void OpenGLESPage::OnSwapChainPanelSizeChanged(Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e) void OpenGLESPage::OnSwapChainPanelSizeChanged(Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e)
{ {
// Size change events occur outside of the render thread. A lock is required when updating // Size change events occur outside of the render thread. A lock is required when updating
@ -283,6 +303,11 @@ void OpenGLESPage::StartRenderLoop()
{ {
m_deviceLost = true; m_deviceLost = true;
if (m_renderer)
{
m_renderer->Pause();
}
// XAML objects like the SwapChainPanel must only be manipulated on the UI thread. // XAML objects like the SwapChainPanel must only be manipulated on the UI thread.
swapChainPanel->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::High, ref new Windows::UI::Core::DispatchedHandler([=]() swapChainPanel->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::High, ref new Windows::UI::Core::DispatchedHandler([=]()
{ {
@ -292,6 +317,11 @@ void OpenGLESPage::StartRenderLoop()
return; return;
} }
} }
if (m_renderer)
{
m_renderer->Pause();
}
}); });
// Run task on a dedicated high priority background thread. // Run task on a dedicated high priority background thread.
@ -305,9 +335,4 @@ void OpenGLESPage::StopRenderLoop()
mRenderLoopWorker->Cancel(); mRenderLoopWorker->Cancel();
mRenderLoopWorker = nullptr; mRenderLoopWorker = nullptr;
} }
if (m_renderer)
{
m_renderer->Pause();
}
} }

View File

@ -39,6 +39,9 @@ namespace cocos2d
void OnPageLoaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void OnPageLoaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args); void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args);
void OnSwapChainPanelSizeChanged(Platform::Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e); void OnSwapChainPanelSizeChanged(Platform::Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e);
#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
void OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args);
#endif
void GetSwapChainPanelSize(GLsizei* width, GLsizei* height); void GetSwapChainPanelSize(GLsizei* width, GLsizei* height);
void CreateRenderSurface(); void CreateRenderSurface();
void DestroyRenderSurface(); void DestroyRenderSurface();

View File

@ -325,23 +325,21 @@ WICPixelFormatGUID WICImageLoader::getPixelFormat()
return _format; return _format;
} }
bool WICImageLoader::encodeImageData(std::string path, ImageBlob data, size_t dataLen, WICPixelFormatGUID pixelFormat, int width, int height, GUID containerFormat) bool WICImageLoader::encodeImageData(std::string path, const unsigned char* data, size_t dataLen, WICPixelFormatGUID pixelFormat, int width, int height, GUID containerFormat)
{ {
assert(data != NULL); assert(data != NULL);
assert(dataLen > 0 && width > 0 && height > 0); assert(dataLen > 0 && width > 0 && height > 0);
IWICImagingFactory* pFact = getWICFactory(); IWICImagingFactory* pFact = getWICFactory();
HRESULT hr = S_FALSE; HRESULT hr = E_FAIL;
IWICStream* pStream = NULL; IWICStream* pStream = NULL;
if(NULL != pFact) if (NULL != pFact) {
{
hr = pFact->CreateStream(&pStream); hr = pFact->CreateStream(&pStream);
} }
if(SUCCEEDED(hr)) if (SUCCEEDED(hr)) {
{
std::wstring wpath; std::wstring wpath;
wpath.assign(path.begin(), path.end()); wpath.assign(path.begin(), path.end());
hr = pStream->InitializeFromFilename(wpath.c_str(), GENERIC_WRITE); hr = pStream->InitializeFromFilename(wpath.c_str(), GENERIC_WRITE);
@ -349,54 +347,50 @@ bool WICImageLoader::encodeImageData(std::string path, ImageBlob data, size_t da
IWICBitmapEncoder* pEnc = NULL; IWICBitmapEncoder* pEnc = NULL;
if(SUCCEEDED(hr)) if (SUCCEEDED(hr)) {
{
hr = pFact->CreateEncoder(containerFormat, NULL, &pEnc); hr = pFact->CreateEncoder(containerFormat, NULL, &pEnc);
} }
if(SUCCEEDED(hr)) if (SUCCEEDED(hr)) {
{
hr = pEnc->Initialize(pStream, WICBitmapEncoderNoCache); hr = pEnc->Initialize(pStream, WICBitmapEncoderNoCache);
} }
IWICBitmapFrameEncode* pFrame = NULL; IWICBitmapFrameEncode* pFrame = NULL;
IPropertyBag2* pProp = NULL; IPropertyBag2* pProp = NULL;
if(SUCCEEDED(hr)) if (SUCCEEDED(hr)) {
{
hr = pEnc->CreateNewFrame(&pFrame, &pProp); hr = pEnc->CreateNewFrame(&pFrame, &pProp);
} }
if(SUCCEEDED(hr)) if (SUCCEEDED(hr)) {
{
hr = pFrame->Initialize(pProp); hr = pFrame->Initialize(pProp);
} }
if(SUCCEEDED(hr)) if (SUCCEEDED(hr)) {
{
hr = pFrame->SetSize(width, height); hr = pFrame->SetSize(width, height);
} }
if(SUCCEEDED(hr)) if (SUCCEEDED(hr)) {
{ WICPixelFormatGUID targetFormat = pixelFormat;
hr = pFrame->SetPixelFormat(&pixelFormat); hr = pFrame->SetPixelFormat(&targetFormat);
if (targetFormat != pixelFormat) {
hr = E_INVALIDARG;
}
} }
if(SUCCEEDED(hr)) if (SUCCEEDED(hr)) {
{
size_t bpp = getBitsPerPixel(pixelFormat); size_t bpp = getBitsPerPixel(pixelFormat);
size_t stride = (width * bpp + 7) / 8; size_t stride = (width * bpp + 7) / 8;
hr = pFrame->WritePixels(height, stride, dataLen, (BYTE*)data); hr = pFrame->WritePixels(height, stride, dataLen, (BYTE*)data);
} }
if(SUCCEEDED(hr)) if (SUCCEEDED(hr)) {
{
hr = pFrame->Commit(); hr = pFrame->Commit();
} }
if(SUCCEEDED(hr)) if (SUCCEEDED(hr)) {
{
hr = pEnc->Commit(); hr = pEnc->Commit();
} }

View File

@ -59,7 +59,7 @@ public:
WICPixelFormatGUID getPixelFormat(); WICPixelFormatGUID getPixelFormat();
int getImageData(ImageBlob rawData, size_t dataLen); int getImageData(ImageBlob rawData, size_t dataLen);
bool decodeImageData(ImageBlob data, size_t dataLen); bool decodeImageData(ImageBlob data, size_t dataLen);
bool encodeImageData(std::string path, ImageBlob data, size_t dataLen, WICPixelFormatGUID pixelFormat, int width, int height, GUID containerFormat); bool encodeImageData(std::string path, const unsigned char* data, size_t dataLen, WICPixelFormatGUID pixelFormat, int width, int height, GUID containerFormat);
protected: protected:
bool processImage(IWICBitmapDecoder* decoder); bool processImage(IWICBitmapDecoder* decoder);

View File

@ -502,11 +502,11 @@ void Layout::setStencilClippingSize(const Size &size)
if (_clippingEnabled && _clippingType == ClippingType::STENCIL) if (_clippingEnabled && _clippingType == ClippingType::STENCIL)
{ {
Vec2 rect[4]; Vec2 rect[4];
rect[0] = Vec2::ZERO; // rect[0].setZero(); Zero default
rect[1] = Vec2(_contentSize.width, 0); rect[1].set(_contentSize.width, 0.0f);
rect[2] = Vec2(_contentSize.width, _contentSize.height); rect[2].set(_contentSize.width, _contentSize.height);
rect[3] = Vec2(0, _contentSize.height); rect[3].set(0.0f, _contentSize.height);
Color4F green(0, 1, 0, 1); Color4F green(0.0f, 1.0f, 0.0f, 1.0f);
_clippingStencil->clear(); _clippingStencil->clear();
_clippingStencil->drawPolygon(rect, 4, green, 0, green); _clippingStencil->drawPolygon(rect, 4, green, 0, green);
} }

View File

@ -30,17 +30,16 @@ namespace ui {
static const float AUTOSCROLLMAXSPEED = 1000.0f; static const float AUTOSCROLLMAXSPEED = 1000.0f;
const Vec2 SCROLLDIR_UP = Vec2(0.0f, 1.0f); const Vec2 SCROLLDIR_UP(0.0f, 1.0f);
const Vec2 SCROLLDIR_DOWN = Vec2(0.0f, -1.0f); const Vec2 SCROLLDIR_DOWN(0.0f, -1.0f);
const Vec2 SCROLLDIR_LEFT = Vec2(-1.0f, 0.0f); const Vec2 SCROLLDIR_LEFT(-1.0f, 0.0f);
const Vec2 SCROLLDIR_RIGHT = Vec2(1.0f, 0.0f); const Vec2 SCROLLDIR_RIGHT(1.0f, 0.0f);
IMPLEMENT_CLASS_GUI_INFO(ScrollView) IMPLEMENT_CLASS_GUI_INFO(ScrollView)
ScrollView::ScrollView(): ScrollView::ScrollView():
_innerContainer(nullptr), _innerContainer(nullptr),
_direction(Direction::VERTICAL), _direction(Direction::VERTICAL),
_autoScrollDir(Vec2::ZERO),
_topBoundary(0.0f), _topBoundary(0.0f),
_bottomBoundary(0.0f), _bottomBoundary(0.0f),
_leftBoundary(0.0f), _leftBoundary(0.0f),
@ -55,10 +54,8 @@ _autoScrollOriginalSpeed(0.0f),
_autoScrollAcceleration(-1000.0f), _autoScrollAcceleration(-1000.0f),
_isAutoScrollSpeedAttenuated(false), _isAutoScrollSpeedAttenuated(false),
_needCheckAutoScrollDestination(false), _needCheckAutoScrollDestination(false),
_autoScrollDestination(Vec2::ZERO),
_bePressed(false), _bePressed(false),
_slidTime(0.0f), _slidTime(0.0f),
_moveChildPoint(Vec2::ZERO),
_childFocusCancelOffset(5.0f), _childFocusCancelOffset(5.0f),
_leftBounceNeeded(false), _leftBounceNeeded(false),
_topBounceNeeded(false), _topBounceNeeded(false),
@ -66,7 +63,6 @@ _rightBounceNeeded(false),
_bottomBounceNeeded(false), _bottomBounceNeeded(false),
_bounceEnabled(false), _bounceEnabled(false),
_bouncing(false), _bouncing(false),
_bounceDir(Vec2::ZERO),
_bounceOriginalSpeed(0.0f), _bounceOriginalSpeed(0.0f),
_inertiaScrollEnabled(true), _inertiaScrollEnabled(true),
_scrollViewEventListener(nullptr), _scrollViewEventListener(nullptr),

View File

@ -154,13 +154,8 @@ _sizeType(SizeType::ABSOLUTE),
_positionType(PositionType::ABSOLUTE), _positionType(PositionType::ABSOLUTE),
_actionTag(0), _actionTag(0),
_customSize(Size::ZERO), _customSize(Size::ZERO),
_sizePercent(Vec2::ZERO),
_positionPercent(Vec2::ZERO),
_hitted(false), _hitted(false),
_touchListener(nullptr), _touchListener(nullptr),
_touchBeganPosition(Vec2::ZERO),
_touchMovePosition(Vec2::ZERO),
_touchEndPosition(Vec2::ZERO),
_flippedX(false), _flippedX(false),
_flippedY(false), _flippedY(false),
_layoutParameterType(LayoutParameter::Type::NONE), _layoutParameterType(LayoutParameter::Type::NONE),
@ -309,7 +304,7 @@ void Widget::setContentSize(const cocos2d::Size &contentSize)
{ {
spy = _customSize.height / pSize.height; spy = _customSize.height / pSize.height;
} }
_sizePercent = Vec2(spx, spy); _sizePercent.set(spx, spy);
} }
onSizeChanged(); onSizeChanged();
} }
@ -387,7 +382,7 @@ void Widget::updateSizeAndPosition(const cocos2d::Size &parentSize)
{ {
spy = _customSize.height / parentSize.height; spy = _customSize.height / parentSize.height;
} }
_sizePercent = Vec2(spx, spy); _sizePercent.set(spx, spy);
break; break;
} }
case SizeType::PERCENT: case SizeType::PERCENT:
@ -416,17 +411,17 @@ void Widget::updateSizeAndPosition(const cocos2d::Size &parentSize)
{ {
if (parentSize.width <= 0.0f || parentSize.height <= 0.0f) if (parentSize.width <= 0.0f || parentSize.height <= 0.0f)
{ {
_positionPercent = Vec2::ZERO; _positionPercent.setZero();
} }
else else
{ {
_positionPercent = Vec2(absPos.x / parentSize.width, absPos.y / parentSize.height); _positionPercent.set(absPos.x / parentSize.width, absPos.y / parentSize.height);
} }
break; break;
} }
case PositionType::PERCENT: case PositionType::PERCENT:
{ {
absPos = Vec2(parentSize.width * _positionPercent.x, parentSize.height * _positionPercent.y); absPos.set(parentSize.width * _positionPercent.x, parentSize.height * _positionPercent.y);
break; break;
} }
default: default:
@ -994,11 +989,11 @@ void Widget::setPosition(const Vec2 &pos)
Size pSize = widgetParent->getContentSize(); Size pSize = widgetParent->getContentSize();
if (pSize.width <= 0.0f || pSize.height <= 0.0f) if (pSize.width <= 0.0f || pSize.height <= 0.0f)
{ {
_positionPercent = Vec2::ZERO; _positionPercent.setZero();
} }
else else
{ {
_positionPercent = Vec2(pos.x / pSize.width, pos.y / pSize.height); _positionPercent.set(pos.x / pSize.width, pos.y / pSize.height);
} }
} }
} }
@ -1023,7 +1018,7 @@ void Widget::setPositionPercent(const Vec2 &percent)
if (widgetParent) if (widgetParent)
{ {
Size parentSize = widgetParent->getContentSize(); Size parentSize = widgetParent->getContentSize();
Vec2 absPos = Vec2(parentSize.width * _positionPercent.x, parentSize.height * _positionPercent.y); Vec2 absPos(parentSize.width * _positionPercent.x, parentSize.height * _positionPercent.y);
setPosition(absPos); setPosition(absPos);
} }
} }
@ -1038,7 +1033,7 @@ const Vec2& Widget::getPositionPercent(){
float percentX = component->getPositionPercentX(); float percentX = component->getPositionPercentX();
float percentY = component->getPositionPercentY(); float percentY = component->getPositionPercentY();
_positionPercent = Vec2(percentX, percentY); _positionPercent.set(percentX, percentY);
} }
return _positionPercent; return _positionPercent;
} }

View File

@ -108,7 +108,7 @@ void ControlSaturationBrightnessPicker::updateWithHSV(HSV hsv)
void ControlSaturationBrightnessPicker::updateDraggerWithHSV(HSV hsv) void ControlSaturationBrightnessPicker::updateDraggerWithHSV(HSV hsv)
{ {
// Set the position of the slider to the correct saturation and brightness // Set the position of the slider to the correct saturation and brightness
Vec2 pos = Vec2(_startPos.x + boxPos + (boxSize*(1 - hsv.s)), Vec2 pos(_startPos.x + boxPos + (boxSize*(1 - hsv.s)),
_startPos.y + boxPos + (boxSize*hsv.v)); _startPos.y + boxPos + (boxSize*hsv.v));
// update // update

View File

@ -254,7 +254,7 @@ void ScrollView::setZoomScale(float s)
if (_touchLength == 0.0f) if (_touchLength == 0.0f)
{ {
center = Vec2(_viewSize.width*0.5f, _viewSize.height*0.5f); center.set(_viewSize.width*0.5f, _viewSize.height*0.5f);
center = this->convertToWorldSpace(center); center = this->convertToWorldSpace(center);
} }
else else
@ -481,10 +481,10 @@ void ScrollView::updateInset()
if (this->getContainer() != nullptr) if (this->getContainer() != nullptr)
{ {
_maxInset = this->maxContainerOffset(); _maxInset = this->maxContainerOffset();
_maxInset = Vec2(_maxInset.x + _viewSize.width * INSET_RATIO, _maxInset.set(_maxInset.x + _viewSize.width * INSET_RATIO,
_maxInset.y + _viewSize.height * INSET_RATIO); _maxInset.y + _viewSize.height * INSET_RATIO);
_minInset = this->minContainerOffset(); _minInset = this->minContainerOffset();
_minInset = Vec2(_minInset.x - _viewSize.width * INSET_RATIO, _minInset.set(_minInset.x - _viewSize.width * INSET_RATIO,
_minInset.y - _viewSize.height * INSET_RATIO); _minInset.y - _viewSize.height * INSET_RATIO);
} }
} }
@ -664,7 +664,7 @@ bool ScrollView::onTouchBegan(Touch* touch, Event* event)
_touchPoint = this->convertTouchToNodeSpace(touch); _touchPoint = this->convertTouchToNodeSpace(touch);
_touchMoved = false; _touchMoved = false;
_dragging = true; //dragging started _dragging = true; //dragging started
_scrollDistance = Vec2(0.0f, 0.0f); _scrollDistance.setZero();
_touchLength = 0.0f; _touchLength = 0.0f;
} }
else if (_touches.size() == 2) else if (_touches.size() == 2)
@ -740,7 +740,7 @@ void ScrollView::onTouchMoved(Touch* touch, Event* event)
if (!_touchMoved) if (!_touchMoved)
{ {
moveDistance = Vec2::ZERO; moveDistance.setZero();
} }
_touchPoint = newPoint; _touchPoint = newPoint;
@ -751,10 +751,10 @@ void ScrollView::onTouchMoved(Touch* touch, Event* event)
switch (_direction) switch (_direction)
{ {
case Direction::VERTICAL: case Direction::VERTICAL:
moveDistance = Vec2(0.0f, moveDistance.y); moveDistance.set(0.0f, moveDistance.y);
break; break;
case Direction::HORIZONTAL: case Direction::HORIZONTAL:
moveDistance = Vec2(moveDistance.x, 0.0f); moveDistance.set(moveDistance.x, 0.0f);
break; break;
default: default:
break; break;

View File

@ -320,10 +320,10 @@ Vec2 TableView::__offsetFromIndex(ssize_t index)
switch (this->getDirection()) switch (this->getDirection())
{ {
case Direction::HORIZONTAL: case Direction::HORIZONTAL:
offset = Vec2(_vCellsPositions[index], 0.0f); offset.set(_vCellsPositions[index], 0.0f);
break; break;
default: default:
offset = Vec2(0.0f, _vCellsPositions[index]); offset.set(0.0f, _vCellsPositions[index]);
break; break;
} }

View File

@ -124,19 +124,19 @@ void Particle3DQuadRender::render(Renderer* renderer, const Mat4 &transform, Par
position = particle->position; position = particle->position;
_posuvcolors[vertexindex].position = (position + (- halfwidth - halfheight)); _posuvcolors[vertexindex].position = (position + (- halfwidth - halfheight));
_posuvcolors[vertexindex].color = particle->color; _posuvcolors[vertexindex].color = particle->color;
_posuvcolors[vertexindex].uv = Vec2(particle->lb_uv); _posuvcolors[vertexindex].uv.set(particle->lb_uv);
_posuvcolors[vertexindex + 1].position = (position + (halfwidth - halfheight)); _posuvcolors[vertexindex + 1].position = (position + (halfwidth - halfheight));
_posuvcolors[vertexindex + 1].color = particle->color; _posuvcolors[vertexindex + 1].color = particle->color;
_posuvcolors[vertexindex + 1].uv = Vec2(particle->rt_uv.x, particle->lb_uv.y); _posuvcolors[vertexindex + 1].uv.set(particle->rt_uv.x, particle->lb_uv.y);
_posuvcolors[vertexindex + 2].position = (position + (- halfwidth + halfheight)); _posuvcolors[vertexindex + 2].position = (position + (- halfwidth + halfheight));
_posuvcolors[vertexindex + 2].color = particle->color; _posuvcolors[vertexindex + 2].color = particle->color;
_posuvcolors[vertexindex + 2].uv = Vec2(particle->lb_uv.x, particle->rt_uv.y); _posuvcolors[vertexindex + 2].uv.set(particle->lb_uv.x, particle->rt_uv.y);
_posuvcolors[vertexindex + 3].position = (position + (halfwidth + halfheight)); _posuvcolors[vertexindex + 3].position = (position + (halfwidth + halfheight));
_posuvcolors[vertexindex + 3].color = particle->color; _posuvcolors[vertexindex + 3].color = particle->color;
_posuvcolors[vertexindex + 3].uv = Vec2(particle->rt_uv); _posuvcolors[vertexindex + 3].uv.set(particle->rt_uv);
_indexData[index] = vertexindex; _indexData[index] = vertexindex;

View File

@ -32,7 +32,6 @@ NS_CC_BEGIN
Particle3D::Particle3D() Particle3D::Particle3D()
: position(Vec3::ZERO) : position(Vec3::ZERO)
, color(Vec4::ONE) , color(Vec4::ONE)
, lb_uv(Vec2::ZERO)
, rt_uv(Vec2::ONE) , rt_uv(Vec2::ONE)
, width(1.0f) , width(1.0f)
, height(1.0f) , height(1.0f)

View File

@ -174,20 +174,20 @@ void PUParticle3DQuadRender::render(Renderer* renderer, const Mat4 &transform, P
float sintheta = sinf(-particle->zRotation); float sintheta = sinf(-particle->zRotation);
Vec2 texOffset = particle->lb_uv + 0.5f * (particle->rt_uv - particle->lb_uv); Vec2 texOffset = particle->lb_uv + 0.5f * (particle->rt_uv - particle->lb_uv);
Vec2 val; Vec2 val;
val = Vec2((particle->lb_uv.x - texOffset.x), (particle->lb_uv.y - texOffset.y)); val.set((particle->lb_uv.x - texOffset.x), (particle->lb_uv.y - texOffset.y));
val = Vec2(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta); val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta);
fillVertex(vertexindex, (position + (- halfwidth - halfheight + halfwidth * offsetX + halfheight * offsetY)), particle->color, Vec2(val.x + texOffset.x, val.y + texOffset.y)); fillVertex(vertexindex, (position + (- halfwidth - halfheight + halfwidth * offsetX + halfheight * offsetY)), particle->color, Vec2(val.x + texOffset.x, val.y + texOffset.y));
val = Vec2(particle->rt_uv.x - texOffset.x, particle->lb_uv.y - texOffset.y); val.set(particle->rt_uv.x - texOffset.x, particle->lb_uv.y - texOffset.y);
val = Vec2(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta); val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta);
fillVertex(vertexindex + 1, (position + (halfwidth - halfheight + halfwidth * offsetX + halfheight * offsetY)), particle->color, Vec2(val.x + texOffset.x, val.y + texOffset.y)); fillVertex(vertexindex + 1, (position + (halfwidth - halfheight + halfwidth * offsetX + halfheight * offsetY)), particle->color, Vec2(val.x + texOffset.x, val.y + texOffset.y));
val = Vec2(particle->lb_uv.x - texOffset.x, particle->rt_uv.y - texOffset.y); val.set(particle->lb_uv.x - texOffset.x, particle->rt_uv.y - texOffset.y);
val = Vec2(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta); val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta);
fillVertex(vertexindex + 2, (position + (- halfwidth + halfheight + halfwidth * offsetX + halfheight * offsetY)), particle->color, Vec2(val.x + texOffset.x, val.y + texOffset.y)); fillVertex(vertexindex + 2, (position + (- halfwidth + halfheight + halfwidth * offsetX + halfheight * offsetY)), particle->color, Vec2(val.x + texOffset.x, val.y + texOffset.y));
val = Vec2(particle->rt_uv.x - texOffset.x, particle->rt_uv.y - texOffset.y); val.set(particle->rt_uv.x - texOffset.x, particle->rt_uv.y - texOffset.y);
val = Vec2(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta); val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta);
fillVertex(vertexindex + 3, (position + (halfwidth + halfheight + halfwidth * offsetX + halfheight * offsetY)), particle->color, Vec2(val.x + texOffset.x, val.y + texOffset.y)); fillVertex(vertexindex + 3, (position + (halfwidth + halfheight + halfwidth * offsetX + halfheight * offsetY)), particle->color, Vec2(val.x + texOffset.x, val.y + texOffset.y));
}else{ }else{
Mat4::createRotation(backward, -particle->zRotation, &pRotMat); Mat4::createRotation(backward, -particle->zRotation, &pRotMat);
@ -202,25 +202,25 @@ void PUParticle3DQuadRender::render(Renderer* renderer, const Mat4 &transform, P
//_posuvcolors[vertexindex].position = (position + (- halfwidth - halfheight + halfwidth * offsetX + halfheight * offsetY)); //_posuvcolors[vertexindex].position = (position + (- halfwidth - halfheight + halfwidth * offsetX + halfheight * offsetY));
//_posuvcolors[vertexindex].color = particle->color; //_posuvcolors[vertexindex].color = particle->color;
//_posuvcolors[vertexindex].uv = Vec2(val.x + texOffset.x, val.y + texOffset.y); //_posuvcolors[vertexindex].uv.set(val.x + texOffset.x, val.y + texOffset.y);
//val = Vec2(particle->rt_uv.x - texOffset.x, particle->lb_uv.y - texOffset.y); //val.set(particle->rt_uv.x - texOffset.x, particle->lb_uv.y - texOffset.y);
//val = Vec2(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta); //val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta);
//_posuvcolors[vertexindex + 1].position = (position + (halfwidth - halfheight + halfwidth * offsetX + halfheight * offsetY)); //_posuvcolors[vertexindex + 1].position = (position + (halfwidth - halfheight + halfwidth * offsetX + halfheight * offsetY));
//_posuvcolors[vertexindex + 1].color = particle->color; //_posuvcolors[vertexindex + 1].color = particle->color;
//_posuvcolors[vertexindex + 1].uv = Vec2(val.x + texOffset.x, val.y + texOffset.y); //_posuvcolors[vertexindex + 1].uv.set(val.x + texOffset.x, val.y + texOffset.y);
// //
//val = Vec2(particle->lb_uv.x - texOffset.x, particle->rt_uv.y - texOffset.y); //val.set(particle->lb_uv.x - texOffset.x, particle->rt_uv.y - texOffset.y);
//val = Vec2(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta); //val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta);
//_posuvcolors[vertexindex + 2].position = (position + (- halfwidth + halfheight + halfwidth * offsetX + halfheight * offsetY)); //_posuvcolors[vertexindex + 2].position = (position + (- halfwidth + halfheight + halfwidth * offsetX + halfheight * offsetY));
//_posuvcolors[vertexindex + 2].color = particle->color; //_posuvcolors[vertexindex + 2].color = particle->color;
//_posuvcolors[vertexindex + 2].uv = Vec2(val.x + texOffset.x, val.y + texOffset.y); //_posuvcolors[vertexindex + 2].uv.set(val.x + texOffset.x, val.y + texOffset.y);
// //
//val = Vec2(particle->rt_uv.x - texOffset.x, particle->rt_uv.y - texOffset.y); //val.set(particle->rt_uv.x - texOffset.x, particle->rt_uv.y - texOffset.y);
//val = Vec2(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta); //val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta);
//_posuvcolors[vertexindex + 3].position = (position + (halfwidth + halfheight + halfwidth * offsetX + halfheight * offsetY)); //_posuvcolors[vertexindex + 3].position = (position + (halfwidth + halfheight + halfwidth * offsetX + halfheight * offsetY));
//_posuvcolors[vertexindex + 3].color = particle->color; //_posuvcolors[vertexindex + 3].color = particle->color;
//_posuvcolors[vertexindex + 3].uv = Vec2(val.x + texOffset.x, val.y + texOffset.y); //_posuvcolors[vertexindex + 3].uv.set(val.x + texOffset.x, val.y + texOffset.y);
// //
// //
//_indexData[index] = vertexindex; //_indexData[index] = vertexindex;
@ -372,7 +372,7 @@ void PUParticle3DQuadRender::determineUVCoords( PUParticle3D *particle )
unsigned short currentCol = particle->textureCoordsCurrent - _textureCoordsColumns * currentRow; unsigned short currentCol = particle->textureCoordsCurrent - _textureCoordsColumns * currentRow;
currentRow = _textureCoordsRows - currentRow - 1; currentRow = _textureCoordsRows - currentRow - 1;
particle->lb_uv = Vec2(_textureCoordsColStep * currentCol, _textureCoordsRowStep * currentRow); particle->lb_uv.set(_textureCoordsColStep * currentCol, _textureCoordsRowStep * currentRow);
particle->rt_uv = particle->lb_uv + Vec2(_textureCoordsColStep, _textureCoordsRowStep); particle->rt_uv = particle->lb_uv + Vec2(_textureCoordsColStep, _textureCoordsRowStep);
} }

View File

@ -265,14 +265,14 @@ const Vec2& PhysicsSprite::getPosFromPhysics() const
#if CC_ENABLE_CHIPMUNK_INTEGRATION #if CC_ENABLE_CHIPMUNK_INTEGRATION
cpVect cpPos = cpBodyGetPos(_CPBody); cpVect cpPos = cpBodyGetPos(_CPBody);
s_physicPosion = Vec2(cpPos.x, cpPos.y); s_physicPosion.set(cpPos.x, cpPos.y);
#elif CC_ENABLE_BOX2D_INTEGRATION #elif CC_ENABLE_BOX2D_INTEGRATION
b2Vec2 pos = _pB2Body->GetPosition(); b2Vec2 pos = _pB2Body->GetPosition();
float x = pos.x * _PTMRatio; float x = pos.x * _PTMRatio;
float y = pos.y * _PTMRatio; float y = pos.y * _PTMRatio;
s_physicPosion = Vec2(x,y); s_physicPosion.set(x,y);
#endif #endif
return s_physicPosion; return s_physicPosion;
} }
@ -376,7 +376,7 @@ void PhysicsSprite::syncPhysicsTransform() const
float c = cosf(radians); float c = cosf(radians);
float s = sinf(radians); float s = sinf(radians);
if (!_anchorPointInPoints.equals(Vec2::ZERO)) if (!_anchorPointInPoints.isZero())
{ {
x += ((c * -_anchorPointInPoints.x * _scaleX) + (-s * -_anchorPointInPoints.y * _scaleY)); x += ((c * -_anchorPointInPoints.x * _scaleX) + (-s * -_anchorPointInPoints.y * _scaleY));
y += ((s * -_anchorPointInPoints.x * _scaleX) + (c * -_anchorPointInPoints.y * _scaleY)); y += ((s * -_anchorPointInPoints.x * _scaleX) + (c * -_anchorPointInPoints.y * _scaleY));

View File

@ -36,6 +36,10 @@ using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media; using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation; using namespace Windows::UI::Xaml::Navigation;
#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
using namespace Windows::Phone::UI::Input;
#endif
OpenGLESPage::OpenGLESPage() : OpenGLESPage::OpenGLESPage() :
OpenGLESPage(nullptr) OpenGLESPage(nullptr)
{ {
@ -76,6 +80,7 @@ OpenGLESPage::OpenGLESPage(OpenGLES* openGLES) :
#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) #if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
Windows::UI::ViewManagement::StatusBar::GetForCurrentView()->HideAsync(); Windows::UI::ViewManagement::StatusBar::GetForCurrentView()->HideAsync();
HardwareButtons::BackPressed += ref new EventHandler<BackPressedEventArgs^>(this, &OpenGLESPage::OnBackButtonPressed);
#else #else
// Disable all pointer visual feedback for better performance when touching. // Disable all pointer visual feedback for better performance when touching.
// This is not supported on Windows Phone applications. // This is not supported on Windows Phone applications.
@ -163,6 +168,21 @@ void OpenGLESPage::OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Wi
} }
} }
#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
void OpenGLESPage::OnBackButtonPressed(Object^ sender, BackPressedEventArgs^ args)
{
bool myAppCanNavigate = false;
if (myAppCanNavigate)
{
args->Handled = true;
}
else {
// Do nothing. Leave args->Handled set to the current value, false.
}
}
#endif
void OpenGLESPage::OnSwapChainPanelSizeChanged(Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e) void OpenGLESPage::OnSwapChainPanelSizeChanged(Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e)
{ {
// Size change events occur outside of the render thread. A lock is required when updating // Size change events occur outside of the render thread. A lock is required when updating
@ -283,6 +303,11 @@ void OpenGLESPage::StartRenderLoop()
{ {
m_deviceLost = true; m_deviceLost = true;
if (m_renderer)
{
m_renderer->Pause();
}
// XAML objects like the SwapChainPanel must only be manipulated on the UI thread. // XAML objects like the SwapChainPanel must only be manipulated on the UI thread.
swapChainPanel->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::High, ref new Windows::UI::Core::DispatchedHandler([=]() swapChainPanel->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::High, ref new Windows::UI::Core::DispatchedHandler([=]()
{ {
@ -292,6 +317,11 @@ void OpenGLESPage::StartRenderLoop()
return; return;
} }
} }
if (m_renderer)
{
m_renderer->Pause();
}
}); });
// Run task on a dedicated high priority background thread. // Run task on a dedicated high priority background thread.
@ -305,9 +335,4 @@ void OpenGLESPage::StopRenderLoop()
mRenderLoopWorker->Cancel(); mRenderLoopWorker->Cancel();
mRenderLoopWorker = nullptr; mRenderLoopWorker = nullptr;
} }
if (m_renderer)
{
m_renderer->Pause();
}
} }

View File

@ -39,6 +39,9 @@ namespace cocos2d
void OnPageLoaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void OnPageLoaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args); void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args);
void OnSwapChainPanelSizeChanged(Platform::Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e); void OnSwapChainPanelSizeChanged(Platform::Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e);
#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
void OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args);
#endif
void GetSwapChainPanelSize(GLsizei* width, GLsizei* height); void GetSwapChainPanelSize(GLsizei* width, GLsizei* height);
void CreateRenderSurface(); void CreateRenderSurface();
void DestroyRenderSurface(); void DestroyRenderSurface();