problem getting result when calling a function
I have sorted out my earlier problem but now have a different. I have defined an array of objects called LineArray. Each of these objects has an array called m_XYCoOrds which hold ten x,y co-ordinate points. The 2nd dimension in the array holds x points at 0 and y points at 1. e.g. the first X point would be found by
m_XYCoOrds and the y at
The function ncrosses takes two points (x1,y1 and x2,y2) as arguments and checks to see if they cross any other lines that are defined as illegal in the map. The function ncrosses looks like
the function crosses called in this function is the one that looks for the crossed lines. I know these functions work because, as you might be able to tell from the comments they are from an original piece of work in C. When I call ncrosses I want to store the value count in an object variable LineArray.m_LineCrosses.
int ncrosses(int x1,int y1,int x2,int y2)
struct lineSeg *l1;
/*printf("hit %d ",i); */ /* only need to know about one line
crossed to know zone crossed or partially
crossed, could modify to get more info.*/
And this is where the problem is coming from.
Because each line object has 10 different xy points it is necessary to call ncrosses 9 times for each object. I set up a simple for loop to do this when the document initialises.
the i in LineArray is simply because I am working my way through the array calling this for every line object.
x1 = LineArray[i].m_XYCoOrds;
y1 = LineArray[i].m_XYCoOrds;
x2 = LineArray[i].m_XYCoOrds;
y2 = LineArray[i].m_XYCoOrds;
temp = ncrosses(x1,y1,x2,y2);//get the number of lines crossed
total = total + temp;
LineArray[i].m_LineCrosses = total;
The problem is that the value is always whatever I initialise total to be. e.g. if i set the line total=400; before calling this section of code LineArray[i].m_LineCrosses always equals 400. Its almost as thought the line LineArray[i].m_LineCrosses = total; does not exist. Any thoughts would be much appreciated.