|
Author
|
Topic: Large playing area problems
|
nukomod
 Elite Member
    Posts: 124 From: Registered: Jul 2003
|
posted 06/14/04 12:12 PM
IP: Logged
I've come across a problem I'm
hoping someone will be able to help me with. The further a mesh travels
from the 0,0,0 origin the more it begins to 'break apart'. There seems
to be some inaccuracy in positioning child entities and the whole model
begins to 'shake'. At first I was using a small scale, so I doubled the
size of everything. This had the effect of doubling the distance from the origin
you could travel before noticing the shaking but relatively I have the
exact same playing field as before! Is this a known problem, or am I
just abusing the scale in Blitz? Any advice would be helpful.As
a work around I suppose I could write the code to move the whole world
around the camera at the 0,0,0 position, so you don't see any of this
shaking where ever you go, but this doesn't seem very elegant to me. Here's a quick example showing the problem. The problem is even worse in the game I'm writing, as the players camera is very close to the model and it is very obvious something has gone wrong! [This message has been edited by nukomod (edited 06-14-2004).] [This message has been edited by nukomod (edited 06-29-2004).]
|
gabrielknight74
 1,000 Post Club!
        
*BlitzCoder VIP*
Posts: 3894 From: UK Registered: Mar 2002
|
posted 06/14/04 12:46 PM
IP: Logged
Floating point inaccuracy
causes this. Blitz floats start getting unreliable somewhere between 6
and 7 digits ( totalling both before and after the decimal point. ) The
only real solution is to scale your world and all your entities so that
you can fit the area you need into a smaller numerical distance, thus
not reaching the distances where Blitz floats get out of control.------------------ Tennis has never been more fun :
|
nukomod
 Elite Member
    Posts: 124 From: Registered: Jul 2003
|
posted 06/14/04 01:01 PM
IP: Logged
6 to 7 digits with or without
the decimal point? By reducing the size of my entities I'd need greater
accuracy in their positions by the same amount, so the playing size
looks to be somewhat fixed in my case. I think I shall have to
implement the solution where the entire world is parented to the camea
or a pivot and move it around the origin.I am using Tokamak for the positions of objects and I don't believe it suffers as Blitz does (higher precision floats probably) so as long as a render everything local to the camera Tokamak shouldn't care. I
don't suppose Mark would every consider increasing the accuracy of the
float internally? I wouldn't want another data type, just more internal
precision!
|
morduun
 Moderator
 Stickman Contest Winner 1st Place!
       Contributing Author Posts: 2426 From: NJ, USA Registered: Jul 2002
ICQ: 44373244
|
posted 06/14/04 01:10 PM
IP: Logged
Unlikely. Invoking DirectX
apparently removes support for doubles in order to add speed (Mark's
words, not my research) so you'll need a different approach.------------------ Error reading brain: (A)bort, (R)etry, (I)gnore, (F)ail?
|
nukomod
 Elite Member
    Posts: 124 From: Registered: Jul 2003
|
posted 06/14/04 02:29 PM
IP: Logged
Oh well, thanks anyway guys.
|
Scienthsine
 500 Post Club!
       Posts: 763 From: Registered: Jul 2003
|
posted 06/14/04 06:48 PM
IP: Logged
Hmmm... well I have developed
a hate fore floats... and after reading that as being the reason hwy
Blitz doesn't have doubles, I started doing some searching. My first
hit says: quote:
Intel
processor floating-point unit (FPU) operates only with double values.
To make operation with float it converts it first to double. So, c*d is
faster. Float operations may be faster than double only when SSE texhnology is used.
|EDIT| Ohh
the question that this post was replying to was if multiplying two
floats was faster than two doubles. (floats a&b and doubles c&d) |EDIT| But this is off of a forum-type thingy, so I'm not sure of it's accuracy...------------------ 0100101001100001011011010110010101110011 010011100110010101110111011011010110000101101110 [This message has been edited by Scienthsine (edited 06-14-2004).]
|
Scienthsine
 500 Post Club!
       Posts: 763 From: Registered: Jul 2003
|
posted 06/14/04 06:54 PM
IP: Logged
Second Hit: quote:
Direct3D and the FPU.. I
had an email this morning about Managed Direct3D 'breaking' the math
functions in the CLR. The person who wrote discovered that this method:public void AssertMath() { double dMin = 0.54797677334988781; double dMax = 4.61816551621179; double dScale = 1/(dMax - dMin); double dNewMax = 1/dScale + dMin; System.Diagnostics.Debug.Assert( dMax == dNewMax); } Behaved
differently depending on whether or not a Direct3D device had been
created. It worked before the device was created, and failed
afterwords. Naturally, he assumed this was a bug, and was concerned.
Since i've had to answer questions similar to this multiple times now,
well that pretty much assures it needs it's own blog entry. The
short of it is this is caused by the floating point unit (FPU). When a
Direct3D device is created, the runtime will change the FPU to suit its
needs (by default switch to single precision, the default for the CLR is double precision). This is done because it has better performance than double precision (naturally). Now, the code above works before the device is created because the CLR is running in double precision. Then you create a Direct3D device, the FPU is switched to single precision, and there are no longer enough digits of precision to accurately calculate the above code. Thus the 'failure'. Luckily,
you can avoid all of this by simply telling Direct3D not to mess with
the FPU at all. When creating the device you should use the
CreateFlags.FpuPreserve flag to keep the CLR's double precision, and have your code functioning as you expect it.
Taken from some website with a "Managed DirectX" lib I think. |EDIT| Also found something saying that DarkBasic has floats and doubles... not sure though. |EDIT| ------------------ 0100101001100001011011010110010101110011 010011100110010101110111011011010110000101101110 [This message has been edited by Scienthsine (edited 06-14-2004).]
|
nukomod
 Elite Member
    Posts: 124 From: Registered: Jul 2003
|
posted 06/18/04 12:57 AM
IP: Logged
Thanks for the info, it's
quite interesting. At least I won't have a grudge with Blitz basic over
it. I've just finished the system that keeps the camera at the origin
and its eliminated the problem. Now Tokamak precision
is the limitation and so far I haven't run in to it. The useable area
seems to be way bigger than I'll ever need so I'm very happy now  [This message has been edited by nukomod (edited 06-18-2004).]
|
slenkar
 1,000 Post Club!
         Posts: 1818 From: Louisville Kentucky Registered: Aug 2003
|
posted 06/18/04 02:32 AM
IP: Logged
Think of blitz like a theatre stage instead of a real world. Set pieces have to be moved off the stage and the actors dont really travel although they may say they are!------------------
|
nukomod
 Elite Member
    Posts: 124 From: Registered: Jul 2003
|
posted 06/28/04 05:35 PM
IP: Logged
I've been busy thinking of work arounds for the problem, but still need help!At
first I set up the world so the camera remained at 0,0,0 (global) and
everything moved around it, but it had the same problem. I figured this
was because everything was parented to a single entity, and there
distance from this entity was causing the same problem. So
I came up with another idea. I parented everything to the camera, but
positioned everything still with global positions from Tokamak. So
everything was still in its correct place, but relative positions were
all from the camera. Anything far away enough to become unstable is out
of view range so it doesn't matter. The problem remains though. The
camera can still go too far and reach the 'unstable' distance, but
because everything is relative to the camera I didn't think this would
matter. Does anyone have any practical experience with this problem?
|
nukomod
 Elite Member
    Posts: 124 From: Registered: Jul 2003
|
posted 06/28/04 09:49 PM
IP: Logged
Really need suggestions! I
created this flash file (7kb) to help explain the problem. I can't
believe nobody else has had to tackle this problem, I'm sure anyone
whose made a 3D space game in Blitz has run across this.explanation
|
nukomod
 Elite Member
    Posts: 124 From: Registered: Jul 2003
|
posted 06/29/04 12:31 AM
IP: Logged
Crazy, I think I've cracked
it.. but its a very slight change on a method I tried before. Needs
more testing but I've been at ranges of around 100,000 blitz units
without any problems.If anyone's interested in how this is done I can post a full explanation... but for now precious sleep.
|
cR@wLy
 1,000 Post Club!
         Posts: 1063 From: bradford- uk Registered: Mar 2003
|
posted 06/29/04 04:37 PM
IP: Logged
Umm, I haven't read the
thread, but from that diagram, why don't you offset everything by the
camera? By this I mean actually storing the positions of objects based
on the camera as the origin, as opposed to using the actual origin as
the origin, and then just offsetting the camera to the origin for
rendering as this wouldn't help. To do this, basically just store tuff
like normal, but instead of moving the camera move all the objects. Now
it would mean you couldn't attatch everything to a pivot, you would
have to go through everything manually with a loop or whatever, and I
imagine that things will become slightly out of place if you move them
really far out and then in again, infact if you move the camera (so to
speak) really slowly towards them it might round their movement to
nothing and they might never come back... hmm well thats only in
extreme cases anyway. Try it, it might work.------------------ I'm with STUPID ^^^^
|
nukomod
 Elite Member
    Posts: 124 From: Registered: Jul 2003
|
posted 06/29/04 04:44 PM
IP: Logged
I thought I'd got it working
last night, but it didn't work very well when there were a few entities
parented together like most of the B3D's I'm using. It was fine with a
simple hierarchy though. I have another method to try, like cR@wLy was
describing. This is the method I've had the most success with so far,
but I have a couple of ideas to improve it.As
a note it probably wasn't very clear but on the explanation there are
arrows at the top to move between the different pages. (there's 6)
|
Andy Veteran Member
     Posts: 493 From: Registered: Aug 2001
|
posted 06/29/04 09:26 PM
IP: Logged
>I can't believe nobody else has had to tackle this problem, I'm sure >anyone whose made a 3D space game in Blitz has run across this.If you had searched the board, you would have found many threads on this subject... http://www.blitzcoder.com/cgi-bin/ubb-cgi/postdisplay.cgi?forum=Forum4&topic=000352 With code and everything... Just read the whole thread and remember to disable/enable collisions. EDIT:
Maybe this should be in a FAQ of some sort... It would help newbies if
they didn't have to reinvent the wheel all of the time... Andy [This message has been edited by Andy (edited 06-29-2004).]
|
nukomod
 Elite Member
    Posts: 124 From: Registered: Jul 2003
|
posted 06/29/04 10:38 PM
IP: Logged
Thanks Andy. I had searched
the main blitz site's forum and found some similar threads but they
didn't really lead anywhere. That thread you linked to was interesting,
but I tried the method used there without much success. I pivoted the
whole world and moved it so the camera remained at 0,0,0 but the
problem continued. I'm guessing this is because the pivot got so far
away that the local positions to the pivot of the entities were causing
inaccuracies.What I'm trying to do now is basically use the Tokamak double precision
floats to position everything, but keep a blitz pivot to offset the
world so the camera is at 0,0,0. None of the blitz entities positioned
with tokamak will be parented to the pivot however, it'll just be used
for reference. This way the objects that are too far from the origin
will become unstable, but won't be visible. As the player approaches
them their positions will become more accurate as the original Tokamak
positions are always used as the source. I think the problem may be magnified in my game as many of the objects affected have slightly more complex hierarchies than usual. If you have any other ideas and suggestions their definatley welcome.
|
Andy Veteran Member
     Posts: 493 From: Registered: Aug 2001
|
posted 06/30/04 02:27 AM
IP: Logged
>That thread you linked to was interesting, but I tried the method used >there without much success.Weird... It works for me and many others. >I pivoted the whole world and moved it so the >camera remained at 0,0,0 but the problem continued. I'm guessing this is >because the pivot got so far away that the local positions to the pivot >of the entities were causing inaccuracies. So basically you didn't use the method described at all. >What I'm trying to do now is basically use the Tokamak double precision >floats to position everything, but keep a blitz pivot to offset the world >so the camera is at 0,0,0. So you convert from double precision floats to single precision floats and expect them to be more accurate than usual? Then you add a pivot, decreasing accuracy even further! >None of the blitz entities positioned with tokamak will be parented to >the pivot however, it'll just be used for reference. This way the objects >that are too far from the origin will become unstable, but won't be >visible. As the player approaches them their positions will become more >accurate as the original Tokamak positions are always used as the source. It doesn't matter what you use as a source... You try to achieve double precision accuracy with single precision
numbers... It can't be done, except if you have access to B3D's
internals... AFAIU, B3D uses double precission floats internally. Are
you using a dll or userlib to mess around with the programs in memory? I
have to admit that I am confused! It sounds like you are trying to do
the same thing as is described in the post, but instead of doing it the
simple way we all know works, you have decided to reinvent it in a
complex way that won't easily work... Andy
|
nukomod
 Elite Member
    Posts: 124 From: Registered: Jul 2003
|
posted 06/30/04 11:09 AM
IP: Logged
I'm sorry if what I've done is
confusing, but I do appreciate the help. I'm not trying to redo
anything when there's a known work around for this problem!I'm going to have another crack at it today.. wish me luck. ------------------ NovaStorm Scrolling Shoot 'Em up SDK|Magic Mokey Spaceship|AI Germs|Voxel Demo 3
|
Andy Veteran Member
     Posts: 493 From: Registered: Aug 2001
|
posted 06/30/04 11:26 AM
IP: Logged
What are you trying to do?What
is the connection between tokamak(a physics library I believe?) and the
3D world coordinates? Surely the physics work in local space? Is there a special reason why you use double precision floats and then convert to single precision? I am not being critical, but I am just not sure I understand how the work around for FP precision is related to the physics library in your program!? Moving the world around the camera is very processor intensive and will easily introduce problems with precision
and movement of entities, which is why the simpler approach of moving
entities and just resetting the camera to 0,0,0 every once in a while
is better suited to B3D... Unless of course you wish to do in code what
B3D already does for you. Anyway, I wish you luck and hope you get it working! Andy
|
Scienthsine
 500 Post Club!
       Posts: 763 From: Registered: Jul 2003
|
posted 06/30/04 12:36 PM
IP: Logged
I've been playing around with
Morrowind alot lately, and that's probley one of the reasons they have
their system set up the way they do. The whole loading new areas, and
some of the surroundings thing most likely repositions everything so
that the positions are ok..? This can be done without loading screens
like in Project Entropia... but I think you'll have problems trying to
stream from disk with Blitz.|EDIT| The
way I would do it, is to divide the entire world into sections. Then
the world consists of a 2d dimensional array of sections of land (or
whatever) each so big. The character has an area that is always
positioned around him. This area moves with him. (Probley best to have
it move after he has gotten so close to one of it's sides or
something.) Ohh and the player has a section position, as well as a
position in that section like everything else. Then, with a very small
bit of math, and logic, when you move the "Active" area around the
player, place everything that should be somewhere in their respective
places. Hmmm
I'm not sure how to describe it better than that... Basically though
your infact just increasing how many bytes are used to store your
position. Ohhh and you can load everything into ram, streaming from
disk isn't required. |EDIT| ------------------ 0100101001100001011011010110010101110011 010011100110010101110111011011010110000101101110 [This message has been edited by Scienthsine (edited 06-30-2004).]
|