Installing Cuda on Ubuntu 11.10
To install Cuda, I followed some hints on bottom of this thread, but also had to fix a few more issues.
Download the current Cuda Toolkit for Ubuntu and the GPU Computing SDK, and save the .run files somewhere.
Install and select gcc/g++ 4.4
sudo apt-get install \ gcc-4.4 g++-4.4 build-essential sudo update-alternatives \ --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 40 \ --slave /usr/bin/g++ g++ /usr/bin/g++-4.6 sudo update-alternatives \ --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 60 \ --slave /usr/bin/g++ g++ /usr/bin/g++-4.4Check with
sudo update-alternatives —config gcc gcc —versionthat you have now version 4.4.x of the compilers.
Install the nvidia drivers
sudo apt-get install \ nvidia-current\ nvidia-current-dev\ nvidia-current-updates\ nvidia-current-updates-devAs root, run the two .run files from nvidia (see 1.).
For compiling the SDK examples, you also need to install
sudo apt-get install freeglut3-dev libxi-devand create the following links
sudo ln -s /usr/lib/libXmu.so.6 /usr/lib/libXmu.so sudo ln -s /usr/lib/nvidia-173/libGL.so /usr/lib/libGL.soThen go to the
NVIDIA_GPU_COMPUTING_SDK_...folder. In the fileC/common/common.mkchange the lineLINKFLAGS +=to
LINKFLAGS += -L/usr/lib/nvidia-currentThen run make. This should compile everything, indicating that the CUDA stuff works.
How to convert Blender camera settings into a projection matrix
I was looking for an easy way to derive a projection matrix corresponding to
the camera of images rendered with blender. Given
such a 3x4 projection matrix P, I want to define a 3D point in the blender
scene, multiply it with the matrix and paint it into the existing image. For
example, using Matlab to draw the scene origin as a red plus sign onto the
image, I want to write
imshow('blender_img.jpg');
hold on;
X = [0 0 0 1]';
x = P*X;
x = x(1:2)/x(3);
plot(x(1),x(2),'r+');
hold off;
Deriving P turns out to be not documented at all, and besides knowledge on the computer graphics pipelines requires some trial and error. Today I managed to solve the problem, so here's the solution.

First of all, collect the camera position and orientation from the "Transform Properties" dialog, as shown in the image above. In Matlab you get the translation vector and rotation matrix via
X0 = [2 -10 4]';
o = 70*pi/180;
p = 15*pi/180;
k = -10*pi/180;
Ro=[1 0 0; 0 cos(o) -sin(o); 0 sin(o) cos(o)];
Rp=[cos(p) 0 sin(p); 0 1 0; -sin(p) 0 cos(p)];
Rk=[cos(k) -sin(k) 0; sin(k) cos(k) 0; 0 0 1];
R = Rk*Rp*Ro;
Now we need to derive the calibration matrix. Unfortunately, the focal length
value in blender is neither documented nor standard. However, it is possible to
display the lens angle alpha in degrees, referring to the wider image
dimension, as shown in the image below. In the example we have alpha=49.13.

From the image resolution, which is here assumed to be 800x600, we get the
focal length in pixel from fl=-400/(49.13*pi/180/2). Observe the minus!
The final projection matrix P is obtained in Matlab using
fl = -400/tan(49.13*pi/180/2);
K = [fl 0 400; 0 fl 300; 0 0 1];
P = K*diag([1 -1 1])*R'*[eye(3) -X0];
Thanks to Daniel Berjon at Disney Research for pointing me to the tangens that
was missing in the above code snippet. Note the flipping of the y axis which
results in a left handed system. A
student is planning to write an export script for blender to write
P to file.