Tool with mirror
I would like to create a tool that has a mirror at its end.
Following the example 23-tooth I created a secondary camera and attached it to my mirror tool.
Then I created a frameBuffer but I don't want to use it in a cViewPanel like in the example.
// attach mirror to tool
tool->m_image->addChild(mirror);
// create secondary camera for side view
cCamera* cameraTool = new cCamera(world);
// attach camera to tool
mirror->addChild(cameraTool);
cameraTool->setLocalPos(0.0, 0.0, 0.1);
// create framebuffer for side view
frameBuffer = cFrameBuffer::create();
frameBuffer->setup(cameraTool);
I would like to apply the frameBuffer as a texture on my mirror tool (or maybe at one of its child objects), so it would appear as a real mirror that changes view in run-time. Is there a way to do something like that ?
This of course doesn't work because of the wrong casting, but it gives an idea of the goal:
mirror->m_texture->setImage((cImagePtr)frameBuffer);
Thank you very much in advance.
Please Log in or Create an account to join the conversation.
You can create a mirror by using a cMesh object and by assigning the texture to the framebuffer:
// create mirror
cMesh* mirror = new cMesh();
// add mirror to world
world->addChild(mirror);
// create disc
cCreateDisk(mirror, 0.2, 0.2);
// assign framebuffer texture
mirror->setTexture(frameBuffer->m_imageBuffer);
// enable texture rendering
mirror->setUseTexture(true);
// disable material properties
mirror->setUseMaterial(false);
To generate the mirror framebuffer image, you could try to attach a camera to the mirror by keeping in mind that you will probably have to adjust its position and orientation according the angle between the surface normal of the mirror and the location of the viewer.
You can check example 23-tooth to see how to create the camera and framebuffer. You will also need to render the framebuffer view before the camera view.
// render framebuffer
frameBuffer->renderView();
// render world
camera->renderView(windowW, windowH);
Please Log in or Create an account to join the conversation.
That's what I needed :
// assign framebuffer
texturemirror->setTexture(frameBuffer->m_imageBuffer);
Thank you. I'll check out the angle now.
Please Log in or Create an account to join the conversation.
- Posts: 1
I want to create an object with mirror at the end, too. But my device is custom device with non-actuated rotation.
When I add a camera to the tool image and render the frame buffer, I get a picture from another viewpoint which I don't know the logic of its place and for some small time I get frames from the real position of the camera. In other words I get some blinks from real position of camera.
Anybody knows what the problem is?
Please Log in or Create an account to join the conversation.
You will have update the orientation of the camera on the mirror according to the position of the camera rendering the full scene so that the reflection angle is consistent.
Regarding the device orientation, does your device support orientations? From you message its sounds like your device support 3-DOF in translation.
Please Log in or Create an account to join the conversation.