|
-
Dec 7th, 2003, 10:08 AM
#1
Thread Starter
Not NoteMe
Values randomly changing to zero!!
Ok, I've got a class as shown below (using a struct, also shown), the important bit is the function 'CreateTriabglePolys':
Code:
struct CUSTOMVERTEX
{
float x,y,z; //The absolute 3D position for this vertex (not transformed)
DWORD colour; //The colour of this vertex
};
class SquarePoly
{
CUSTOMVERTEX Corners[3];
public:
SquarePoly(float x1, float y1, float z1,DWORD colour1,
float x2, float y2, float z2,DWORD colour2,
float x3, float y3, float z3,DWORD colour3,
float x4, float y4, float z4,DWORD colour4)
{
Corners[0].x = x1;//Top-Left
Corners[0].y = y1;
Corners[0].z = z1;
Corners[0].colour = colour1;
Corners[1].x = x2;//Top-Right
Corners[1].y = y2;
Corners[1].z = z2;
orners[1].colour = colour2;
Corners[2].x = x3;//Bottom-Right
Corners[2].y = y3;
Corners[2].z = z3;
Corners[2].colour = colour3;
Corners[3].x = x4;//Bottom-Left
Corners[3].y = y4;
Corners[3].z = z4;
Corners[3].colour = colour4;
};
SquarePoly(){};
void CreateTrianglePolys(CUSTOMVERTEX *Vertices,const int Start)
{
Vertices[Start] = Corners[0];
Vertices[Start+1] = Corners[1];
Vertices[Start+2] = Corners[2];
Vertices[Start+3] = Corners[0];
Vertices[Start+4] = Corners[2];
Vertices[Start+5] = Corners[3];
};
};
I'm calling it in a loop with the code below:
Code:
CUSTOMVERTEX Vertices[TERRAINWIDTH*TERRAINDEPTH*2*3-1];//2 = # of triangle to represent a square, 3 = a vertices of a triangle
for(i=0;i<=TERRAINWIDTH;i++)
{
for(j=0;j<=TERRAINDEPTH;j++)
{
sqPolygons[i][j].CreateTrianglePolys(Vertices,VertexCount);
VertexCount +=2;
}
}
I've added watches to i, j and VertexCount (which is passed as a const!!) and before the call to CreateTriabglePolys, they have their correct values, but directly after, the change back to zero and i cannot for the life of me work out why.
Thanks for any help.
Last edited by SLH; Dec 7th, 2003 at 12:13 PM.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Dec 7th, 2003, 01:32 PM
#2
just a hunch
CUSTOMVERTEX Corners[3]; //shouldn't this be 4?
I don't live here any more.
-
Dec 7th, 2003, 02:48 PM
#3
Thread Starter
Not NoteMe
Don't think so because arrays start from 0 don't they? So the array has 4 elements numbered 0 up to 3
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Dec 7th, 2003, 03:26 PM
#4
Don't think so because arrays start from 0 don't they? So the array has 4 elements numbered 0 up to 3
Close
The number inside the brackets is the number of elements. There are 3 elements, numbered from 0 to 2.
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
Dec 7th, 2003, 04:10 PM
#5
Thread Starter
Not NoteMe
Ah, thanks for the clarification
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Dec 7th, 2003, 04:37 PM
#6
Which explains the changing values: you were overwriting them by changing other variables, because those variables shared the memory with your fictional variables.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 7th, 2003, 04:38 PM
#7
BTW, this is one of the most common VB convert mistakes made.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 7th, 2003, 05:03 PM
#8
Thread Starter
Not NoteMe
Originally posted by CornedBee
BTW, this is one of the most common VB convert mistakes made.
Ah well, glad to see i'm not the first.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Dec 9th, 2003, 03:25 AM
#9
Frankly, I'm stunned, I actually managed to spot a C++ problem!
I've arrived.
I don't live here any more.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|