<p>I have a cube with 8 vertices representing the <span class="math-container">$[-1,1]^3$</span> cube vulkan uses for device coordinates.</p>
<p>The perspective projection matrix takes a frustum and maps it onto this cube. It thus makes sense that the inverse of this transformation applied to the cube should yield the frustum.</p>
<p>To that effect I have this little snippet:</p>
<pre class="lang-cpp prettyprint-override"><code>
    Eigen::Matrix4d perspective_mat = Perspective(80.f, 1.f, 0.1f, node.normal.norm()).cast&lt;double&gt;(); // delete
    HMesh&lt;VertexData&gt; cube(&quot;cube.obj&quot;);                                                                // delete
    for (auto &amp;vert : cube.VertexDataD())
    {
        const auto &amp;pos = vert.position;
        auto tmp = ((perspective_mat).inverse().eval() * Edvec4(pos.x(), pos.y(), pos.z(), 1));

        vert.position = {tmp.x() / tmp[3], tmp.y() / tmp[3], tmp.z() / tmp[3]};
     }

</code></pre>
<p>Well this little guy creates this thing:</p>
<p><a href="https://i.sstatic.net/EYvRD.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/EYvRD.png" alt="enter image description here" /></a></p>
<p>Which does not look like a frustum.</p>
<p>What am I doing wrong? I know it's not a coding error in the sense I trust all my functions, but I might have a math error.</p>

CC BY-SA 4.0
2022-12-14T15:00:36.207Z
have you mixed degree with radiant? Or what does the "80.f" in the first line represent?
Thomas
CC BY-SA 4.0
2022-12-14T17:10:44.500Z
"*cube with 8 vertices representing the [−1,1]3 cube vulkan uses for device coordinates.*" Vulkan's standard device coordinates [are not a cube](https://registry.khronos.org/vulkan/specs/1.3-khr-extensions/html/chap24.html#vertexpostproc-viewport).
Nicol Bolas
<rendering><geometry><perspective><camera-matrix>
Inverting perspective projection doesn't yield frustum?
Makogan
# Inverting perspective projection doesn't yield frustum?

(Asked by: username_0 on 2022-12-14)

I have a cube with 8 vertices representing the $[-1,1]^3$ cube vulkan uses for device coordinates.

The perspective projection matrix takes a frustum and maps it onto this cube. It thus makes sense that the inverse of this transformation applied to the cube should yield the frustum.

To that effect I have this little snippet:

```cpp

    Eigen::Matrix4d perspective_mat = Perspective(80.f, 1.f, 0.1f, node.normal.norm()).cast<double>(); // delete
    HMesh<VertexData> cube("cube.obj");                                                                // delete
    for (auto &vert : cube.VertexDataD())
    {
        const auto &pos = vert.position;
        auto tmp = ((perspective_mat).inverse().eval() * Edvec4(pos.x(), pos.y(), pos.z(), 1));

        vert.position = {tmp.x() / tmp[3], tmp.y() / tmp[3], tmp.z() / tmp[3]};
     }

```

Well this little guy creates this thing:

[![enter image description here](https://i.sstatic.net/EYvRD.png)](https://i.sstatic.net/EYvRD.png)

Which does not look like a frustum.

What am I doing wrong? I know it's not a coding error in the sense I trust all my functions, but I might have a math error.

**Tags:** rendering, geometry, perspective, camera-matrix

> **Comments:**
> **username_1**: have you mixed degree with radiant? Or what does the "80.f" in the first line represent?  
> **username_2**: "*cube with 8 vertices representing the [−1,1]3 cube vulkan uses for device coordinates.*" Vulkan's standard device coordinates [are not a cube](https://registry.khronos.org/vulkan/specs/1.3-khr-extensions/html/chap24.html#vertexpostproc-viewport).  

---

## 0 answers

