| 171 | void TerrainWalkThru::onTouchesBegan(const std::vector<ax::Touch*>& touches, ax::Event* event) {} |
| 172 | |
| 173 | void 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 | |
| 206 | bool Player::isDone() const |
| 207 | { |
nothing calls this directly
no test coverage detected