Original Post
Hello all. I have made a lot of progress from my last post here, but I have encountered another snag. I've been following Reimer's tutorial on terrain, and am trying to create water reflections. I've done his jpg output debugging and my Refraction map looks perfectly correct. My problem is with the reflection map. The difference between my code and his is that I'm storing my camera's orientation in a quaternion whereas he has a simpler implementation, so I am having difficulty figuring out how to get the reflection camera. I understand that I need Camera B's position, target and up vector. This is the code I have to figure them out based on the camera's Orentation quaternion. Note that Camera A is an orbit camera, so its target is always player1.Position.
Matrix cameraRotation = Matrix.CreateFromQuaternion(camera.Orientation);
Vector3 cameraFinalTarget = Player1.Position;
Vector3 reflCameraPosition = camera.Position;
reflCameraPosition.Y = -camera.Position.Y + waterHeight * 2;
Vector3 reflTargetPos = cameraFinalTarget;
reflTargetPos.Y = -cameraFinalTarget.Y + waterHeight * 2;
Vector3 cameraRight = Vector3.Transform(new Vector3(1, 0, 0), cameraRotation);
Vector3 invUpVector = Vector3.Cross(cameraRight, reflTargetPos - reflCameraPosition);
reflectionViewMatrix = Matrix.CreateLookAt(reflCameraPosition, reflTargetPos, invUpVector);
I have tried to model the code Reimer uses in his UpdateViewMatrix function, but I can't seem to get it to work right for quaternions. I get endlessly repeating patterns of little sky ovals stretching away into the distance between huge black bands. Is this enough information, or should I post a screenshot?