Original Post
Hi, I'm having wierd problems trying to reflect a scene along an arbitrary Plane (not Axis-aligned). Here is what I currently do: - Reflect the camera position against the plane...
public void reflectCamera(Plane plane)
{
Vector3 pos = camera.getPosition();
Vector3 n = plane.normal;
float distance = (n.x*pos.x + n.y*pos.y + n.z*pos.z + plane.constant) / Vector3.Magnitude(n);
Vector3 reflectedPos = Vector3.Add(pos, Vector3.multiplyByScalar(n, -2*distance));
}
- Reflect the View direction...
public void reflectView(Plane plane)
{
Vector3 viewDir = camera.getView();
Vector3 n = plane.normal;
float distance = (n.x*viewDir.x + n.y*viewDir.y + n.z*viewDir.z + plane.constant) / Vector3.Magnitude(n);
Vector3 reflectedView = Vector3.Add(viewDir, Vector3.multiplyByScalar(n, -2*distance));
}
- Set the ModelView matrix...
GLU.gluLookAt( reflectedPos .x, reflectedPos .y, reflectedPos .z,
reflectedView .x, reflectedView .y, reflectedView .z,
camera.getUp().x, camera.getUp().y, camera.getUp().z);
- Render the scene using the modifed ModelView matrix in the Mirror using the Stencil buffer. I'm probably making an enourmously stupid mistake but the scene isn't rendered correctly (it's hard to explain in words, but the scene isn't reflected correctly). The camera-position is reflected correctly so I think my reflected View-vector is wrong...I'm probably overlooking something, but I can't see what at the moment. It is correct I just have to reflect the Viewdirection, right? Thanks in advance!