问题描述
假设我必须在画布上绘制3D形状的两个面.在OpenGL中,我们使用顶点的顺时针和非顺时针顺序来检测正面是正面,背面是正面,但是我不能使用OpenGL ,而我将使用画布.看来,如果我们先在脸部后面绘制,然后再在其前面绘制,它就会隐藏在脸部后面,但是我的3D形状会旋转,并且每个脸部有时必须在前面,而某些时候必须在后面.
Suppose that I have to draw two faces of a 3D shape in a canvas. In OpenGL, we use clockwise and non clockwise ordering of vertices to detect what face is front face and what is behind face, but I can not use OpenGL and I would to use canvas. It seems that if we draw behind face and then draw front face, it hides behind face, but my 3D shape rotates and each face some times must be front and some times must be behind.
我的问题是:当形状旋转时,如何检测女巫的脸在前面?还是其他任何方法可以将当前物体隐藏在正面背后?
My question is: When shape is rotating, how I can detect witch face is front? Or any other way to hide current behind face with front face?
推荐答案
您描述的过程称为背面剔除(这将大大提高您的Google在该主题上的实力).
The process you describe is called back-face culling (this will greatly improve your google prowess on the topic).
直接实现的方法是取下face
的normal vector
,并检查它是否朝向或远离相机.
The straight forward way to implement is to take the normal vector
of your face
, and check if it faces towards or away from the camera.
您可以使用normal
的dot product
和相机的view vector
进行此操作.根据点积的sign
,多边形朝向或远离相机.
You do this using the dot product
of the normal
and the view vector
of your camera. Depending on the sign
of the dot product, the polygon is facing towards or away from the camera.
如果此时实际上还没有相机,请在屏幕中替换一个矢量(即[0, 0, 1]
或[0, 0, -1]
取决于您的轴系).
If you don't actually have a camera at this point, substitute a vector into the screen (i.e. [0, 0, 1]
or [0, 0, -1]
depending on your axis system).
这篇关于将3D形状的面孔隐藏在另一个Android画布后面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!