Jump to content
  • Advertisement
Sign in to follow this  
Miranda

OpenGL precision issues when importing 3d model

This topic is 4825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, once again this is a mobile / opengl crossover post, but I am hoping I will get a better response here. Ok so I have a 3ds model that I am exporting to a .cpp file using the program Deep Exploration. This basically spits out the 3ds data as vertices, faces and normals. My problem is that the normals and vertices are in GLfloat format, but as I am using OpenGL ES for a Symbian Series 60 phone I can only draw using glDrawElements or glDrawArrays. I am using glDrawElements and need my data to be in glShort and glByte format. I have tried using a #define function to convert the data into scalars, but I am getting a loss of precision. The model should look like: But it looks like: Some of the numbers look like -2.38144e-007 and I think this might be causing the problem. Forgive me for my lack of maths knowledge, but I'm not sure what this number means... So basically I'm asking if anyone knows a way I can convert glFloats into glBytes without too much loss of precision. Any help would be greatly appreciated!

Share this post


Link to post
Share on other sites
Advertisement
You are probably better of converting it to fixed point rather than bytes. This will also probably give precision errors but will be quite less. Converting a float to 1 6bit fixed point is to simply multiply by 65536 and to conver it back to float is to divide by 65536. You will however have to take care of overflow and underflow errors.

For eg:-

#define FIXED(x) (x * 65536)

int a = FIXED(10.5);

Hope this helps.

I think Nokia gives a fp lib, I am not sure but if they do, I suggest you can make use of it.

In the end I am no expert so there might always be a better solution.

Share this post


Link to post
Share on other sites
Hmmm, that doesn't seem to help unfortunately... It seems to work better when I use
#define scalar(a) ((short)(a*300))
That I got from a Nokia 3d example.

Does anyone else have any ideas?

Share this post


Link to post
Share on other sites
Supposed your vertixles are v_1, ... , v_n you could convert your to shorts like this:

x = the maximum number in any dimention of v_1, ..., v_n
y = the minimum numver in any dimention of v_1, ..., v_n

Then you transform each verticle with (65536*(v-y) / abs(x-y)) - 32768 and convert it to short.

This will scale the model to fit exactly in [32768, -32768], preserving as much precision as posible. You have to scale it down using apropriate transformation matrices. The downside is that the zero point of the object is also moved.

(disclaymer. This is OTOMH and it might not work.)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!