glm::vec2 Servo2D::redrawLaser() { // Return (-1, -1) if the laser doesn't intersect z=0 glm::vec2 result = glm::vec2(-1.0, -1.0); // Convert to prism coordinates glm::vec3 position = glm::inverse(prism_->getTransform()) * glm::vec4(controller_position_, 1.0f); glm::quat orientation = glm::inverse(prism_->getRotation()) * controller_orientation_; // 1m in the direction of the controller glm::vec3 direction = orientation * glm::vec3(0.0f, 0.0f, -1.0f); // The endpoint of the laser, in prism coordinates glm::vec3 endpoint = position + direction * LASER_LENGTH; // The laser color glm::vec4 color = glm::vec4(1.0, 0.0, 0.0, 1.0); // Does the laser intersect z=0? if ((position.z > 0) && (endpoint.z < 0)) { // How far along the laser did it intersect? float ratio = 1.0 / (1.0 - (endpoint.z / position.z)); // The intersection point glm::vec3 intersection = ((1 - ratio) * position) + (ratio * endpoint); // Is the intersection inside the viewport? result = viewportPosition(intersection); if (pointInsideViewport(result)) { color = glm::vec4(0.0, 1.0, 0.0, 1.0); endpoint = intersection; } } laser_->clearPoints(); laser_->addPoints(position); laser_->addPoints(endpoint); laser_->setColor(color); return result; }
void RiftGlfwApp::viewport(ovrEyeType eye) { const glm::uvec2 & windowSize = getSize(); glm::ivec2 viewportPosition(eye == ovrEye_Left ? 0 : windowSize.x / 2, 0); GlfwApp::viewport(glm::uvec2(windowSize.x / 2, windowSize.y), viewportPosition); }