When drawing patches in Matlab, both faces are always drawn and with the same color. But when rotating the camera, I need that all the back faces do not be drawn. Any help would be appreciated.
No Lixiang. I mean that when simple polygons in 3D are drawn (using patch command for example), and you orbit the camera, both sides of the polygons are drawn with the same color. I need that only front-faced polygon be drawn on the screen (see this image as an example)
I see, Agustin. You can filter the data of the back face and then redraw the patch. Here I give you a simple example assumed that the plane slicing the front face and the back face is x=0.
Thanks Lixiang. Your solution is right, but the problem is that the plane slicing front and back faces is not constant. It depends on the camera position, so I would need to capture mouse movement (using a callback I suppose) and compute the new plane in every movement.
You can refer to Camera Graphics Terminology. I am not sure that you use camorbit function or campan function. The normal of the slicing plane is determined by the camera position and the camera target.
1) get the direction of the camera as the vector pointing from the current camera position get(gca,'CameraPosition') to the camera target get(gca,'CameraTarget); also, get(gca,'CameraUpVector')
2) create an orthonormal frame based on the viewing direction (the unitary vector CameraUpVector is the Z versor)
3) get a representation of the vertices and of the vertex normals of your patch in the new orthonormal frame
4) the backfire are those with negative Z normals face
You can implement this as a callback on mouse click/camera position.
Thank you all. With your help, I have achieved what I wanted. The steps have been:
Create my own callbacks for rotate3d.ButtonDownFilter (just when user press rotate3d button) and rotate3d.ActionPostCallback (just when user finish the mouse rotation movement)
In the first callback (button down), create my third callback for WindowButtonMotionFcn event. Then, every mouse movement with the rotate3d button activated is captured by me.
In the second callback (mouse up) remove the pointer to my third callback. Then no more mouse movements are captured by me
In the third callback (mouse moving), I compute camera view direction, and make dot product with all the normals in the scene, and then only draw faces whose dot product be positive