View Single Post
  #3 (permalink)  
Old 05-20-2008, 01:30 PM
MrPickle's Avatar
MrPickle MrPickle is online now
Sr. Programmer
Join Date: Nov 2007
Location: England, Lincolnshire
Posts: 255
iTrader: (0)
MrPickle is on a distinguished roadMrPickle is on a distinguished roadMrPickle is on a distinguished road
I don't think you need to delete in reverse, I never have in the past.

I've changed the function completely now in an attempt to fix it but it's saying "Segmentation Fault" which means it's trying to access something out of range according to wiki. But I don't see how :3

Code:
void Terrain::setNormals(void){
    Vector Sum, Out, In, Left, Right;    
    for(int w = 0; w < Width-1; w++){
        for(int l = 0; l < Length-1; l++){
            Sum.setValue(0.0f, 0.0f, 0.0f);
            
            if(l > 0)
                Out.setValue(0.0f, Heights[w - 1][l] - Heights[w][l], -1.0f);
            
            if(l < Length - 1)
                In.setValue(0.0f, Heights[w + 1][l] - Heights[w][l], 1.0f);
            
            if(w > 0)
                Left.setValue(-1.0f, Heights[w][l - 1] - Heights[w][l], 0.0f);
            
            if(w < Width - 1)
                Right.setValue(1.0f, Heights[w][l + 1] - Heights[w][l], 0.0f);
            
            if(w > 0 && l > 0){
                Sum += Out.CrossProduct(Left);
                Sum.Normalize();
            }
            
            if(w > 0 && l < Length - 1){
                Sum += Left.CrossProduct(In);
                Sum.Normalize();
            }

            if(w < Width - 1 && l < Length - 1){
                Sum += In.CrossProduct(Right);
                Sum.Normalize();
            }
            
            if(w < Width - 1 && l > 0){
                Sum += Right.CrossProduct(Out);
                Sum.Normalize();
            }
            
            Normals[w][l] = Sum;
        }
    }
}

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote