obtaining the view vector of the active camera

Compiling, libraries, modules, coding guidelines and porting

Moderators: jesterKing, stiv

Post Reply
Kai Kostack
Posts: 0
Joined: Tue Feb 07, 2006 5:24 pm

obtaining the view vector of the active camera

Post by Kai Kostack »

hi,

i'm working on the AdaptiveSubsurf modifier and i didn't found an appropriate function to obtain the view vector of the active camera yet. what would be the best way?

handydan
Posts: 0
Joined: Mon Nov 19, 2007 4:40 pm

Post by handydan »

After looking quickly at the source, I think you can get the camera's object matrix through "G->scene->camera.obmat". This may be different with multiple scenes or cameras. Although I'm not sure, I think if you multiply the matrix by a vector facing downward (because when the rotation of a camera is 0 it points downward), it will give you the vector of the camera.

You can find information about vector matrix multiplication here http://www.openscenegraph.org/projects/ ... formations I'm pretty sure blender uses opengl's standard.

The structures are defined in:
BKE_global.h
DNA_object_types.h
and DNA_scene_types.h

If you need any more help feel free to join #blendercoders on freenode,

Hope this helps,

Dan

Kai Kostack
Posts: 0
Joined: Tue Feb 07, 2006 5:24 pm

Post by Kai Kostack »

thank you, it works.

Code: Select all

float camVec[3] = {0,0,1};
Mat4Mul3Vecfl(G.scene->camera->obmat, camVec);
after this camVec contains the correct camera vector.

handydan
Posts: 0
Joined: Mon Nov 19, 2007 4:40 pm

Post by handydan »

ohh... so close [= , an upward vector instead of a downward one (that would have been my second choice) and I put G->scene->camera.obmat instead of G.scene->camera->obmat. Sorry my bad.

Just make sure that G.Scene->camera and G.scene->camera->obmat aren't null pointers before calling them, otherwise you'll get some weird results or a segmentation fault.

Dan

Post Reply