void gpp::CameraComponent::move(const gep::vec3& delta) { gep::vec3 pos =m_transform.getWorldPosition(); pos += getUpDirection() * delta.z; pos += getRightDirection() * delta.x; pos += getViewDirection() * delta.y; m_pCamera->setPosition(pos); m_transform.setPosition(pos); }
Selection ViewpointCursor::getCursor(const SelectableList& selectables) { Selectable* closestObject = NULL; Selection closestIntersection; if (updatePending) { closestIntersection.distance = std::numeric_limits<float>::max(); glm::vec3 p = getUserPosition(); glm::vec3 d = getCursorDirection(); // First up, see if we intersect one of the objects. for (SelectableList::const_iterator it = selectables.begin(); it < selectables.end(); ++it) { Selectable* s = *it; Selection i = s->intersect(p, d); if (i.distance > 0 && i.distance < closestIntersection.distance) { closestObject = s; closestIntersection = i; } } updatePending = false; // Return the closest object, if there was one. if (closestObject != NULL) { cursorPlaced = true; cursor3D = closestIntersection.pos; cursorNormal = closestIntersection.normal; closestIntersection.rotationMatrix = getCursorRotation(); closestIntersection.object = closestObject; } // intersect with magic plane so at least the cursor appears... else { glm::vec3 userDirection = getViewDirection(); Plane plane(p + userDirection*planeDistance, userDirection); Plane::Intersection ip = plane.intersect(p, d); if (ip.intersects) { cursorPlaced = true; cursor3D = ip.intersectionPoint; cursorNormal = userDirection*-1.0f; cursorPlaced = true; closestIntersection.pos = cursor3D; closestIntersection.normal = cursorNormal; closestIntersection.rotationMatrix = getCursorRotation(); closestIntersection.object = NULL; } } } return closestIntersection; }
void Camera::setUpVector(const Vec3f& up) { setupCameraOrientation(getViewDirection(), up); }