Jim Blinn's Corner

Jim Blinn

Mentioned 3

The author, a computer graphicist, shares his insight and experience in "Jim Blinn's Corner", an award-winning column in the technical magazine "IEEE Computer Graphics and Applications" in which he unveils his graphics methods and observations. This compendium presents 20 of the column's articles, leading you through the 'graphics pipeline'

More on Amazon.com

Mentioned in questions and answers.

I'm looking for an algorithm to fit a bounding box inside a viewport (in my case a DirectX scene). I know about algorithms for centering a bounding sphere in a orthographic camera but would need the same for a bounding box and a perspective camera. I can not just change the FOV because this app has FOV as a user editable variable, so it must move the camera.

I have most of the data:

  • I have the up-vector for the camera
  • I have the center point of the bounding box
  • I have the look-at vector (direction and distance) from the camera point to the box center
  • I have projected the points on a plane perpendicular to the camera and retrieved the coefficients describing how much the max/min X and Y coords are within or outside the viewing plane.

Problems I have:

  • Center of the bounding box isn't necessarily in the center of the viewport (that is, it's bounding rectangle after projection).
  • Since the field of view "skew" the projection (see http://en.wikipedia.org/wiki/File:Perspective-foreshortening.svg) I cannot simply use the coefficients as a scale factor to move the camera because it will overshoot/undershoot the desired camera position

How do I find the camera position so that it fills the viewport as pixel perfect as possible (exception being if the aspect ratio is far from 1.0, it only needs to fill one of the screen axis)?

I've tried some other things:

  • Using a bounding sphere and Tangent to find a scale factor to move the camera. This doesn't work well, because, it doesn't take into account the perspective projection, and secondly spheres are bad bounding volumes for my use because I have a lot of flat and long geometries.
  • Iterating calls to the function to get a smaller and smaller error in the camera position. This has worked somewhat, but I can sometimes run into weird edge cases where the camera position overshoots too much and the error factor increases. Also, when doing this I didn't recenter the model based on the position of the bounding rectangle. I couldn't find a solid, robust way to do that reliably.

Help please!

I don't have it at hand at the moment but the book you want is http://www.amazon.com/Jim-Blinns-Corner-Graphics-Pipeline/dp/1558603875/ref=ntt_at_ep_dpi_1

He has a whole chapter on this

Will you please provide me a reference to help me understand how scanline based rendering engines works? I want to implement a 2D rendering engine which can support region-based clipping, basic shape drawing and filling with anti aliasing, and basic transformations (Perspective, Rotation, Scaling). I need algorithms which give priority to performance rather than quality because I want to implement it for embedded systems with no fpu.

I'm probably showing my age, but I still love my copy of Foley, Feiner, van Dam, and Hughes (The White Book).

Jim Blinn had a great column that's available as a book called Jim Blinn's Corner: A Trip Down the Graphics Pipeline.

Both of these are quited dated now, and aside from the principles of 3D geometry, they're not very useful for programming today's powerful pixel pushers.

OTOH, they're probably just perfect for an embedded environment with no GPU or FPU!

I am trying to understand how I can draw a set of points (/set the pixels) that form a circle without using the library functions.

Now, getting the (x,y) co-ordinates of the points given the radius is straightforward.

    for (x=-r; x <r; x=x+0.1) {
         y = sqrt(r*r - x*x);
         draw(x,y, 0, 0);

But once I have the points, how do you actually draw the circle is what is confusing to me. I can use the graphic library but I want to understand how you can do it without using the graphics library

    void draw(float x, float y, float center_x, float center_y) {
          //logic to set pixel given x, y and circle's center_x and center_y
          // basically print x and y on the screen say print as a dot .
          // u 'd need some sort of a 2d char array but how do you translate x and y
          // to pixel positions

Could someone share any links/references or explain how this works?

It's a tough question because technically C doesn't have any built-in input/output capability. Even writing to a file requires a library. On certain systems, like real-mode DOS, you could directly access the video memory and set pixels by writing values into that memory, but modern OSes really get in the way of doing that. You could try writing a bootloader to launch the program in a more permissive CPU mode without an OS, but that's an enormous can of worms.

So, using the bare mimimum, the stdio library, you can write to stdout using ascii graphics as the other answer shows, or you can output a simple graphics format like xbm which can be viewed with a separate image-viewing program. A better choice might be the formats.

For the circle-drawing part, take a look at the classic Bresenham algorithm. Or, for way too much information, chapter 1 of Jim Blinn's A Trip Down the Graphics Pipeline describes 15 different circle-drawing algorithms!