static void Main() { IrrlichtDevice device = IrrlichtDevice.CreateDevice( DriverType.Software, new Dimension2Di(640, 480), 16, false, false, false); device.SetWindowCaption("Hello World! - Irrlicht Engine Demo"); VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; GUIEnvironment gui = device.GUIEnvironment; gui.AddStaticText("Hello World! This is the Irrlicht Software renderer!", new Recti(10, 10, 260, 22), true); AnimatedMesh mesh = smgr.GetMesh("../../media/sydney.md2"); AnimatedMeshSceneNode node = smgr.AddAnimatedMeshSceneNode(mesh); if (node != null) { node.SetMaterialFlag(MaterialFlag.Lighting, false); node.SetMD2Animation(AnimationTypeMD2.Stand); node.SetMaterialTexture(0, driver.GetTexture("../../media/sydney.bmp")); } smgr.AddCameraSceneNode(null, new Vector3Df(0, 30, -40), new Vector3Df(0, 5, 0)); while (device.Run()) { driver.BeginScene(ClearBufferFlag.All, new Color(100, 101, 140)); smgr.DrawAll(); gui.DrawAll(); driver.EndScene(); } device.Drop(); }
static void Main() { DriverType?driverType = AskForDriver(); if (!driverType.HasValue) { return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType.Value, new Dimension2Di(640, 480)); if (device == null) { return; } VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; GUIEnvironment env = device.GUIEnvironment; // load and display animated fairy mesh AnimatedMeshSceneNode fairy = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("../../media/faerie.md2")); if (fairy != null) { fairy.SetMaterialTexture(0, driver.GetTexture("../../media/faerie2.bmp")); // set diffuse texture fairy.SetMaterialFlag(MaterialFlag.Lighting, true); // enable dynamic lighting fairy.GetMaterial(0).Shininess = 20.0f; // set size of specular highlights fairy.Position = new Vector3Df(-10, 0, -100); fairy.SetMD2Animation(AnimationTypeMD2.Stand); } // add white light smgr.AddLightSceneNode(null, new Vector3Df(-15, 5, -105), new Colorf(1, 1, 1)); // set ambient light smgr.AmbientLight = new Colorf(0.25f, 0.25f, 0.25f); // add fps camera CameraSceneNode fpsCamera = smgr.AddCameraSceneNodeFPS(); fpsCamera.Position = new Vector3Df(-50, 50, -150); // disable mouse cursor device.CursorControl.Visible = false; // create test cube SceneNode test = smgr.AddCubeSceneNode(60); // let the cube rotate and set some light settings SceneNodeAnimator anim = smgr.CreateRotationAnimator(new Vector3Df(0.3f, 0.3f, 0)); test.Position = new Vector3Df(-100, 0, -100); test.SetMaterialFlag(MaterialFlag.Lighting, false); // disable dynamic lighting test.AddAnimator(anim); anim.Drop(); // create render target Texture rt = null; CameraSceneNode fixedCam = null; if (driver.QueryFeature(VideoDriverFeature.RenderToTarget)) { rt = driver.AddRenderTargetTexture(new Dimension2Di(256), "RTT1"); test.SetMaterialTexture(0, rt); // set material of cube to render target // add fixed camera fixedCam = smgr.AddCameraSceneNode(null, new Vector3Df(10, 10, -80), new Vector3Df(-10, 10, -100)); } else { // create problem text GUIFont font = env.GetFont("../../media/fonthaettenschweiler.bmp"); if (font != null) { env.Skin.SetFont(font); } GUIStaticText text = env.AddStaticText( "Your hardware or this renderer is not able to use the " + "render to texture feature. RTT Disabled.", new Recti(150, 20, 470, 60)); text.OverrideColor = new Color(255, 255, 255, 100); } int lastFPS = -1; while (device.Run()) { if (device.WindowActive) { driver.BeginScene(ClearBufferFlag.All, new Color(0)); if (rt != null) { // draw scene into render target // set render target texture driver.SetRenderTarget(rt, ClearBufferFlag.All, new Color(0, 0, 255)); // make cube invisible and set fixed camera as active camera test.Visible = false; smgr.ActiveCamera = fixedCam; // draw whole scene into render buffer smgr.DrawAll(); // set back old render target // The buffer might have been distorted, so clear it driver.SetRenderTarget(null, ClearBufferFlag.All, new Color(0)); // make the cube visible and set the user controlled camera as active one test.Visible = true; smgr.ActiveCamera = fpsCamera; } // draw scene normally smgr.DrawAll(); env.DrawAll(); driver.EndScene(); // display frames per second in window title int fps = driver.FPS; if (lastFPS != fps) { device.SetWindowCaption(String.Format( "Render to Texture and Specular Highlights example - Irrlicht Engine [{0}] fps: {1}", driver.Name, fps)); lastFPS = fps; } } } device.Drop(); }
private static float _playerVerticalSpeed = 0.0f; // used to calculate vertical speed for gravity and jump static void Main(string[] args) { IrrlichtDevice device = IrrlichtDevice.CreateDevice(DriverType.OpenGL, new Dimension2Di(ResolutionX, ResolutionY), 24, false, false, false); device.OnEvent += Device_OnEvent; device.SetWindowCaption("Hello World! - Irrlicht Engine Demo"); VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; GUIEnvironment gui = device.GUIEnvironment; gui.AddStaticText("Hello World! This is the Irrlicht Software renderer!", new Recti(10, 10, 260, 22), true); AnimatedMesh mesh = smgr.GetMesh("../../media/sydney.md2"); AnimatedMeshSceneNode sydneyNode = smgr.AddAnimatedMeshSceneNode(mesh); var cubeSceneNode = smgr.AddCubeSceneNode(2.0f); cubeSceneNode.Scale = new Vector3Df(6.0f, 2.0f, 100.0f); cubeSceneNode.Position = new Vector3Df(cubeSceneNode.Position.X, GroundAltitude + 0.5f, cubeSceneNode.Position.Z); if (sydneyNode != null) { sydneyNode.SetMaterialFlag(MaterialFlag.Lighting, true); sydneyNode.SetMD2Animation(AnimationTypeMD2.Stand); sydneyNode.SetMaterialTexture(0, driver.GetTexture("../../media/sydney.bmp")); } var lightSceneNode = smgr.AddLightSceneNode(); var light = lightSceneNode.LightData; light.DiffuseColor = new Colorf(0.8f, 1.0f, 1.0f); light.Type = LightType.Directional; light.Position = new Vector3Df(0.0f, 5.0f, 5.0f); var cam = smgr.AddCameraSceneNode(null, new Vector3Df(20, 30, -40), new Vector3Df(20, 5, 0)); device.Timer.Start(); uint then = device.Timer.RealTime; while (device.Run()) { // As the game is simple we will handle our simple physics ourselves uint now = device.Timer.RealTime; uint elapsed = now - then; float elapsedTimeSec = (float)elapsed / 1000.0f; then = now; // we target 58.8 FPS if (elapsed < 17) { device.Sleep(17 - (int)elapsed); } else { // uh-oh, it took more than .125 sec to do render loop! // what do we do now? } _playerVerticalSpeed += elapsedTimeSec * -(VerticalGravity * 10.0f); var calculatedNewPos = sydneyNode.Position - new Vector3Df(0.0f, _playerVerticalSpeed * elapsedTimeSec, 0.0f); float offsetSydney = sydneyNode.BoundingBox.Extent.Y / 2.0f; _isGrounded = calculatedNewPos.Y <= (GroundAltitude + offsetSydney); if (_isGrounded) { _playerVerticalSpeed = 0.0f; calculatedNewPos.Y = GroundAltitude + offsetSydney; } else { calculatedNewPos.Y = calculatedNewPos.Y; } sydneyNode.Position = calculatedNewPos; driver.BeginScene(true, true, new Color(100, 101, 140)); smgr.DrawAll(); gui.DrawAll(); driver.EndScene(); } device.Drop(); }
static void Main() { DriverType?driverType = AskForDriver(); if (!driverType.HasValue) { return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType.Value, new Dimension2Di(640, 480)); if (device == null) { return; } VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3"); AnimatedMesh q3levelmesh = smgr.GetMesh("20kdm2.bsp"); MeshSceneNode q3node = null; // The Quake mesh is pickable, but doesn't get highlighted. if (q3levelmesh != null) { q3node = smgr.AddOctreeSceneNode(q3levelmesh.GetMesh(0), null, IDFlag_IsPickable); } TriangleSelector selector = null; if (q3node != null) { q3node.Position = new Vector3Df(-1350, -130, -1400); selector = smgr.CreateOctreeTriangleSelector(q3node.Mesh, q3node, 128); q3node.TriangleSelector = selector; // We're not done with this selector yet, so don't drop it. } // Set a jump speed of 3 units per second, which gives a fairly realistic jump // when used with the gravity of (0, -1000, 0) in the collision response animator. CameraSceneNode camera = smgr.AddCameraSceneNodeFPS(null, 100.0f, 0.3f, ID_IsNotPickable, null, true, 3.0f); camera.Position = new Vector3Df(50, 50, -60); camera.Target = new Vector3Df(-70, 30, -60); if (selector != null) { SceneNodeAnimator anim = smgr.CreateCollisionResponseAnimator( selector, camera, new Vector3Df(30, 50, 30), new Vector3Df(0, -1000, 0), new Vector3Df(0, 30, 0)); selector.Drop(); // As soon as we're done with the selector, drop it. camera.AddAnimator(anim); anim.Drop(); // And likewise, drop the animator when we're done referring to it. } // Now I create three animated characters which we can pick, a dynamic light for // lighting them, and a billboard for drawing where we found an intersection. // First, let's get rid of the mouse cursor. We'll use a billboard to show what we're looking at. device.CursorControl.Visible = false; // Add the billboard. BillboardSceneNode bill = smgr.AddBillboardSceneNode(); bill.SetMaterialType(MaterialType.TransparentAddColor); bill.SetMaterialTexture(0, driver.GetTexture("../../media/particle.bmp")); bill.SetMaterialFlag(MaterialFlag.Lighting, false); bill.SetMaterialFlag(MaterialFlag.ZBuffer, false); bill.SetSize(20, 20, 20); bill.ID = ID_IsNotPickable; // This ensures that we don't accidentally ray-pick it AnimatedMeshSceneNode node = null; // Add an MD2 node, which uses vertex-based animation. node = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("../../media/faerie.md2"), null, IDFlag_IsPickable | IDFlag_IsHighlightable); node.Position = new Vector3Df(-90, -15, -140); // Put its feet on the floor. node.Scale = new Vector3Df(1.6f); // Make it appear realistically scaled node.SetMD2Animation(AnimationTypeMD2.Point); node.AnimationSpeed = 20.0f; node.GetMaterial(0).SetTexture(0, driver.GetTexture("../../media/faerie2.bmp")); node.GetMaterial(0).Lighting = true; node.GetMaterial(0).NormalizeNormals = true; // Now create a triangle selector for it. The selector will know that it // is associated with an animated node, and will update itself as necessary. selector = smgr.CreateTriangleSelector(node); node.TriangleSelector = selector; selector.Drop(); // We're done with this selector, so drop it now. // And this B3D file uses skinned skeletal animation. node = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("../../media/ninja.b3d"), null, IDFlag_IsPickable | IDFlag_IsHighlightable); node.Scale = new Vector3Df(10); node.Position = new Vector3Df(-75, -66, -80); node.Rotation = new Vector3Df(0, 90, 0); node.AnimationSpeed = 8.0f; node.GetMaterial(0).NormalizeNormals = true; // Just do the same as we did above. selector = smgr.CreateTriangleSelector(node); node.TriangleSelector = selector; selector.Drop(); // This X files uses skeletal animation, but without skinning. node = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("../../media/dwarf.x"), null, IDFlag_IsPickable | IDFlag_IsHighlightable); node.Position = new Vector3Df(-70, -66, -30); // Put its feet on the floor. node.Rotation = new Vector3Df(0, -90, 0); // And turn it towards the camera. node.AnimationSpeed = 20.0f; selector = smgr.CreateTriangleSelector(node); node.TriangleSelector = selector; selector.Drop(); // And this mdl file uses skinned skeletal animation. node = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("../../media/yodan.mdl"), null, IDFlag_IsPickable | IDFlag_IsHighlightable); node.Position = new Vector3Df(-90, -25, 20); node.Scale = new Vector3Df(0.8f); node.GetMaterial(0).Lighting = true; node.AnimationSpeed = 20.0f; // Just do the same as we did above. selector = smgr.CreateTriangleSelector(node); node.TriangleSelector = selector; selector.Drop(); // Add a light, so that the unselected nodes aren't completely dark. LightSceneNode light = smgr.AddLightSceneNode(null, new Vector3Df(-60, 100, 400), new Colorf(1.0f, 1.0f, 1.0f), 600.0f); light.ID = ID_IsNotPickable; // Make it an invalid target for selection. // Remember which scene node is highlighted SceneNode highlightedSceneNode = null; SceneCollisionManager collMan = smgr.SceneCollisionManager; int lastFPS = -1; // draw the selection triangle only as wireframe Material material = new Material(); material.Lighting = false; material.Wireframe = true; while (device.Run()) { if (device.WindowActive) { driver.BeginScene(ClearBufferFlag.All, new Color(0)); smgr.DrawAll(); // Unlight any currently highlighted scene node if (highlightedSceneNode != null) { highlightedSceneNode.SetMaterialFlag(MaterialFlag.Lighting, true); highlightedSceneNode = null; } // All intersections in this example are done with a ray cast out from the camera to // a distance of 1000. You can easily modify this to check (e.g.) a bullet // trajectory or a sword's position, or create a ray from a mouse click position using // collMan.GetRayFromScreenCoordinates() Line3Df ray = new Line3Df(); ray.Start = camera.Position; ray.End = ray.Start + (camera.Target - ray.Start).Normalize() * 1000.0f; // This call is all you need to perform ray/triangle collision on every scene node // that has a triangle selector, including the Quake level mesh. It finds the nearest // collision point/triangle, and returns the scene node containing that point. // Irrlicht provides other types of selection, including ray/triangle selector, // ray/box and ellipse/triangle selector, plus associated helpers. // See the methods of ISceneCollisionManager SceneNode selectedSceneNode = collMan.GetSceneNodeAndCollisionPointFromRay( ray, out Vector3Df intersection, // This will be the position of the collision out Triangle3Df hitTriangle, // This will be the triangle hit in the collision IDFlag_IsPickable); // This ensures that only nodes that we have set up to be pickable are considered // If the ray hit anything, move the billboard to the collision position // and draw the triangle that was hit. if (selectedSceneNode != null) { bill.Position = intersection; // We need to reset the transform before doing our own rendering. driver.SetTransform(TransformationState.World, Matrix.Identity); driver.SetMaterial(material); driver.Draw3DTriangle(hitTriangle, new Color(255, 0, 0)); // We can check the flags for the scene node that was hit to see if it should be // highlighted. The animated nodes can be highlighted, but not the Quake level mesh if ((selectedSceneNode.ID & IDFlag_IsHighlightable) == IDFlag_IsHighlightable) { highlightedSceneNode = selectedSceneNode; // Highlighting in this case means turning lighting OFF for this node, // which means that it will be drawn with full brightness. highlightedSceneNode.SetMaterialFlag(MaterialFlag.Lighting, false); } } // We're all done drawing, so end the scene. driver.EndScene(); int fps = driver.FPS; if (lastFPS != fps) { device.SetWindowCaption(String.Format( "Collision detection example - Irrlicht Engine [{0}] fps: {1}", driver.Name, fps)); lastFPS = fps; } } } device.Drop(); }
static void Main(string[] args) { DriverType driverType; if (!AskUserForDriver(out driverType)) { return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType, new Dimension2Di(ResX, ResY), 32, fullScreen); if (device == null) { return; } device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; // load model AnimatedMesh model = smgr.GetMesh("../../media/sydney.md2"); if (model == null) { return; } AnimatedMeshSceneNode model_node = smgr.AddAnimatedMeshSceneNode(model); // load texture if (model_node != null) { Texture texture = driver.GetTexture("../../media/sydney.bmp"); model_node.SetMaterialTexture(0, texture); model_node.SetMD2Animation(AnimationTypeMD2.Run); model_node.SetMaterialFlag(MaterialFlag.Lighting, false); } // load map device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3"); AnimatedMesh map = smgr.GetMesh("20kdm2.bsp"); if (map != null) { SceneNode map_node = smgr.AddOctreeSceneNode(map.GetMesh(0)); map_node.Position = new Vector3Df(-850, -220, -850); } // create 3 fixed and one user-controlled cameras camera[0] = smgr.AddCameraSceneNode(null, new Vector3Df(50, 0, 0), new Vector3Df(0)); // font camera[1] = smgr.AddCameraSceneNode(null, new Vector3Df(0, 50, 0), new Vector3Df(0)); // top camera[2] = smgr.AddCameraSceneNode(null, new Vector3Df(0, 0, 50), new Vector3Df(0)); // left camera[3] = smgr.AddCameraSceneNodeFPS(); // user-controlled camera[3].Position = new Vector3Df(-50, 0, -50); device.CursorControl.Visible = false; int lastFPS = -1; while (device.Run()) { // set the viewpoint to the whole screen and begin scene driver.ViewPort = new Recti(0, 0, ResX, ResY); driver.BeginScene(true, true, new Color(100, 100, 100)); if (splitScreen) { smgr.ActiveCamera = camera[0]; driver.ViewPort = new Recti(0, 0, ResX / 2, ResY / 2); // top left smgr.DrawAll(); smgr.ActiveCamera = camera[1]; driver.ViewPort = new Recti(ResX / 2, 0, ResX, ResY / 2); // top right smgr.DrawAll(); smgr.ActiveCamera = camera[2]; driver.ViewPort = new Recti(0, ResY / 2, ResX / 2, ResY); // bottom left smgr.DrawAll(); driver.ViewPort = new Recti(ResX / 2, ResY / 2, ResX, ResY); // bottom right } smgr.ActiveCamera = camera[3]; smgr.DrawAll(); driver.EndScene(); int fps = driver.FPS; if (lastFPS != fps) { device.SetWindowCaption(String.Format( "Split Screen example - Irrlicht Engine [{0}] fps: {1}", driver.Name, fps)); lastFPS = fps; } } device.Drop(); }
static void Main() { // setup Irrlicht device = IrrlichtDevice.CreateDevice(DriverType.OpenGL, new Dimension2Di(1024, 768), 32, false, true); if (device == null) { return; } device.SetWindowCaption("Stencil Shadows - Irrlicht Engine"); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); VideoDriver driver = device.VideoDriver; SceneManager scene = device.SceneManager; GUIFont statsFont = device.GUIEnvironment.GetFont("../../media/fontlucida.png"); cameraNode = scene.AddCameraSceneNodeFPS(); cameraNode.FarValue = 20000; device.CursorControl.Visible = false; // setup shadows shadows = new Shadows(new Color(0xa0000000), 4000); // load quake level device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3"); Mesh m = scene.GetMesh("20kdm2.bsp").GetMesh(0); MeshSceneNode n = scene.AddOctreeSceneNode(m, null, -1, 1024); n.Position = new Vector3Df(-1300, -144, -1249); quakeLevelNode = n; // add faerie faerieNode = scene.AddAnimatedMeshSceneNode( scene.GetMesh("../../media/faerie.md2"), null, -1, new Vector3Df(100, -40, 80), new Vector3Df(0, 30, 0), new Vector3Df(1.6f)); faerieNode.SetMD2Animation(AnimationTypeMD2.Wave); faerieNode.AnimationSpeed = 20; faerieNode.GetMaterial(0).SetTexture(0, driver.GetTexture("../../media/faerie2.bmp")); faerieNode.GetMaterial(0).Lighting = false; faerieNode.GetMaterial(0).NormalizeNormals = true; shadows.AddObject(faerieNode); // add light lightMovementHelperNode = scene.AddEmptySceneNode(); n = scene.AddSphereSceneNode(2, 6, lightMovementHelperNode, -1, new Vector3Df(15, -10, 15)); n.SetMaterialFlag(MaterialFlag.Lighting, false); lightNode = n; shadows.AddLight(lightNode); // add flashlight m = scene.GetMesh("../../media/flashlight.obj"); n = scene.AddMeshSceneNode(m, lightNode, -1, new Vector3Df(0), new Vector3Df(0), new Vector3Df(5)); n.SetMaterialFlag(MaterialFlag.Lighting, false); flashlightNode = n; flashlightNode.Visible = false; // render uint shdFrameTime = 0; uint shdFrames = 0; uint shdFps = 0; while (device.Run()) { if (useShadowsRebuilding && shadows.BuildShadowVolume()) { shdFrames++; } uint t = device.Timer.Time; if (t - shdFrameTime > 1000) { shdFrameTime = t; shdFps = shdFrames; shdFrames = 0; } if (useLightBinding) { lightMovementHelperNode.Position = cameraNode.AbsolutePosition.GetInterpolated(lightMovementHelperNode.Position, 0.1); lightMovementHelperNode.Rotation = cameraNode.AbsoluteTransformation.Rotation; } driver.BeginScene(ClearBufferFlag.All, new Color(0xff112244)); scene.DrawAll(); if (useShadowsRendering) { shadows.DrawShadowVolume(driver); } // display stats driver.Draw2DRectangle(new Recti(10, 10, 150, 220), new Color(0x7f000000)); Vector2Di v = new Vector2Di(20, 20); statsFont.Draw("Rendering", v, Color.SolidYellow); v.Y += 16; statsFont.Draw(driver.FPS + " fps", v, Color.SolidWhite); v.Y += 16; statsFont.Draw("[S]hadows " + (useShadowsRendering ? "ON" : "OFF"), v, Color.SolidGreen); v.Y += 16; statsFont.Draw("[L]ight binding " + (useLightBinding ? "ON" : "OFF"), v, Color.SolidGreen); v.Y += 16; statsFont.Draw("[F]lashlight " + (useFlashlight ? "ON" : "OFF"), v, Color.SolidGreen); v.Y += 32; statsFont.Draw("Shadows", v, Color.SolidYellow); v.Y += 16; statsFont.Draw(shdFps + " fps", v, Color.SolidWhite); v.Y += 16; statsFont.Draw(shadows.VerticesBuilt + " vertices", v, Color.SolidWhite); v.Y += 16; statsFont.Draw("[R]ebuilding " + (useShadowsRebuilding ? "ON" : "OFF"), v, Color.SolidGreen); v.Y += 16; statsFont.Draw("[Q]uake level " + (useShadowsQuakeLevel ? "ON" : "OFF"), v, Color.SolidGreen); driver.EndScene(); } shadows.Drop(); device.Drop(); }
static void Main(string[] args) { // setup Irrlicht device = IrrlichtDevice.CreateDevice(DriverType.Direct3D9, new Dimension2Di(1024, 768), 32, false, true); if (device == null) return; device.SetWindowCaption("Stencil Shadows - Irrlicht Engine"); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); VideoDriver driver = device.VideoDriver; SceneManager scene = device.SceneManager; GUIFont statsFont = device.GUIEnvironment.GetFont("../../media/fontlucida.png"); Material statsMaterial = Material.IdentityNoLighting; cameraNode = scene.AddCameraSceneNodeFPS(); cameraNode.FarValue = 20000; device.CursorControl.Visible = false; // setup shadows shadows = new Shadows(new Color(0xa0000000), 4000); // load quake level device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3"); Mesh m = scene.GetMesh("20kdm2.bsp").GetMesh(0); MeshSceneNode n = scene.AddOctreeSceneNode(m, null, -1, 1024); n.Position = new Vector3Df(-1300, -144, -1249); quakeLevelNode = n; // add faerie faerieNode = scene.AddAnimatedMeshSceneNode( scene.GetMesh("../../media/faerie.md2"), null, -1, new Vector3Df(100, -40, 80), new Vector3Df(0, 30, 0), new Vector3Df(1.6f)); faerieNode.SetMD2Animation(AnimationTypeMD2.Wave); faerieNode.AnimationSpeed = 20; faerieNode.GetMaterial(0).SetTexture(0, driver.GetTexture("../../media/faerie2.bmp")); faerieNode.GetMaterial(0).Lighting = false; faerieNode.GetMaterial(0).NormalizeNormals = true; shadows.AddObject(faerieNode); // add light lightMovementHelperNode = scene.AddEmptySceneNode(); n = scene.AddSphereSceneNode(2, 6, lightMovementHelperNode, -1, new Vector3Df(15, -10, 15)); n.SetMaterialFlag(MaterialFlag.Lighting, false); lightNode = n; shadows.AddLight(lightNode); // add flashlight m = scene.GetMesh("../../media/flashlight.obj"); n = scene.AddMeshSceneNode(m, lightNode, -1, new Vector3Df(0), new Vector3Df(0), new Vector3Df(5)); n.SetMaterialFlag(MaterialFlag.Lighting, false); flashlightNode = n; flashlightNode.Visible = false; // render uint shdFrameTime = 0; uint shdFrames = 0; uint shdFps = 0; while (device.Run()) { if (useShadowsRebuilding && shadows.BuildShadowVolume()) shdFrames++; uint t = device.Timer.Time; if (t - shdFrameTime > 1000) { shdFrameTime = t; shdFps = shdFrames; shdFrames = 0; } if (useLightBinding) { lightMovementHelperNode.Position = cameraNode.AbsolutePosition.GetInterpolated(lightMovementHelperNode.Position, 0.1); lightMovementHelperNode.Rotation = cameraNode.AbsoluteTransformation.Rotation; } driver.BeginScene(true, true, new Color(0xff112244)); scene.DrawAll(); if (useShadowsRendering) shadows.DrawShadowVolume(driver); // display stats device.VideoDriver.SetMaterial(statsMaterial); driver.Draw2DRectangle(new Recti(10, 10, 150, 220), new Color(0x7f000000)); Vector2Di v = new Vector2Di(20, 20); statsFont.Draw("Rendering", v, Color.OpaqueYellow); v.Y += 16; statsFont.Draw(driver.FPS + " fps", v, Color.OpaqueWhite); v.Y += 16; statsFont.Draw("[S]hadows " + (useShadowsRendering ? "ON" : "OFF"), v, Color.OpaqueGreen); v.Y += 16; statsFont.Draw("[L]ight binding " + (useLightBinding ? "ON" : "OFF"), v, Color.OpaqueGreen); v.Y += 16; statsFont.Draw("[F]lashlight " + (useFlashlight ? "ON" : "OFF"), v, Color.OpaqueGreen); v.Y += 32; statsFont.Draw("Shadows", v, Color.OpaqueYellow); v.Y += 16; statsFont.Draw(shdFps + " fps", v, Color.OpaqueWhite); v.Y += 16; statsFont.Draw(shadows.VerticesBuilt + " vertices", v, Color.OpaqueWhite); v.Y += 16; statsFont.Draw("[R]ebuilding " + (useShadowsRebuilding ? "ON" : "OFF"), v, Color.OpaqueGreen); v.Y += 16; statsFont.Draw("[Q]uake level " + (useShadowsQuakeLevel ? "ON" : "OFF"), v, Color.OpaqueGreen); driver.EndScene(); } shadows.Drop(); device.Drop(); }