Click here to Skip to main content
15,893,588 members

Z-buffer Algorithm problem in finding depth of surface of polygon.

smokindinesh asked:

Open original thread
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
C#
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
C#
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.
Tags: C#, Graphics

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900