#### Archived

This topic is now archived and is closed to further replies.

# Lesson 26 : Reflections

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

## Recommended Posts

Hi, i have some trouble with reflection, what if we move around the ground : left, right, up and down, but always looking at the center of the ground ? we have to change the clip plane equation, but i can''t understand how... Regards, and great thanks to NeHe.

##### Share on other sites
If it''s the ground that you''re moving, then you have to do just one thing. Before you invert the world with glScalef, you have to do a translation so that your reflective plane/ground intersects the origin. If you don''t do this then the objects won''t be reflected respect to the plane but to the origin. Also, if you don''t do it, the objects won''t be propperly culled.

The equation of the clipping stays the same if what you are doing is just translating the plane (moving it up, down, etc). If you rotate the plane, then you have to rotate the clipping plane equation the same way.

That''s it, hope I''ve helped you.

(First post, yay!!)

Defeat only makes me wiser

##### Share on other sites
In fact, the reflected objects are all right, they move with the board. But we can see them under the board, anytime. Even without rotation, there is no clipping on the side of the board.

##### Share on other sites
I don''t know if this is your problem, but try this:

When writing to the stencil buffer ( when you are drawing the reflector in the stencil buffer), you only want to draw the side that is facing you. To do this, cull the back face

glCullFace( GL_BACK );
glEnable( GL_CULL_FACE );

//draw reflector into stencil

//disable if you need/want to
glDisable( GL_CULL_FACE );

Sorry if you already know how to cull faces, but I just want to make sure

##### Share on other sites
Thanks, i did''nt know about cullface, i''m quite newbie with OpenGL. I tried and i saw what it did, but this doesn''t solve the problem.

Here is a screenshot, i think you''ll have a better idea :
http://wjchess.jeffprod.com/images/wjc3dreflection.gif

Nehe was kind to answer me by mail : "You don''t clip under the board", but i do clip ! :-(

I tried all i could.

##### Share on other sites
It looks like the problem is the stencil buffer. Before rendering your reflected objects you need to stencil the reflective area so that the any objects that overlap outside of the reflective area don''t get drawn. Are you using the stencil buffer? If not then you need to do so. If you are then I suspect there is something wrong with this bit of your code.

Enigma

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631706
• Total Posts
3001835
×