I’m developing a car game and I want to put a rearview mirror to show the rear of the car. Now I have a Camera that looks at rear, but i want a mirror efect, and i don’t know how can I do this. I tried to invert camera’s projection matrix but the viewport not show the image that I want.
Code:
//Define new camera and set his location, lookAt and viewport situation.
camTrasera = cam.clone();
camTrasera.setViewPort(0.39f,0.61f ,0.76f,0.94f);
camTrasera.setLocation(new Vector3f(0, 3, 0));
camTrasera.lookAt(lookAtRear, Vector3f.UNIT_Y);
//Show camera view into a new viewport
ViewPort view2 = renderManager.createMainView(“Camara trasera”, camTrasera);
view2.setClearFlags(true, true, true);
//To update Camera’s position I have this function:
public void updateMirror(Vector3f lookAtRear, Vector3f cameraPos){
camTrasera.lookAt(lookAtRear, Vector3f.UNIT_Y);
camTrasera.setLocation(cameraPos);
}
view2.attachScene(rootNode);
//When I want to update parameters of camera, I call updateMirror function in main:
display.updateMirror(car.getSpatial().localToWorld(new Vector3f(0,3,-15), null),car.getSpatial().localToWorld( new Vector3f( 0, 3, 0), null));
Thank you in advance
render to texture ?
i think if u place the texture on a negative scaled quad u will get a mirror. or the back face of a quad with no face cull.
1 Like