Need help converting pseudo-code to c#
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.c开发者_运维技巧om/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 * "
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?
float dotp = Vector3.Dot(temp1, dotCamera.GetDirection * p_pGraphics.get_Matrix(eModelView));
精彩评论