• 15
• 15
• 11
• 9
• 10

# Arbitrary planar reflections

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

## 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 on other sites
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 on other sites
Quote:
 Original post by StonemonkeyHello,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.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.1502818763256073, "perplexity": 6489.526661687708}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2018-13/segments/1521257649627.3/warc/CC-MAIN-20180324015136-20180324035136-00566.warc.gz"}