Hi Mohammed,
At 12:00 26.10.00 , you wrote:
>how can I construct a Locale at Origine(x,y.z)?.I want to have two
>locale under my universe. I read about the HiResCoord classe but I
>didn't really understand how it works. let's say I want the origine at
>(12,10,45) how do I come then to the following
>Constructor parameters values:
>public HiResCoord(int[] X,
> int[] Y,
> int[] Z)
>
> x - an eight element array specifying the x position
> y - an eight element array specifying the y position
> z - an eight element array specifying the z position
I checked the documentation for HiResCoord (you DO have the JavaDocs for
the J3D library, don't you?) and found this:
(-----quote-----)
The HiResCoord defines a point using a set of three high-resolution
coordinates, each of which consists of three
two's-complement fixed-point numbers. Each high-resolution number consists
of 256 total bits with a binary point at bit 128, or
between the integers at index 3 and 4. A high-resolution coordinate of 1.0
is defined to be exactly 1 meter. This coordinate
system is sufficient to describe a universe in excess of several billion
light years across, yet still define objects smaller than a
proton.
(-----end quote-----)
This isn't immediately obvious if you're not into binary math, but it can
be worked out.
Here is a picture of the first 3 of those 8 integers and the bytes
contained therein.
Note 1: I'm only showing part of the number because an email line is only
so long.
Note 2: Change the font of this text to Courier to look at it, or it will
not be aligned right.
Int index: -----0----- -----1----- -----2-----
Contents (hex): 00 00 00 00 00 00 00 00 00 00 00 00
So... an integer is 4 bytes = 32 bits.
With all those bits, one integer can count up to 2 billion or so before the
high bit flips and it becomes negative.
The description says that we should imagine a binary point between the
third and fourth integer. This means that the bits to the left of this
position form a whole number and the bits to the right form a fraction. To
show this, I'll zoom out of my picture a bit now, showing integers, not bytes:
Index: ----0--- ----1--- ----2--- ----3--- . ----4--- ...
Contents: 00000000 00000000 00000000 00000000 | 00000000 ...
You said you wanted your X to be 12. All you have to do is make the
decimal/binary point in your number (it's to the right of the 12) line up
with the decimal/binary/whatever point in this 256-bit-long number
describing your position. Your 12 is 0C in hex, if you line it up in the
big number it looks like this (note where I put the 'C'):
Index: ----0--- ----1--- ----2--- ----3--- . ----4--- ...
Contents: 00000000 00000000 00000000 0000000C | 00000000 ...
which tells you that to create a '12' as a HiResCoord all you have to do is
put that 12, as an ordinary integer, into the 4th word (word index 3 in the
array) of an array containing 8 zeroes. Bingo, done! This approach will
take you all the way up to about 2 billion; after that you need to do some
bit twiddling to get the right numbers into the right integers.
If you want fractions behind the decimal point, say 0.25, then you need to
set some bits in the 5th integer (word 4). To create 0.25, you need to put
0.25 of 0x100000000 into that integer, or roughly 1 billion.
So... positioning a Locale is not so hard, especially if the position is a
whole number less than 2 billion.
Happy hacking, I hope it works out for you!
-Carl-
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".