Code archives/3D Graphics - Misc/Homekeeping
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
Moving a player mesh far away from 0,0,0 results in mesh jitter due inaccuracy of vertex float positions (or even "jumping" meshes). If you want to use very large distances like in a space game (>100.000), the homekeeping function is the answer. It just moves the player mesh in a given distance (ex. 1000 Units) and puts it back to the opposite position while moving the world instead of the player. The world must be attached to a "masterpivot", even collisions work this way. Here is a demo, homekeeping is disabled by default to show the jitter effect first. To enable homekeeping just uncomment this line in the main loop: ;HomeKeeping(player,masterpivot,1000) Moving with mouse/arrow keys, SPACE=wireframe, LMB=Zoom 10x, RMB=Move 10x faster ![]() demo.bb | |||||
Global localx#,localy#,localz# Global globalx#,globaly#,globalz# Global simx#,simy#,simz# ; keeps the player in a given distance while the world can move far away Function HomeKeeping(player%,world%,homesize%=100) ; store local player position localx=EntityX(player) localy=EntityY(player) localz=EntityZ(player) ; check X axis While localx>homesize globalx=globalx+homesize localx=localx-homesize PositionEntity player,localx,localy,localz MoveEntity world,-homesize,0,0 Wend While localx<-homesize globalx=globalx-homesize localx=localx+homesize PositionEntity player,localx,localy,localz MoveEntity world,homesize,0,0 Wend ; check Y axis While localy>homesize globaly=globaly+homesize localy=localy-homesize PositionEntity player,localx,localy,localz MoveEntity world,0,-homesize,0 Wend While localy<-homesize globaly=globaly-homesize localy=localy+homesize PositionEntity player,localx,localy,localz MoveEntity world,0,homesize,0 Wend ; check Z axis While localz>homesize globalz=globalz+homesize localz=localz-homesize PositionEntity player,localx,localy,localz MoveEntity world,0,0,-homesize Wend While localz<-homesize globalz=globalz-homesize localz=localz+homesize PositionEntity player,localx,localy,localz MoveEntity world,0,0,homesize Wend ; store simulated player position simx=localx+globalx simy=localy+globaly simz=localz+globalz End Function |
Comments
| ||
This may come in handy, Thanks! |
| ||
I have done something similar but in a zone of 100x100x100units. The next step is to find a way to save then delete then load then create the environment and entities in real time, without causing slowdown... |
Code Archives Forum