2
$\begingroup$

I've the following problem:

Let the camera opening angle be $\frac{3}{4}\pi$ and the window be $15 \times 15$ pixels large.

Which pixels does the midpoint algorithm (without anti-aliasing) set for the line from $p_1 = (1, 1, 4)$ to $p_2 = (2, 1, 1)$, given in global coordinates?

My question are:

  1. Why is the detail that the points are given in global coordinates important?

  2. Could the points be given in local coordinates? If yes, how would they would look like? How would that affect the answer?

  3. What would that mean local coordinates in this case?

I think I understood what are local coordinates, i.e. coordinates of an object given with respect to a local system to the object. I think that global coordinates at the end are just local coordinates with respect to the camera or the viewer. Am I right?

Note: I'm not asking you to solve the problem, i.e. telling me which pixels are set, maybe I'm going to ask another question regarding that.

$\endgroup$
3
$\begingroup$

When drawing objects that exist in 3D space to a 2D plane (like your monitor or an image), there are a number of spaces that are useful to work in:

  • Global Coordinates - Somewhere in your 3D world there is an origin, and objects will be placed relative to that origin. The camera will also be placed somewhere relative to that origin and will point in some direction in the world.
  • Object Coordinates - If you have 3D objects in your scene, they are generally created outside of the world and then transformed in some way to be placed in the world. You might create, say, a chair, with the origin of the chair where the front right leg touches the ground. In Object space, that's (0,0,0). But you'll transform that chair to where it needs to go in the scene and put it at some location in world (global) coordinates.
  • View Coordinates - Your virtual camera, as mentioned above, is placed somewhere and is pointing at something. Whatever your camera is pointing at will generate a space relative to the camera. You can think of the camera as always being at the origin of camera space.
  • Clip Space - eventually during rendering, you will use a projection matrix of some sort (perspective, orthographic, etc.) to render the final image. When running your geometry through this matrix, any coordinates that end up outside of [-1..1] will be clipped out. (In some cases [0..1] is used instead, but this detail doesn't change the point.)

  • Screen Space - finally, after you've clipped everything and gotten it into normalized coordinates, you then have to flatten it to 2D and display it to the user. This is screen space, and is often the same as the pixels (or some portion of them) on the user's physical display (or in an image if your rendering to an image).

So in the original problem, you've been given the requirement of having a field of view for your camera of 135° (3/4π radians), and a window that's 15x15 pixels large. So you need to construct a projection matrix with a 135° field of view and an aspect ratio of 1:1.

The view parameters aren't specified in your problem, so I guess the camera is at the world's origin, so camera/view space and world space are the same for now.

Normally, you'd take the world coordinates, (p1 and p2) and multiply them by the view matrix (identity here, so no work to do), then multiply that result by the projection matrix to get to clip space. Once you have coordinates in the normalized range, you can multiply them by the window's size (15x15 in this case) to get them into screen space and determine which pixels to set.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Ok, thanks for trying to clarify all of these! But I would to know in particular why they are giving us the points in global coordinates and how does it affect my calculations of the pixels that are set. $\endgroup$ – nbro Nov 16 '16 at 0:10
  • 1
    $\begingroup$ I've expanded my explanation to show how it relates to your problem. I suspect there are parts you might not be required to do yet, as the problem doesn't specify a view matrix (or camera position and orientation). So it might not be a 1:1 mapping of your problem, but hopefully will get you going in the right direction. $\endgroup$ – user1118321 Nov 16 '16 at 0:56
0
$\begingroup$

I think the mention of "global coordinates" is a lead to the next lecture of learning different coordinate systems (object, camera, etc.), so you are kind of jumping a head I suppose (:

The points could indeed be given in local coordinates, which would then require definition of transformation from local to global coordinate system, and understanding how this transformation is performed. This transformation is usually defined as a 4x4 matrix, and the 3D points are defined as homogeneous coordinates [x, y, z, 1], which are multiplied with the matrix to bring them into global coordinate system.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Not really, actually. I we have already treated global and local coordinates systems, but my question was more related to the fact to why, for example, as you're saying, would I need to convert the coordinates to global coordinates, if they were given as local coordinates. I mean, what's the relevance of the coordinate system in this case/problem given in my question. $\endgroup$ – nbro Nov 18 '16 at 12:35
  • $\begingroup$ You need to convert from local to global coordinate system to define objects position and orientation in the world. In local coordinate system objects are defined relatively to their pivot point (e.g. object center), so that you can move and rotate the object about that point in the world, by defining the local$\rightarrow$global transformation. The "global coordinates" is there to disambiguate the coordinate system in question and that you don't need to worry about this transformation. What's confusing though is that there's no disambiguation of the camera coordinate system. $\endgroup$ – JarkkoL Nov 18 '16 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.