// Just override the mandatory create scene method protected override void CreateScene() { // Set ambient light scene.AmbientLight = new ColorEx(0.2f, 0.2f, 0.2f); // Create point light Light light = scene.CreateLight("MainLight"); // Accept default settings: point light, white diffuse, just set position. // I could attach the light to a SceneNode if I wanted it to move automatically with // other objects, but I don't. light.Type = LightType.Directional; light.Direction = new Vector3(-0.5f, -0.5f, 0); // Create patch with positions, normals, and 1 set of texcoords patchDeclaration = HardwareBufferManager.Instance.CreateVertexDeclaration(); patchDeclaration.AddElement(0, 0, VertexElementType.Float3, VertexElementSemantic.Position); patchDeclaration.AddElement(0, 12, VertexElementType.Float3, VertexElementSemantic.Normal); patchDeclaration.AddElement(0, 24, VertexElementType.Float2, VertexElementSemantic.TexCoords, 0); // Patch data PatchVertex[] patchVertices = new PatchVertex[9]; patchVertices[0].X = -500; patchVertices[0].Y = 200; patchVertices[0].Z = -500; patchVertices[0].Nx = -0.5f; patchVertices[0].Ny = 0.5f; patchVertices[0].Nz = 0; patchVertices[0].U = 0; patchVertices[0].V = 0; patchVertices[1].X = 0; patchVertices[1].Y = 500; patchVertices[1].Z = -750; patchVertices[1].Nx = 0; patchVertices[1].Ny = 0.5f; patchVertices[1].Nz = 0; patchVertices[1].U = 0.5f; patchVertices[1].V = 0; patchVertices[2].X = 500; patchVertices[2].Y = 1000; patchVertices[2].Z = -500; patchVertices[2].Nx = 0.5f; patchVertices[2].Ny = 0.5f; patchVertices[2].Nz = 0; patchVertices[2].U = 1; patchVertices[2].V = 0; patchVertices[3].X = -500; patchVertices[3].Y = 0; patchVertices[3].Z = 0; patchVertices[3].Nx = -0.5f; patchVertices[3].Ny = 0.5f; patchVertices[3].Nz = 0; patchVertices[3].U = 0; patchVertices[3].V = 0.5f; patchVertices[4].X = 0; patchVertices[4].Y = 500; patchVertices[4].Z = 0; patchVertices[4].Nx = 0; patchVertices[4].Ny = 0.5f; patchVertices[4].Nz = 0; patchVertices[4].U = 0.5f; patchVertices[4].V = 0.5f; patchVertices[5].X = 500; patchVertices[5].Y = -50; patchVertices[5].Z = 0; patchVertices[5].Nx = 0.5f; patchVertices[5].Ny = 0.5f; patchVertices[5].Nz = 0; patchVertices[5].U = 1; patchVertices[5].V = 0.5f; patchVertices[6].X = -500; patchVertices[6].Y = 0; patchVertices[6].Z = 500; patchVertices[6].Nx = -0.5f; patchVertices[6].Ny = 0.5f; patchVertices[6].Nz = 0; patchVertices[6].U = 0; patchVertices[6].V = 1; patchVertices[7].X = 0; patchVertices[7].Y = 500; patchVertices[7].Z = 500; patchVertices[7].Nx = 0; patchVertices[7].Ny = 0.5f; patchVertices[7].Nz = 0; patchVertices[7].U = 0.5f; patchVertices[7].V = 1; patchVertices[8].X = 500; patchVertices[8].Y = 200; patchVertices[8].Z = 800; patchVertices[8].Nx = 0.5f; patchVertices[8].Ny = 0.5f; patchVertices[8].Nz = 0; patchVertices[8].U = 1; patchVertices[8].V = 1; patch = MeshManager.Instance.CreateBezierPatch("Bezier1", patchVertices, patchDeclaration, 3, 3, 5, 5, VisibleSide.Both, BufferUsage.StaticWriteOnly, BufferUsage.DynamicWriteOnly, true, true); // Start patch a 0 detail patch.SetSubdivision(0); // Create entity based on patch patchEntity = scene.CreateEntity("Entity1", "Bezier1"); Material material = (Material)MaterialManager.Instance.Create("TextMat"); material.GetTechnique(0).GetPass(0).CreateTextureUnitState("BumpyMetal.jpg"); patchEntity.MaterialName = "TextMat"; // Attach the entity to the root of the scene scene.RootSceneNode.AttachObject(patchEntity); camera.Position = new Vector3(500, 500, 1500); camera.LookAt(new Vector3(0, 200, -300)); }
protected override void SetupContent() { ResourceGroupManager.Instance.InitializeAllResourceGroups(); // setup some basic lighting for our scene SceneManager.AmbientLight = new ColorEx( 0.5f, 0.5f, 0.5f ); SceneManager.CreateLight( "BezierLight" ).Position = new Vector3( 100, 100, 100 ); // define the control point vertices for our patch // Patch data PatchVertex[] patchVertices = new PatchVertex[ 9 ]; patchVertices[ 0 ].X = -500; patchVertices[ 0 ].Y = 200; patchVertices[ 0 ].Z = -500; patchVertices[ 0 ].Nx = -0.5f; patchVertices[ 0 ].Ny = 0.5f; patchVertices[ 0 ].Nz = 0; patchVertices[ 0 ].U = 0; patchVertices[ 0 ].V = 0; patchVertices[ 1 ].X = 0; patchVertices[ 1 ].Y = 500; patchVertices[ 1 ].Z = -750; patchVertices[ 1 ].Nx = 0; patchVertices[ 1 ].Ny = 0.5f; patchVertices[ 1 ].Nz = 0; patchVertices[ 1 ].U = 0.5f; patchVertices[ 1 ].V = 0; patchVertices[ 2 ].X = 500; patchVertices[ 2 ].Y = 1000; patchVertices[ 2 ].Z = -500; patchVertices[ 2 ].Nx = 0.5f; patchVertices[ 2 ].Ny = 0.5f; patchVertices[ 2 ].Nz = 0; patchVertices[ 2 ].U = 1; patchVertices[ 2 ].V = 0; patchVertices[ 3 ].X = -500; patchVertices[ 3 ].Y = 0; patchVertices[ 3 ].Z = 0; patchVertices[ 3 ].Nx = -0.5f; patchVertices[ 3 ].Ny = 0.5f; patchVertices[ 3 ].Nz = 0; patchVertices[ 3 ].U = 0; patchVertices[ 3 ].V = 0.5f; patchVertices[ 4 ].X = 0; patchVertices[ 4 ].Y = 500; patchVertices[ 4 ].Z = 0; patchVertices[ 4 ].Nx = 0; patchVertices[ 4 ].Ny = 0.5f; patchVertices[ 4 ].Nz = 0; patchVertices[ 4 ].U = 0.5f; patchVertices[ 4 ].V = 0.5f; patchVertices[ 5 ].X = 500; patchVertices[ 5 ].Y = -50; patchVertices[ 5 ].Z = 0; patchVertices[ 5 ].Nx = 0.5f; patchVertices[ 5 ].Ny = 0.5f; patchVertices[ 5 ].Nz = 0; patchVertices[ 5 ].U = 1; patchVertices[ 5 ].V = 0.5f; patchVertices[ 6 ].X = -500; patchVertices[ 6 ].Y = 0; patchVertices[ 6 ].Z = 500; patchVertices[ 6 ].Nx = -0.5f; patchVertices[ 6 ].Ny = 0.5f; patchVertices[ 6 ].Nz = 0; patchVertices[ 6 ].U = 0; patchVertices[ 6 ].V = 1; patchVertices[ 7 ].X = 0; patchVertices[ 7 ].Y = 500; patchVertices[ 7 ].Z = 500; patchVertices[ 7 ].Nx = 0; patchVertices[ 7 ].Ny = 0.5f; patchVertices[ 7 ].Nz = 0; patchVertices[ 7 ].U = 0.5f; patchVertices[ 7 ].V = 1; patchVertices[ 8 ].X = 500; patchVertices[ 8 ].Y = 200; patchVertices[ 8 ].Z = 800; patchVertices[ 8 ].Nx = 0.5f; patchVertices[ 8 ].Ny = 0.5f; patchVertices[ 8 ].Nz = 0; patchVertices[ 8 ].U = 1; patchVertices[ 8 ].V = 1; // specify a vertex format declaration for our patch: 3 floats for position, 3 floats for normal, 2 floats for UV patchDeclaration = HardwareBufferManager.Instance.CreateVertexDeclaration(); patchDeclaration.AddElement( 0, 0, VertexElementType.Float3, VertexElementSemantic.Position ); patchDeclaration.AddElement( 0, 12, VertexElementType.Float3, VertexElementSemantic.Normal ); patchDeclaration.AddElement( 0, 24, VertexElementType.Float2, VertexElementSemantic.TexCoords, 0 ); // create a patch mesh using vertices and declaration patch = MeshManager.Instance.CreateBezierPatch( "patch", ResourceGroupManager.DefaultResourceGroupName, patchVertices, patchDeclaration, 3, 3, 5, 5, VisibleSide.Both, BufferUsage.StaticWriteOnly, BufferUsage.DynamicWriteOnly, true, true ); // Start patch at 0 detail patch.Subdivision = 0; // Create entity based on patch patchEntity = SceneManager.CreateEntity( "Entity1", "patch" ); Material material = (Material)MaterialManager.Instance.Create( "TextMat", ResourceGroupManager.DefaultResourceGroupName, null ); material.GetTechnique( 0 ).GetPass( 0 ).CreateTextureUnitState( "BumpyMetal.jpg" ); patchEntity.MaterialName = "TextMat"; patchPass = material.GetTechnique( 0 ).GetPass( 0 ); // Attach the entity to the root of the scene SceneManager.RootSceneNode.AttachObject( patchEntity ); // save the main pass of the material so we can toggle wireframe on it if ( material != null ) { patchPass = material.GetTechnique( 0 ).GetPass( 0 ); // use an orbit style camera CameraManager.setStyle( CameraStyle.Orbit ); CameraManager.SetYawPitchDist( 0, 0, 250 ); TrayManager.ShowCursor(); // create slider to adjust detail and checkbox to toggle wireframe Slider slider = TrayManager.CreateThickSlider( TrayLocation.TopLeft, "Detail", "Detail", 120, 44, 0, 1, 6 ); CheckBox box = TrayManager.CreateCheckBox( TrayLocation.TopLeft, "Wireframe", "Wireframe", 120 ); slider.SliderMoved += new SliderMovedHandler( slider_SliderMoved ); box.CheckChanged += new CheckChangedHandler( box_CheckChanged ); } }
// --- Protected Override Methods --- #region CreateScene() // Just override the mandatory create scene method protected override void CreateScene() { // Set ambient light scene.AmbientLight = new ColorEx(0.2f, 0.2f, 0.2f); // Create point light Light light = scene.CreateLight("MainLight"); // Accept default settings: point light, white diffuse, just set position. // I could attach the light to a SceneNode if I wanted it to move automatically with // other objects, but I don't. light.Type = LightType.Directional; light.Direction = new Vector3(-0.5f, -0.5f, 0); // Create patch with positions, normals, and 1 set of texcoords patchDeclaration = HardwareBufferManager.Instance.CreateVertexDeclaration(); patchDeclaration.AddElement(0, 0, VertexElementType.Float3, VertexElementSemantic.Position); patchDeclaration.AddElement(0, 12, VertexElementType.Float3, VertexElementSemantic.Normal); patchDeclaration.AddElement(0, 24, VertexElementType.Float2, VertexElementSemantic.TexCoords, 0); // Patch data PatchVertex[] patchVertices = new PatchVertex[9]; patchVertices[0].X = -500; patchVertices[0].Y = 200; patchVertices[0].Z = -500; patchVertices[0].Nx = -0.5f; patchVertices[0].Ny = 0.5f; patchVertices[0].Nz = 0; patchVertices[0].U = 0; patchVertices[0].V = 0; patchVertices[1].X = 0; patchVertices[1].Y = 500; patchVertices[1].Z = -750; patchVertices[1].Nx = 0; patchVertices[1].Ny = 0.5f; patchVertices[1].Nz = 0; patchVertices[1].U = 0.5f; patchVertices[1].V = 0; patchVertices[2].X = 500; patchVertices[2].Y = 1000; patchVertices[2].Z = -500; patchVertices[2].Nx = 0.5f; patchVertices[2].Ny = 0.5f; patchVertices[2].Nz = 0; patchVertices[2].U = 1; patchVertices[2].V = 0; patchVertices[3].X = -500; patchVertices[3].Y = 0; patchVertices[3].Z = 0; patchVertices[3].Nx = -0.5f; patchVertices[3].Ny = 0.5f; patchVertices[3].Nz = 0; patchVertices[3].U = 0; patchVertices[3].V = 0.5f; patchVertices[4].X = 0; patchVertices[4].Y = 500; patchVertices[4].Z = 0; patchVertices[4].Nx = 0; patchVertices[4].Ny = 0.5f; patchVertices[4].Nz = 0; patchVertices[4].U = 0.5f; patchVertices[4].V = 0.5f; patchVertices[5].X = 500; patchVertices[5].Y = -50; patchVertices[5].Z = 0; patchVertices[5].Nx = 0.5f; patchVertices[5].Ny = 0.5f; patchVertices[5].Nz = 0; patchVertices[5].U = 1; patchVertices[5].V = 0.5f; patchVertices[6].X = -500; patchVertices[6].Y = 0; patchVertices[6].Z = 500; patchVertices[6].Nx = -0.5f; patchVertices[6].Ny = 0.5f; patchVertices[6].Nz = 0; patchVertices[6].U = 0; patchVertices[6].V = 1; patchVertices[7].X = 0; patchVertices[7].Y = 500; patchVertices[7].Z = 500; patchVertices[7].Nx = 0; patchVertices[7].Ny = 0.5f; patchVertices[7].Nz = 0; patchVertices[7].U = 0.5f; patchVertices[7].V = 1; patchVertices[8].X = 500; patchVertices[8].Y = 200; patchVertices[8].Z = 800; patchVertices[8].Nx = 0.5f; patchVertices[8].Ny = 0.5f; patchVertices[8].Nz = 0; patchVertices[8].U = 1; patchVertices[8].V = 1; patch = MeshManager.Instance.CreateBezierPatch("Bezier1", patchVertices, patchDeclaration, 3, 3, 5, 5, VisibleSide.Both, BufferUsage.StaticWriteOnly, BufferUsage.DynamicWriteOnly, true, true); // Start patch a 0 detail patch.SetSubdivision(0); // Create entity based on patch patchEntity = scene.CreateEntity("Entity1", "Bezier1"); Material material = (Material)MaterialManager.Instance.Create("TextMat"); material.GetTechnique(0).GetPass(0).CreateTextureUnitState("BumpyMetal.jpg"); patchEntity.MaterialName = "TextMat"; // Attach the entity to the root of the scene scene.RootSceneNode.AttachObject(patchEntity); camera.Position = new Vector3(500, 500, 1500); camera.LookAt(new Vector3(0, 200, -300)); }
// Just override the mandatory create scene method public override void CreateScene() { // Set ambient light sceneMgr.AmbientLight = new ColourValue(0.2f, 0.2f, 0.2f); // Create a point light Light l = sceneMgr.CreateLight("MainLight"); // Accept default settings: point light, white diffuse, just set position // NB I could attach the light to a SceneNode if I wanted it to move automatically with // other objects, but I don't l.Type = Light.LightTypes.LT_DIRECTIONAL; l.SetDirection(-0.5f, -0.5f, 0); // Create patch patchDecl = HardwareBufferManager.Singleton.CreateVertexDeclaration(); patchDecl.AddElement(0, 0, VertexElementType.VET_FLOAT3, VertexElementSemantic.VES_POSITION); patchDecl.AddElement(0, sizeof(float)*3, VertexElementType.VET_FLOAT3, VertexElementSemantic.VES_NORMAL); patchDecl.AddElement(0, sizeof(float)*6, VertexElementType.VET_FLOAT2, VertexElementSemantic.VES_TEXTURE_COORDINATES, 0); // Make a 3x3 patch for test patchCtlPoints = new PatchVertex[9]; // Patch data patchCtlPoints[0] = new PatchVertex(); patchCtlPoints[0].x = -500.0f; patchCtlPoints[0].y = 200.0f; patchCtlPoints[0].z = -500.0f; patchCtlPoints[0].nx = -0.5f; patchCtlPoints[0].ny = 0.5f; patchCtlPoints[0].nz = 0.0f; patchCtlPoints[0].u = 0.0f; patchCtlPoints[0].v = 0.0f; patchCtlPoints[1] = new PatchVertex(); patchCtlPoints[1].x = 0.0f; patchCtlPoints[1].y = 500.0f; patchCtlPoints[1].z = -750.0f; patchCtlPoints[1].nx = 0.0f; patchCtlPoints[1].ny = 0.5f; patchCtlPoints[1].nz = 0.0f; patchCtlPoints[1].u = 0.5f; patchCtlPoints[1].v = 0.0f; patchCtlPoints[2] = new PatchVertex(); patchCtlPoints[2].x = 500.0f; patchCtlPoints[2].y = 1000.0f; patchCtlPoints[2].z = -500.0f; patchCtlPoints[2].nx = 0.5f; patchCtlPoints[2].ny = 0.5f; patchCtlPoints[2].nz = 0.0f; patchCtlPoints[2].u = 1.0f; patchCtlPoints[2].v = 0.0f; patchCtlPoints[3] = new PatchVertex(); patchCtlPoints[3].x = -500.0f; patchCtlPoints[3].y = 0.0f; patchCtlPoints[3].z = 0.0f; patchCtlPoints[3].nx = -0.5f; patchCtlPoints[3].ny = 0.5f; patchCtlPoints[3].nz = 0.0f; patchCtlPoints[3].u = 0.0f; patchCtlPoints[3].v = 0.5f; patchCtlPoints[4] = new PatchVertex(); patchCtlPoints[4].x = 0.0f; patchCtlPoints[4].y = 500.0f; patchCtlPoints[4].z = 0.0f; patchCtlPoints[4].nx = 0.0f; patchCtlPoints[4].ny = 0.5f; patchCtlPoints[4].nz = 0.0f; patchCtlPoints[4].u = 0.5f; patchCtlPoints[4].v = 0.5f; patchCtlPoints[5] = new PatchVertex(); patchCtlPoints[5].x = 500.0f; patchCtlPoints[5].y = -50.0f; patchCtlPoints[5].z = 0.0f; patchCtlPoints[5].nx = 0.5f; patchCtlPoints[5].ny = 0.5f; patchCtlPoints[5].nz = 0.0f; patchCtlPoints[5].u = 1.0f; patchCtlPoints[5].v = 0.5f; patchCtlPoints[6] = new PatchVertex(); patchCtlPoints[6].x = -500.0f; patchCtlPoints[6].y = 0.0f; patchCtlPoints[6].z = 500.0f; patchCtlPoints[6].nx = -0.5f; patchCtlPoints[6].ny = 0.5f; patchCtlPoints[6].nz = 0.0f; patchCtlPoints[6].u = 0.0f; patchCtlPoints[6].v = 1.0f; patchCtlPoints[7] = new PatchVertex(); patchCtlPoints[7].x = 0.0f; patchCtlPoints[7].y = 500.0f; patchCtlPoints[7].z = 500.0f; patchCtlPoints[7].nx = 0.0f; patchCtlPoints[7].ny = 0.5f; patchCtlPoints[7].nz = 0.0f; patchCtlPoints[7].u = 0.5f; patchCtlPoints[7].v = 1.0f; patchCtlPoints[8] = new PatchVertex(); patchCtlPoints[8].x = 500.0f; patchCtlPoints[8].y = 200.0f; patchCtlPoints[8].z = 800.0f; patchCtlPoints[8].nx = 0.5f; patchCtlPoints[8].ny = 0.5f; patchCtlPoints[8].nz = 0.0f; patchCtlPoints[8].u = 1.0f; patchCtlPoints[8].v = 1.0f; patch = MeshManager.Singleton.CreateBezierPatch( "Bezier1", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, patchCtlPoints, patchDecl, 3, 3, 5, 5, PatchSurface.VisibleSide.VS_BOTH, HardwareVertexBuffer.Usage.HBU_STATIC_WRITE_ONLY, HardwareIndexBuffer.Usage.HBU_DYNAMIC_WRITE_ONLY, true, true); // Start patch at 0 detail patch.SetSubdivision(0.0f); // Create entity based on patch Entity patchEntity = sceneMgr.CreateEntity("Entity1", "Bezier1"); MaterialPtr pMat = MaterialManager.Singleton.Create("TextMat", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); pMat.GetTechnique(0).GetPass(0).CreateTextureUnitState( "BumpyMetal.jpg" ); patchEntity.SetMaterialName("TextMat"); patchPass = pMat.GetTechnique(0).GetPass(0); // Attach the entity to the root of the scene sceneMgr.RootSceneNode.AttachObject(patchEntity); camera.SetPosition(500,500, 1500); camera.LookAt(0,200,-300); }
protected override void SetupContent() { ResourceGroupManager.Instance.InitializeAllResourceGroups(); // setup some basic lighting for our scene SceneManager.AmbientLight = new ColorEx(0.5f, 0.5f, 0.5f); SceneManager.CreateLight("BezierLight").Position = new Vector3(100, 100, 100); // define the control point vertices for our patch // Patch data var patchVertices = new PatchVertex[9]; patchVertices[0].X = -500; patchVertices[0].Y = 200; patchVertices[0].Z = -500; patchVertices[0].Nx = -0.5f; patchVertices[0].Ny = 0.5f; patchVertices[0].Nz = 0; patchVertices[0].U = 0; patchVertices[0].V = 0; patchVertices[1].X = 0; patchVertices[1].Y = 500; patchVertices[1].Z = -750; patchVertices[1].Nx = 0; patchVertices[1].Ny = 0.5f; patchVertices[1].Nz = 0; patchVertices[1].U = 0.5f; patchVertices[1].V = 0; patchVertices[2].X = 500; patchVertices[2].Y = 1000; patchVertices[2].Z = -500; patchVertices[2].Nx = 0.5f; patchVertices[2].Ny = 0.5f; patchVertices[2].Nz = 0; patchVertices[2].U = 1; patchVertices[2].V = 0; patchVertices[3].X = -500; patchVertices[3].Y = 0; patchVertices[3].Z = 0; patchVertices[3].Nx = -0.5f; patchVertices[3].Ny = 0.5f; patchVertices[3].Nz = 0; patchVertices[3].U = 0; patchVertices[3].V = 0.5f; patchVertices[4].X = 0; patchVertices[4].Y = 500; patchVertices[4].Z = 0; patchVertices[4].Nx = 0; patchVertices[4].Ny = 0.5f; patchVertices[4].Nz = 0; patchVertices[4].U = 0.5f; patchVertices[4].V = 0.5f; patchVertices[5].X = 500; patchVertices[5].Y = -50; patchVertices[5].Z = 0; patchVertices[5].Nx = 0.5f; patchVertices[5].Ny = 0.5f; patchVertices[5].Nz = 0; patchVertices[5].U = 1; patchVertices[5].V = 0.5f; patchVertices[6].X = -500; patchVertices[6].Y = 0; patchVertices[6].Z = 500; patchVertices[6].Nx = -0.5f; patchVertices[6].Ny = 0.5f; patchVertices[6].Nz = 0; patchVertices[6].U = 0; patchVertices[6].V = 1; patchVertices[7].X = 0; patchVertices[7].Y = 500; patchVertices[7].Z = 500; patchVertices[7].Nx = 0; patchVertices[7].Ny = 0.5f; patchVertices[7].Nz = 0; patchVertices[7].U = 0.5f; patchVertices[7].V = 1; patchVertices[8].X = 500; patchVertices[8].Y = 200; patchVertices[8].Z = 800; patchVertices[8].Nx = 0.5f; patchVertices[8].Ny = 0.5f; patchVertices[8].Nz = 0; patchVertices[8].U = 1; patchVertices[8].V = 1; // specify a vertex format declaration for our patch: 3 floats for position, 3 floats for normal, 2 floats for UV this.patchDeclaration = HardwareBufferManager.Instance.CreateVertexDeclaration(); this.patchDeclaration.AddElement(0, 0, VertexElementType.Float3, VertexElementSemantic.Position); this.patchDeclaration.AddElement(0, 12, VertexElementType.Float3, VertexElementSemantic.Normal); this.patchDeclaration.AddElement(0, 24, VertexElementType.Float2, VertexElementSemantic.TexCoords, 0); // create a patch mesh using vertices and declaration this.patch = MeshManager.Instance.CreateBezierPatch("patch", ResourceGroupManager.DefaultResourceGroupName, patchVertices, this.patchDeclaration, 3, 3, 5, 5, VisibleSide.Both, BufferUsage.StaticWriteOnly, BufferUsage.DynamicWriteOnly, true, true); // Start patch at 0 detail this.patch.Subdivision = 0; // Create entity based on patch this.patchEntity = SceneManager.CreateEntity("Entity1", "patch"); var material = (Material)MaterialManager.Instance.Create("TextMat", ResourceGroupManager.DefaultResourceGroupName, null); material.GetTechnique(0).GetPass(0).CreateTextureUnitState("BumpyMetal.jpg"); this.patchEntity.MaterialName = "TextMat"; this.patchPass = material.GetTechnique(0).GetPass(0); // Attach the entity to the root of the scene SceneManager.RootSceneNode.AttachObject(this.patchEntity); // save the main pass of the material so we can toggle wireframe on it if (material != null) { this.patchPass = material.GetTechnique(0).GetPass(0); // use an orbit style camera CameraManager.setStyle(CameraStyle.Orbit); CameraManager.SetYawPitchDist(0, 0, 250); TrayManager.ShowCursor(); // create slider to adjust detail and checkbox to toggle wireframe Slider slider = TrayManager.CreateThickSlider(TrayLocation.TopLeft, "Detail", "Detail", 120, 44, 0, 1, 6); CheckBox box = TrayManager.CreateCheckBox(TrayLocation.TopLeft, "Wireframe", "Wireframe", 120); slider.SliderMoved += new SliderMovedHandler(slider_SliderMoved); box.CheckChanged += new CheckChangedHandler(box_CheckChanged); } }
// Just override the mandatory create scene method public override void CreateScene() { // Set ambient light sceneMgr.AmbientLight = new ColourValue(0.2f, 0.2f, 0.2f); // Create a point light Light l = sceneMgr.CreateLight("MainLight"); // Accept default settings: point light, white diffuse, just set position // NB I could attach the light to a SceneNode if I wanted it to move automatically with // other objects, but I don't l.Type = Light.LightTypes.LT_DIRECTIONAL; l.SetDirection(-0.5f, -0.5f, 0); // Create patch patchDecl = HardwareBufferManager.Singleton.CreateVertexDeclaration(); patchDecl.AddElement(0, 0, VertexElementType.VET_FLOAT3, VertexElementSemantic.VES_POSITION); patchDecl.AddElement(0, sizeof(float) * 3, VertexElementType.VET_FLOAT3, VertexElementSemantic.VES_NORMAL); patchDecl.AddElement(0, sizeof(float) * 6, VertexElementType.VET_FLOAT2, VertexElementSemantic.VES_TEXTURE_COORDINATES, 0); // Make a 3x3 patch for test patchCtlPoints = new PatchVertex[9]; // Patch data patchCtlPoints[0] = new PatchVertex(); patchCtlPoints[0].x = -500.0f; patchCtlPoints[0].y = 200.0f; patchCtlPoints[0].z = -500.0f; patchCtlPoints[0].nx = -0.5f; patchCtlPoints[0].ny = 0.5f; patchCtlPoints[0].nz = 0.0f; patchCtlPoints[0].u = 0.0f; patchCtlPoints[0].v = 0.0f; patchCtlPoints[1] = new PatchVertex(); patchCtlPoints[1].x = 0.0f; patchCtlPoints[1].y = 500.0f; patchCtlPoints[1].z = -750.0f; patchCtlPoints[1].nx = 0.0f; patchCtlPoints[1].ny = 0.5f; patchCtlPoints[1].nz = 0.0f; patchCtlPoints[1].u = 0.5f; patchCtlPoints[1].v = 0.0f; patchCtlPoints[2] = new PatchVertex(); patchCtlPoints[2].x = 500.0f; patchCtlPoints[2].y = 1000.0f; patchCtlPoints[2].z = -500.0f; patchCtlPoints[2].nx = 0.5f; patchCtlPoints[2].ny = 0.5f; patchCtlPoints[2].nz = 0.0f; patchCtlPoints[2].u = 1.0f; patchCtlPoints[2].v = 0.0f; patchCtlPoints[3] = new PatchVertex(); patchCtlPoints[3].x = -500.0f; patchCtlPoints[3].y = 0.0f; patchCtlPoints[3].z = 0.0f; patchCtlPoints[3].nx = -0.5f; patchCtlPoints[3].ny = 0.5f; patchCtlPoints[3].nz = 0.0f; patchCtlPoints[3].u = 0.0f; patchCtlPoints[3].v = 0.5f; patchCtlPoints[4] = new PatchVertex(); patchCtlPoints[4].x = 0.0f; patchCtlPoints[4].y = 500.0f; patchCtlPoints[4].z = 0.0f; patchCtlPoints[4].nx = 0.0f; patchCtlPoints[4].ny = 0.5f; patchCtlPoints[4].nz = 0.0f; patchCtlPoints[4].u = 0.5f; patchCtlPoints[4].v = 0.5f; patchCtlPoints[5] = new PatchVertex(); patchCtlPoints[5].x = 500.0f; patchCtlPoints[5].y = -50.0f; patchCtlPoints[5].z = 0.0f; patchCtlPoints[5].nx = 0.5f; patchCtlPoints[5].ny = 0.5f; patchCtlPoints[5].nz = 0.0f; patchCtlPoints[5].u = 1.0f; patchCtlPoints[5].v = 0.5f; patchCtlPoints[6] = new PatchVertex(); patchCtlPoints[6].x = -500.0f; patchCtlPoints[6].y = 0.0f; patchCtlPoints[6].z = 500.0f; patchCtlPoints[6].nx = -0.5f; patchCtlPoints[6].ny = 0.5f; patchCtlPoints[6].nz = 0.0f; patchCtlPoints[6].u = 0.0f; patchCtlPoints[6].v = 1.0f; patchCtlPoints[7] = new PatchVertex(); patchCtlPoints[7].x = 0.0f; patchCtlPoints[7].y = 500.0f; patchCtlPoints[7].z = 500.0f; patchCtlPoints[7].nx = 0.0f; patchCtlPoints[7].ny = 0.5f; patchCtlPoints[7].nz = 0.0f; patchCtlPoints[7].u = 0.5f; patchCtlPoints[7].v = 1.0f; patchCtlPoints[8] = new PatchVertex(); patchCtlPoints[8].x = 500.0f; patchCtlPoints[8].y = 200.0f; patchCtlPoints[8].z = 800.0f; patchCtlPoints[8].nx = 0.5f; patchCtlPoints[8].ny = 0.5f; patchCtlPoints[8].nz = 0.0f; patchCtlPoints[8].u = 1.0f; patchCtlPoints[8].v = 1.0f; patch = MeshManager.Singleton.CreateBezierPatch( "Bezier1", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, patchCtlPoints, patchDecl, 3, 3, 5, 5, PatchSurface.VisibleSide.VS_BOTH, HardwareVertexBuffer.Usage.HBU_STATIC_WRITE_ONLY, HardwareIndexBuffer.Usage.HBU_DYNAMIC_WRITE_ONLY, true, true); // Start patch at 0 detail patch.SetSubdivision(0.0f); // Create entity based on patch Entity patchEntity = sceneMgr.CreateEntity("Entity1", "Bezier1"); MaterialPtr pMat = MaterialManager.Singleton.Create("TextMat", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); pMat.GetTechnique(0).GetPass(0).CreateTextureUnitState("BumpyMetal.jpg"); patchEntity.SetMaterialName("TextMat"); patchPass = pMat.GetTechnique(0).GetPass(0); // Attach the entity to the root of the scene sceneMgr.RootSceneNode.AttachObject(patchEntity); camera.SetPosition(500, 500, 1500); camera.LookAt(0, 200, -300); }
public void OnLoad() { // Create patch with positions, normals, and 1 set of texcoords var patchDeclaration = HardwareBufferManager.Instance.CreateVertexDeclaration(); patchDeclaration.AddElement(0, 0, VertexElementType.Float3, VertexElementSemantic.Position); patchDeclaration.AddElement(0, 12, VertexElementType.Float3, VertexElementSemantic.Normal); patchDeclaration.AddElement(0, 24, VertexElementType.Float2, VertexElementSemantic.TexCoords, 0); var patchVertices = new PatchVertex[9]; patchVertices[0].X = -500; patchVertices[0].Y = 200; patchVertices[0].Z = -500; patchVertices[0].Nx = -0.5f; patchVertices[0].Ny = 0.5f; patchVertices[0].Nz = 0; patchVertices[0].U = 0; patchVertices[0].V = 0; patchVertices[1].X = 0; patchVertices[1].Y = 500; patchVertices[1].Z = -750; patchVertices[1].Nx = 0; patchVertices[1].Ny = 0.5f; patchVertices[1].Nz = 0; patchVertices[1].U = 0.5f; patchVertices[1].V = 0; patchVertices[2].X = 500; patchVertices[2].Y = 1000; patchVertices[2].Z = -500; patchVertices[2].Nx = 0.5f; patchVertices[2].Ny = 0.5f; patchVertices[2].Nz = 0; patchVertices[2].U = 1; patchVertices[2].V = 0; patchVertices[3].X = -500; patchVertices[3].Y = 0; patchVertices[3].Z = 0; patchVertices[3].Nx = -0.5f; patchVertices[3].Ny = 0.5f; patchVertices[3].Nz = 0; patchVertices[3].U = 0; patchVertices[3].V = 0.5f; patchVertices[4].X = 0; patchVertices[4].Y = 500; patchVertices[4].Z = 0; patchVertices[4].Nx = 0; patchVertices[4].Ny = 0.5f; patchVertices[4].Nz = 0; patchVertices[4].U = 0.5f; patchVertices[4].V = 0.5f; patchVertices[5].X = 500; patchVertices[5].Y = -50; patchVertices[5].Z = 0; patchVertices[5].Nx = 0.5f; patchVertices[5].Ny = 0.5f; patchVertices[5].Nz = 0; patchVertices[5].U = 1; patchVertices[5].V = 0.5f; patchVertices[6].X = -500; patchVertices[6].Y = 0; patchVertices[6].Z = 500; patchVertices[6].Nx = -0.5f; patchVertices[6].Ny = 0.5f; patchVertices[6].Nz = 0; patchVertices[6].U = 0; patchVertices[6].V = 1; patchVertices[7].X = 0; patchVertices[7].Y = 500; patchVertices[7].Z = 500; patchVertices[7].Nx = 0; patchVertices[7].Ny = 0.5f; patchVertices[7].Nz = 0; patchVertices[7].U = 0.5f; patchVertices[7].V = 1; patchVertices[8].X = 500; patchVertices[8].Y = 200; patchVertices[8].Z = 800; patchVertices[8].Nx = 0.5f; patchVertices[8].Ny = 0.5f; patchVertices[8].Nz = 0; patchVertices[8].U = 1; patchVertices[8].V = 1; _patch = MeshManager.Instance.CreateBezierPatch("Bezier1", ResourceGroupManager.DefaultResourceGroupName, patchVertices, patchDeclaration, 3, 3, 5, 5, VisibleSide.Both, BufferUsage.StaticWriteOnly, BufferUsage.DynamicWriteOnly, true, true); _patch.Subdivision = 1.0f; _scene = _root.CreateSceneManager("DefaultSceneManager", "SLSharpInstance"); _scene.ClearScene(); _patchEntity = _scene.CreateEntity("Entity1", "Bezier1"); _camera = _scene.CreateCamera("MainCamera"); var mat = (Material)MaterialManager.Instance.Create("test", ResourceGroupManager.DefaultResourceGroupName); var pass = mat.GetTechnique(0).GetPass(0); pass.LightingEnabled = false; _patchEntity.MaterialName = mat.Name; _scene.RootSceneNode.AttachObject(_patchEntity); _camera.LookAt(Vector3.Zero); _camera.Near = 5; _camera.AutoAspectRatio = true; var vp = _root.AutoWindow.AddViewport(_camera, 0, 0, 1.0f, 1.0f, 100); vp.BackgroundColor = ColorEx.CornflowerBlue; }