elezaza

04-24-2007, 09:01 AM

Hi,

I need the direction vector of the camera in my shader. Is there an easy way to find it in a shader ( I don't wants the direction between the camera and the current vertex but the direction of the camera)

best regards

canuckle

04-24-2007, 12:26 PM

Elezaza:

The camera's direction is <0, 0, -1> in camera coordinate system. If you would like to get this vector in Model (or World) coordinate system, then multiply it by the CameraToModel (or CameraToWorld) matrix. Notice the *direction* <0, 0, -1> is represented as <0, 0, -1, 0> in homogenous space.

The OpenGL ModelView matrix is the ModelToCamera matrix (that is, when you multiply a vector by this matrix, you transform it from Model coordinates to Camera coordinates). Therefore, if you take its inverse, you get the ModelToCamera matrix. Multiply that by <0, 0, -1, 0> and you get the camera's direction vector in Model space: <x, y, z, 0> (you can drop the last zero after).

Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.