reversing camera space

Started by raft, January 09, 2014, 09:52:07 PM

Previous topic - Next topic

raft

I have a default camera at origin looking through z axis. I also have an object in camera's field of view with some rotation and translation. I want to place the object to origin with no transform (identity matrix) and place camera such that what camera sees was identical to before. how to do that?

I'm planning to take the object's world transform, invert it and set as back buffer to camera? not tried yet.

EgonOlsen

Quote from: raft on January 09, 2014, 09:52:07 PM
I'm planning to take the object's world transform, invert it and set as back buffer to camera? not tried yet.
Not so good. It might work, but it will stuff the translation into the matrix instead of keeping it separated. That will cause the lighting calculations to fail. If you don't use any light sources, it might work.

It's better to move the camera by the object's negative translation and setBack() with the inverted rotation matrix of the object. That should work IMHO...

raft

neither will work I suppose. applying inverse rotation of object to camera does not make sense in this case. ie: when camera is at origin, rotation of object does not change object's location at screen, but when that rotation is applied to camera, camera's field of view changes.

I guess the right way is:

* calculate reverse object translation
* rotate that by inverse of object rotation
* move camera to that point
* rotate camera by object rotation

BTW, can I use a detached camera in Interact2D.reproject2D3D? i.e. a camera which is not actually used to render scene

EgonOlsen

Isn't it much simpler? Isn't it just to translate the camera by the reverted vector from the origin of world space to the object's origin in world space?

About the camera in Interact2D...just try it. It should be OK, but i'm not 100% sure.

raft

Quote from: EgonOlsen on January 10, 2014, 05:17:46 PM
Isn't it much simpler? Isn't it just to translate the camera by the reverted vector from the origin of world space to the object's origin in world space?
that camera will see the same scene but I also want the object has no rotation.