internal void SetPlayerPosition( VoxelWorld world, ref btVector3 v )
		{
			{
				//Player_Position.x = v.x;
				//Player_Position.y = v.y;
				//Player_Position.z = v.z;
				Player_Sector.x = (int)( v.x / ( world.VoxelBlockSize * VoxelSector.ZVOXELBLOCSIZE_X ) );
				Player_Sector.y = (int)( v.y / ( world.VoxelBlockSize * VoxelSector.ZVOXELBLOCSIZE_Y ) );
				Player_Sector.z = (int)( v.z / ( world.VoxelBlockSize * VoxelSector.ZVOXELBLOCSIZE_Z ) );
				//Player_Voxel.x = (int)( v.x / world.VoxelBlockSize );
				//Player_Voxel.y = (int)( v.y / world.VoxelBlockSize );
				//Player_Voxel.z = (int)( v.z / world.VoxelBlockSize );
			}
		}
Exemple #2
0
		internal VoxelRef( VoxelWorld world, VoxelTypeManager vtm, byte x = 0, byte y = 0, byte z = 0, VoxelSector Sector = null, ushort VoxelType = 0 )
		{
			this.x = x;
			this.y = y;
			this.z = z;
			this.wx = ( Sector.Pos_x << VoxelSector.ZVOXELBLOCSHIFT_X )+ x;
			this.wy = ( Sector.Pos_y << VoxelSector.ZVOXELBLOCSHIFT_Y )+y;
			this.wz = ( Sector.Pos_z << VoxelSector.ZVOXELBLOCSHIFT_Z )+z;
			this.Sector = Sector;
			this.Offset = ( (uint)x << VoxelSector.ZVOXELBLOCSHIFT_Y )  + y + ((uint)z << ( VoxelSector.ZVOXELBLOCSHIFT_X+VoxelSector.ZVOXELBLOCSHIFT_Y));
			this.World = world;
			this.Type = vtm[VoxelType];
			VoxelTypeManager = vtm;
			VoxelExtension = null;
		}
		internal void SetWorld( VoxelWorld World ) { this.World = World; }
Exemple #4
0
			internal Sector( PhysicsEngine pe, VoxelWorld world, VoxelSector sector )
			{
				this.sector = sector;
				content = new VoxelShape[sector.Size_x * sector.Size_y * sector.Size_z];
				shape = new VoxelGridShape( content, world.VoxelBlockSize );
				grid = new VoxelGrid( shape, new Vector3( sector.Pos_x * sector.Size_x * world.VoxelBlockSize
													, sector.Pos_y * sector.Size_y * world.VoxelBlockSize
													, sector.Pos_z * sector.Size_z * world.VoxelBlockSize ) );
				PhysicsSpace = pe.world;
			}
Exemple #5
0
		static int ForEachVoxel( VoxelWorld World, ref VoxelRef v1, ref VoxelRef v2, ForEachCallback f, bool not_zero )
		{
			if( v1.Sector == null || v2.Sector == null )
				return not_zero ? 1 : 0;
			int v1x = v1.x + ( v1.Sector.Pos_x << VoxelSector.ZVOXELBLOCSHIFT_X );
			int v1y = v1.y + ( v1.Sector.Pos_y << VoxelSector.ZVOXELBLOCSHIFT_Y );
			int v1z = v1.z + ( v1.Sector.Pos_z << VoxelSector.ZVOXELBLOCSHIFT_Z );
			int v2x = v2.x + ( v2.Sector.Pos_x << VoxelSector.ZVOXELBLOCSHIFT_X );
			int v2y = v2.y + ( v2.Sector.Pos_y << VoxelSector.ZVOXELBLOCSHIFT_Y );
			int v2z = v2.z + ( v2.Sector.Pos_z << VoxelSector.ZVOXELBLOCSHIFT_Z );
			int del_x = v2x - v1x;
			int del_y = v2y - v1y;
			int del_z = v2z - v1z;
			int abs_x = del_x < 0 ? -del_x : del_x;
			int abs_y = del_y < 0 ? -del_y : del_y;
			int abs_z = del_z < 0 ? -del_z : del_z;
			// cannot use iterate if either end is undefined.
			if( del_x != 0 )
			{
				if( del_y != 0 )
				{
					if( del_z != 0 )
					{
						if( abs_x > abs_y || ( abs_z > abs_y ) )
						{
							if( abs_z > abs_x )
							{
								// z is longest path
								int erry = -abs_z / 2;
								int errx = -abs_z / 2;
								int incy = del_y < 0 ? -1 : 1;
								int incx = del_x < 0 ? -1 : 1;
								int incz = del_z < 0 ? -1 : 1;
								{
									int x = v1x;
									int y = v1y;
									for( int z = v1z + incz; z != v2z; z += incz )
									{
										errx += abs_x;
										if( errx > 0 )
										{
											errx -= abs_z;
											x += incx;
										}
										erry += abs_y;
										if( erry > 0 )
										{
											erry -= abs_z;
											y += incy;
										}
										{
											int val;
											VoxelRef v;
											if( World.GetVoxelRef( out v, x, y, z ) )
											{
												val = f( ref v );
												if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
													return val;
											}
										}
									}
								}
							}
							else
							{
								// x is longest.
								int erry = -abs_x / 2;
								int errz = -abs_x / 2;
								int incy = del_y < 0 ? -1 : 1;
								int incx = del_x < 0 ? -1 : 1;
								int incz = del_z < 0 ? -1 : 1;
								{
									int y = v1y;
									int z = v1z;
									for( int x = v1x + incx; x != v2x; x += incx )
									{
										errz += abs_z;
										if( errz > 0 )
										{
											errz -= abs_x;
											z += incx;
										}
										erry += abs_y;
										if( erry > 0 )
										{
											erry -= abs_x;
											y += incy;
										}
										{
											int val;
											VoxelRef v;
											if( World.GetVoxelRef( out v, x, y, z ) )
											{
												val = f( ref v );
												if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
													return val;
											}
										}
									}
								}
							}
						}
						else
						{
							// y is longest.
							int errx = -abs_y / 2;
							int errz = -abs_y / 2;
							int incy = del_y < 0 ? -1 : 1;
							int incx = del_x < 0 ? -1 : 1;
							int incz = del_z < 0 ? -1 : 1;
							{
								int x = v1x;
								int z = v1x;
								for( int y = v1y + incy; y != v2y; y += incy )
								{
									errx += abs_x;
									if( errx > 0 )
									{
										errx -= abs_y;
										x += incx;
									}
									errz += abs_z;
									if( errz > 0 )
									{
										errz -= abs_y;
										z += incz;
									}
									{
										int val;
										VoxelRef v;
										if( World.GetVoxelRef( out v, x, y, z ) )
										{
											val = f( ref v );
											if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
												return val;
										}
									}
								}
							}
						}
					}
					else
					{
						// z is constant
						if( abs_x > abs_y )
						{
							// x is longest
							int erry = -abs_x / 2;
							int incy = del_y < 0 ? -1 : 1;
							int incx = del_x < 0 ? -1 : 1;
							{
								int y = v1y;
								int z = v1z;
								for( int x = v1x + incx; x != v2x; x += incx )
								{
									erry += abs_y;
									if( erry > 0 )
									{
										erry -= abs_x;
										y += incy;
									}
									{
										int val;
										VoxelRef v;
										if( World.GetVoxelRef( out v, x, y, z ) )
										{
											val = f( ref v );
											if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
												return val;
										}
									}
								}
							}
						}
						else
						{
							// y is longest.
							int errx = -abs_y / 2;
							int incy = del_y < 0 ? -1 : 1;
							int incx = del_x < 0 ? -1 : 1;
							// z is longest path
							{
								int x = v1x;
								int z = v1x;
								for( int y = v1y + incy; y != v2y; y += incy )
								{
									errx += abs_x;
									if( errx > 0 )
									{
										errx -= abs_y;
										x += incx;
									}
									{
										int val;
										VoxelRef v;
										if( World.GetVoxelRef( out v, x, y, z ) )
										{
											val = f( ref v );
											if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
												return val;
										}
									}
								}
							}
						}
					}
				}
				else
				{
					if( del_z != 0 )
					{
						if( abs_x > abs_z )
						{
							// x is longest.
							int errz = -abs_x / 2;
							int incx = del_x < 0 ? -1 : 1;
							int incz = del_z < 0 ? -1 : 1;
							{
								int y = v1y;
								int z = v1z;
								for( int x = v1x + incx; x != v2x; x += incx )
								{
									errz += abs_z;
									if( errz > 0 )
									{
										errz -= abs_x;
										z += incx;
									}
									{
										int val;
										VoxelRef v;
										if( World.GetVoxelRef( out v, x, y, z ) )
										{
											val = f( ref v );
											if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
												return val;
										}
									}
								}
							}
						}
						else
						{
							// z is longest path
							int errx = -abs_z / 2;
							int incx = del_x < 0 ? -1 : 1;
							int incz = del_z < 0 ? -1 : 1;
							{
								int x = v1x;
								int y = v1y;
								for( int z = v1z + incz; z != v2z; z += incz )
								{
									errx += abs_x;
									if( errx > 0 )
									{
										errx -= abs_z;
										x += incx;
									}
									{
										int val;
										VoxelRef v;
										if( World.GetVoxelRef( out v, x, y, z ) )
										{
											val = f( ref v );
											if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
												return val;
										}
									}
								}
							}
						}
					}
					else
					{
						// x is only changing.
						int incx = del_x < 0 ? -1 : 1;
						for( int x = v1x + incx; x != v2x; x += incx )
						{
							int val;
							VoxelRef v;
							if( World.GetVoxelRef( out v, x, v1y, v1z ) )
							{
								val = f( ref v );
								if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
									return val;
							}
						}
					}
				}
			}
			else
			{
				if( del_y != 0 )
				{
					if( del_z != 0 )
					{
						if( abs_y > abs_z )
						{
							// y is longest.
							int errz = -abs_y / 2;
							int incy = del_y < 0 ? -1 : 1;
							int incz = del_z < 0 ? -1 : 1;
							{
								int x = v1x;
								int z = v1x;
								for( int y = v1y + incy; y != v2y; y += incy )
								{
									errz += abs_z;
									if( errz > 0 )
									{
										errz -= abs_y;
										z += incz;
									}
									{
										int val;
										VoxelRef v;
										if( World.GetVoxelRef( out v, x, y, z ) )
										{
											val = f( ref v );
											if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
												return val;
										}
									}
								}
							}
						}
						else
						{
							// z is longest path
							int erry = -abs_z / 2;
							int incy = del_y < 0 ? -1 : 1;
							int incz = del_z < 0 ? -1 : 1;
							{
								int x = v1x;
								int y = v1y;
								for( int z = v1z + incz; z != v2z; z += incz )
								{
									erry += abs_y;
									if( erry > 0 )
									{
										erry -= abs_z;
										y += incy;
									}
									{
										int val;
										VoxelRef v;
										if( World.GetVoxelRef( out v, x, y, z ) )
										{
											val = f( ref v );
											if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
												return val;
										}
									}
								}
							}
						}
					}
					else
					{
						// no del_x, no del_z
						// y is only changing.
						int incy = del_y < 0 ? -1 : 1;
						for( int y = v1y + incy; y != v2y; y += incy )
						{
							int val;
							VoxelRef v;
							if( World.GetVoxelRef( out v, v1x, y, v1z ) )
							{
								val = f( ref v );
								if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
									return val;
							}
						}
					}
				}
				else
				{
					// no del_x, no del_y...
					if( del_z != 0 )
					{
						if( del_z > 0 )
							for( int z = v1z + 1; z < v2z; z++ )
							{
								int val;
								VoxelRef v;
								if( World.GetVoxelRef( out v, v1x, v1y, z ) )
								{
									val = f( ref v );
									if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
										return val;
								}
							}
						else
							for( int z = v2z + 1; z < v1z; z++ )
							{
								int val;
								VoxelRef v;
								if( World.GetVoxelRef( out v, v1x, v1y, z ) )
								{
									val = f( ref v );
									if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
										return val;
								}
							}

					}
					else
					{
						// no delta diff, nothing to do.
					}
				}
			}
			return not_zero ? 1 : 0;
		}
Exemple #6
0
		} //

		public void Dispose()
		{
			int i;
			if( VoxelTypeManager != null )
			{
				for( i = 0; i < DataSize; i++ )
				{
					if( Data.OtherInfos[i] != null )
						Data.OtherInfos[i].Dispose();
					Data.OtherInfos[i] = null;
				}
			}
			Data.Dispose();
#if VOXEL_CULLER
			if( Culling ) { delete[] Culling; Culling = 0; }
#endif
			solid_geometry.Dispose();
			transparent_geometry.Dispose();
			custom_geometry.Dispose();
			world = null;

			SectorsInMemory--;
		}
Exemple #7
0
		public VoxelSector( VoxelGameEnvironment GameEnv, VoxelWorld world, int x = 0, int y = 0, int z = 0 )
		{
			//Console.WriteLine( "Sectors in memory : " + SectorsInMemory + " at " + x + ","+y+","+z );
			Pos_x = x;
			Pos_y = y;
			Pos_z = z;
			this.world = world;

			ModifTracker.Init( ZVOXELBLOCSIZE_X * ZVOXELBLOCSIZE_Y * ZVOXELBLOCSIZE_Z );
			DefaultInit();

			if( world != null )
			{
				physics = new PhysicsEngine.Sector( GameEnv.Engine, world, this );
			}
		}
Exemple #8
0
		internal void Render_EmptySector( Display display, VoxelWorld world, int x, int y, int z, float r, float g, float b )
		{
			Vector4 c;
			int sx = (int)(VoxelSector.ZVOXELBLOCSIZE_X * world.VoxelBlockSize );
			int sy = (int)(VoxelSector.ZVOXELBLOCSIZE_Y * world.VoxelBlockSize );
			int sz = (int)(VoxelSector.ZVOXELBLOCSIZE_Z * world.VoxelBlockSize );

			c.X = r;
			c.Y = g;
			c.Z = b;
			c.W = 0.5f;
			unsafe
			{
				fixed ( float* _v = sector_verts )
				{
					float* v = _v;
					*(v++) = x * sx;
					*(v++) = y * sy;
					*(v++) = z * sz;
					*(v++) = x * sx;
					*(v++) = y * sy;
					*(v++) = z * sz + sz;

					*(v++) = x * sx;
					*(v++) = y * sy;
					*(v++) = z * sz + sz;
					*(v++) = x * sx + sx;
					*(v++) = y * sy;
					*(v++) = z * sz + sz;

					*(v++) = x * sx + sx;
					*(v++) = y * sy;
					*(v++) = z * sz + sz;
					*(v++) = x * sx + sx;
					*(v++) = y * sy;
					*(v++) = z * sz;


					*(v++) = x * sx + sx;
					*(v++) = y * sy;
					*(v++) = z * sz;
					*(v++) = x * sx;
					*(v++) = y * sy;
					*(v++) = z * sz;

					*(v++) = x * sx;
					*(v++) = y * sy + sy;
					*(v++) = z * sz;
					*(v++) = x * sx;
					*(v++) = y * sy + sy;
					*(v++) = z * sz + sz;

					*(v++) = x * sx;
					*(v++) = y * sy + sy;
					*(v++) = z * sz + sz;
					*(v++) = x * sx + sx;
					*(v++) = y * sy + sy;
					*(v++) = z * sz + sz;

					*(v++) = x * sx + sx;
					*(v++) = y * sy + sy;
					*(v++) = z * sz + sz;
					*(v++) = x * sx + sx;
					*(v++) = y * sy + sy;
					*(v++) = z * sz;

					*(v++) = x * sx + sx;
					*(v++) = y * sy + sy;
					*(v++) = z * sz;
					*(v++) = x * sx;
					*(v++) = y * sy + sy;
					*(v++) = z * sz;

					*(v++) = x * sx;
					*(v++) = y * sy;
					*(v++) = z * sz;
					*(v++) = x * sx;
					*(v++) = y * sy + sy;
					*(v++) = z * sz;

					*(v++) = x * sx;
					*(v++) = y * sy;
					*(v++) = z * sz + sz;
					*(v++) = x * sx;
					*(v++) = y * sy + sy;
					*(v++) = z * sz + sz;

					*(v++) = x * sx + sx;
					*(v++) = y * sy;
					*(v++) = z * sz + sz;
					*(v++) = x * sx + sx;
					*(v++) = y * sy + sy;
					*(v++) = z * sz + sz;

					*(v++) = x * sx + sx;
					*(v++) = y * sy;
					*(v++) = z * sz;
					*(v++) = x * sx + sx;
					*(v++) = y * sy + sy;
					*(v++) = z * sz;
					if( display.simple.Activate() )
						display.simple.DrawBox( sector_verts, ref c );
				}
			}
		}
Exemple #9
0
		internal abstract void Render( Display display, VoxelGameEnvironment game, VoxelWorld world );
Exemple #10
0
		void SetWorld( VoxelWorld World )
		{

		}