Hi all,

I'm using a vector to store x,y,z values for objects to be draw using OpenGL. I manipulate my vector in a function and then pass it to the method which uses it to draw objects. Basically the value at an element is supposed to be '-2' but if it is used to draw an object the object is drawn with a value that must have been 0. However, if I insert a breakpoint into the code it shows the variable as '-2'.

glPushMatrix();
	glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
	//Head
	glTranslatef(bodyPos.at(0), bodyPos.at(1), bodyPos.at(2));
	gluSphere(quadratic,1.0f,32,32);
	glPopMatrix();
	glPushMatrix();
	//Body
	glTranslatef(bodyPos.at(3), bodyPos.at(4), bodyPos.at(5));
	gluSphere(quadratic,1.0f,32,32);
	glPopMatrix();
	//Tail
	glTranslatef(bodyPos.at(6), [B]bodyPos.at(7)[/B], bodyPos.at(8));
	gluSphere(quadratic,1.0f,32,32);

The vector call in bold is the one that is messing up. If I replace it with the actual number '-2' it is fine and works. I don't see how this is as if I mouse over the variable when the code is in break straight after this point, the variable shows '-2' at that element location.

I have even taken out the code to generate and manipulate the vector into another small print program to print out all the values as it is calculated, and it prints out that value as -2.

Very stumped!

Could it be that functions alter vector add some elemts?

The function to alter the vector is:

void shuffleArray()
{
	int a = 5;
	for (int c = 8; c > 2; c--) {
		//swap(bodyPos[c], bodyPos[a]);
		float temp = bodyPos.at(a);
		bodyPos[c] = temp;
		a--;
	}
}

Its all pure shuffling of the data.

You never reassign bodyPos[c] to bodyPos[a], there should be a third line to your swap on line 6-7.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.