Snap grid overlay to major worldlines

This commit is contained in:
Zach Pomerantz 2016-02-19 13:46:59 -08:00
parent fd6aa9a78b
commit 0b4e82405f

View file

@ -59,9 +59,14 @@ void Grid3DOverlay::render(RenderArgs* args) {
if (_followCamera) {
auto avatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
// Add the camera position at the plane of the avatar's base (the floor)
auto cameraPosition = args->_viewFrustum->getPosition();
// Get the camera position rounded to the nearest major grid line
// This grid is for UI and should lie on worldlines
auto cameraPosition =
(float)_majorGridEvery * glm::round(args->_viewFrustum->getPosition() / (float)_majorGridEvery);
// Get the plane of the avatar's feet (or collision ground)
auto avatarBaseHeight = avatar->getPosition().y - avatar->getUniformScale();
position += glm::vec3(cameraPosition.x, avatarBaseHeight, cameraPosition.z);
}