Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualirreversible

Posted 04 February 2013 - 08:33 AM

EDIT: Ack, wait! Replied too soon smile.png


#4irreversible

Posted 04 February 2013 - 08:10 AM

EDIT: Ack, wait! Replied too soon :)


#3irreversible

Posted 04 February 2013 - 08:05 AM


Hm - I tried it out and on paper it makes perfect sense and all; however, I'm not getting expected results. Here's my test setup:

 

[attachment=13507:barycentric.jpg]

 

1) I calculate the bounding box and assign each corner a value { 0, 1, 2, 3 }. The value is quite arbitrarily called udf. Don't ask. (see code below)

2) I bilerp the BB corner udf values to get vertex udf values

3) I use the below code (per BB corner) to calculate the value of udf at that point

 

 

            //calculate the BB from min/max bounds - the BB is correct
 
            vcorner[0] = IVector3D(minxf, minyf);
            vcorner[1] = IVector3D(maxxf, minyf);
            vcorner[2] = IVector3D(maxxf, maxyf);
            vcorner[3] = IVector3D(minxf, maxyf);
 
/////////////////////////////////////////////-------/////////////////////////////////////////////
 
 
 
            IVector3D f1 = points[0].vertex - vcorner[0];
            IVector3D f2 = points[1].vertex - vcorner[0];
            IVector3D f3 = points[2].vertex - vcorner[0];
 
            float a =  VecCrossProduct(points[0].vertex - points[1].vertex, points[0].vertex - points[2].vertex).Magnitude();
            float a1 = VecCrossProduct(f2, f3).Magnitude() / a;
            float a2 = VecCrossProduct(f3, f1).Magnitude() / a;
            float a3 = VecCrossProduct(f1, f2).Magnitude() / a;
            float udf = a1 * points[0].udf + a2 * points[1].udf + a3 * points[2].udf;
 
It's clean cut and all that, but the values I'm getting are wrong. Here are the bilerped udf values for triangle vertices:
 
[float] points[0].udf = 1.982759
[float] points[1].udf = 0.862069
[float] points[2].udf = 1.758621
 
Here are the "reconstructed" udf values for the BB corner vertices:
 
[float] udf0 = 3.008400
[float] udf1 = 2.374742
[float] udf2 = 3.767315
[float] udf3 = 1.982759
 

 

These couldn't possibly be correct.

 

Am I missing something?


#2irreversible

Posted 04 February 2013 - 08:05 AM


Hm - I tried it out and on paper it makes perfect sense and all; however, I'm not getting expected results. Here's my test setup:

 

[attachment=13507:barycentric.jpg]

 

1) I calculate the bounding box and assign each corner a value { 0, 1, 2, 3 }. The value is quite arbitrarily called udf. Don't ask. (see code below)

2) I bilerp the BB corner udf values to get vertex udf values

3) I use the below code (per BB corner) to calculate the value of udf at that point

 

            //calculate the BB from min/max bounds - the BB is correct
 
            vcorner[0] = IVector3D(minxf, minyf);
            vcorner[1] = IVector3D(maxxf, minyf);
            vcorner[2] = IVector3D(maxxf, maxyf);
            vcorner[3] = IVector3D(minxf, maxyf);
 
/////////////////////////////////////////////-------/////////////////////////////////////////////
 
 
 
            IVector3D f1 = points[0].vertex - vcorner[0];
            IVector3D f2 = points[1].vertex - vcorner[0];
            IVector3D f3 = points[2].vertex - vcorner[0];
 
            float a =  VecCrossProduct(points[0].vertex - points[1].vertex, points[0].vertex - points[2].vertex).Magnitude();
            float a1 = VecCrossProduct(f2, f3).Magnitude() / a;
            float a2 = VecCrossProduct(f3, f1).Magnitude() / a;
            float a3 = VecCrossProduct(f1, f2).Magnitude() / a;
            float udf = a1 * points[0].udf + a2 * points[1].udf + a3 * points[2].udf;

#1irreversible

Posted 04 February 2013 - 08:04 AM

Hm - I tried it out and on paper it makes perfect sense and all; however, I'm not getting expected results. Here's my test setup:

 

[attachment=13507:barycentric.jpg]

 

1) I calculate the bounding box and assign each corner a value { 0, 1, 2, 3 }. The value is quite arbitrarily called udf. Don't ask. (see code below)

2) I bilerp the BB corner udf values to get vertex udf values

3) I use the below code (per BB corner) to calculate the value of udf at that point

 

            //calculate the BB from min/max bounds - the BB is correct
 
            vcorner[0] = IVector3D(minxf, minyf);
            vcorner[1] = IVector3D(maxxf, minyf);
            vcorner[2] = IVector3D(maxxf, maxyf);
            vcorner[3] = IVector3D(minxf, maxyf);
 
/////////////////////////////////////////////-------/////////////////////////////////////////////
 
 
            IVector3D f1 = points[0].vertex - vcorner[0];
            IVector3D f2 = points[1].vertex - vcorner[0];
            IVector3D f3 = points[2].vertex - vcorner[0];
 
            float a =  VecCrossProduct(points[0].vertex - points[1].vertex, points[0].vertex - points[2].vertex).Magnitude();
            float a1 = VecCrossProduct(f2, f3).Magnitude() / a;
            float a2 = VecCrossProduct(f3, f1).Magnitude() / a;
            float a3 = VecCrossProduct(f1, f2).Magnitude() / a;
            float udf = a1 * points[0].udf + a2 * points[1].udf + a3 * points[2].udf;

PARTNERS