Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Arbitrary planar reflections

Started by HolyFish Dec 3, 2005 at 11:55 AM 1 replies 600+ views
Original Post
HolyFish
HolyFish
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!
Stonemonkey
Stonemonkey
Hello,
I'm not sure if this is what is wrong with what you're doing but you have to reverse which sides of your polys are visible otherwise things end up kind of inside out in the reflection.
HolyFish
HolyFish
Quote:
Original post by Stonemonkey
Hello,
I'm not sure if this is what is wrong with what you're doing but you have to reverse which sides of your polys are visible otherwise things end up kind of inside out in the reflection.

No, that's not the problem.
Everything is rendered "correctly" (walls and textures are where they should be), though the reflection isn't right: moving the camera around doesn't update the reflection correctly.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.