寻找多边形表面深度的Z缓冲区算法问题. [英] Z-buffer Algorithm problem in finding depth of surface of polygon.

查看:71
本文介绍了寻找多边形表面深度的Z缓冲区算法问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用z缓冲区算法来查找我的大学计算机图形学项​​目的可见表面检测.我使用了以下坐标系,即正x轴向右,正z轴朝上, y轴正向在屏幕上向前移动.我的最大深度是200个单位.
问题是,当我计算立方体的所有表面的深度时,我发现前后的深度准确,但是另一侧的深度大于我的最大深度.
我计算平面系数的代码是

I am trying to use z-buffer algorithm to find the visible surface detection for my college computer graphics project.I have used following co-ordinate system that the positive x-axis to the right, the positive z-axis upward, and the positive y-axis forward on the screen. My maximum depth is 200 units.
Problem is that when I calculate the depth of all surface of cube I found the depth of back and front accurate but depth of other side is more than my maximum depth.
My code for calculating co-efficient of plane is

public Coefficient_Of_Plane Coefficient_Value(_3Dpoint pt1, _3Dpoint pt2, _3Dpoint pt3)
       {
          // double Y = 0;
           Coefficient_Of_Plane pt;
           pt = new Coefficient_Of_Plane();
           pt.A = (pt2.z - pt3.z) * (pt1.y - pt2.y) - (pt1.z - pt2.z) * (pt2.y - pt3.y);
           pt.B = (pt2.x - pt3.x) * (pt1.z - pt2.z) - (pt1.x - pt2.x) * (pt2.z - pt3.z);
           pt.C = (pt2.y - pt3.y) * (pt1.x - pt2.x) - (pt1.y - pt2.y) * (pt2.x - pt3.x);
           pt.D = - pt1.x * (pt2.y * pt3.z - pt2.z * pt3.y) + pt1.y * (pt2.x * pt3.z - pt2.z * pt3.x) - pt1.z * (pt2.x * pt3.y - pt2.y * pt3.x);
           return pt;

       }



并找到深度值是



and finding the depth value is

public double DepthValue(Coefficient_Of_Plane surface,int x,int y)
      {


          double z = 0;
          if (surface.B != 0)
              z = (-surface.A * x - surface.C * y - surface.D) / surface.B;
          return z;
      }


我需要帮助来解决此问题,如果需要的话,我也准备发布代码的其他部分,如果我的问题不完整,我还准备发布问题的进一步描述.


I need a help to solve this problem and I am also ready to post other part of code if required and further description of problem if my question is incomplete.

推荐答案

@比约恩·兰夫特(Bjorn Ranft)感谢您的评论.
我已经解决了我的错误.查找深度时,点x和y必须保持固定
我已将原点(x,y)=(0,0)作为固定点.
@Bjorn Ranft thanks for your comment.
I have solve my error . While finding depth the points x and y must be kept fixed
I have taken origin (x,y)=(0,0) as a fixed point.


这篇关于寻找多边形表面深度的Z缓冲区算法问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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