Portals Math Problem

Hello!
So, i guess i’m stuck with math.
I’m working on Portals right now, and currently i’m doing it like this:

Get the Rotation from my Camera to my Portal #1, and set the rotation of Portal 2 to that.

Works, kinda.

But, of course i have to include my rotation of my camera too.

Any idea how i get the correct rotation?

Do not use rotation, instead use vectors. Portals work like modified mirror, or rather split in two (one part is before light bounces, second is after light bounces). To get clear idea about it look at some optics and mirror drawings.
Get that done for 2 parallel portals first.

Then all you need to do is rotate result vector by difference of angles for 2 portals (Dot product between their 2 normals is cos of that angle).

Ps. I have suspicious feeling that with angles you get some edge cases around +180 and -180, and vectors are way to go whatever possible.