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

Method onTouchEnd

tests/cpp-tests/Source/Scene3DTest/Scene3DTest.cpp:881–917  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

879}
880
881void Scene3DTestScene::onTouchEnd(Touch* touch, ax::Event* event)
882{
883 auto location = touch->getLocation();
884 auto camera = _gameCameras[CAMERA_WORLD_3D_SCENE];
885 if (camera != Camera::getVisitingCamera())
886 {
887 return;
888 }
889
890 if (_player)
891 {
892 Vec3 nearP(location.x, location.y, 0.0f), farP(location.x, location.y, 1.0f);
893 // convert screen touch location to the world location on near and far plane
894 auto size = Director::getInstance()->getWinSize();
895 camera->unprojectGL(size, &nearP, &nearP);
896 camera->unprojectGL(size, &farP, &farP);
897 Vec3 dir = farP - nearP;
898 dir.normalize();
899 Vec3 collisionPoint;
900 bool isInTerrain = _terrain->getIntersectionPoint(Ray(nearP, dir), collisionPoint);
901 if (!isInTerrain)
902 {
903 _player->idle();
904 }
905 else
906 {
907 dir = collisionPoint - _player->getPosition3D();
908 dir.y = 0;
909 dir.normalize();
910 _player->_headingAngle = -1 * acos(dir.dot(Vec3(0, 0, -1)));
911 Vec3::cross(dir, Vec3(0, 0, -1), &_player->_headingAxis);
912 _player->_targetPos = collisionPoint;
913 _player->forward();
914 }
915 }
916 event->stopPropagation();
917}
918
919////////////////////////////////////////////////////////////////////////////////
920// Implements Scene3DTests

Callers

nothing calls this directly

Calls 13

getInstanceFunction · 0.85
RayClass · 0.85
unprojectGLMethod · 0.80
getIntersectionPointMethod · 0.80
idleMethod · 0.80
stopPropagationMethod · 0.80
Vec3Function · 0.50
crossFunction · 0.50
getLocationMethod · 0.45
normalizeMethod · 0.45
getPosition3DMethod · 0.45
dotMethod · 0.45

Tested by

no test coverage detected