by Julio Jerez » Thu Dec 16, 2010 10:18 am
The operation is not costly at all. It is not exactly translation the world origin, basically this is a technique that CPU use to implement virtual memory, and multitasking operation system.
It works like this:
Everybody in body matrix is compost of two parts, the real address and the virtual address just like is a computer.
The real address is and address that is compose by the sum of few float values, say 4 float, (the number is irrelevant and does not affect the performance.
The virtual address will and offset part of the real address.
Say for example you have computer and you launch the same program twice. Say the program is not complete in a way that is can be memory independent, therefore it can only works in one fix location in memory.
What the operation system does is that is use a feature of the CPU called virtual address space.
What that is, is that it finds a free place in the lineal memory space, where the program fixes.
Then it calls the operation system to create a Virtual address space for the address and the size of eth program.
The OS places that address range into a look table all starting with the initial origin.
Then the virtual address mechanism is set make that every address between the origin and the range is substrate for the initial address using the hardware.
For example say a program start at address 0 and it is 1000 byte long
Say you lance the program the first time.
The OS find that location 5000 is free, and it call the OS to make a virtual address space at location 5000, 1000 bytes long.
The CPU returns the segment index.
The OS now run eth program at address 0, by the hardware know that at that segment anything less than 1000 sue be added to 5000,
So the program runs normally at for address 0, to 1000, but in reality it is locate at 5000 to 6000.
If you launch the same program again The OS fin the next available address space. An repeat the same process, so you can have more than one copy of the same program all running on same address virtual address, but internally they are running on different lineal addresses.
When the OS run out of linear memory, this functionality also extends easily to Storage space.
How does this translate to our game?
The matrix of a body remain the same they location is the address of the body.
In addition each body will also have a virtual address which is made from the sum of several float values.
Now say you are making a multiplayer space game and you has tow player large world,
In your side you are looking at the world form you player which is say near the origin, but another player is looking the world from his location which is say 100,000 miles away.
Both players can only see as far as the camera cal reach which is say 4 miles.
What you do is that you for you call you say Set Virtual address by passing the location of you player
And all call back will make the bodies location relative to that position. But internally the real address remains the same. The other players made the same call but they pass their player location and from his view point everything is relative to his location.
As you can see the functionality is not a Camera function but it can be use for that.
Any Game that does not use that feature still work the same way since all real address will have the sam segment and as long as bodies do not pass the limit of Victual address precision the they offset will no change.
For that there will be a function that set precision of the virtual address, for example
Say the precision is set to 6 significant decimal digit
Is a body location is say: 10.0031 is the X direction
Say another body is at the same location but 100000 units away.
Than would be 100010.0031
As you can see that number require more than six digit of float precision to keep all it significant digits.
The engine will keep those tow address as
Body1 0.0e0 + 1.00031e1
Body2 1.0e5 + 1.00031e1
The magic of floating point arithmetic allows for this to work automatically with very lithe performance impact.
If you are on body1 you set segment at zero,
For your body1 zero will be at 0.0 and body tow at 100010.00 but you could not see the second body, so it does not matter, you will see without jitter anything in the view frustum.
If the other player is on body2 he set segment at 100000,
he sees his body2 at 0.0 and the body1 at -100010.00