Example #1
0
		public void LoadDemos( string DemoAssembly )
		{
			AxiomSortedCollection<string, DemoItem> demoList = new AxiomSortedCollection<string, DemoItem>();

			Assembly demos = Assembly.LoadFrom( DemoAssembly );
			Type[] demoTypes = demos.GetTypes();
			Type techDemo = demos.GetType( "Axiom.Demos.TechDemo" );

			foreach ( Type demoType in demoTypes )
			{
				if ( demoType.IsSubclassOf( techDemo ) )
				{

					demoList.Add( demoType.Name, new DemoItem( demoType.Name, demoType ) );
				}
			}

			foreach ( KeyValuePair<string, DemoItem> demoItem in demoList )
			{
				lstDemos.Items.Add( demoItem.Value );
			}

			this.lstDemos.SelectedIndexChanged += new EventHandler( lstDemos_SelectedIndexChanged );
			this.lstDemos.DoubleClick += new EventHandler( cmdOk_Click );

			if ( lstDemos.Items.Count > 0 )
				lstDemos.SelectedIndex = 0;

			this.tmrRotator.Start();

		}
		public void Initialize( int startx, int startz, Real[] pageHeightData )
#endif
		{
			if ( this.mOptions.maxGeoMipMapLevel != 0 )
			{
				var i = (int)1 << ( this.mOptions.maxGeoMipMapLevel - 1 );

				if ( ( i + 1 ) > this.mOptions.tileSize )
				{
					LogManager.Instance.Write( "Invalid maximum mipmap specifed, must be n, such that 2^(n-1)+1 < tileSize \n" );
					return;
				}
			}

			DeleteGeometry();

			//calculate min and max heights;
			Real min = 256000, max = 0;

			this.mTerrain = new VertexData();
			this.mTerrain.vertexStart = 0;
			this.mTerrain.vertexCount = this.mOptions.tileSize*this.mOptions.tileSize;

			renderOperation.useIndices = true;
			renderOperation.operationType = this.mOptions.useTriStrips ? OperationType.TriangleStrip : OperationType.TriangleList;
			renderOperation.vertexData = this.mTerrain;
			renderOperation.indexData = GetIndexData();

			var decl = this.mTerrain.vertexDeclaration;
			var bind = this.mTerrain.vertexBufferBinding;

			// positions
			var offset = 0;
			decl.AddElement( MAIN_BINDING, offset, VertexElementType.Float3, VertexElementSemantic.Position );
			offset += VertexElement.GetTypeSize( VertexElementType.Float3 );
			if ( this.mOptions.lit )
			{
				decl.AddElement( MAIN_BINDING, offset, VertexElementType.Float3, VertexElementSemantic.Position );
				offset += VertexElement.GetTypeSize( VertexElementType.Float3 );
			}
			// texture coord sets
			decl.AddElement( MAIN_BINDING, offset, VertexElementType.Float2, VertexElementSemantic.TexCoords, 0 );
			offset += VertexElement.GetTypeSize( VertexElementType.Float2 );
			decl.AddElement( MAIN_BINDING, offset, VertexElementType.Float2, VertexElementSemantic.TexCoords, 1 );
			offset += VertexElement.GetTypeSize( VertexElementType.Float2 );
			if ( this.mOptions.coloured )
			{
				decl.AddElement( MAIN_BINDING, offset, VertexElementType.Color, VertexElementSemantic.Diffuse );
				offset += VertexElement.GetTypeSize( VertexElementType.Color );
			}

			// Create shared vertex buffer
			this.mMainBuffer = HardwareBufferManager.Instance.CreateVertexBuffer( decl.Clone( MAIN_BINDING ),
			                                                                      this.mTerrain.vertexCount,
			                                                                      BufferUsage.StaticWriteOnly );
			// Create system memory copy with just positions in it, for use in simple reads
			//mPositionBuffer = OGRE_ALLOC_T(float, mTerrain.vertexCount * 3, MEMCATEGORY_GEOMETRY);
			this.mPositionBuffer = new float[this.mTerrain.vertexCount*3];

			bind.SetBinding( MAIN_BINDING, this.mMainBuffer );

			if ( this.mOptions.lodMorph )
			{
				// Create additional element for delta
				decl.AddElement( DELTA_BINDING, 0, VertexElementType.Float1, VertexElementSemantic.BlendWeights );
				// NB binding is not set here, it is set when deriving the LOD
			}


			this.mInit = true;

			this.mRenderLevel = 0;

			this.mMinLevelDistSqr = new Real[this.mOptions.maxGeoMipMapLevel];

			var endx = startx + this.mOptions.tileSize;

			var endz = startz + this.mOptions.tileSize;

			Vector3 left, down, here;

			var poselem = decl.FindElementBySemantic( VertexElementSemantic.Position );
			var texelem0 = decl.FindElementBySemantic( VertexElementSemantic.TexCoords, 0 );
			var texelem1 = decl.FindElementBySemantic( VertexElementSemantic.TexCoords, 1 );
			//fixed ( float* pSysPos = mPositionBuffer )
			{
				var pos = 0;
				var pBase = this.mMainBuffer.Lock( BufferLocking.Discard );

				for ( var j = startz; j < endz; j++ )
				{
					for ( var i = startx; i < endx; i++ )
					{
						var pPos = ( pBase + poselem.Offset ).ToFloatPointer();
						var pTex0 = ( pBase + texelem0.Offset ).ToFloatPointer();
						var pTex1 = ( pBase + texelem1.Offset ).ToFloatPointer();
						//poselem.baseVertexPointerToElement(pBase, &pPos);

						//texelem0.baseVertexPointerToElement(pBase, &pTex0);
						//texelem1.baseVertexPointerToElement(pBase, &pTex1);

						var height = pageHeightData[ j*this.mOptions.pageSize + i ];
						height = height*this.mOptions.scale.y; // scale height

						//*pSysPos++ = *pPos++ = (float) i*mOptions.scale.x; //x
						//*pSysPos++ = *pPos++ = height; // y
						//*pSysPos++ = *pPos++ = (float) j*mOptions.scale.z; //z

						this.mPositionBuffer[ pos++ ] = pPos[ 0 ] = (float)i*this.mOptions.scale.x; //x
						this.mPositionBuffer[ pos++ ] = pPos[ 1 ] = height; // y
						this.mPositionBuffer[ pos++ ] = pPos[ 2 ] = (float)j*this.mOptions.scale.z; //z

						pTex0[ 0 ] = (float)i/(float)( this.mOptions.pageSize - 1 );
						pTex0[ 1 ] = (float)j/(float)( this.mOptions.pageSize - 1 );

						pTex1[ 0 ] = ( (float)i/(float)( this.mOptions.tileSize - 1 ) )*this.mOptions.detailTile;
						pTex1[ 1 ] = ( (float)j/(float)( this.mOptions.tileSize - 1 ) )*this.mOptions.detailTile;

						if ( height < min )
						{
							min = (Real)height;
						}

						if ( height > max )
						{
							max = (Real)height;
						}

						pBase += this.mMainBuffer.VertexSize;
					}
				}

				this.mMainBuffer.Unlock();
				this.mBounds = new AxisAlignedBox();
				this.mBounds.SetExtents( new Vector3( (Real)startx*this.mOptions.scale.x, min, (Real)startz*this.mOptions.scale.z ),
				                         new Vector3( (Real)( endx - 1 )*this.mOptions.scale.x, max,
				                                      (Real)( endz - 1 )*this.mOptions.scale.z ) );

				this.mCenter = new Vector3( ( startx*this.mOptions.scale.x + ( endx - 1 )*this.mOptions.scale.x )/2, ( min + max )/2,
				                            ( startz*this.mOptions.scale.z + ( endz - 1 )*this.mOptions.scale.z )/2 );
				this.boundingRadius =
					Math.Sqrt( Utility.Sqr( max - min ) + Utility.Sqr( ( endx - 1 - startx )*this.mOptions.scale.x ) +
					           Utility.Sqr( ( endz - 1 - startz )*this.mOptions.scale.z ) )/2;

				// Create delta buffer list if required to morph
				if ( this.mOptions.lodMorph )
				{
					// Create delta buffer for all except the lowest mip
					this.mDeltaBuffers = new AxiomSortedCollection<int, HardwareVertexBuffer>( this.mOptions.maxGeoMipMapLevel - 1 );
				}

				var C = CalculateCFactor();

				CalculateMinLevelDist2( C );
			}
		}
Example #3
0
        public void Run( )
        {
#if !(XBOX || XBOX360 || SILVERLIGHT)
            AxiomSortedCollection<string, DemoItem> demoList = new AxiomSortedCollection<string, DemoItem>();
#endif
            try
            {
#if !(XBOX || XBOX360 || SILVERLIGHT)
                if (_configure())
                {

                    Assembly demos = Assembly.LoadFrom("Axiom.Demos.dll");
                    Type[] demoTypes = demos.GetTypes();
                    Type techDemo = demos.GetType("Axiom.Demos.TechDemo");

                    foreach (Type demoType in demoTypes)
                    {
                        if (demoType.IsSubclassOf(techDemo))
                        {
                            demoList.Add(demoType.Name, new DemoItem(demoType.Name, demoType));
                        }
                    }

                    {
                        Type demoType;
                        int i = 1;
                        foreach (KeyValuePair<string, DemoItem> typeName in demoList)
                        {
                            Console.WriteLine("{0}) {1}", i++, typeName.Key);
                        }
                        Console.WriteLine("Enter the number of the demo that you want to run and press enter.");
                        while (true)
                        {
                            string line = Console.ReadLine();
                            int number = -1;
                            if (line != string.Empty)
                            {
                                number = int.Parse(line.Trim());
                            }
                            if (number < 1 || number > demoList.Count)
                                Console.WriteLine("The number of the demo game must be between 1 and {0}, the number of demos games available.", demoList.Count);
                            else
                            {
                                demoType = demoList.Values[number - 1].Demo;
                                break;
                            }
                        }

                        if (demoType != null)
                        {
                            using (TechDemo demo = (TechDemo)Activator.CreateInstance(demoType))
                            {
                                demo.SetupResources();
                                demo.Start();//show and start rendering
                            }//dispose of it when done
                        }
                    }

                }
#else
                            using ( TechDemo demo = (TechDemo)(new Axiom.Demos.SkyPlane()))
                            {
                                demo.Start();//show and start rendering
                            }//dispose of it when done
#endif
            }
            catch ( Exception caughtException )
            {
                LogManager.Instance.Write( BuildExceptionString( caughtException ) );
            }
        }