将 3D 形状的脸隐藏在另一个 Android 画布后面? [英] Hide a face of a 3D shape behind another, Android canvas?

查看:19
本文介绍了将 3D 形状的脸隐藏在另一个 Android 画布后面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我必须在画布中绘制一个 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法线向量,并检查它是朝向还是背离相机.

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点积 和相机的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 画布后面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆