Create a camera where the mesh at Z=0 is behind the camera. Camera at (0.5, 0.5, -5), looking along -Z in world (away from mesh).
| 94 | // Create a camera where the mesh at Z=0 is behind the camera. |
| 95 | // Camera at (0.5, 0.5, -5), looking along -Z in world (away from mesh). |
| 96 | Image MakeBehindCameraImage(int width, int height) { |
| 97 | float K[9] = {0}; |
| 98 | K[0] = static_cast<float>(width); |
| 99 | K[4] = static_cast<float>(height); |
| 100 | K[2] = static_cast<float>(width) / 2.0f; |
| 101 | K[5] = static_cast<float>(height) / 2.0f; |
| 102 | K[8] = 1.0f; |
| 103 | |
| 104 | // R: 180° around X, looks along -Z in world. |
| 105 | float R[9] = {1, 0, 0, 0, -1, 0, 0, 0, -1}; |
| 106 | |
| 107 | // C = (0.5, 0.5, -5), T = -R*C = [-0.5, 0.5, -5] |
| 108 | float T[3] = {-0.5f, 0.5f, -5.0f}; |
| 109 | |
| 110 | Image image("behind.png", |
| 111 | static_cast<size_t>(width), |
| 112 | static_cast<size_t>(height), |
| 113 | K, |
| 114 | R, |
| 115 | T); |
| 116 | |
| 117 | Bitmap bitmap(width, height, /*as_rgb=*/true); |
| 118 | bitmap.Fill(BitmapColor<uint8_t>(0)); |
| 119 | image.SetBitmap(std::move(bitmap)); |
| 120 | |
| 121 | return image; |
| 122 | } |
| 123 | |
| 124 | // Create a camera that views the mesh at a very grazing angle. |
| 125 | // Camera nearly in-plane with XY mesh, at (0.5, 0.5, 0.01), looking along -Z. |