Jump to content
  • Advertisement
Sign in to follow this  
HolyFish

Arbitrary planar reflections

This topic is 4764 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!