Lesson 26 : Reflections

Started by
4 comments, last by jeffgazet 20 years, 5 months ago
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.
Advertisement
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
Defeat only makes me wiser
Thanks for your help.
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.
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
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.
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

This topic is closed to new replies.

Advertisement