Skip to content

Commit 056c3e1

Browse files
committed
fix shader, add multiple sprite to Sprite3DEffectTest
1 parent 94d7896 commit 056c3e1

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,10 @@ Sprite3DEffectTest::Sprite3DEffectTest()
397397
{
398398
auto s = Director::getInstance()->getWinSize();
399399
addNewSpriteWithCoords( Vec2(s.width/2, s.height/2) );
400+
401+
auto listener = EventListenerTouchAllAtOnce::create();
402+
listener->onTouchesEnded = CC_CALLBACK_2(Sprite3DEffectTest::onTouchesEnded, this);
403+
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
400404
}
401405

402406
std::string Sprite3DEffectTest::title() const
@@ -414,10 +418,11 @@ void Sprite3DEffectTest::addNewSpriteWithCoords(Vec2 p)
414418
auto sprite = EffectSprite3D::createFromObjFileAndTexture("Sprite3DTest/boss1.obj", "Sprite3DTest/boss.png");
415419
Effect3DOutline* effect = Effect3DOutline::create();
416420
effect->setOutlineColor(Vec3(1,0,0));
417-
effect->setOutlineWidth(0.1);
421+
effect->setOutlineWidth(0.001);
418422
sprite->addEffect(effect, -1);
419423
Effect3DOutline* effect2 = Effect3DOutline::create();
420-
effect->setOutlineWidth(0.3);
424+
effect2->setOutlineWidth(0.002);
425+
effect2->setOutlineColor(Vec3(1,1,0));
421426
sprite->addEffect(effect2, -2);
422427
//sprite->setEffect3D(effect);
423428
sprite->setScale(6.f);
@@ -445,3 +450,13 @@ void Sprite3DEffectTest::addNewSpriteWithCoords(Vec2 p)
445450

446451
sprite->runAction( RepeatForever::create(seq) );
447452
}
453+
454+
void Sprite3DEffectTest::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
455+
{
456+
for (auto touch: touches)
457+
{
458+
auto location = touch->getLocation();
459+
460+
addNewSpriteWithCoords( location );
461+
}
462+
}

tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ class Sprite3DEffectTest : public Sprite3DTestDemo
125125
virtual std::string subtitle() const override;
126126

127127
void addNewSpriteWithCoords(Vec2 p);
128+
129+
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
128130
};
129131

130132
class Sprite3DTestScene : public TestScene

tests/cpp-tests/Resources/Shaders3D/OutLine.vert

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ uniform float OutlineWidth;
44

55
void main(void)
66
{
7-
vec4 pos = a_position;
8-
vec3 normal = a_normal;
9-
pos.xyz += a_normal * OutlineWidth;
10-
gl_Position = CC_MVPMatrix * pos;
7+
vec4 pos = CC_MVPMatrix * a_position;
8+
vec4 normalproj = CC_MVPMatrix * vec4(a_normal, 0);
9+
pos.xy += normalproj.xy * (OutlineWidth * (pos.z * 0.5 + 0.5));
10+
11+
gl_Position = pos;
1112
}

0 commit comments

Comments
 (0)