I love the recent videos about the renderer in particular, but in my code I can't find what's causing the following bug. I made a short recording. In the screen recording I rotate a rectangle with the screen center as origin, x-axis is (cos angle, sin angle), and the y-axis the perpendicular. I verified that I compute the correct dot products in the draw rectangle function and check that the result for every edge is < 0 etc. In between the 0, 90, 180, and 270 degrees angles the rectangle changes shape... Anyone have an idea what I'm doing wrong?

Thank you very much

Thank you very much

It's hard to say without looking at code, but could you humour me and verify that the x axis and y axis are actually perpendicular? Like, take their dot product and make sure that the result is close to zero.

I printed the dot product of the x-axis and y-axis in the game_update_and_render loop to the console each frame and it's always 0.

**Update**: I removed the edge tests in the render function and clamped the u and v values to [0, 1] and this makes it work as expected. I don't know what I should change here, though:

Vector2 p = {(float)x, (float)y};

Vector2 v = p - origin;

float edge0 = dotProduct(v, -perpendicular(xAxis));

float edge1 = dotProduct(v - xAxis, -perpendicular(yAxis));

float edge2 = dotProduct(v - xAxis - yAxis, perpendicular(xAxis));

float edge3 = dotProduct(v - yAxis, perpendicular(yAxis));

(x and y are the values in the loop.)

if ((edge0 < 0) &&

(edge1 < 0) &&

(edge2 < 0) &&

(edge3 < 0)) {

// draw code

}

If I change this test to if (1) {}, the rectangle draws and rotates correctly. :S

**Update 2**; I also tried the following to verify if the perpendicular function is wrong but the results are the same:

float edge0 = dotProduct(v, -yAxis);

float edge1 = dotProduct(v - xAxis, xAxis);

float edge2 = dotProduct(v - xAxis - yAxis, yAxis);

float edge3 = dotProduct(v - yAxis, -xAxis);

**Update3**: I disabled each edge test separately and apparently they all play a part in the problem or the data passed to the edges is wrong...

How can I debug this? :(

Vector2 p = {(float)x, (float)y};

Vector2 v = p - origin;

float edge0 = dotProduct(v, -perpendicular(xAxis));

float edge1 = dotProduct(v - xAxis, -perpendicular(yAxis));

float edge2 = dotProduct(v - xAxis - yAxis, perpendicular(xAxis));

float edge3 = dotProduct(v - yAxis, perpendicular(yAxis));

(x and y are the values in the loop.)

if ((edge0 < 0) &&

(edge1 < 0) &&

(edge2 < 0) &&

(edge3 < 0)) {

// draw code

}

If I change this test to if (1) {}, the rectangle draws and rotates correctly. :S

float edge0 = dotProduct(v, -yAxis);

float edge1 = dotProduct(v - xAxis, xAxis);

float edge2 = dotProduct(v - xAxis - yAxis, yAxis);

float edge3 = dotProduct(v - yAxis, -xAxis);

How can I debug this? :(

Edited by elle
on