View Full Version : Tilted Mirror ?
DarkShadow44
09302009, 05:53 AM
I'm using the Nehe Example 26, can you say, how I can use tiled mirrors and multimirrors ?
What if there is a mirror in front of another ?
And how can I rotate a mirror ?
Thanks for your help in advance !
trinitrotoluene
09302009, 08:28 AM
For tilted mirror you can read this file (http://www.opengl.org/resources/code/samples/mjktips/TimHall_Reflections.txt) at section 2.
Try to avoid the case where two mirrors are exactly parallel because in real life it generate and infinite recursion of the scene in the mirror. With the above technique, I think you can only draw the first iteration of the recursion in each of the parallel mirror, so it doesn't look real but it's better than nothing.
DarkShadow44
09302009, 11:14 AM
I didn't find it in this file...
I mean like rotated 23° around the Xaxis ore something like that...
That is complicated because of the clipping...
And isn't there a possibility to draw this recursion (10 mirrors deep for example), can I do that with Raytracking, or is that something else ?
trinitrotoluene
09302009, 12:42 PM
Did you find this in the file?
It is relatively straight forward to render a scene with reflections
in the floor. What if the mirror is placed and oriented arbitrarily in
the world? This complicates the construction of the reflection matrix.
Conceptually the steps to construct this reflection matrix are:
1. The mirror and object in world coordinates
 < Mirror





 @
 ^Object

2. Transform into mirror space, so the mirror lies in the XY plane and passes
through the origin. This is the inverse of the mirror's transformation
matrix.
__________________________
@
3. Now reflect about the Zaxis. ie scale by x = 1.0, y = 1.0, z = 1.0
@
__________________________
4. Finally transform back to the mirrors original position. This is the
mirror's original transformation matrix.






@ 


The position of the object is now reflected about the plane of the mirror.
In a more direct form three matrices are needed.
MirrorT  The transformation that maps the mirror into world
space.
MirrorT'  The inverse of MirrorT. This maps from world space to
mirror space.
ScaleZ  A scale matrix with a scale of 1.0 in z.
reflectionMatrix = MirrorT * ScaleZ * MirrorT'
(Note: This assumes vertices are represented as column vectors. If
the application uses row vectors the order of the matrix multiplies
will have to be reversed.)
The reflection matrix can be used in the same manner as the previous
example.
And isn't there a possibility to draw this recursion (10 mirrors deep for example), can I do that with Raytracking, or is that something else ?
You can limit the recursion 10 mirrors deep for example, but it can hurt a lot the performance of your OpenGL program if complex objects are between the mirrors. In the case of 10 mirror deep, you have to draw each object at least 20 + 1 times with the right transform matrix.
For Raytracking do you mean ray tracing? If you do not need real time rendering, rendering scene with mirror is a lot easier with ray tracing.
knackered
09302009, 03:31 PM
what a lovely little article, thanks. Feel very nostalgic now.
DarkShadow44
02102010, 01:21 PM
Sorry, it still doesn't work. I used this Thread, because so I don't have to create a new Thread.
If I use the method of this text, it is not mirrored at the zaxis.
An with my method, it works only with x OR y rotation...
What's wrong, when I use both at the same time ??
float ObjectRX=2*SpiegelRX;
float ObjectRY=2*SpiegelRY;
float SpiegelMitte[3]={(XmaxXmin)/2+Xmin, (YmaxYmin)/2+Ymin+yyyyy, (ZmaxZmin)/2+Zmin+zzzzz};
float KugelMitte[3]={xxx,yyy + height,zzz};
float diff[3];
int i;
for(i=0;i<3;i++)
{
diff[i]=SpiegelMitte[i]KugelMitte[i];
}
GLdouble matrixReverse[16];
int i;
for(i=0;i<16;i++)
{
matrixReverse[i]=matrix[i];
}
MatrixInverse(matrixReverse);
changeMatrix(matrix);
changeMatrix(matrixReverse);
glTranslatef(0.0f, height, 0.0f);
glTranslatef(xxx+1,yyy,zzz);
glRotatef(xrot, 1.0f, 0.0f, 0.0f);
glRotatef(yrot, 0.0f, 1.0f, 0.0f);
glMultMatrixd(matrixReverse);
glScalef(1,1,1);
glMultMatrixd(matrix);
//My alternative Method:
glRotatef(ObjectRY,0,1,0);
glRotatef(ObjectRX,1,0,0);
glTranslatef(diff[0],0,0);
glTranslatef(0,0,diff[2]);
glTranslatef(0,diff[1],0);
//Draw mirrored object:
DrawObject();
Hope you can help me. :sorrow:
I tried to get that to work, but I always found a position of the mirror where the ball is not correctly reflected...
trinitrotoluene
03022010, 03:37 PM
DarkShadow44, sorry for reading your post late. What algorithm do you use for inverting your matrix?. I will try to make a simple demo program to implement the algorithm and I will post my solution here if it successful.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.