Hey all

I'm writing a rasterizer at the moment, and one of the basic transformations you can perform is rotation. This demands the use of trig functions. However, when rotating a cube, my cube slowly shrinks. Is this s result of loss of accuracy in Math.sin() and Math.cos()? Or is it possibly because I'm casting these values to float, since I use this later for drawing...

Any thoughts?

Thanks, M

Recommended Answers

All 2 Replies

It's because of the float casting. Double is the native floating point type in Java and you should try to maintain your calcs in that if you want to maximize accuracy.

>> However, when rotating a cube, my cube slowly shrinks. Is this s result of loss of accuracy in Math.sin() and Math.cos()? Or is it possibly because I'm casting these values to float, since I use this later for drawing...

Rotating the cube has nothing to do with its size!
Sin and cos are accurate enough. Its probably your logic somewhere.
Maybe if you show some code we can help you.
So maybe you are changing its z axis, thus making it appear smaller.

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.