Ray Casting w/ Orthographic Camera

Started by
5 comments, last by timw 18 years, 8 months ago
I wish to setup a very basic ray casting Orthographic Camera for use in a medical imaging tool I am working on... However, I think that there is a bug in my OrthographicCamera Class - how I generate the ray or even in my constructor maybe? Could someone double check my work? Mant Thanks.

class OrthographicCamera : public Camera
{
public:
   OrthographicCamera(vector3f c, vector3f d, vector3f u, float s) : center(c), direction(d), up(u), size(s)
   {
      direction.Normalise();
      up.Normalise();
      horizontal = vector3f::Cross(direction, up);
   }

   virtual Ray GenerateRay(vector2f point) // A Point on screen (unit square [0,0]-> [1,1])!!!
   {
      float fx = center[x] + (point[x] - 0.5f) * size * up[x] + (point[x] - 0.5f) * size * horizontal[x];
      float fy = center[y] + (point[y] - 0.5f) * size * up[y] + (point[y] - 0.5f) * size * horizontal[y];
      
      Ray r(vector3f(fx, fy, center[z]), direction);

      return r;
   }

   virtual float GetTMin() const
   {
      return FLT_MIN; /* From float.h. */
   }

protected:

private:
   vector3f center;
   vector3f direction;
   vector3f up;
   vector3f horizontal;
   float size;
};

Advertisement
I'm guessing that your up vector is NOT always up?

What you want to do is normalize the up and direction vertors. Then FIND a vector that is perpendicular to the direction!!! The up vector is not always perpendicular to the direction!!! The dot product comes to mind... ...and that is all the help I can render.

Hoping someone else can finsh the question/problem...
So in summary:

The input direction might not be a unit vector and must be normalized. The input up vector might not be a unit vector or perpendicular to the direction. It must be modified to be orthonormal to the direction. The third basis vector, the horizontal vector of the image plane, is deduced from the direction and the up vector (the cross product!) - like you have.

I can not help you with "[the up vector] must be modified to be orthonormal to the direction"...

Anyone?
Yeah, you have said it better than I did.

So can anyone help? The silly spec states that the "up" vector may or may not be "up". Go figure...
I'm not sure if I fully understand the question, but to readjust the up vector so it's perpendicular (and lies in the same plane as direction and the original up vector), you'd simply recalculate it from direction and horizontal after calculating horizontal:
direction.Normalise();up.Normalise();horizontal = vector3f::Cross(direction, up);up = vector3f::Cross(horizontal, direction);
Yeah, thanks, I tried that just now, but still no luck.

I'm now thinking it may not be my OrthographicCamera class after all.

Does anyone have a ready made or know a link to a OrthographicCamera class in C++/Java? So I can compare my class to it.

Thanks peeps!
ray casting wiht orthographics is just as simple as with perspective, even easier.

suppose you're view plane is defined as the plane specivied by the 4 pts
a,b,c,d

where a is the top left and d is the bottom right


width(in world space) = mag(b - a);
height(" " " " " ) = mag(c - a);

if I want to cast a ray from pixel i, j into the world I use something like this

widthScreen, heightScreen = width and hight in pixels(not the same as above)

create a basis for the plane the points on the plane are all the points satifiying the equation

P = s*(b - a) + t*(c - a)

where s, t <= 1 and >=0
note that s,t are scalers and a,b,c,d are vectors. this is just a convienet parameterization for a plane. so to cast a ray from pixel i, j I do this

P = (i/widthScreen)*(b - a) + (j/HeightScreen)*(c - a)

now this P is the origin of our ray and the direction for our ray is simply the view direction. all of our rays will have the same direction because it's orthographic of course. this respect it's even easier then casting form perspective situations.. hope it help

Tim

This topic is closed to new replies.

Advertisement