<blockquote>
  <p>I don't understand why, if I make the first argument to glm::lookAt be glm::vec3(0.0f, 0.0f, 2.0f), I see nothing.</p>
</blockquote>

<p>It's because of the <em>up</em> vector. If you think about the look-at operation, you specify where the camera is and what point it's looking towards. These two things alone leave one degree of freedom: the rotation around that axis. Which way is up on your screen? The third argument is for specifying that: it's a direction in world space which will correspond to <em>up</em> on the screen. If your first argument is that and the rest of the code is as your example, you're calling <code>lookAt((0,0,2), (0,0,0), (0,0,1))</code>. Your up vector points along the $z$-axis, which is the same direction the camera is looking (well, the opposite direction. This can't define which way is <em>up</em> on the screen. </p>

<p>You probably want to pass a vector <code>(0,1,0)</code> as the third argument, which will make $y$ point up on your screen.</p>

<p>If you're making a plan view of a 3D scene, then perspective projection is probably the right answer, but if all your content is going to be in the $z=0$ plane, then you probably want to use an orthographic rather than a perspective projection. Look at <a href="https://computergraphics.stackexchange.com/questions/2383/whats-the-difference-between-orthographic-and-perspective-projection">What&#39;s the difference between orthographic and perspective projection?</a> to learn more about that.</p>

<p>Last of all, remember that if you're projecting an $800m \times 800m$ scene onto $800 \times 800$ pixels, then a $1m$ radius circle will only be one pixel large. You probably need to scale up the size of your circle.</p>

CC BY-SA 3.0
2017-02-09T13:19:08.063Z
Let me get this straight. So the 3 arguments to lookAt are eye, center, up.  Eye is the position of the camera.  I'm kind of confused on what center does.  Up is the where the top of the camera is pointing?
mikeglaz
CC BY-SA 3.0
2017-02-09T13:49:41.377Z
`center` is the point the eye is looking at, i.e. the point that will be in the middle of the screen. `up` is the direction (not a point) the top of the camera is pointing; i.e. if you draw a line from `center` in the direction `up`, this line will be in the 12 o'clock position on the screen.
Dan Hulme
CC BY-SA 3.0
2017-02-08T16:47:44.643Z
2017-02-08T16:47:44.643Z
2017-04-13T13:00:43.660Z
Dan Hulme
<p>I'm new to computer graphics.  I played around with OpenGL and now am trying out Vulkan.</p>

<p>Basically what I want to do, in 2D is have an 800x800 window, and I want that to represent 800 meters by 800 meters.  Then I want a circle with a radius of 1 meter.</p>

<p>I am going off of the Vulkan tutorial.  </p>

<p>My data structure is this:</p>

<pre><code>struct Vertex {
    glm::vec2 pos;
};
</code></pre>

<p>I create my circle:</p>

<pre><code>const int NUM_POINTS = 20;
uint32_t angle = 360/NUM_POINTS;
Vertex vertex;
std::vector&lt;Vertex&gt; vertices;

for(uint32_t i=0; i &lt;= 360; i+=angle){
  vertex.pos.x = cos(glm::radians(float(i)));
  vertex.pos.y = sin(glm::radians(float(i)));
  vertices.push_back(vertex);
}
</code></pre>

<p>Something to do with the viewport:</p>

<pre><code>VkViewport viewport = {};
viewport.x = 0.0f;
viewport.y = 0.0f;
viewport.width = (float) swapChainExtent.width;
viewport.height = (float) swapChainExtent.height;
viewport.minDepth = 0.0f;
viewport.maxDepth = 1.0f;
</code></pre>

<p>viewport.width and viewport.height both equal 800.0f.</p>

<p>Projection matrices:</p>

<pre><code>struct UniformBufferObject{
  glm::mat4 model;
  glm::mat4 view;
  glm::mat4 proj;
};
</code></pre>

<p>projections:</p>

<pre><code>ubo.view = glm::lookAt(glm::vec3(2.0f, 2.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
ubo.proj = glm::perspective(glm::radians(45.0f), swapChainExtent.width / (float) swapChainExtent.height, 0.1f, 10.0f);
ubo.proj[1][1] *= -1;
</code></pre>

<p>This shows the circle, but it's almost as big as the window and it's tilted 45° away from me.</p>

<p>First of all, I don't understand why, if I make the first argument to glm::lookAt be glm::vec3(0.0f, 0.0f, 2.0f), I see nothing.  I mean the circle is in the x-y plane.  If I move in the z-direction, shouldn't I see it?</p>

<p>Then I tried glu::ortho</p>

<pre><code>ubo.proj = glm::ortho(0.0f, 800.0f, 800.0f, 0.0f);
</code></pre>

<p>But I still see nothing.</p>

CC BY-SA 3.0
2017-02-08T13:43:35.713Z
carefull vulkan and opengl expect different Z bound in clipspace. GLM should have a #define for that somewhere.
ratchet freak
<projections><vulkan><glm>
understanding glm::perspective vs glm::ortho
mikeglaz
# understanding glm::perspective vs glm::ortho

(Asked by: username_0 on 2017-02-08)

I'm new to computer graphics. I played around with OpenGL and now am trying out Vulkan.

Basically what I want to do, in 2D is have an 800x800 window, and I want that to represent 800 meters by 800 meters. Then I want a circle with a radius of 1 meter.

I am going off of the Vulkan tutorial.

My data structure is this:

```
struct Vertex {
    glm::vec2 pos;
};

```

I create my circle:

```
const int NUM_POINTS = 20;
uint32_t angle = 360/NUM_POINTS;
Vertex vertex;
std::vector<Vertex> vertices;

for(uint32_t i=0; i <= 360; i+=angle){
  vertex.pos.x = cos(glm::radians(float(i)));
  vertex.pos.y = sin(glm::radians(float(i)));
  vertices.push_back(vertex);
}

```

Something to do with the viewport:

```
VkViewport viewport = {};
viewport.x = 0.0f;
viewport.y = 0.0f;
viewport.width = (float) swapChainExtent.width;
viewport.height = (float) swapChainExtent.height;
viewport.minDepth = 0.0f;
viewport.maxDepth = 1.0f;

```

viewport.width and viewport.height both equal 800.0f.

Projection matrices:

```
struct UniformBufferObject{
  glm::mat4 model;
  glm::mat4 view;
  glm::mat4 proj;
};

```

projections:

```
ubo.view = glm::lookAt(glm::vec3(2.0f, 2.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
ubo.proj = glm::perspective(glm::radians(45.0f), swapChainExtent.width / (float) swapChainExtent.height, 0.1f, 10.0f);
ubo.proj[1][1] *= -1;

```

This shows the circle, but it's almost as big as the window and it's tilted 45° away from me.

First of all, I don't understand why, if I make the first argument to glm::lookAt be glm::vec3(0.0f, 0.0f, 2.0f), I see nothing. I mean the circle is in the x-y plane. If I move in the z-direction, shouldn't I see it?

Then I tried glu::ortho

```
ubo.proj = glm::ortho(0.0f, 800.0f, 800.0f, 0.0f);

```

But I still see nothing.

**Tags:** projections, vulkan, glm

> **Comments:**
> **username_1**: carefull vulkan and opengl expect different Z bound in clipspace. GLM should have a #define for that somewhere.  

---

## 1 answers

### Answer by username_2 on 2017-02-08. Score: 2

> I don't understand why, if I make the first argument to glm::lookAt be glm::vec3(0.0f, 0.0f, 2.0f), I see nothing.

It's because of the *up* vector. If you think about the look-at operation, you specify where the camera is and what point it's looking towards. These two things alone leave one degree of freedom: the rotation around that axis. Which way is up on your screen? The third argument is for specifying that: it's a direction in world space which will correspond to *up* on the screen. If your first argument is that and the rest of the code is as your example, you're calling `lookAt((0,0,2), (0,0,0), (0,0,1))`. Your up vector points along the $z$-axis, which is the same direction the camera is looking (well, the opposite direction. This can't define which way is *up* on the screen.

You probably want to pass a vector `(0,1,0)` as the third argument, which will make $y$ point up on your screen.

If you're making a plan view of a 3D scene, then perspective projection is probably the right answer, but if all your content is going to be in the $z=0$ plane, then you probably want to use an orthographic rather than a perspective projection. Look at [What's the difference between orthographic and perspective projection?](https://computergraphics.stackexchange.com/questions/2383/whats-the-difference-between-orthographic-and-perspective-projection) to learn more about that.

Last of all, remember that if you're projecting an $800m \times 800m$ scene onto $800 \times 800$ pixels, then a $1m$ radius circle will only be one pixel large. You probably need to scale up the size of your circle.

> **Comments:**
> **username_0**: Let me get this straight. So the 3 arguments to lookAt are eye, center, up.  Eye is the position of the camera.  I'm kind of confused on what center does.  Up is the where the top of the camera is pointing?  
> **username_2**: `center` is the point the eye is looking at, i.e. the point that will be in the middle of the screen. `up` is the direction (not a point) the top of the camera is pointing; i.e. if you draw a line from `center` in the direction `up`, this line will be in the 12 o'clock position on the screen.  

---

