Vertex Coordinate Limits

Post Reply
Rexhunter99
Posts: 23
Joined: Thu Sep 09, 2010 1:28 pm
Location: Australia
Contact:

Vertex Coordinate Limits

Post by Rexhunter99 » Sun Dec 05, 2010 12:17 am

I discovered the hard way that the vertices in a scene can't extend past a certain unit, if they do they get capped at it and/or return to 0,0,0 and start again, which is annoying because I am used to being able to make my scenes use whole numbers for a scale system but I have to scale them down to a micro size. For instance, one of the vertices on my player model is at 157, 117, 643 (relative to it's origin which for the excersize was at the world origins) I need to take these down to minute floating point values under 0.0999999 for them to not hit this bounding limit (and make my scene look like a spastic cube)
Move over Mario... and cruise by Crash... Croc Rocks!
It's a serious adventure 3D platformer for all retro gamers to drool over =D

zeromus
Posts: 212
Joined: Wed Mar 31, 2010 6:05 pm

Re: Vertex Coordinate Limits

Post by zeromus » Sun Dec 05, 2010 1:41 am

such is life. model your objects -8 < x,y,z < 8 and scale them before rendering.

Rexhunter99
Posts: 23
Joined: Thu Sep 09, 2010 1:28 pm
Location: Australia
Contact:

Re: Vertex Coordinate Limits

Post by Rexhunter99 » Sun Dec 05, 2010 2:39 am

zeromus wrote:such is life. model your objects -8 < x,y,z < 8 and scale them before rendering.
No need to tell me such is life ;) I just thought that other than my whining, it might be helpful for other users to know this when they are working with VideoGL and have come directly from OpenGL for PC/Mac.
My only concern is that the bit operations in MAXScript are really finicky and sometimes cause problems in my scripts so I may just have to write a GUI application that can do all that work for me so the data is readily useable on the DS.
Move over Mario... and cruise by Crash... Croc Rocks!
It's a serious adventure 3D platformer for all retro gamers to drool over =D

Rexhunter99
Posts: 23
Joined: Thu Sep 09, 2010 1:28 pm
Location: Australia
Contact:

Re: Vertex Coordinate Limits

Post by Rexhunter99 » Wed Feb 08, 2012 4:13 am

Didn't think this was going to warrant a new topic, so I'm reviving this old one.

Been fiddling around with normals, now I wrote an exporter for a generalized file format for animations and models for 3dsMax, it works a charm, exports the model and materials and sorts them so they can be easily batched, etc, but normals are being a pain. I copied the floattov10/PACK_NORMAL functions over so the result was the exact same but encountered the obvious sign issue, for instance, -256 is converted to 768 from a packed normal, so I did some bit sniffing and saw that:
-256 (11 0000 0000)
becomes:
768 (00 1111 1111)

Is the 10th bit always reserved as the signage? Bits and signage on a bit level were never my strongpoint so some friendly answers/advice/direction would be appreciated.

When I changed the function to unpack the normal to three 10-bit integers, I changed the bitwise and from 0x3FF to 0x1FF to exclude the 10th bit and 768 became 256 which makes sense, so I should probably just check the 10th bit, if it's set then the integer is negative?
Move over Mario... and cruise by Crash... Croc Rocks!
It's a serious adventure 3D platformer for all retro gamers to drool over =D

eradsoft
Posts: 30
Joined: Fri Dec 17, 2010 1:34 pm
Location: Either side of South Bypass, Madrid, Spain

Re: Vertex Coordinate Limits

Post by eradsoft » Wed Feb 08, 2012 8:56 am

Been fiddling around with normals, now I wrote an exporter for a generalized file format for animations and models for 3dsMax, it works a charm, exports the model and materials and sorts them so they can be easily batched, etc, but normals are being a pain. I copied the floattov10/PACK_NORMAL functions over so the result was the exact same but encountered the obvious sign issue, for instance, -256 is converted to 768 from a packed normal, so I did some bit sniffing and saw that:
-256 (11 0000 0000)
becomes:
768 (00 1111 1111)

Is the 10th bit always reserved as the signage? Bits and signage on a bit level were never my strongpoint so some friendly answers/advice/direction would be appreciated.

When I changed the function to unpack the normal to three 10-bit integers, I changed the bitwise and from 0x3FF to 0x1FF to exclude the 10th bit and 768 became 256 which makes sense, so I should probably just check the 10th bit, if it's set then the integer is negative?
I do the following and seems to be working properly:

Code: Select all

param = (((int)(normal[0]*511))& 0x3FF) | 
        (((int)(normal[1]*511))& 0x3FF)<<10 | 
        (((int)(normal[2]*511))& 0x3FF)<<20;
and later issue:

Code: Select all

glNormal(param); 
where:

Code: Select all

unsigned int param;
float   normal[3];

I hope this helps!!
--------------------------------
Welcome, my son, to the machine.
Pink Floyd.

eradsoft
Posts: 30
Joined: Fri Dec 17, 2010 1:34 pm
Location: Either side of South Bypass, Madrid, Spain

Re: Vertex Coordinate Limits

Post by eradsoft » Wed Feb 08, 2012 9:47 am

Sorry I did not answer to your question:
Signed integers are stored in what is called two's complement:
  • Your reserve half of your precision for negative numbers.
  • For obtaining a negative number you invert 0s and 1s and add 1
This way signed integers of 8 bits range is (b stands for binary):
  • Positives from 1 (0000 0001b) to 127 (0111 1111b)
  • Negatives from -1 (1111 1111b) to -128(1000 0000b)
  • Zero 0 is just 0000 0000b
So you could say that in signed integers you know the sign of the number by taking a look at the
most significant bit : 0 for positive, 1 for negative.


With normals it is a little tricky:
  • We have 10 bits, 1 reserved for integer part and 9 for fractional part
  • But you cannot use 1 or -1 because you integer part bit is needed for the sign
For example in 16 bit format with 7 bits for integer part and 9 bits for fractional part you will have:
  • 0000 001.0 0000 0000b for 1 and
  • 1111 111.0 0000 0000b for -1
If you strip the upper 6 bits you cannot tell -1 from 1 they both are 1.0 0000 0000b

So the maximum positive number for normals coordinates in the DS hw is:
0.1 1111 1111b which is a little less than 1 (0.99609375)
An the minimum negative number for normals coordinates is:
1.0 0000 0000b which is a exactly -1

That is why I multiply the float value by 511 instead of 512.
I don't know if I was able to explain it.
--------------------------------
Welcome, my son, to the machine.
Pink Floyd.

Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 3 guests