Jump to content


Perspective matrix problem


9 replies to this topic

#1 Bazukaz

    New Member

  • Members
  • Pip
  • 3 posts

Posted 08 March 2007 - 03:23 PM

Hi ,
I have written a class to rotate 3d objects.I followed this article : http://en.wikipedia....i/3D_projection

I used the formula :

V' = C*B*A*V , where :

C - perspective matrix,
B - camera matrix,
A - rotation matrix,
V - points coordinates.
V' - point's coordinates after transformation.

Everything works all right , until I add perspective matrix.
x'/w' and y'/'w are not in the range they should be (<-1 or >1),
and the results are undefined.
What can be the problem ? Is it possible that there are errors in wikipedia's article ?

Regards,
Lukas.

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 08 March 2007 - 04:31 PM

The results will be outside of [-1, 1] if the point falls outside the camera's field of view. You'll need to do clipping after you do the perspective transformation and before you divide by w.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 Bazukaz

    New Member

  • Members
  • Pip
  • 3 posts

Posted 08 March 2007 - 05:17 PM

Reedbeta said:

The results will be outside of [-1, 1] if the point falls outside the camera's field of view. You'll need to do clipping after you do the perspective transformation and before you divide by w.

I don't think that clipping is the problem.If i try to draw my cube with perspective enabled , it no longer looks as a cube , but rather a strange figure ,
that transforms to totally differently looking figures if i try to rotate it :(.
I tried tried to check if -1<= z'/w' <=1 , but , in this case , the whole figure is clipped out , regardless of parameters i supply(back , front of clipping plane , and angles).

#4 Dom_152

    Member

  • Members
  • PipPip
  • 67 posts

Posted 08 March 2007 - 05:38 PM

This sounds like the same problem I'm having. If you can solve it it would be much appreciated.

#5 Rubicon

    Member

  • Members
  • PipPip
  • 90 posts

Posted 08 March 2007 - 06:58 PM

Just a thought: Are all your matrices following the same handedness ?

The article on wikipedia looked wrong to me because I'm more used to using D3D style left-handed systems. Wikipedia's is equally valid, but right-handed. You need to pick a method and stick to it for all of them else the world will end.
Regards, Paul Johnson
www.rubicondev.com
My Free 3D Tower Defence Game

#6 SigKILL

    Valued Member

  • Members
  • PipPipPip
  • 200 posts

Posted 08 March 2007 - 09:01 PM

That projective transform looks kind of fishy, but I'm not in a mood to check it. What you could do is use the projective transformation described in the red-book appendix (which ofcourse is exactly what glFrustum() outputs). If you don't know the red-book (which you all should) you can find it online by googling for red book and opengl...

The worst part of the article is probably the "Note about terminology" section which should have been written by someone who knows what he/she is talking about.

#7 Rubicon

    Member

  • Members
  • PipPip
  • 90 posts

Posted 08 March 2007 - 09:22 PM

Agreed, it's a bit of a mess.

There is a pretty good description of all this stuff in the D3D help amongst the fixed-function pipeline stuff. Even if you're not using the FFP, or D3D at all for that matter, it's still a good read.
Regards, Paul Johnson
www.rubicondev.com
My Free 3D Tower Defence Game

#8 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 08 March 2007 - 11:26 PM

Hmm. That article uses 'omega' instead of w, too. Maybe I'll clean it up one of these days...(or, one of you can do it, it's a wiki after all. :lol:)
reedbeta.com - developer blog, OpenGL demos, and other projects

#9 Rubicon

    Member

  • Members
  • PipPip
  • 90 posts

Posted 09 March 2007 - 09:34 AM

Nah, you get too many people moaning about the slightest innacuracy :)
Regards, Paul Johnson
www.rubicondev.com
My Free 3D Tower Defence Game

#10 Bazukaz

    New Member

  • Members
  • Pip
  • 3 posts

Posted 09 March 2007 - 01:49 PM

Hi,
Finally, i solved the problem. I swapped the coordinates x , z and x,y (like in mathematics usually is) , while still using PC - like coordinates while generating matrixes :). So i couldn't set up camera's coordinates properly , and perspective projection didn't work.
BTW , the perspective matrix in Wikipedia's article is almost the same as generated in OpenGL's glPerspective() , the only difference is that OpenGL uses one angle and aspect ratio and in wikipedia there are two angles.
Thanks for all of your help anyway.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users