| Topic: Efficient reflection matrix
|
|
 | Efficient reflection matrix | |  |
| Poster | : lordikon | | Posts | : 57 | | Country | : USA | | City | : Denver |
| | | | Posted by lordikon on 30/09/2007 at 00:46:34
| | Riemer,
Been playing around with your water tutorial, and I wanted to let you know I found a decent way of creating the reflectionView matrix. Not sure if it is more efficient or not, I'll let you be the judge, just thought I'd post it.
Vector3 reflectPos = Cam.GetPosition();
reflectPos.Z = Elevation - (reflectPos.Z - Elevation); // Move camera under the water
Vector3 reflectForward = Cam.ForwardVector;
reflectForward.Z *= -1;
ReflectionViewMatrix = Matrix.CreateLookAt(reflectPos, reflectPos + reflectForward, Cam.UpVector); | |
|
| | | | | | Poster | : riemer | | Posts | : 1388 | | Country | : Belgium | | City | : Antwerp |
| | | | Posted by riemer on 30/09/2007 at 05:33:23
| | Hmmm not sure if this will always work :)
I'll just give some thoughts on this, dont take them as comments as I think people playing around with the code is the best appreciation of a tutorial.
This line
reflectPos.Z = Elevation - (reflectPos.Z - Elevation);
|
is the same as
reflectPos.Z = -reflectPos.Z + 2*Elevation;
|
which is what I use. The way you calculate the reflectForward vector is not 100% correct, as it does not take the height of the water into account. Using your code , you should do something like
Vector3 reflectForward = Cam.ForwardVector;
reflectForward.Z = Elevation - (reflectForward.Z - Elevation);
|
Try to increase your Elevation value, you should see you're getting strange results.
As you can see in the image on my page, both cameras have a different Up vector. If you specify Cam.UpVector as Up vector for your underwater cam, XNA projects this axis for you, which will be correct in 99% of the cases (probably even more ;), in my text I've calculated the exact vector, based on cross product between forward and side vector.
anyhow, you showed you understand the principle of reflection, and that's the main goal of that page ;) | |
|
| | | | | | Poster | : Anonymous | | Posts | : | | Country | : | | City | : |
| | | | Posted by Anonymous on 14/02/2009 at 09:11:45
| | I think that this image could be useful to some people.

| |
|
|
 | | |  |
|
|
|
If you appreciate the amount of time I spend creating and updating these pages, feel free to donate -- any amount is welcome !
|
- Website design & DirectX code : Riemer Grootjans - ©2006 Riemer Grootjans
|
|