user1429171
user1429171

Reputation: 165

Understanding Assimp's camera output

I'm writing a program to display 3d scene using Assimp3.0.

My work flow is:

  1. Blender2.71 export fbx.
  2. Assimp read fbx file.

The camera attribute from aiCamera is strange.


I have a camera in blender with:

(blender's coordinate)

location : (0, -5, 0)

rotation : (90, 0, 0)

This should be a simple front view camera.


Since Assimp will rotate all models -90 degree along x-axis I suppose Assimp will change this camera to

(OpenGL's coordinate (x : right) (y : up) (z : out of screen))

postion : (0, -5, 0)

up : (0, 0, 1)

lookAt : (0, 1, 0)


But in the aiCamera struct I got:

mPosition : (5, 0, 0)

mUp : (0, 1, 0)

mLookAt : (0, 0, 1)


What's the correct way to use aiCamera?

Upvotes: 1

Views: 1578

Answers (1)

Thorbjorn
Thorbjorn

Reputation: 317

An aiCamera lives in the aiNode graph. To quote the documentation for aiCamera and aiNode

aiCamera: Cameras have a representation in the node graph [...]. This means, any values such as the look-at vector are not absolute, they're relative to the coordinate system defined by the node which corresponds to the camera.

aiNode: Cameras and lights are assigned to a specific node name - if there are multiple nodes with this name, they're assigned to each of them.

So somewhere in your node graph there is a node with the same name as your camera. This note contains the homogeneous transformation matrix corresponding to your camera's coordinate system. The product T*v will translate a homogeneous vector v from the camera coordinate system to the world coordinate system. (Denoting the root coordinate system as the world system and assuming the parent of the camera is the root).

The mPosition, mUp, and mLookAt are given in coordinates of the camera coordinate system, so they must be transformed to the world coordinate system. It is important to differentiate between mPosition which is a point in space, and the mUp and mLookAt which are direction vectors. The transformation matrix is composed of a rotation matrix R and a translation vector t.

       R   |  t
T = --------------
     0 0 0 |  1

mPosition in world coordinates is calculated as mPositionWorld = T*mPosition, while the direction vectors are calculated as mLookAtWorld = R*mLookAt and mUpWorld = R*mUp

In c++ the transformation matrix can be found by the following (assume the aiScene 'scene' has been loaded):

//find the camera's mLookAt
aiCamera** cameraList = scene->mCameras;
aiCamera* camera = cameraList[0] //Using the first camera as an    example
mVector3D camera->mLookAt;

//find the transformation matrix corresponding to the camera node
aiNode* rootNode = scene->mRootNode;
aiNode* cameraNode = rootNode->FindNode(camera->mName);
aiMatrix4x4 cameraTransformationMatrix = cameraNode->mTransformation;

The rest of the calculations can then be done using Assimp's linear algebra functions.

Upvotes: 2

Related Questions