To render the scene from the other portals viewpoint, the camera position/rotation must be same relative to the other portal as it was to the first portal.

Of course the other portal will be facing out of the wall, while the first portal will be facing into the wall.

So if you camera is 5 meters in front of the first portal, it needs to be 5 meters inside the wall when rendering the scene from the other portals point of view.

This 'relative position/rotation' would normally be encoded in a 4x4 affine matrix and you would use matrix math to calculate the correct location for the camera.

The logic would be something akin to (portal1 and portal2 are matrices that hold the pos/rot of the portals):

Matrix relative = portal1:toObjectSpace(camera) Matrix renderFrom = portal2:toWorldSpace(relative) //if portal2 faces out of the wall and portal1 faces into it, this works. If not, I think you need to transpose/inverse the relative matrix first

I dont know how to express that using 'proper' matrix notation. Probably something like

relative = camera * inverse(portal1)

renderFrom = portal2*relative

(renderFrom = portal2*inverse(relative) if portal2 is pointing into wall just like portal1)

But Im really not sure.

If you are not using matrices, you can use the same logic as in the first piece of code except instead of matrices you do the operations on position/rotation or whatever it is youre using.

Also since the camera will be inside the wall when rendering the scene from other portals PoV, you need to make sure nothing behind the portal gets rendered somehow (unless required for reflections or whatever).