Author Topic: reversing camera space  (Read 1157 times)

raft

• Posts: 1984
reversing camera space
« on: January 09, 2014, 09:52:07 pm »
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

• Posts: 11884
Re: reversing camera space
« Reply #1 on: January 09, 2014, 10:19:47 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

• Posts: 1984
Re: reversing camera space
« Reply #2 on: January 10, 2014, 01:09:18 pm »
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

• Posts: 11884
Re: reversing camera space
« Reply #3 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?

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