MCPcopy Create free account
hub / github.com/axmolengine/axmol / onTouchesEnd

Method onTouchesEnd

tests/cpp-tests/Source/TerrainTest/TerrainTest.cpp:173–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171void TerrainWalkThru::onTouchesBegan(const std::vector<ax::Touch*>& touches, ax::Event* event) {}
172
173void TerrainWalkThru::onTouchesEnd(const std::vector<ax::Touch*>& touches, ax::Event* event)
174{
175 auto touch = touches[0];
176 auto location = touch->getLocationInView();
177 if (_camera)
178 {
179 if (_player)
180 {
181 Vec3 nearP(location.x, location.y, 0.0f), farP(location.x, location.y, 1.0f);
182
183 auto size = Director::getInstance()->getWinSize();
184 _camera->unproject(size, &nearP, &nearP);
185 _camera->unproject(size, &farP, &farP);
186 Vec3 dir = farP - nearP;
187 dir.normalize();
188 Vec3 collisionPoint(-999, -999, -999);
189 bool isInTerrain = _terrain->getIntersectionPoint(Ray(nearP, dir), collisionPoint);
190 if (!isInTerrain)
191 {
192 _player->idle();
193 return;
194 }
195 dir = collisionPoint - _player->getPosition3D();
196 dir.y = 0;
197 dir.normalize();
198 _player->_headingAngle = -1 * acos(dir.dot(Vec3(0, 0, -1)));
199 dir.cross(dir, Vec3(0, 0, -1), &_player->_headingAxis);
200 _player->_targetPos = collisionPoint;
201 _player->forward();
202 }
203 }
204}
205
206bool Player::isDone() const
207{

Callers

nothing calls this directly

Calls 12

getInstanceFunction · 0.85
RayClass · 0.85
getIntersectionPointMethod · 0.80
idleMethod · 0.80
Vec3Function · 0.50
getLocationInViewMethod · 0.45
unprojectMethod · 0.45
normalizeMethod · 0.45
getPosition3DMethod · 0.45
dotMethod · 0.45
crossMethod · 0.45
forwardMethod · 0.45

Tested by

no test coverage detected