| 879 | } |
| 880 | |
| 881 | void 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 |
nothing calls this directly
no test coverage detected