static void Main(string[] args) { device = IrrlichtDevice.CreateDevice(DriverType.OpenGL, new Dimension2Di(1024, 600)); device.SetWindowCaption("LightningShots - Irrlicht Engine"); VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3"); AnimatedMesh mesh = smgr.GetMesh("20kdm2.bsp"); MeshSceneNode node = smgr.AddMeshSceneNode(mesh.GetMesh(0)); node.Position = new Vector3Df(-1300, -144, -1249); node.SetMaterialType(MaterialType.LightMapLightingM4); node.SetMaterialFlag(MaterialFlag.Lighting, true); node.TriangleSelector = smgr.CreateTriangleSelector(node.Mesh, node); node.TriangleSelector.Drop(); smgr.AmbientLight = new Colorf(0.15f, 0.14f, 0.13f); CameraSceneNode camera = smgr.AddCameraSceneNodeFPS(); lightningShot = new LightningShot(smgr, node.TriangleSelector); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); device.CursorControl.Visible = false; while (device.Run()) { driver.BeginScene(true, true, new Color(100, 80, 75)); smgr.DrawAll(); lightningShot.Draw(device.Timer.Time); GUIFont f = device.GUIEnvironment.BuiltInFont; f.Draw("Use [LMB] to shoot", 10, 10, Color.OpaqueYellow); f.Draw("Total lightnings: " + lightningShot.TotalLightnings, 10, 20, Color.OpaqueWhite); f.Draw("Total shots: " + lightningShot.TotalShots, 10, 30, Color.OpaqueWhite); f.Draw(driver.FPS + " fps", 10, 40, Color.OpaqueWhite); driver.EndScene(); } lightningShot.Drop(); device.Drop(); }
static void Main() { device = IrrlichtDevice.CreateDevice(DriverType.OpenGL, new Dimension2Di(1024, 768), 32, false, true); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); device.SetWindowCaption("Minesweeper - Irrlicht Engine"); VideoDriver driver = device.VideoDriver; SceneManager scene = device.SceneManager; GUIEnvironment gui = device.GUIEnvironment; device.FileSystem.AddFileArchive("../../media/minesweeper.media.files"); game = new Game(device); // set up camera camera = scene.AddCameraSceneNode(); // Maya(null, -500, 50, 200); setupCameraPositionAndTarget(); // set up background Mesh m = scene.GetMesh("back.obj"); scene.MeshManipulator.Scale(m, new Vector3Df(80)); scene.MeshManipulator.FlipSurfaces(m); scene.MeshManipulator.RecalculateNormals(m); scene.MeshManipulator.SetVertexColors(m, new Color(80, 80, 80)); Material t = new Material(); t.Type = MaterialType.Reflection2Layer; t.Lighting = false; t.SetTexture(0, device.VideoDriver.GetTexture("TEXTURE-ref.jpg")); t.SetTexture(1, device.VideoDriver.GetTexture("TEXTURE-ref.jpg")); MeshSceneNode n = scene.AddMeshSceneNode(m, null, 7777); n.SetMaterial(0, t); n.Position = game.CenterOfTheBoard; SceneNodeAnimator a = scene.CreateRotationAnimator(new Vector3Df(0.07f, 0.01f, 0.05f)); n.AddAnimator(a); a.Drop(); // set up light light = scene.AddLightSceneNode(null, game.CenterOfTheBoard, new Colorf(1, 1, 1), 200); m = scene.AddVolumeLightMesh("lvol1", 32, 32, new Color(5, 5, 5)); scene.MeshManipulator.Scale(m, new Vector3Df(15, 30, 15)); n = scene.AddMeshSceneNode(m, light); n.Position = new Vector3Df(0, -10, 0); n.Rotation = new Vector3Df(180, 0, 0); n.SetMaterialType(MaterialType.TransparentAddColor); m = scene.AddVolumeLightMesh("lvol2", 32, 32, new Color(5, 5, 5)); scene.MeshManipulator.Scale(m, new Vector3Df(15, 30, 15)); n = scene.AddMeshSceneNode(m, light); n.Position = new Vector3Df(0, -10, 0); n.SetMaterialType(MaterialType.TransparentAddColor); // add gui hint text = gui.AddStaticText(TextStart, new Recti(10, 10, 200, 40)); text.OverrideColor = Color.SolidYellow; // main loop while (device.Run()) { driver.BeginScene(); scene.DrawAll(); gui.DrawAll(); if (optionFPS) { gui.BuiltInFont.Draw(driver.FPS + " FPS", driver.ScreenSize.Width - 50, 10, Color.SolidWhite); } driver.EndScene(); } device.Drop(); }
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(); }