3D mirror question

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Killingsworth
Posts: 11
Joined: Mon Dec 05, 2005 11:21 pm
Location: Griffin, Georgia

3D mirror question

Post by Killingsworth »

Hi. I'm a little new to irrlicht, and I wanted to make a 3D mirror, that could seem to be realistic. However I've got two questions. The first is how do I find the posistion that the second camera should be in (maybe by some transformations, but I'm not good at 3d math so I dont know how to do that). Another is how to make the texture the proper size to prevent scaling.
Heres a small picture of what I've done.

Image

As you can see, That's not a true reflection. The size is also off. That's what my two questions are about.

Any help is greatly appreciated. Thanks in advance.
You wouldn't hit a kid with contacts would you?!
MikeR
Posts: 767
Joined: Sun Dec 26, 2004 4:03 pm
Location: Northern California USA
Contact:

Post by MikeR »

The texture can be made in any paint program. I made a + that filled the screen so that I could get the sides and top/bottom correct.

As for the camera position, just make a box in your favorite app, color the side that faces you, and save it. render that box where you want to put your camera and you will see where it will be, and the direction it's facing. (the one colored side should be pointing in the same direction as the camera)
If it exists in the real world, it can be created in 3d

Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram
Killingsworth
Posts: 11
Joined: Mon Dec 05, 2005 11:21 pm
Location: Griffin, Georgia

Post by Killingsworth »

I wanted it to do this realtime, that's why im using two cameras and a render target. The way this should work is one camera will be the main viewpoint (the real camera) and the other should be the mirror's viewpoint relative to the real viewpoint (The virtual camera). The virtual camera should obey mirror laws. that is that the angle of reflection is equal to the angle of incidence. Theres alot of things on the internet you can look at on how mirrors work, but its really simple physics. I need to know how to make the virtual camera show the correct angle, and the texture be the right size.
You wouldn't hit a kid with contacts would you?!
Killingsworth
Posts: 11
Joined: Mon Dec 05, 2005 11:21 pm
Location: Griffin, Georgia

Post by Killingsworth »

Ok I fixed the texture size problem (I think). I changed the texture to 320x240, seems to work. I also started using a transformation matrix on the other camera. However I don't have it right. I need the transformation matrix to basically make the camera appear to be the same angle as the original camera. but appear behind the mirror. I think what has to be done is that the Z axis has to be transformed... If anyone could help me get the proper transformation needed it would be appreciated.

Edit: I think I've got the matrix right, but theres a problem. The second camera isnt at the right posistion Z wise, if the main camera comes in contact with the mirror, the virtual camera should contact the mirror as well. This doesnt happen, the camera and the virtual camera meet each other in front of the mirror, and this isnt good.

Heres the code im using to find the posistion for the virtual camera.

Code: Select all

matrix4 m = camera->getProjectionMatrix();
        matrix4 trans;
        trans(0,0)=1;
        trans(1,0)=0;
        trans(2,0)=0;
        trans(3,0)=0;
        trans(0,1)=0;
        trans(1,1)=1;
        trans(2,1)=0;
        trans(3,1)=0;
        trans(0,2)=0;
        trans(1,2)=0;
        trans(2,2)=-1;
        trans(3,2)=0;
        trans(0,3)=0;
        trans(1,3)=0;
        trans(2,3)=0;
        trans(3,3)=1;
        m*=trans;
        vector3df vect = camera->getPosition();
        m.transformVect(vect);
        test2->setPosition(vect); //test2 shows me where the second camera is
        camera2->setPosition(vect);
You wouldn't hit a kid with contacts would you?!
Post Reply