Rotate Vertex

Pages: 12
Right now you're doing a little too much multiplying.. You should change line 19 to c = Multiply(c, t1);(the idea is that c = c * rz * t1 and with matrices order of multiplication is important)
Wouldn't it make sense:

1
2
3
for (int i=1; i<3; i++){
newPts[i] = Multiply(c, pts[i]);
}


to loop thru the second that last vertices? That way we don't effect the one we chose? "A" (pts[0]) in this case...
If the matrix is correct multiplying A by it should return A. You may start from B to make your code very very slightly faster, but I think that if the matrix isn't correct it will be easier to understand what's wrong with it.
Last edited on
Thanks for your help!
This is close:

1
2
3
4
5
6
7
8
9
10
11
12
13
                t1.makeTranslationMatrix(-pts[0].x, -pts[0].y, -pts[0].z);
	rz.makeRotationMatrixZ(angle);
	
	c = Multiply(Multiply(t1, rz), c);

	for (int i=1; i<3; i++) {
		newPts[i] = Multiply(c, pts[i]);
	}
	
	t2.makeTranslationMatrix(newPts[0].x = 50, newPts[0].y = 50, newPts[0].z = 0);
	rz.makeRotationMatrixZ(angle);
	
	c = Multiply(Multiply(t2, rz), c);


The above code is close. But I can't explain why though. There is one vertex that doesn't move, but the rest do and it seems that they rotate around it. When I start the program and supply '0' as a rotation angle i get a striaght line, that is the only thing that is wrong with it, i think.
Topic archived. No new replies allowed.
Pages: 12