Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glRotate divide-by-zero

I think I understand why calling glRotate(#, 0, 0, 0) results in a divide-by-zero. The rotation vector, a, is normalized: a' = a/|a| = a/0

Is that the only situation glRotate could result in a divide-by-zero? Yes, I know glRotate is deprecated. Yes, I know the matrix is on the OpenGL manual. No, I don't know linear algebra enough to confidently answer the question from the matrix. Yes, I think it would help. Yes, I asked this already in #opengl (can you tell?). And no, I didn't get an answer.

like image 742
lwiseman Avatar asked Jan 30 '26 05:01

lwiseman


1 Answers

I would say yes. And I would say that you are right about the normalization step as well. The matrix shown in the OpenGL manual only consists of multiplications. And multiplying a vector would result into the same. Of course, it would do strange things if you result in a vector of (0,0,0). OpenGL states in the same manual that |x,y,z|=1 (or OpenGL will normalize).

So IF it wouldn't normalize, you would end up with a very empty matrix of:

0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 1

Which will implode your object in the strangest ways. So DON'T call this function with a zero-vector. If you would like to, tell me why.

And I recommend using a library like GLM to do your matrix calculations if it gets too complicated for some simple glRotates.

like image 117
Marnix Avatar answered Jan 31 '26 19:01

Marnix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!