Jump to content
  • Advertisement
Sign in to follow this  
maxalba

Ray Casting w/ Orthographic Camera

This topic is 4841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
};

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
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...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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?

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!