axmol/core/2d/CCActionGrid3D.cpp

739 lines
17 KiB
C++
Raw Normal View History

/****************************************************************************
Copyright (c) 2009 On-Core
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2021-12-25 10:04:45 +08:00
https://axis-project.github.io/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "2d/CCActionGrid3D.h"
2014-04-30 08:37:36 +08:00
#include "base/CCDirector.h"
NS_AX_BEGIN
// implementation of Waves3D
2021-10-23 23:27:14 +08:00
Waves3D* Waves3D::create(float duration, const Vec2& gridSize, unsigned int waves, float amplitude)
{
2021-12-25 10:04:45 +08:00
Waves3D* action = new Waves3D();
2021-12-08 00:11:53 +08:00
if (action->initWithDuration(duration, gridSize, waves, amplitude))
{
action->autorelease();
return action;
}
delete action;
return nullptr;
}
2021-10-23 23:27:14 +08:00
bool Waves3D::initWithDuration(float duration, const Vec2& gridSize, unsigned int waves, float amplitude)
{
if (Grid3DAction::initWithDuration(duration, gridSize))
{
2021-12-25 10:04:45 +08:00
_waves = waves;
_amplitude = amplitude;
_amplitudeRate = 1.0f;
return true;
}
return false;
}
Waves3D* Waves3D::clone() const
{
// no copy constructor
return Waves3D::create(_duration, _gridSize, _waves, _amplitude);
}
void Waves3D::update(float time)
{
int i, j;
for (i = 0; i < _gridSize.width + 1; ++i)
{
for (j = 0; j < _gridSize.height + 1; ++j)
{
Vec2 pos((float)i, (float)j);
Vec3 v = getOriginalVertex(pos);
2021-12-25 10:04:45 +08:00
v.z += (sinf((float)M_PI * time * _waves * 2 + (v.y + v.x) * 0.01f) * _amplitude * _amplitudeRate);
2022-07-16 10:43:05 +08:00
// AXLOG("v.z offset is %f\n", (sinf((float)M_PI * time * _waves * 2 + (v.y+v.x) * .01f) * _amplitude *
2021-12-25 10:04:45 +08:00
// _amplitudeRate));
setVertex(pos, v);
}
}
}
// implementation of FlipX3D
FlipX3D* FlipX3D::create(float duration)
{
2021-12-25 10:04:45 +08:00
FlipX3D* action = new FlipX3D();
2021-12-08 00:11:53 +08:00
if (action->initWithDuration(duration))
{
action->autorelease();
return action;
}
delete action;
return nullptr;
}
bool FlipX3D::initWithDuration(float duration)
{
2021-10-23 23:27:14 +08:00
return Grid3DAction::initWithDuration(duration, Vec2(1, 1));
}
2021-10-23 23:27:14 +08:00
bool FlipX3D::initWithSize(const Vec2& gridSize, float duration)
{
if (gridSize.width != 1 || gridSize.height != 1)
{
// Grid size must be (1,1)
2022-07-16 10:43:05 +08:00
AXASSERT(0, "Grid size must be (1,1)");
return false;
}
return Grid3DAction::initWithDuration(duration, gridSize);
}
FlipX3D* FlipX3D::clone() const
{
2021-12-25 10:04:45 +08:00
// no copy constructor
2021-12-08 00:11:53 +08:00
auto a = new FlipX3D();
a->initWithSize(_gridSize, _duration);
a->autorelease();
return a;
}
void FlipX3D::update(float time)
{
2021-12-25 10:04:45 +08:00
float angle = (float)M_PI * time; // 180 degrees
float mz = sinf(angle);
angle = angle / 2.0f; // x calculates degrees from 0 to 90
float mx = cosf(angle);
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
Vec3 v0, v1, v, diff;
v0 = getOriginalVertex(Vec2(1.0f, 1.0f));
v1 = getOriginalVertex(Vec2());
2021-12-25 10:04:45 +08:00
float x0 = v0.x;
float x1 = v1.x;
float x;
Vec2 a, b, c, d;
2021-12-25 10:04:45 +08:00
if (x0 > x1)
{
// Normal Grid
a.setZero();
b.set(0.0f, 1.0f);
c.set(1.0f, 0.0f);
d.set(1.0f, 1.0f);
x = x0;
}
else
{
// Reversed Grid
c.setZero();
d.set(0.0f, 1.0f);
a.set(1.0f, 0.0f);
b.set(1.0f, 1.0f);
x = x1;
}
2021-12-25 10:04:45 +08:00
diff.x = (x - x * mx);
diff.z = fabsf(floorf((x * mz) / 4.0f));
// bottom-left
2021-12-25 10:04:45 +08:00
v = getOriginalVertex(a);
v.x = diff.x;
v.z += diff.z;
setVertex(a, v);
2021-12-25 10:04:45 +08:00
// upper-left
2021-12-25 10:04:45 +08:00
v = getOriginalVertex(b);
v.x = diff.x;
v.z += diff.z;
setVertex(b, v);
2021-12-25 10:04:45 +08:00
// bottom-right
v = getOriginalVertex(c);
v.x -= diff.x;
v.z -= diff.z;
setVertex(c, v);
2021-12-25 10:04:45 +08:00
// upper-right
v = getOriginalVertex(d);
v.x -= diff.x;
v.z -= diff.z;
setVertex(d, v);
}
// implementation of FlipY3D
FlipY3D* FlipY3D::clone() const
{
// no copy constructor
2021-12-08 00:11:53 +08:00
auto a = new FlipY3D();
a->initWithSize(_gridSize, _duration);
a->autorelease();
return a;
}
FlipY3D* FlipY3D::create(float duration)
{
2021-12-25 10:04:45 +08:00
FlipY3D* action = new FlipY3D();
2021-12-08 00:11:53 +08:00
if (action->initWithDuration(duration))
{
2021-12-08 00:11:53 +08:00
action->autorelease();
}
else
{
2022-07-15 19:17:01 +08:00
AX_SAFE_DELETE(action);
}
2013-11-16 21:08:00 +08:00
return action;
}
void FlipY3D::update(float time)
{
2021-12-25 10:04:45 +08:00
float angle = (float)M_PI * time; // 180 degrees
float mz = sinf(angle);
angle = angle / 2.0f; // x calculates degrees from 0 to 90
float my = cosf(angle);
Vec3 v0, v1, v, diff;
v0 = getOriginalVertex(Vec2(1.0f, 1.0f));
v1 = getOriginalVertex(Vec2());
2021-12-25 10:04:45 +08:00
float y0 = v0.y;
float y1 = v1.y;
float y;
2021-12-25 10:04:45 +08:00
Vec2 a, b, c, d;
if (y0 > y1)
{
// Normal Grid
a.setZero();
b.set(0.0f, 1.0f);
c.set(1.0f, 0.0f);
d.set(1.0f, 1.0f);
y = y0;
}
else
{
// Reversed Grid
b.setZero();
a.set(0.0f, 1.0f);
d.set(1.0f, 0.0f);
c.set(1.0f, 1.0f);
y = y1;
}
2021-12-25 10:04:45 +08:00
diff.y = y - y * my;
diff.z = fabsf(floorf((y * mz) / 4.0f));
2021-12-25 10:04:45 +08:00
// bottom-left
2021-12-25 10:04:45 +08:00
v = getOriginalVertex(a);
v.y = diff.y;
v.z += diff.z;
setVertex(a, v);
2021-12-25 10:04:45 +08:00
// upper-left
v = getOriginalVertex(b);
v.y -= diff.y;
v.z -= diff.z;
setVertex(b, v);
2021-12-25 10:04:45 +08:00
// bottom-right
2021-12-25 10:04:45 +08:00
v = getOriginalVertex(c);
v.y = diff.y;
v.z += diff.z;
setVertex(c, v);
2021-12-25 10:04:45 +08:00
// upper-right
v = getOriginalVertex(d);
v.y -= diff.y;
v.z -= diff.z;
setVertex(d, v);
}
// implementation of Lens3D
2021-10-23 23:27:14 +08:00
Lens3D* Lens3D::create(float duration, const Vec2& gridSize, const Vec2& position, float radius)
{
2021-12-25 10:04:45 +08:00
Lens3D* action = new Lens3D();
2021-12-08 00:11:53 +08:00
if (action->initWithDuration(duration, gridSize, position, radius))
{
2021-12-08 00:11:53 +08:00
action->autorelease();
}
else
{
2022-07-15 19:17:01 +08:00
AX_SAFE_DELETE(action);
}
2013-11-16 21:08:00 +08:00
return action;
}
2021-10-23 23:27:14 +08:00
bool Lens3D::initWithDuration(float duration, const Vec2& gridSize, const Vec2& position, float radius)
{
if (Grid3DAction::initWithDuration(duration, gridSize))
{
_position.set(-1.0f, -1.0f);
setPosition(position);
2021-12-25 10:04:45 +08:00
_radius = radius;
_lensEffect = 0.7f;
2021-12-25 10:04:45 +08:00
_concave = false;
_dirty = true;
return true;
}
return false;
}
Lens3D* Lens3D::clone() const
{
// no copy constructor
2021-12-08 00:11:53 +08:00
auto a = new Lens3D();
a->initWithDuration(_duration, _gridSize, _position, _radius);
a->autorelease();
return a;
}
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
void Lens3D::setPosition(const Vec2& pos)
{
2021-12-25 10:04:45 +08:00
if (!pos.equals(_position))
{
_position = pos;
2021-12-25 10:04:45 +08:00
_dirty = true;
}
}
void Lens3D::update(float /*time*/)
{
if (_dirty)
{
int i, j;
2021-12-25 10:04:45 +08:00
for (i = 0; i < _gridSize.width + 1; ++i)
{
for (j = 0; j < _gridSize.height + 1; ++j)
{
Vec2 pos((float)i, (float)j);
2021-12-25 10:04:45 +08:00
Vec3 v = getOriginalVertex(pos);
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
Vec2 vect = _position - Vec2(v.x, v.y);
2021-12-25 10:04:45 +08:00
float r = vect.getLength();
if (r < _radius)
{
2021-12-25 10:04:45 +08:00
r = _radius - r;
float pre_log = r / _radius;
2021-12-25 10:04:45 +08:00
if (pre_log == 0)
{
pre_log = 0.001f;
}
2021-12-25 10:04:45 +08:00
float l = logf(pre_log) * _lensEffect;
float new_r = expf(l) * _radius;
if (vect.getLength() > 0)
{
2014-04-30 18:07:05 +08:00
vect.normalize();
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
Vec2 new_vect = vect * new_r;
v.z += (_concave ? -1.0f : 1.0f) * new_vect.getLength() * _lensEffect;
}
}
2021-12-25 10:04:45 +08:00
setVertex(pos, v);
}
}
2021-12-25 10:04:45 +08:00
_dirty = false;
}
}
// implementation of Ripple3D
2021-12-25 10:04:45 +08:00
Ripple3D* Ripple3D::create(float duration,
const Vec2& gridSize,
const Vec2& position,
float radius,
unsigned int waves,
float amplitude)
{
2021-12-25 10:04:45 +08:00
Ripple3D* action = new Ripple3D();
2021-12-08 00:11:53 +08:00
if (action->initWithDuration(duration, gridSize, position, radius, waves, amplitude))
{
2021-12-08 00:11:53 +08:00
action->autorelease();
}
else
{
2022-07-15 19:17:01 +08:00
AX_SAFE_DELETE(action);
}
2013-11-16 21:08:00 +08:00
return action;
}
2021-12-25 10:04:45 +08:00
bool Ripple3D::initWithDuration(float duration,
const Vec2& gridSize,
const Vec2& position,
float radius,
unsigned int waves,
float amplitude)
{
if (Grid3DAction::initWithDuration(duration, gridSize))
{
setPosition(position);
2021-12-25 10:04:45 +08:00
_radius = radius;
_waves = waves;
_amplitude = amplitude;
_amplitudeRate = 1.0f;
return true;
}
return false;
}
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
void Ripple3D::setPosition(const Vec2& position)
{
_position = position;
}
Ripple3D* Ripple3D::clone() const
{
// no copy constructor
2021-12-08 00:11:53 +08:00
auto a = new Ripple3D();
a->initWithDuration(_duration, _gridSize, _position, _radius, _waves, _amplitude);
a->autorelease();
return a;
}
void Ripple3D::update(float time)
{
int i, j;
2021-12-25 10:04:45 +08:00
for (i = 0; i < (_gridSize.width + 1); ++i)
{
2021-12-25 10:04:45 +08:00
for (j = 0; j < (_gridSize.height + 1); ++j)
{
Vec2 pos((float)i, (float)j);
2021-12-25 10:04:45 +08:00
Vec3 v = getOriginalVertex(pos);
Vec2 vect = _position - Vec2(v.x, v.y);
float r = vect.getLength();
if (r < _radius)
{
2021-12-25 10:04:45 +08:00
r = _radius - r;
float rate = powf(r / _radius, 2);
2021-12-25 10:04:45 +08:00
v.z += (sinf(time * (float)M_PI * _waves * 2 + r * 0.1f) * _amplitude * _amplitudeRate * rate);
}
2021-12-25 10:04:45 +08:00
setVertex(pos, v);
}
}
}
// implementation of Shaky3D
2021-10-23 23:27:14 +08:00
Shaky3D* Shaky3D::create(float duration, const Vec2& gridSize, int range, bool shakeZ)
{
2021-12-25 10:04:45 +08:00
Shaky3D* action = new Shaky3D();
2021-12-08 00:11:53 +08:00
if (action->initWithDuration(duration, gridSize, range, shakeZ))
{
2021-12-08 00:11:53 +08:00
action->autorelease();
}
else
{
2022-07-15 19:17:01 +08:00
AX_SAFE_DELETE(action);
}
2013-11-16 21:08:00 +08:00
return action;
}
2021-10-23 23:27:14 +08:00
bool Shaky3D::initWithDuration(float duration, const Vec2& gridSize, int range, bool shakeZ)
{
if (Grid3DAction::initWithDuration(duration, gridSize))
{
_randrange = range;
2021-12-25 10:04:45 +08:00
_shakeZ = shakeZ;
return true;
}
return false;
}
Shaky3D* Shaky3D::clone() const
{
// no copy constructor
2021-12-08 00:11:53 +08:00
auto a = new Shaky3D();
a->initWithDuration(_duration, _gridSize, _randrange, _shakeZ);
a->autorelease();
return a;
}
void Shaky3D::update(float /*time*/)
{
int i, j;
2021-12-25 10:04:45 +08:00
for (i = 0; i < (_gridSize.width + 1); ++i)
{
2021-12-25 10:04:45 +08:00
for (j = 0; j < (_gridSize.height + 1); ++j)
{
Vec2 pos((float)i, (float)j);
Vec3 v = getOriginalVertex(pos);
2021-12-25 10:04:45 +08:00
v.x += (rand() % (_randrange * 2)) - _randrange;
v.y += (rand() % (_randrange * 2)) - _randrange;
if (_shakeZ)
{
2021-12-25 10:04:45 +08:00
v.z += (rand() % (_randrange * 2)) - _randrange;
}
2021-12-25 10:04:45 +08:00
setVertex(pos, v);
}
}
}
// implementation of Liquid
2021-10-23 23:27:14 +08:00
Liquid* Liquid::create(float duration, const Vec2& gridSize, unsigned int waves, float amplitude)
{
2021-12-25 10:04:45 +08:00
Liquid* action = new Liquid();
2021-12-08 00:11:53 +08:00
if (action->initWithDuration(duration, gridSize, waves, amplitude))
{
2021-12-08 00:11:53 +08:00
action->autorelease();
}
2021-12-08 00:11:53 +08:00
else
{
2022-07-15 19:17:01 +08:00
AX_SAFE_DELETE(action);
2021-12-08 00:11:53 +08:00
}
2021-12-25 10:04:45 +08:00
2013-11-16 21:08:00 +08:00
return action;
}
2021-10-23 23:27:14 +08:00
bool Liquid::initWithDuration(float duration, const Vec2& gridSize, unsigned int waves, float amplitude)
{
if (Grid3DAction::initWithDuration(duration, gridSize))
{
2021-12-25 10:04:45 +08:00
_waves = waves;
_amplitude = amplitude;
_amplitudeRate = 1.0f;
return true;
}
return false;
}
Liquid* Liquid::clone() const
{
// no copy constructor
2021-12-08 00:11:53 +08:00
auto a = new Liquid();
a->initWithDuration(_duration, _gridSize, _waves, _amplitude);
a->autorelease();
return a;
}
void Liquid::update(float time)
{
int i, j;
for (i = 1; i < _gridSize.width; ++i)
{
for (j = 1; j < _gridSize.height; ++j)
{
Vec2 pos((float)i, (float)j);
Vec3 v = getOriginalVertex(pos);
2021-12-25 10:04:45 +08:00
v.x = (v.x + (sinf(time * (float)M_PI * _waves * 2 + v.x * .01f) * _amplitude * _amplitudeRate));
v.y = (v.y + (sinf(time * (float)M_PI * _waves * 2 + v.y * .01f) * _amplitude * _amplitudeRate));
setVertex(pos, v);
}
}
}
// implementation of Waves
2021-12-25 10:04:45 +08:00
Waves* Waves::create(float duration,
const Vec2& gridSize,
unsigned int waves,
float amplitude,
bool horizontal,
bool vertical)
{
2021-12-25 10:04:45 +08:00
Waves* action = new Waves();
2021-12-08 00:11:53 +08:00
if (action->initWithDuration(duration, gridSize, waves, amplitude, horizontal, vertical))
{
2021-12-08 00:11:53 +08:00
action->autorelease();
}
else
{
2022-07-15 19:17:01 +08:00
AX_SAFE_DELETE(action);
}
2013-11-16 21:08:00 +08:00
return action;
}
2021-12-25 10:04:45 +08:00
bool Waves::initWithDuration(float duration,
const Vec2& gridSize,
unsigned int waves,
float amplitude,
bool horizontal,
bool vertical)
{
if (Grid3DAction::initWithDuration(duration, gridSize))
{
2021-12-25 10:04:45 +08:00
_waves = waves;
_amplitude = amplitude;
_amplitudeRate = 1.0f;
2021-12-25 10:04:45 +08:00
_horizontal = horizontal;
_vertical = vertical;
return true;
}
return false;
}
Waves* Waves::clone() const
{
// no copy constructor
2021-12-08 00:11:53 +08:00
auto a = new Waves();
a->initWithDuration(_duration, _gridSize, _waves, _amplitude, _horizontal, _vertical);
a->autorelease();
return a;
}
void Waves::update(float time)
{
int i, j;
for (i = 0; i < _gridSize.width + 1; ++i)
{
for (j = 0; j < _gridSize.height + 1; ++j)
{
Vec2 pos((float)i, (float)j);
Vec3 v = getOriginalVertex(pos);
if (_vertical)
{
v.x = (v.x + (sinf(time * (float)M_PI * _waves * 2 + v.y * .01f) * _amplitude * _amplitudeRate));
}
if (_horizontal)
{
v.y = (v.y + (sinf(time * (float)M_PI * _waves * 2 + v.x * .01f) * _amplitude * _amplitudeRate));
}
setVertex(pos, v);
}
}
}
// implementation of Twirl
2021-10-23 23:27:14 +08:00
Twirl* Twirl::create(float duration, const Vec2& gridSize, const Vec2& position, unsigned int twirls, float amplitude)
{
2021-12-25 10:04:45 +08:00
Twirl* action = new Twirl();
2021-12-08 00:11:53 +08:00
if (action->initWithDuration(duration, gridSize, position, twirls, amplitude))
{
2021-12-08 00:11:53 +08:00
action->autorelease();
}
else
{
2022-07-15 19:17:01 +08:00
AX_SAFE_DELETE(action);
}
2013-11-16 21:08:00 +08:00
return action;
}
2021-12-25 10:04:45 +08:00
bool Twirl::initWithDuration(float duration,
const Vec2& gridSize,
const Vec2& position,
unsigned int twirls,
float amplitude)
{
if (Grid3DAction::initWithDuration(duration, gridSize))
{
setPosition(position);
2021-12-25 10:04:45 +08:00
_twirls = twirls;
_amplitude = amplitude;
_amplitudeRate = 1.0f;
return true;
}
return false;
}
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
void Twirl::setPosition(const Vec2& position)
{
_position = position;
}
2021-12-25 10:04:45 +08:00
Twirl* Twirl::clone() const
{
2021-12-25 10:04:45 +08:00
// no copy constructor
2021-12-08 00:11:53 +08:00
auto a = new Twirl();
a->initWithDuration(_duration, _gridSize, _position, _twirls, _amplitude);
a->autorelease();
return a;
}
void Twirl::update(float time)
{
int i, j;
2021-12-25 10:04:45 +08:00
Vec2 c = _position;
for (i = 0; i < (_gridSize.width + 1); ++i)
{
2021-12-25 10:04:45 +08:00
for (j = 0; j < (_gridSize.height + 1); ++j)
{
Vec2 pos((float)i, (float)j);
Vec3 v = getOriginalVertex(pos);
2021-12-25 10:04:45 +08:00
Vec2 avg(i - (_gridSize.width / 2.0f), j - (_gridSize.height / 2.0f));
float r = avg.getLength();
2021-12-25 10:04:45 +08:00
float amp = 0.1f * _amplitude * _amplitudeRate;
2021-12-25 10:04:45 +08:00
float a = r * cosf((float)M_PI / 2.0f + time * (float)M_PI * _twirls * 2) * amp;
Vec2 d(sinf(a) * (v.y - c.y) + cosf(a) * (v.x - c.x), cosf(a) * (v.y - c.y) - sinf(a) * (v.x - c.x));
v.x = c.x + d.x;
v.y = c.y + d.y;
setVertex(pos, v);
}
}
}
NS_AX_END