Author Topic: reversing camera space  (Read 2998 times)

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
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...

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
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.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: reversing camera space
« Reply #4 on: January 11, 2014, 04:58:59 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.