Esempio n. 1
0
		public override void Shown()
		{
			try
			{
				root = new RootDisposable();

				VideoTypes videoType;
				video = Video.Init(VideoTypes.D3D11, out videoType, root, this, DepthStencilFormats.Defualt, true);
				viewPort = ViewPortAPI.New(video, new Point2(), video.BackBufferSize);
				float cameraDis = 10;
				camera = new Camera(viewPort, new Vector3(cameraDis, cameraDis, cameraDis), new Vector3(), new Vector3(cameraDis, cameraDis+1, cameraDis));

				//DiffuseSolidColorMaterial.Init(video, "Data/", video.FileTag, ShaderVersions.Max, null);
				//DiffuseSolidColorMaterial.ApplyInstanceConstantsCallback = applyTransform;
				DiffuseTextureMaterial.Init(video, "Data/", video.FileTag, ShaderVersions.Max, null);
				DiffuseTextureMaterial.ApplyObjectMeshCallback = applyTransform;
				DiffuseTextureMaterial.ApplyInstanceObjectMeshCallback = applyInstanceTransform;

				var materialTypes = new Dictionary<string,Type>();
				materialTypes.Add("Material", typeof(DiffuseTextureMaterial));
				var value3Types = new List<MaterialFieldBinder>();
				var textureTypes = new List<MaterialFieldBinder>();
				textureTypes.Add(new MaterialFieldBinder("Material", "Diffuse", "Diffuse"));
				model = new Model(video, "Data/untitled2.rm", "Data/", materialTypes, null, null, value3Types, null, textureTypes, null, 0, modelLoaded);

				QuickDraw3ColorMaterial.Init(video, "Data/", video.FileTag, ShaderVersions.Max, quickDrawShaderLoaded);
				qdMaterial = new QuickDraw3ColorMaterial();

				rasterizerState = RasterizerStateAPI.New(video, RasterizerStateDescAPI.New(RasterizerStateTypes.Solid_CullCW));
				depthState = DepthStencilStateAPI.New(video, DepthStencilStateDescAPI.New(DepthStencilStateTypes.ReadWrite_Less));
				blendState = BlendStateAPI.New(video, BlendStateDescAPI.New(BlendStateTypes.None));
				samplerState = SamplerStateAPI.New(video, SamplerStateDescAPI.New(SamplerStateTypes.Linear_Wrap));

				inited = true;
			}
			catch (Exception e)
			{
				Message.Show("Error", e.Message);
				dispose();
			}
		}
Esempio n. 2
0
		protected override void shown()
		{
			try
			{
				root = new RootDisposable();

				// video objects
				VideoTypes videoType;
				#if METRO
				VideoTypes createVideoTypes = VideoTypes.D3D11;
				#elif WIN32
				VideoTypes createVideoTypes = VideoTypes.D3D11 | VideoTypes.D3D9 | VideoTypes.OpenGL;
				#elif XNA
				VideoTypes createVideoTypes = VideoTypes.XNA;
				#endif

				#if WIN32 || METRO
				video = Video.Init(createVideoTypes, out videoType, root, this, true);
				#elif XNA
				video = Video.Create(createVideoTypes, out videoType, root, this);
				#endif

				// shaders
				DiffuseTextureMaterial.Init(video, "Data/", video.FileTag, ShaderVersions.Max, null);
				DiffuseTextureMaterial.ApplyInstanceConstantsCallback = applyDiffuseCallbackMethod;
				QuickDraw3ColorMaterial.Init(video, "Data/", video.FileTag, ShaderVersions.Max, null);
				material = new QuickDraw3ColorMaterial();
				texture = Texture2DAPI.New(video, "Data/Rocks.dds", null);
				qd = QuickDrawAPI.New(video, QuickDraw3ColorMaterial.BufferLayoutDesc);

				var frame = FrameSize;
				viewPort = ViewPortAPI.New(video, 0, 0, frame.Width, frame.Height);
				float camDis = 50;
				camera = new Camera(viewPort, new Vector3(0, 5, camDis), new Vector3(), new Vector3(0, 5+1, camDis));

				// states
				rasterizerState = RasterizerStateAPI.New(video, RasterizerStateDescAPI.New(RasterizerStateTypes.Solid_CullCW));
				samplerState = SamplerStateAPI.New(video, SamplerStateDescAPI.New(SamplerStateTypes.Linear_Wrap));
				blendState = BlendStateAPI.New(video, BlendStateDescAPI.New(BlendStateTypes.None));
				depthStencilState = DepthStencilStateAPI.New(video, DepthStencilStateDescAPI.New(DepthStencilStateTypes.ReadWrite_Less));

				// models
				var materialTypes = new Dictionary<string,Type>();
				materialTypes.Add("Material", typeof(DiffuseTextureMaterial));

				var materialFieldTypes = new List<MaterialFieldBinder>();
				materialFieldTypes.Add(new MaterialFieldBinder("Material", "Paint_dds", "Diffuse"));

				var extOverrides = new Dictionary<string,string>();
				var emptyBinders = new List<MaterialFieldBinder>();
				sphereModel = new Model(video, "Data/sphere.rm", "Data/", materialTypes, emptyBinders, emptyBinders, emptyBinders, emptyBinders, materialFieldTypes, extOverrides, 0, null);
				//capsuleModel = Model.Create(videoType, video, "Data/capsule.rm", "Data/", materialTypes, emptyBinders, emptyBinders, emptyBinders, emptyBinders, materialFieldTypes, extOverrides);
				boxModel = new Model(video, "Data/box.rm", "Data/", materialTypes, emptyBinders, emptyBinders, emptyBinders, emptyBinders, materialFieldTypes, extOverrides, 0, null);
				monkeyModel = new Model(video, "Data/monkeyFlat.rm", "Data/", materialTypes, emptyBinders, emptyBinders, emptyBinders, emptyBinders, materialFieldTypes, extOverrides, 0, null);
				
				// physics
				collisionSystem = new CollisionSystemPersistentSAP();
				world = new World(collisionSystem);
				world.Gravity = new JVector(0, -9.81f, 0);
				
				spheres = new RigidBody[35];
				for (int i = 0; i != spheres.Length; ++i)
				{
					spheres[i] = new RigidBody(new SphereShape(1));
					spheres[i].Position = new JVector(spheres.Length/(float)(i+1), (i*3)+5, 0);
					world.AddBody(spheres[i]);
				}
				floorBox = new RigidBody(new BoxShape(30, 1, 30));
				floorBox.Shape.TransformScale = new Vector3(30, 1, 30) * .5f;
				floorBox.Position = new JVector(0, -7, 0);
				floorBox.IsStatic = true;
				//floorBox.Orientation = JMatrix.CreateFromYawPitchRoll(0, -.25f, 0);
				world.AddBody(floorBox);
				triangleMesh = new TriangleMesh("Data/monkeyFlat.rtmm", loadTiangleMesh);

				loaded = true;
			}
			catch (Exception e)
			{
				Message.Show("Error", e.Message);
				dispose();
			}
		}