Sun flares and hud sprites 'shaking'!
Blitz3D Forums/Blitz3D Programming/Sun flares and hud sprites 'shaking'!
| ||
My current project is a 3d space simulation game in which the player has completely free movement in all directions, 'elite' style. I'm experiencing a problem with sprites shaking the further away the player gets from postion 0,0,0. It first came to light when I downloaded the absolutely AWESOME sun flares demo by Barliesque. You can get it here; http://www.blitzbasic.com/codearcs/codearcs.php?code=1107 In the demo it worked perfectly. When I got the code working in my game, I noticed at times the flares were shaking and even blinking in and out of view. You can see this for yourself by modifying the code in the above demo. After 'Scene = LoadAnimMesh("Media\Scene.b3d")'. Add the following line ScaleEntity scene,700,700,700 Then modify the player controls function so the movement speed is scaled up. If KeyDown(203) Then mvx=mvx-100 If KeyDown(205) Then mvx=mvx+100 If KeyDown(200) Then mvz=mvz+100 If KeyDown(208) Then mvz=mvz-100 If KeyDown(30) Then mvx=mvx-100 If KeyDown(32) Then mvx=mvx+100 If KeyDown(17) Then mvz=mvz+100 If KeyDown(31) Then mvz=mvz-100 Now if you run the code you'll notice (at least on my machine and another I tested it on) that the flares start jumping and shaking the further away you walk. The program uses CAMERAPROJECT, PROJECTEDX & PROJECTEDY to determine the 2d location of the sun on the screen before placing the sprites. The x and y values returned by these functions dont 'shake'. If you print them to the screen while the program is running you can see the flares shaking uncontrollably even when the player is stationary and the values returned by the above functions are static. I've now noticed by hud sprites, which are parented to the camera, also shake but to a lesser degree. It only seems to become noticeable when the player moves about 10000 away from position 0,0,0. Is there a fix for this (other than scaling my entire world down)? or is it one of those floating point problems I keep reading about? |
| ||
JOhn, Hm, I thought this 'bug' had gone away! With real-time worlds floating point accuracy is no where near something like 3D Max or Lightwave, so the further you travel from the origin the worse this problem will become. The way to solve it is to use a second camera for all your HUD stuff. Check out HUD and second camera code in the Archives or check on BlitzCoder. I am sure the answers are here. I use Swifts HUD and Filax's HUDs when I want one. IPete2. |
| ||
I've now noticed by hud sprites, which are parented to the camera, also shake but to a lesser degree. The way to solve it is to use a second camera for all your HUD stuff. You can also get this problem if your HUD sprites are too close to the camera, regardless of where in your 3D world everything is. |
| ||
It does sound like a float thing, and 10000.0 is coincidentally enough where you lose a digit of precision. You'll probably have to scale down. |
| ||
Hmmmm. Thanks for the replies. Scaling down it is! |
| ||
http://www.blitzcoder.com/cgi-bin/ubb-cgi/postdisplay.cgi?forum=Forum4&topic=000352 Andy |