需要帮助将伪代码转换为 C#
我一直在致力于建立一个生态圈,并且已经快完成了。
现在我想做的是使任何不面向相机的三角形都不会添加到绘制列表中,因为我正在处理很多三角形,并且正在填充顶点缓冲区。我已经设法做到了,因此隐藏了面向初始相机位置的三角形(参见附图),但是当我移动相机时,隐藏的三角形不会更新。
以下是显示此内容的两张图片:
http://i41.photobucket.com /albums/e262/cstgirllover/Cho/IcosphereCulledFront.png
http://i41.photobucket.com/albums/e262/cstgirllover/Cho/IcosphereCulledSide .png
我一直在使用此网站的(伪)代码来帮助我走到这一步:
http://decadeengine.blogspot.com/2011/03/remove -back-faces-patches-before.html
但我似乎找不到任何相应的代码:
p_pGraphics->get_Matrix(eModelView)
这是页面上最后一段代码,它解决了我遇到的问题。
我的周围代码如下所示:
public float isFacing(Vector3 pos1, Vector3 pos2, Vector3 pos3, Camera dotCamera)
{
Vector3 temp1 = CalculateNormal(pos1, pos2, pos3);
float dotp = Vector3.Dot(temp1, dotCamera.GetDirection * _________);
return dotp;
}
等效代码需要在“dotCamera.GetDirection *”之后输入
I've been working on building an icosphere, and am almost done with it.
Right now what I am trying to do is make it so that any triangles not facing the camera aren't added to the draw list, because I'm dealing with a lot of triangles, and am filling up the vertex buffer. I've managed to make it so the triangles facing the initial camera position are hidden (see attached images), but the hidden triangles do no update as I move the camera around.
Here are the two images showing this:
http://i41.photobucket.com/albums/e262/cstgirllover/Cho/IcosphereCulledFront.png
http://i41.photobucket.com/albums/e262/cstgirllover/Cho/IcosphereCulledSide.png
I've been using (pseudo)code from this site to help me get this far:
http://decadeengine.blogspot.com/2011/03/remove-back-facing-patches-before.html
but I cannot seem to find any corresponding code for this:
p_pGraphics->get_Matrix(eModelView)
That is from the last segment of code on the page, which fixes the problem I'm having.
My surrounding code looks like this:
public float isFacing(Vector3 pos1, Vector3 pos2, Vector3 pos3, Camera dotCamera)
{
Vector3 temp1 = CalculateNormal(pos1, pos2, pos3);
float dotp = Vector3.Dot(temp1, dotCamera.GetDirection * _________);
return dotp;
}
The equivalent code need to go in after "dotCamera.GetDirection * "
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这个代码片段将取决于您使用的 3d 引擎。
实际上它正在做什么来尝试获取表示视图当前旋转/位置的矩阵。
如果您的目标是 XNA,您可能会找到此帮助 Rotation&翻译:
I think this code snippet will depend on which 3d engine you are using.
effectively what it's doing to to try and get a matrix representing the current rotation/position of the view.
if you are targetting XNA you might find this of help Rotation&Transaltion:
那不是伪代码。没有足够的信息来给出可靠的答案,但您尝试过吗?
That's not pseudo code. There isn't enough information to give a solid answer but have you tried this?