static bool device_OnEvent(Event evnt) { if (evnt.Type == EventType.Key && evnt.Key.PressedDown) { switch (evnt.Key.Key) { case KeyCode.Space: simPaused = !simPaused; return(true); case KeyCode.KeyT: useTrails = !useTrails; return(true); } } if (evnt.Type == EventType.Mouse) { if (evnt.Mouse.IsLeftPressed()) { if (!mouseCanShoot) { return(true); } MeshSceneNode n = device.SceneManager.AddSphereSceneNode(sphereRadius); n.SetMaterialTexture(0, device.VideoDriver.GetTexture("../../media/wall.bmp")); n.SetMaterialFlag(MaterialFlag.Lighting, false); Vector3Df v = (device.SceneManager.ActiveCamera.Target - device.SceneManager.ActiveCamera.Position).Normalize(); n.Position = device.SceneManager.ActiveCamera.Position + v * 100; if (useTrails) { particles.Add(n, device.Timer.Time); } physics.AddShape(Physics.Shape.Shpere, n, sphereMass, false, v * cubeMass * 10000); mouseCanShoot = false; return(true); } else { mouseCanShoot = true; } } return(false); }
static void Main() { device = IrrlichtDevice.CreateDevice(DriverType.OpenGL, new Dimension2Di(800, 600)); device.SetWindowCaption("Sphere Camera - Irrlicht Engine"); driver = device.VideoDriver; scene = device.SceneManager; sphere = scene.AddSphereSceneNode(5, 100); sphere.SetMaterialTexture(0, driver.GetTexture("../../media/earth.jpg")); sphere.TriangleSelector = scene.CreateTriangleSelector(sphere.Mesh, sphere); sphere.TriangleSelector.Drop(); scene.AmbientLight = new Colorf(0.2f, 0.2f, 0.2f); LightSceneNode light = scene.AddLightSceneNode(); light.Position = new Vector3Df(-10, 10, -10); camera = new SphereCamera(device, new Vector3Df(0), 8, 20, 10, 0, 0); camera.Inclination = 200; path = new SpherePath(5.4f); GUIFont font = device.GUIEnvironment.BuiltInFont; device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); device.PostEvent(new Event('r', KeyCode.KeyR, true)); // pretend user pressed [R] while (device.Run()) { driver.BeginScene(); scene.DrawAll(); path.Draw(driver); font.Draw("Press [Arrows], [LMB] and [Mouse Scroll] to change view", 10, 10, Color.SolidYellow); font.Draw("Press [RMB] on Earth to place new path point", 10, 20, Color.SolidYellow); font.Draw("Press [R] to reload path data from file", 10, 30, Color.SolidYellow); font.Draw("Press [C] to clean up", 10, 40, Color.SolidYellow); font.Draw(driver.FPS.ToString() + " fps", 10, driver.ScreenSize.Height - 40, Color.SolidYellow); font.Draw(path.PointCount.ToString() + " point(s)", 10, driver.ScreenSize.Height - 30, Color.SolidYellow); font.Draw(camera.ToString(), 10, driver.ScreenSize.Height - 20, Color.SolidYellow); driver.EndScene(); device.Yield(); } path.Drop(); device.Drop(); }
static void Main(string[] args) { device = IrrlichtDevice.CreateDevice(DriverType.OpenGL, new Dimension2Di(800, 600)); device.SetWindowCaption("Sphere Camera - Irrlicht Engine"); driver = device.VideoDriver; scene = device.SceneManager; sphere = scene.AddSphereSceneNode(5, 100); sphere.SetMaterialTexture(0, driver.GetTexture("../../media/earth.jpg")); sphere.TriangleSelector = scene.CreateTriangleSelector(sphere.Mesh, sphere); sphere.TriangleSelector.Drop(); scene.AmbientLight = new Colorf(0.2f, 0.2f, 0.2f); LightSceneNode light = scene.AddLightSceneNode(); light.Position = new Vector3Df(-10, 10, -10); camera = new SphereCamera(device, new Vector3Df(0), 8, 20, 10, 0, 0); camera.Inclination = 200; path = new SpherePath(5.4f); GUIFont font = device.GUIEnvironment.BuiltInFont; device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); device.PostEvent(new Event('r', KeyCode.KeyR, true)); // pretend user pressed [R] while (device.Run()) { driver.BeginScene(); scene.DrawAll(); path.Draw(driver); font.Draw("Press [Arrows], [LMB] and [Mouse Scroll] to change view", 10, 10, Color.OpaqueYellow); font.Draw("Press [RMB] on Earth to place new path point", 10, 20, Color.OpaqueYellow); font.Draw("Press [R] to reload path data from file", 10, 30, Color.OpaqueYellow); font.Draw("Press [C] to clean up", 10, 40, Color.OpaqueYellow); font.Draw(driver.FPS.ToString() + " fps", 10, driver.ScreenSize.Height - 40, Color.OpaqueYellow); font.Draw(path.PointCount.ToString() + " point(s)", 10, driver.ScreenSize.Height - 30, Color.OpaqueYellow); font.Draw(camera.ToString(), 10, driver.ScreenSize.Height - 20, Color.OpaqueYellow); driver.EndScene(); } path.Drop(); device.Drop(); }
static bool Device_OnEvent(Event evnt) { if (evnt.Type == EventType.GUI && evnt.GUI.Type == GUIEventType.ButtonClicked && evnt.GUI.Caller.ID == ChooseFolderButtonId) { wantChangeFolder = true; return(true); } if (evnt.Type == EventType.Mouse && evnt.Mouse.Type == MouseEventType.Wheel && selectedNode == null) { Vector3Df p = irr.Scene.ActiveCamera.Position; Vector3Df t = irr.Scene.ActiveCamera.Target; float s = irr.Scene.ActiveCamera.Position.Z + evnt.Mouse.Wheel * 16; if (s < 0) { s = 0; } if (s > maxScrollPosition) { s = maxScrollPosition; } t.Z = t.Z - p.Z + s; p.Z = s; irr.Scene.ActiveCamera.Position = p; irr.Scene.ActiveCamera.Target = t; return(true); } if (evnt.Type == EventType.Mouse && evnt.Mouse.Type == MouseEventType.Move && selectedNode == null) { SceneNode n = irr.Scene.SceneCollisionManager.GetSceneNodeFromScreenCoordinatesBB( new Vector2Di(evnt.Mouse.X, evnt.Mouse.Y), 0, irr.Scene.GetSceneNodeFromID(PreviewRootNodeId)); if (hoveredNode != n) { if (hoveredNode != null) { animationManager.Remove(hoveredNode); animationManager.Add( hoveredNode, 500, new Vector3Df(hoveredNode.Position.X, hoveredNode.Position.Y - 15, hoveredNode.Position.Z), new Vector3Df(0), hoveredNode.Scale / 1.5f); } if (n != null) { animationManager.Remove(n); animationManager.Add( n, 40, new Vector3Df(n.Position.X, n.Position.Y + 15, n.Position.Z), new Vector3Df(-20, 0, 0), n.Scale * 1.5f); } hoveredNode = n; } return(true); } if (evnt.Type == EventType.Mouse && evnt.Mouse.Type == MouseEventType.LeftUp && hoveredNode != null && (hoveredNode.ID & SelectableNodeIdFlag) == SelectableNodeIdFlag && selectedNode == null) { animationManager.Remove(hoveredNode); Mesh m = irr.Scene.MeshCache.GetMesh(PreviewPlateMeshName); MeshSceneNode n = irr.Scene.AddMeshSceneNode(m); n.SetMaterialFlag(MaterialFlag.Lighting, false); n.Position = hoveredNode.Position; n.Rotation = hoveredNode.Rotation; n.Scale = hoveredNode.Scale; string t = hoveredNode.GetMaterial(0).GetTexture(0).Name.Path.Split('|')[0]; Dimension2Di d = new Dimension2Di(2048); if (d.Area > irr.Driver.MaxTextureSize.Area) { d = irr.Driver.MaxTextureSize; } n.SetMaterialTexture(0, hoveredNode.GetMaterial(0).GetTexture(0)); textureManager.LoadTexture(n, t, d, true); animationManager.Add( n, 200, irr.Scene.ActiveCamera.AbsolutePosition + new Vector3Df(0, -48, 40), // TODO: this magic numbers should be calculated somehow new Vector3Df(-39.85f, 0, 0), // using current active camera info (like view matrix or projection one) n.Scale * ((irr.Scene.ActiveCamera.FOV - 0.125f) / n.Scale.Z)); selectedNode = n; hoveredNode.Visible = false; irr.GUI.RootElement.GetElementFromID(ChooseFolderButtonId).Enabled = false; return(true); } if (evnt.Type == EventType.Mouse && evnt.Mouse.Type == MouseEventType.LeftUp && selectedNode != null && selectedNode.GetMaterial(0).GetTexture(0) != hoveredNode.GetMaterial(0).GetTexture(0)) { if (animationManager.IsAnimated(selectedNode)) { return(true); } Texture t = selectedNode.GetMaterial(0).GetTexture(0); if (t != null) { string s = t.Name.Path; selectedNode.SetMaterialTexture(0, null); textureManager.UnloadTexture(s); } selectedNode.Remove(); selectedNode = null; hoveredNode.Visible = true; irr.GUI.RootElement.GetElementFromID(ChooseFolderButtonId).Enabled = true; return(true); } if (evnt.Type == EventType.Log && evnt.Log.Text.StartsWith("Resizing window")) { wantUpdateActiveCameraAspectRatio = true; } return(false); }
static void Main() { DriverType?driverType = AskForDriver(); if (!driverType.HasValue) { return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType.Value, new Dimension2Di(640, 480)); if (device == null) { return; } device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); VideoDriver driver = device.VideoDriver; SceneManager scene = device.SceneManager; scene.GUIEnvironment.AddStaticText("Press Space to hide occluder.", new Recti(10, 10, 200, 50)); // Create the node to be occluded. We create a sphere node with high poly count. MeshSceneNode node = scene.AddSphereSceneNode(10, 64); if (node != null) { node.Position = new Vector3Df(0, 0, 60); node.SetMaterialTexture(0, driver.GetTexture("../../media/wall.bmp")); node.SetMaterialFlag(MaterialFlag.Lighting, false); } // Now we create another node, the occluder. It's a simple plane. SceneNode plane = scene.AddMeshSceneNode( scene.AddHillPlaneMesh("plane", new Dimension2Df(10), new Dimension2Di(2)), // mesh null, // parent -1, // id new Vector3Df(0, 0, 20), // position new Vector3Df(270, 0, 0)); // rotation if (plane != null) { plane.SetMaterialTexture(0, driver.GetTexture("../../media/t351sml.jpg")); plane.SetMaterialFlag(MaterialFlag.Lighting, false); plane.SetMaterialFlag(MaterialFlag.BackFaceCulling, true); } // Here we create the occlusion query. Because we don't have a plain mesh scene node // (SceneNodeType.Mesh or SceneNodeType.AnimatedMesh), we pass the base geometry as well. Instead, // we could also pass a simpler mesh or the bounding box. But we will use a time // based method, where the occlusion query renders to the frame buffer and in case // of success (occlusion), the mesh is not drawn for several frames. driver.AddOcclusionQuery(node, node.Mesh); // We have done everything, just a camera and draw it. We also write the // current frames per second and the name of the driver to the caption of the // window to examine the render speedup. // We also store the time for measuring the time since the last occlusion query ran // and store whether the node should be visible in the next frames. scene.AddCameraSceneNode(); uint timeNow = device.Timer.Time; bool nodeVisible = true; while (device.Run()) { plane.Visible = !IsKeyDown(KeyCode.Space); driver.BeginScene(ClearBufferFlag.All, new Color(113, 113, 133)); // First, we draw the scene, possibly without the occluded element. This is necessary // because we need the occluder to be drawn first. You can also use several scene // managers to collect a number of possible occluders in a separately rendered scene. node.Visible = nodeVisible; scene.DrawAll(); scene.GUIEnvironment.DrawAll(); // Once in a while, here every 100 ms, we check the visibility. We run the queries, // update the pixel value, and query the result. Since we already rendered the node // we render the query invisible. The update is made blocking, as we need the result // immediately. If you don't need the result immediately, e.g. because oyu have other // things to render, you can call the update non-blocking. This gives the GPU more // time to pass back the results without flushing the render pipeline. // If the update was called non-blocking, the result from getOcclusionQueryResult is // either the previous value, or 0xffffffff if no value has been generated at all, yet. // The result is taken immediately as visibility flag for the node. if (device.Timer.Time - timeNow > 100) { driver.RunAllOcclusionQueries(false); driver.UpdateAllOcclusionQueries(); nodeVisible = driver.GetOcclusionQueryResult(node) > 0; timeNow = device.Timer.Time; } driver.EndScene(); device.SetWindowCaption(String.Format( "Occlusion Query Example - Irrlicht Engine [{0}] fps: {1} (primitives: {2})", driver.Name, driver.FPS, driver.PrimitiveCountDrawn)); } device.Drop(); }
static void Main(string[] args) { checkBulletSharpDllPresence(); // setup Irrlicht device = IrrlichtDevice.CreateDevice(DriverType.Direct3D9, new Dimension2Di(1024, 768)); if (device == null) { return; } device.SetWindowCaption("BulletSharp Test - Irrlicht Engine"); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); VideoDriver driver = device.VideoDriver; SceneManager scene = device.SceneManager; GUIFont font = device.GUIEnvironment.GetFont("../../media/fontlucida.png"); CameraSceneNode camera = scene.AddCameraSceneNodeFPS(); camera.Position = new Vector3Df(100, 800, -1000); camera.Target = new Vector3Df(0, 100, 0); camera.FarValue = 30000; camera.AutomaticCulling = CullingType.FrustumBox; device.CursorControl.Visible = false; // setup physics physics = new Physics(); physics.Setup(new Vector3Df(0, -worldGravity, 0)); // setup particles particles = new Particles(device); // load quake level device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3"); Mesh mesh = scene.GetMesh("20kdm2.bsp").GetMesh(0); SceneNode quakeLevel = scene.AddOctreeSceneNode(mesh, null, -1, 1024); quakeLevel.Position = new Vector3Df(-1300, -144, -1249); physics.AddShape(Physics.Shape.Mesh, quakeLevel); // generate dynamic objects for (int i = 0; i < 3; i++) { for (int j = 0; j < 30; j++) { for (int k = 0; k < 3; k++) { MeshSceneNode n = scene.AddCubeSceneNode(cubeSize); n.SetMaterialTexture(0, driver.GetTexture("../../media/wall.bmp")); n.SetMaterialFlag(MaterialFlag.Lighting, false); n.Position = new Vector3Df(70 + i * cubeSize, 520 + j * cubeSize, -650 + k * cubeSize); physics.AddShape(Physics.Shape.Box, n, cubeMass); } } } // main loop uint curTime = 0; uint lastTime = 0; int simFps = 0; int simFrames = 0; uint simFramesTime = 0; while (device.Run()) { if (device.WindowActive) { // simulate physics lastTime = curTime; curTime = device.Timer.Time; if (!simPaused) { float deltaTime = (curTime - lastTime) / 1000.0f; bool b = physics.StepSimulation(deltaTime); if (b) { simFrames++; } } if (curTime - simFramesTime > 1000) { simFramesTime = curTime; simFps = simFrames; simFrames = 0; } // winnow particles particles.Winnow(curTime, simPaused); // render scene driver.BeginScene(true, true, new Color(40, 80, 160)); scene.DrawAll(); Material material = new Material(); material.Lighting = false; device.VideoDriver.SetMaterial(material); // display stats driver.Draw2DRectangle(new Recti(10, 10, 140, 180), new Color(0x7f000000)); Vector2Di v = new Vector2Di(20, 20); font.Draw("Rendering", v, Color.OpaqueYellow); v.Y += 16; font.Draw(scene.Attributes.GetValue("calls") + " nodes", v, Color.OpaqueWhite); v.Y += 16; font.Draw(driver.FPS + " fps", v, Color.OpaqueWhite); v.Y += 16; font.Draw("[T]rails " + (useTrails ? "ON" : "OFF"), v, Color.OpaqueGreen); v.Y += 32; font.Draw("Physics" + (simPaused ? " (paused)" : ""), v, Color.OpaqueYellow); v.Y += 16; font.Draw(physics.NumCollisionObjects + " shapes", v, Color.OpaqueWhite); v.Y += 16; font.Draw(simFps + " fps", v, Color.OpaqueWhite); v.Y += 16; font.Draw("[Space] to pause", v, Color.OpaqueGreen); driver.EndScene(); } device.Yield(); } // drop physics.Drop(); device.Drop(); }
public Jeu() { Device = IrrlichtDevice.CreateDevice( DriverType.Direct3D9, new Dimension2Di(800, 600), 32, false, false, true); Device.SetWindowCaption("Canardstein 3D"); Device.OnEvent += Evenement; Audio = new ISoundEngine(); for (int i = 0; i < 3; i++) { TexturePistolet[i] = Device.VideoDriver.GetTexture(@"Textures\pistolet" + i.ToString() + ".png"); } for (int i = 0; i < 7; i++) { TextureGarde[i] = Device.VideoDriver.GetTexture(@"Textures\nazi" + i.ToString("00") + ".png"); } TextureMur = Device.VideoDriver.GetTexture(@"Textures\mur.png"); TextureMurDeco = Device.VideoDriver.GetTexture(@"Textures\mur_deco.png"); TextureSol = Device.VideoDriver.GetTexture(@"Textures\sol.png"); TexturePlafond = Device.VideoDriver.GetTexture(@"Textures\plafond.png"); TexturePolice = Device.VideoDriver.GetTexture(@"Textures\police.png"); using (Bitmap carte = (Bitmap)System.Drawing.Image.FromFile(@"Textures\carte.png")) { for (int x = 0; x < 32; x++) { for (int y = 0; y < 32; y++) { System.Drawing.Color col = carte.GetPixel(x, y); Murs[x, y] = false; if ((col.R == 255) && (col.G == 255) && (col.B == 255)) { SceneNode cube = Device.SceneManager.AddCubeSceneNode(1, null, 0, new Vector3Df(x, 0, y)); cube.SetMaterialFlag(MaterialFlag.Lighting, false); cube.SetMaterialFlag(MaterialFlag.Fog, true); cube.SetMaterialTexture(0, TextureMur); Murs[x, y] = true; } else if ((col.R == 0) && (col.G == 0) && (col.B == 255)) { SceneNode cube = Device.SceneManager.AddCubeSceneNode(1, null, 0, new Vector3Df(x, 0, y)); cube.SetMaterialFlag(MaterialFlag.Lighting, false); cube.SetMaterialFlag(MaterialFlag.Fog, true); cube.SetMaterialTexture(0, TextureMurDeco); Murs[x, y] = true; } } } } //On va maintenant créer un plancher et un plafond, histoire de mettre un peu d'ordre. On commence par générer meshSol, //le modèle 3D d'un plan que nous allons nommer « plan » (parce qu'il est obligatoire de fournir un nom), divisé en 32 × 32 cases de taille 1 × 1. //On ne va pas lui assigner de texture pour le moment (null). Ce plan sera parfaitement horizontal, avec 0 × 0 variation de hauteur 0. //Enfin, la texture sera répétée 32 fois horizontalement et verticalement. Mesh meshSol = Device.SceneManager.AddHillPlaneMesh("plan", new Dimension2Df(1, 1), new Dimension2Di(32, 32), null, 0, new Dimension2Df(0, 0), new Dimension2Df(32, 32)); //On désactive l'éclairage dynamique sur notre nouvel objet, comme on l'avait déjà fait pour le cube, et on lui assigne TextureSol. //Puis on le positionne à une distance d'une demi-unité sous le zéro (ou, plus précisément, sous les pieds de notre héros, la position Y de la caméra étant de 0), //et à −15.5 sur les axes X et Z (notre plan mesurant 32 par 32 cases de largeur 1, le déplacer de 15,5 unités permet de s'assurer que l'un de ses coins sera à la coordonnée 0,0, //ce sera utile dans la prochaine leçon). MeshSceneNode sol = Device.SceneManager.AddMeshSceneNode(meshSol); sol.SetMaterialFlag(MaterialFlag.Lighting, false); sol.SetMaterialFlag(MaterialFlag.Fog, true); sol.SetMaterialTexture(0, TextureSol); sol.Position = new Vector3Df(15.5f, -0.5f, 15.5f); //Pareil pour le plafond, sauf qu'on le place à une hauteur de 0,5 (et non de −0,5), et qu'on le pivote de 180 sur l'axe X pour le tourner vers le bas. MeshSceneNode plafond = Device.SceneManager.AddMeshSceneNode(meshSol); plafond.SetMaterialFlag(MaterialFlag.Lighting, false); plafond.SetMaterialFlag(MaterialFlag.Fog, true); plafond.SetMaterialTexture(0, TexturePlafond); plafond.Position = new Vector3Df(15.5f, 0.5f, 15.5f); plafond.Rotation = new Vector3Df(180, 0, 0); CameraSceneNode camera = Device.SceneManager.AddCameraSceneNode(null, new Vector3Df(1, 0, 1), new Vector3Df(2, 0, 1)); //Abaisse la distance minimum d'affichage de la caméra. La valeur par défaut est de 1, ce qui ne nous convient pas : //plafond et sol se trouvant à 0,5 unité de la caméra, ils seraient trop près pour être dessinés. camera.NearValue = 0.1f; AjouterChose <Ennemi>(3, 3); AjouterChose <Ennemi>(6, 12); AjouterChose <Ennemi>(12, 12); AjouterChose <Ennemi>(20, 6); AjouterChose <Ennemi>(28, 16); AjouterChose <Ennemi>(11, 27); Device.VideoDriver.Fog = new Fog(new IrrlichtLime.Video.Color(138, 125, 81, 0), FogType.Linear, 0, 10); ParticleSystemSceneNode part = Device.SceneManager.AddParticleSystemSceneNode(false, null, 0, new Vector3Df(29, -.5f, 30)); part.SetMaterialFlag(MaterialFlag.Lighting, false); ParticleEmitter em = part.CreateBoxEmitter( new AABBox(-.5f, 0, -.5f, .5f, 0, .5f), new Vector3Df(0.0f, 0.0015f, 0.0f), 20, 24, new IrrlichtLime.Video.Color(0, 128, 255, 0), new IrrlichtLime.Video.Color(0, 255, 255, 0), 800, 800, 0, new Dimension2Df(0.005f, 0.04f), new Dimension2Df(0.01f, 0.08f)); part.Emitter = em; while (Device.Run()) { float tempsEcoule = (Device.Timer.Time - DerniereFrame) / 1000f; DerniereFrame = Device.Timer.Time; if ((AlphaSang > 0) && (Vies > 0)) { AlphaSang = Math.Max(0, AlphaSang - tempsEcoule * 500); } if (((int)camera.Position.X == 29) && ((int)camera.Position.Z == 30)) { Device.Close(); } if (Device.CursorControl.Position.X != 400) { Rotation += (Device.CursorControl.Position.X - 400) * 0.0025; Device.CursorControl.Position = new Vector2Di(400, 300); VecteurAvant = new Vector3Df((float)Math.Cos(Rotation), 0, -(float)Math.Sin(Rotation)); VecteurDroite = VecteurAvant; VecteurDroite.RotateXZby(-90); } for (int i = 0; i < Choses.Count; i++) { Choses[i].MiseAJour(tempsEcoule, camera); } Vector3Df vitesse = new Vector3Df(); if (K_Avant) { vitesse += VecteurAvant; } else if (K_Arriere) { vitesse -= VecteurAvant; } if (K_Gauche) { vitesse -= VecteurDroite; } else if (K_Droite) { vitesse += VecteurDroite; } vitesse = vitesse.Normalize() * tempsEcoule * 2; if (TenterMouvement(camera, vitesse) || TenterMouvement(camera, new Vector3Df(vitesse.X, 0, 0)) || TenterMouvement(camera, new Vector3Df(0, 0, vitesse.Z))) { camera.Target = camera.Position + VecteurAvant; } Device.VideoDriver.BeginScene(ClearBufferFlag.Color | ClearBufferFlag.Depth, IrrlichtLime.Video.Color.OpaqueMagenta); Device.SceneManager.DrawAll(); Device.VideoDriver.Draw2DImage(TexturePistolet[FramePistolet], new Recti(new Vector2Di(250, 300), new Dimension2Di(300, 300)), new Recti(0, 0, 512, 512), null, COULEUR_BLANC, true); DessinerHUD(); Device.VideoDriver.EndScene(); if (FramePistolet > 0) { ProchaineFramePistolet -= tempsEcoule; if (ProchaineFramePistolet <= 0f) { FramePistolet++; if (FramePistolet > 2) { FramePistolet = 0; } ProchaineFramePistolet = 0.1f; } } } }
public Application() { _01.HelloWorld.Kinect kinect = new _01.HelloWorld.Kinect(); mfX = mouseX = 840; mfY = mouseY = 525; mouseL = false; mouseR = false; //device = IrrlichtDevice.CreateDevice( // DriverType.Direct3D9, new Dimension2Di(800, 600), 16, false, true, false); // | device = IrrlichtDevice.CreateDevice( // \|/ Fullscreen DriverType.Direct3D9, new Dimension2Di(1680, 1050), 32, false, true, false); device.SetWindowCaption("BENder3D"); VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; GUIEnvironment gui = device.GUIEnvironment; device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); smgr.AmbientLight = new Colorf(128, 128, 128, 128); //smgr.AddLightSceneNode(null, new Vector3Df(0, 70, 0), new Colorf(122,0,122,0), (float)10); MeshSceneNode box = smgr.AddCubeSceneNode(100, null, 9001, new Vector3Df(0.0f, -ballRadius * 3 / 2, 0.0f)); box.Scale = new Vector3Df(100.0f, 0.1f, 100.0f); //Mesh cyl = smgr.GeometryCreator.CreateCylinderMesh(ballRadius, 50, 256); //Mesh sphere = smgr.GeometryCreator.CreateSphereMesh(ballRadius, 16,16); //MeshSceneNode t = smgr.AddSphereSceneNode(ballRadius, 32); //MeshSceneNode t = smgr.AddOctreeSceneNode(sphere); MeshSceneNode t = smgr.AddMeshSceneNode(smgr.GetMesh("pill.obj")); //MeshSceneNode t = smgr.AddMeshSceneNode(cyl); TriangleSelector triselect = smgr.CreateTriangleSelector(t.Mesh, t); t.TriangleSelector = triselect; triselect.Drop(); //t = smgr.AddMeshSceneNode(smgr.GetMesh("../../media/sphere.x")); //smgr t.SetMaterialTexture(0, driver.GetTexture("rockwall.jpg")); //t.SetMaterialFlag(MaterialFlag.Lighting, true); t.GetMaterial(0).SpecularColor.Set(0, 0, 0); //t.GetMaterial(0).Lighting = true; t.GetMaterial(0).NormalizeNormals = false; /*Texture citrus = driver.AddTexture(new Dimension2Di(200, 200), "citrus.png"); * gui.AddImage(citrus, new Vector2Di(824, 0), true);*/ gui.AddStaticText("Hey, Listen! Press C to switch the mesh to a cylinder!\n Press S to change to a sphere, and enter to send yourself the obj file!", new Recti(0, 0, 400, 60)); //t.AddShadowVolumeSceneNode(); // driver.GPUProgrammingServices.OnSetConstants += new GPUProgrammingServices.SetConstantsHandler(gpu_OnSetConstants); /* * MaterialType shaderMat = MaterialType.Solid; * shaderMat = driver.GPUProgrammingServices.AddHighLevelShaderMaterialFromFiles("C:/IrrlichtLime-1.4/examples/01.HelloWorld/bumpmap.hlsl", "VertexShaderFunction", VertexShaderType.VS_3_0, * "C:/IrrlichtLime-1.4/examples/01.HelloWorld/bumpmap.hlsl", "PixelShaderFunction", PixelShaderType.PS_3_0, MaterialType.Solid); * * t.SetMaterialType(shaderMat); * t.SetMaterialTexture(1, driver.GetTexture("../../media/rockwall_height.bmp"));*/ GPUProgrammingServices gpu = driver.GPUProgrammingServices; MaterialType newMaterialType1 = MaterialType.Solid; MaterialType newMaterialType2 = MaterialType.TransparentAddColor; gpu.OnSetConstants += new GPUProgrammingServices.SetConstantsHandler(gpu_OnSetConstants); // create the shaders depending on if the user wanted high level or low level shaders newMaterialType1 = gpu.AddHighLevelShaderMaterialFromFiles( "d3d9.hlsl", "vertexMain", VertexShaderType.VS_1_1, "d3d9.hlsl", "pixelMain", PixelShaderType.PS_1_1, MaterialType.Solid, 0, GPUShadingLanguage.Default); t.SetMaterialType(newMaterialType1); //t.GetMaterial(0).Wireframe = true; //t.DebugDataVisible = DebugSceneType.Full; //t.AddShadowVolumeSceneNode(null, -1, false, 1000.0f); smgr.AddLightSceneNode(null, new Vector3Df(40, 150, -50), new Colorf(255, 255, 255, 255), 250.0f); //CSampleSceneNode sceneNode = new CSampleSceneNode(smgr.RootNode, smgr, 667); camera = smgr.AddCameraSceneNode(null, new Vector3Df(0, 50, -140), new Vector3Df(0, 5, 0)); //camera.Target = new Vector3Df(-70, 30, -60); //smgr.AddCameraSceneNodeFPS(null, (float)50.0); Material m = new Material(); m.Lighting = false; double PI = 3.1415926f; float distance = 200.0f; double angle = 180.0f; double angleY = 20.0f; int oldMouseX = mouseX; int oldMouseY = mouseY; uint then = device.Timer.Time; uint currentAutism = device.Timer.Time; bool autism = false; while (device.Run()) { uint now = device.Timer.Time; float frameDeltaTime = (float)(now - then) / 1000.0f; then = now; if (kinect.isTranslating && (kinect.translation.X < 30 && kinect.translation.X > -30)) { mfX -= (int)(kinect.translation.X); mfY -= (int)(kinect.translation.Y); Console.WriteLine(mouseX + ", " + mouseY + " ----------------- " + (int)(kinect.translation.X) + ", " + (int)(kinect.translation.Y)); } kinect.resetTranslation(); /* * if (getDistance((int)mfX, (int)mfY, 512, 384) > 150) * { * mfX = 512; mfY= 384; * }*/ mouseX = Math.Abs((int)mfX) % 1024; mouseY = Math.Abs((int)mfY) % 768; //mouseX = kinect.position.X; device.CursorControl.Position = new Vector2Di(mouseX, mouseY); if (!potterWheelDown && IsKeyDown(KeyCode.Up)) { potterWheelDown = true; deltaAngle = 1.0d; potterWheelActivate = !potterWheelActivate; } else if (!IsKeyDown(KeyCode.Up)) { potterWheelDown = false; } if (!leftKeyPressed && IsKeyDown(KeyCode.Left)) { leftKeyPressed = true; deltaAngle /= 2; } else if (!IsKeyDown(KeyCode.Left)) { leftKeyPressed = false; } if (!rightKeyPressed && IsKeyDown(KeyCode.Right)) { rightKeyPressed = true; deltaAngle *= 2; } else if (!IsKeyDown(KeyCode.Right)) { rightKeyPressed = false; } if (potterWheelActivate) { angle -= 700.0f * deltaAngle * frameDeltaTime; } if (angle > 360) { angle -= 360; } else if (angle < 0) { angle += 360; } if (angleY > 360) { angle -= 360; } else if (angleY < 0) { angleY += 360; } driver.BeginScene(true, true, new Color(100, 101, 140)); camera.Target = new Vector3Df(0, 0, 0); double temp = Math.Cos(angleY * PI / 180.0) * distance; double X = Math.Sin(angle * PI / 180.0) * temp; double Y = Math.Sin(angleY * PI / 180.0) * distance; double Z = Math.Cos(angle * PI / 180.0) * temp; camera.Position = new Vector3Df((float)X, (float)Y, (float)Z); smgr.DrawAll(); gui.DrawAll(); driver.SetMaterial(m); Triangle3Df triangle = interpolateFrom2D(new Vector2Di(mouseX, mouseY)); if (kinect.isMorphing && kinect.morphDist > 0) //if (IsKeyDown(KeyCode.KeyW)) { //Console.WriteLine("PRESSED KEY"); triangle.A *= new Vector3Df(0.5f); triangle.B *= new Vector3Df(0.5f); triangle.C *= new Vector3Df(0.5f); if (isCyl) { deformCyl(t, triangle.A, new Vector3Df(.5f / (potterWheelActivate ? (float)(1 / deltaAngle) : 60f)), triangle); } else { deformMesh(t, triangle.A, new Vector3Df(.5f / (potterWheelActivate ? (float)(1 / deltaAngle) : 60f)), triangle); } } else if (kinect.isMorphing && kinect.morphDist < 0) { //Console.WriteLine("PRESSED KEY"); triangle.A *= new Vector3Df(1.5f); triangle.B *= new Vector3Df(1.5f); triangle.C *= new Vector3Df(1.5f); if (isCyl) { deformCyl(t, triangle.A, new Vector3Df(-.5f / (potterWheelActivate ? (float)(1 / deltaAngle) : 60f)), triangle); } else { deformMesh(t, triangle.A, new Vector3Df(-.5f / (potterWheelActivate ? (float)(1 / deltaAngle) : 60f)), triangle); } } if (kinect.isZoom && kinect.zoomDist < 0) { if (distance < 300.0f) { distance += .0625f; } } if (kinect.isZoom && kinect.zoomDist > 0) { if (distance > 150) { distance -= .0625f; } } if (kinect.isRotating && kinect.rotation > 0) { angle += 200 * frameDeltaTime; } if (kinect.isRotating && kinect.rotation < 0) { angle -= 200 * frameDeltaTime; } //Change shape if (IsKeyDown(KeyCode.KeyA)) { IrrlichtLime.IO.WriteFile file = device.FileSystem.CreateWriteFile("./Saved.obj"); writeMesh(file, t.Mesh, 1); mail(); } if (IsKeyDown(KeyCode.KeyC)) { isCyl = true; t.Remove(); t = smgr.AddMeshSceneNode(smgr.GetMesh("pill.obj")); //MeshSceneNode t = smgr.AddMeshSceneNode(cyl); triselect = smgr.CreateTriangleSelector(t.Mesh, t); t.TriangleSelector = triselect; triselect.Drop(); //t = smgr.AddMeshSceneNode(smgr.GetMesh("../../media/sphere.x")); //smgr t.SetMaterialTexture(0, driver.GetTexture("rockwall.jpg")); //t.SetMaterialFlag(MaterialFlag.Lighting, true); t.GetMaterial(0).SpecularColor.Set(0, 0, 0); //t.GetMaterial(0).Lighting = true; t.GetMaterial(0).NormalizeNormals = false; t.SetMaterialType(newMaterialType1); } else if (IsKeyDown(KeyCode.KeyS)) { isCyl = false; t.Remove(); t = smgr.AddSphereSceneNode(ballRadius, 32); triselect = smgr.CreateTriangleSelector(t.Mesh, t); t.TriangleSelector = triselect; triselect.Drop(); //t = smgr.AddMeshSceneNode(smgr.GetMesh("../../media/sphere.x")); //smgr t.SetMaterialTexture(0, driver.GetTexture("rockwall.jpg")); //t.SetMaterialFlag(MaterialFlag.Lighting, true); t.GetMaterial(0).SpecularColor.Set(0, 0, 0); //t.GetMaterial(0).Lighting = true; t.GetMaterial(0).NormalizeNormals = false; t.SetMaterialType(newMaterialType1); } driver.EndScene(); } device.Drop(); }