[Cg1] Perspective Camera Code

Pascal Grittmann s9pagrit at stud.uni-saarland.de
Fri Nov 13 19:27:41 CET 2015



As some of you are still struggling with the perspective camera, here is the
C++ code.


aspectRatio = tan(horizonalOpeningAngle * 0.5f) / tan(verticalOpeningAngle *

focalLength = 1.0f / std::tan(verticalOpeningAngle * 0.5f);


spanX = cross(forward, up).normalize() * aspectRatio;

spanY = cross(cross(forward, up), forward).normalize();

focalVector = forward.normalize() * focalLength;


Vector dir = focalVector + x * spanX + y * spanY;


I strongly recommend everybody who is still struggling with this, to try and
understand the code. More detailed information can also be found on the
internet, for instance:





Pascal Grittmann

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.cg.uni-saarland.de/pipermail/cg1/attachments/20151113/49b75f0d/attachment-0001.html>

More information about the Cg1 mailing list