Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# graphics
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.
Posted 9-Mar-12 1:40am
Comments
Björn Ranft at 9-Mar-12 14:27pm
   
Hm, sure your formula in DepthValue Method is right?
z = (-Ax - By - D) / C
Regards
smokindinesh at 11-Mar-12 8:32am
   
@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.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

@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.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 230
1 OriginalGriff 202
2 Richard MacCutchan 185
3 Tomas Takac 146
4 CPallini 125
0 OriginalGriff 5,130
1 DamithSL 4,237
2 Maciej Los 3,700
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,846


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 11 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100