| 35 | } |
| 36 | |
| 37 | bool Camera::GetPickLine(int32_t viewX, int32_t viewY, int32_t viewW, int32_t viewH, int32_t x, int32_t y, |
| 38 | Vector4<float>& origin, Vector4<float>& direction) const |
| 39 | { |
| 40 | if (viewX <= x && x <= viewX + viewW && viewY <= y && y <= viewY + viewH) |
| 41 | { |
| 42 | // Get the [0,1]^2-normalized coordinates of (x,y). |
| 43 | float r = (static_cast<float>(x - viewX)) / static_cast<float>(viewW); |
| 44 | float u = (static_cast<float>(y - viewY)) / static_cast<float>(viewH); |
| 45 | |
| 46 | // Get the relative coordinates in [rmin,rmax]x[umin,umax]. |
| 47 | float rBlend = (1.0f - r) * GetRMin() + r * GetRMax(); |
| 48 | float uBlend = (1.0f - u) * GetUMin() + u * GetUMax(); |
| 49 | |
| 50 | if (IsPerspective()) |
| 51 | { |
| 52 | origin = GetPosition(); |
| 53 | direction = GetDMin() * GetDVector() + rBlend * GetRVector() + uBlend * GetUVector(); |
| 54 | Normalize(direction); |
| 55 | } |
| 56 | else |
| 57 | { |
| 58 | origin = GetPosition() + rBlend * GetRVector() + uBlend * GetUVector(); |
| 59 | direction = GetDVector(); |
| 60 | } |
| 61 | return true; |
| 62 | } |
| 63 | else |
| 64 | { |
| 65 | // (x,y) is outside the viewport. |
| 66 | return false; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | void Camera::UpdatePVMatrix() |
| 71 | { |
no test coverage detected