public override void CheckKeyBoard() { base.CheckKeyBoard(); if (GameWindow.Keyboard[Key.F10] && coolDown == 0) { Bitmap bitmapScreenShot = Tools.GrabScreenshot(GameWindow); bitmapScreenShot.Save("ScreenShots\\screenshot.bmp"); coolDown = 20; } if (GameWindow.Keyboard[Key.Space] && coolDown == 0) { Shapes3D["pointSprites"].Position = new Vector3(0, 50, 0); coolDown = 20; } if (GameWindow.Keyboard[Key.F] && coolDown == 0) { Shapes3D["sphereEnvCubeMap"].Position = new Vector3(TargetPosition.X, 0.05f, TargetPosition.Y); coolDown = 20; } if (GameWindow.Keyboard[Key.C] && coolDown == 0) { File.WriteAllText("cmera.txt", "position: " + Camera.Position + "quaternion: " + Camera.Quaternion); coolDown = 20; } if (GameWindow.Keyboard[Key.F11] && coolDown == 0) { Audio.Play(2, Vector3.Zero, true); coolDown = 20; } if (GameWindow.Keyboard[Key.F12] && coolDown == 0) { MyGame.Debug = String.Empty; MyGame.Debug1 = String.Empty; coolDown = 5; } if (GameWindow.Keyboard[Key.F3] && coolDown == 0) { TextRender.Visible = !TextRender.Visible; coolDown = 10; } if (GameWindow.Keyboard[Key.F1] && coolDown == 0) { Vector3 v1 = new Vector3(Camera.CameraUVW.Row0); Vector3 v2 = new Vector3(Camera.CameraUVW.Row0.X, 0f, Camera.CameraUVW.Row0.Z); v2.Normalize(); float CameraUangle = Vector3.Dot(v2, v1); Vector3 axis = new Vector3(Camera.CameraUVW.Row2.X, Camera.CameraUVW.Row2.Y, Camera.CameraUVW.Row2.Z); float angle = (float)Math.Acos(Convert.ToDouble(CameraUangle)); if (Camera.CameraUVW.Row0.Y > 0) { Camera.Rotate(axis, angle); } else { Camera.Rotate(axis, -angle); } coolDown = 20; } if (GameWindow.Keyboard[Key.I] && (MyGame.TableXAngle < MathHelper. DegreesToRadians(MyGame.MaxTableAngle))) { MyGame.TableXAngle += MyGame.DeltaTableAngle; } if (GameWindow.Keyboard[Key.K] && (MyGame.TableXAngle > -MathHelper. DegreesToRadians(MyGame.MaxTableAngle))) { MyGame.TableXAngle -= MyGame.DeltaTableAngle; } if (GameWindow.Keyboard[Key.J] && (MyGame.TableZAngle < MathHelper. DegreesToRadians(MyGame.MaxTableAngle))) { MyGame.TableZAngle += MyGame.DeltaTableAngle; } if (GameWindow.Keyboard[Key.L] && (MyGame.TableZAngle > -MathHelper. DegreesToRadians(MyGame.MaxTableAngle))) { MyGame.TableZAngle -= MyGame.DeltaTableAngle; } if (GameWindow.Keyboard[Key.Q]) { Camera.TranslateLC(0, 0, 5f); } if (GameWindow.Keyboard[Key.A]) { Camera.TranslateLC(0, 0, -5f); } if (GameWindow.Keyboard[Key.X]) { Camera.Position = new Vector3(Camera.Position.X, -5f + Camera.Position.Y, Camera.Position.Z); } if (GameWindow.Keyboard[Key.LShift]) { Camera.Position = new Vector3(Camera.Position.X, 5f + Camera.Position.Y, Camera.Position.Z); } float speed = 2f; if (GameWindow.Keyboard[Key.Keypad8] && coolDown == 0) { Shapes3D["sphereEnvCubeMap"].Physic.Vuvw = new Vector3(Shapes3D["sphereEnvCubeMap"].Physic.Vuvw.X, Shapes3D["sphereEnvCubeMap"].Physic.Vuvw.Y, -speed); coolDown = 5; } if (GameWindow.Keyboard[Key.Keypad2] && coolDown == 0) { Shapes3D["sphereEnvCubeMap"].Physic.Vuvw = new Vector3(0, 0, speed); coolDown = 5; } if (GameWindow.Keyboard[Key.Keypad4] && coolDown == 0) { Shapes3D["sphereEnvCubeMap"].Physic.Vxyz = new Vector3(-speed, 0, 0); coolDown = 5; } if (GameWindow.Keyboard[Key.Keypad6] && coolDown == 0) { Shapes3D["sphereEnvCubeMap"].Physic.Vxyz = new Vector3(speed, 0, 0); coolDown = 5; } if (GameWindow.Keyboard[Key.Number6] && coolDown == 0) { ShadowMap.LightView.TranslateWC(-10, 0, 0); ShadowMap.UpdateView(); Shapes3D["sphereEnvCubeMap"].ShadowMatrix = ShadowMap.ShadowMatrix; coolDown = 30; } if (GameWindow.Keyboard[Key.Number7] && coolDown == 0) { ShadowMap.LightView.TranslateWC(10, 0, 0); ShadowMap.UpdateView(); Shapes3D["sphereEnvCubeMap"].ShadowMatrix = ShadowMap.ShadowMatrix; coolDown = 30; } if (GameWindow.Keyboard[Key.KeypadPlus] && coolDown == 0) { Vector4 tempV4 = new Vector4(SunLightPosition.X, SunLightPosition.Y, SunLightPosition.Z, 0); tempV4 = Vector4.Transform(tempV4, Matrix4.CreateRotationY(0.05f)); SunLightPosition = tempV4.Xyz; } if (GameWindow.Keyboard[Key.KeypadMinus] && coolDown == 0) { Vector4 tempV4 = new Vector4(SunLightPosition.X, SunLightPosition.Y, SunLightPosition.Z, 0); tempV4 = Vector4.Transform(tempV4, Matrix4.CreateRotationY(-0.05f)); SunLightPosition = tempV4.Xyz; } if (GameWindow.Keyboard[Key.KeypadMultiply] && coolDown == 0) { CubesHaveNormalMap = !CubesHaveNormalMap; coolDown = 10; } if (GameWindow.Keyboard[Key.KeypadDecimal] && coolDown == 0) { Shapes3D.Remove("sphereEnvCubeMap"); ToggleSmooth = !ToggleSmooth; Shape3D sphere1 = new Sphere3D(new Vector3(-45f, 1.5f, -45f), 1.5f, Color4.Gold, Textures["sphere_texture"], ToggleSmooth); sphere1.Physic.Mass = 10f; sphere1.Physic.Vxyz = Vector3.Zero; sphere1.ShadowMatrix = ShadowMap.ShadowMatrix; sphere1.TextureShadowMap = ShadowMap.DepthTexture; sphere1.Bounding.R = 1.5f; sphere1.Load(); Shapes3D.Add("sphereEnvCubeMap", sphere1); coolDown = 10; } if (GameWindow.Keyboard[Key.M] && coolDown == 0) { MyGame.MultiView = !MyGame.MultiView; if (MyGame.MultiView) { MyGame.Width = 800; MyGame.Height = (int)(MyGame.Width / aspectRatio); } else { MyGame.Width = GameWindow.Width; MyGame.Height = GameWindow.Height; } MyGame.ProjectionMatrix = Matrix4.CreatePerspectiveFieldOfView( MathHelper.PiOver4, MyGame.Width / (float)MyGame.Height, 0.5f, 1000f); //ShadowMap.ProjectionMatrixLightView = MyGame.ProjectionMatrix; ShadowMap.UpdateView(); foreach (var item in Shapes3D) { item.Value.ShadowMatrix = ShadowMap.ShadowMatrix; } coolDown = 30; } //if (Keyboard[Key.S]) Shapes3D["sphere"]. // VertexBuffer.SerializeBufer(@"Models\sphere.xml"); if (GameWindow.Keyboard[Key.T]) { Tools. GenerateModelFrom3DS(@"Models\sphere3D.x3d"); } }
public static Dictionary <string, Shape3D> LoadShapes(ShadowMap shadowMap, MyGameLevel gameLevel) { Dictionary <string, Shape3D> shapes3D = new Dictionary <string, Shape3D>(); //float deltaRot = MathHelper.PiOver6 / 20; shadowMapG = shadowMap; //textures current_texture = gameLevel.Textures["current_texture"]; int cube_texture = gameLevel.Textures["cube_texture"]; sphere_texture = gameLevel.Textures["sphere_texture"]; int sky_texture = gameLevel.Textures["sky_texture"]; bump_texture = gameLevel.Textures["bump_texture"]; int target_texture = gameLevel.Textures["target_texture"]; // create texture matrix Matrix4 ProjectionMatrixTex = Matrix4.CreateOrthographic(110, 110, -1, 1); Matrix4 ScaleBiasMatrix = new Matrix4(new Vector4(0.5f, 0.0f, 0.0f, 0.0f), new Vector4(0.0f, 0.5f, 0.0f, 0.0f), new Vector4(0.0f, 0.0f, 0.5f, 0.0f), new Vector4(0.5f, 0.5f, 0.5f, 1f)); Matrix4 texMatrix = ProjectionMatrixTex * ScaleBiasMatrix; Camera tex = new Camera(); tex.Position = new Vector3(0, -10, 0); tex.Rotate(new Vector3(tex.CameraUVW.Row0), MathHelper.PiOver2); tex.Update(); texMatrix = tex.View * texMatrix; texMatrixG = texMatrix; #region panels Shape3D basePanel = new Panel3D(new Vector3(0f, 0f, 0), 0f, 0f, 0f, Color4.Chocolate, current_texture); // initialize shaders string vs = File.ReadAllText("Shaders\\vShader_UV_Normal_panel.txt"); string fs = File.ReadAllText("Shaders\\fShader_UV_Normal_panel_base.txt"); Shader shaderBasePanel = new Shader(ref vs, ref fs, basePanel); basePanel.Shader = shaderBasePanel; basePanel.Scale(55); //basePanel.Bounding = new Bounding(basePanel, 100, 1, 100); basePanel.Physic.Mass = 100000000f; basePanel.RotateU(-MathHelper.PiOver2); //basePanel.Position = new Vector3(0f, -20f, 0f); basePanel.TextureShadowMap = shadowMap.DepthTexture; basePanel.ShadowMatrix = shadowMap.ShadowMatrix; basePanel.TextureBumpMap = bump_texture; basePanel.TexMatrix = texMatrix; basePanel.Collision = false; basePanel.Material.HasSpecular = false; basePanel.Load(); shapes3D.Add("basePanel", basePanel); /* * Shape3D leftPanel = new Panel3D(Vector3.Zero, 0f, 0f, 0f, Color4.Chocolate, current_texture); * leftPanel.Scale(2, 52, 0); * leftPanel.RotateZ(-MathHelper.PiOver2); * leftPanel.RotateY(MathHelper.PiOver2); * * leftPanel.Position = new Vector3(-52, 2, 0); * leftPanel.TextureShadowMap = shadowMap.DepthTexture; * leftPanel.TexMatrix = texMatrix; * leftPanel.Collision = false; * leftPanel.Load(); * shapes3D.Add("leftPanel", leftPanel); * * Shape3D rightPanel = new Panel3D(Vector3.Zero, 0f, 0f, 0f, Color4.Chocolate, current_texture); * rightPanel.Scale(2, 52, 0); * rightPanel.RotateZ(-MathHelper.PiOver2); * rightPanel.RotateY(-MathHelper.PiOver2); * * rightPanel.Position = new Vector3(52, 2, 0); * rightPanel.TextureShadowMap = shadowMap.DepthTexture; * rightPanel.TexMatrix = texMatrix; * rightPanel.Collision = false; * rightPanel.Load(); * shapes3D.Add("rightPanel", rightPanel); * * Shape3D topPanel = new Panel3D(Vector3.Zero, 0f, 0f, 0f, Color4.Chocolate, current_texture); * topPanel.Scale(52, 2, 0); * //topPanel.RotateZ(-MathHelper.PiOver2); * //topPanel.RotateY(-MathHelper.PiOver2); * * topPanel.Position = new Vector3(0, 2, -52); * topPanel.TextureShadowMap = shadowMap.DepthTexture; * topPanel.TexMatrix = texMatrix; * topPanel.Collision = false; * topPanel.Load(); * shapes3D.Add("topPanel", topPanel); * * Shape3D bottomPanel = new Panel3D(Vector3.Zero, 0f, 0f, 0f, Color4.Black); * bottomPanel.Scale(52, 2, 0); * //topPanel.RotateZ(-MathHelper.PiOver2); * //topPanel.RotateY(-MathHelper.PiOver2); * * bottomPanel.Position = new Vector3(0, 2, 52); * //bottomPanel.TextureShadowMap = shadowMap.DepthTexture; * bottomPanel.Collision = false; * bottomPanel.Load(); * shapes3D.Add("bottomPanel", bottomPanel); */ #endregion /* * Shape3D sphere1 = new Sphere3D(new Vector3(20f, 2f, 5f), 2, Color4.Gold, sphere_texture); * //sphere.Scale(10f); * sphere1.Physic.Mass = 10f; * sphere1.Physic.Vuvw = new Vector3(-0.05f, 0f, 0.0f); * //sphere1.Physic.AVuvw = new Vector3(0, 0, sphere1.Physic.Vuvw.X / 2); * sphere1.TextureShadowMap = shadowMap.DepthTexture; * sphere1.Load(); * shapes3D.Add("sphere1", sphere1); * * Shape3D sphere2 = new Sphere3D(new Vector3(10f, 2f, 5f), 2, Color4.Gold, sphere_texture); * //sphere.Scale(10f); * sphere2.Physic.Mass = 10f; * sphere2.Physic.Vuvw = new Vector3(0.05f, 0f, 0.0f); * sphere2.TextureShadowMap = shadowMap.DepthTexture; * sphere2.Load(); * shapes3D.Add("sphere2", sphere2); * * Shape3D sphere3 = new Sphere3D(new Vector3(0f, 2f, 0f), 2, Color4.Gold, sphere_texture); * //sphere3.Scale(3f); * sphere3.Physic.Mass = 1000000000f; * //sphere3.Bounding = new Bounding(sphere3, 20, 20, 20); * sphere3.Physic.Vuvw = new Vector3(0.0f, 0f, 0.0f); * sphere3.TextureShadowMap = shadowMap.DepthTexture; * sphere3.Load(); * shapes3D.Add("sphere3", sphere3); */ Shape3D target = new Panel3D(new Vector3(gameLevel.TargetPosition.X, 0.05f, gameLevel.TargetPosition.Y), 0f, 0f, 0f, Color4.Chocolate, target_texture); string vst = File.ReadAllText("Shaders\\vShader_UV_Normal_panel.txt"); string fst = File.ReadAllText("Shaders\\fShader_UV_Normal_panel_.txt"); Shader shaderTarget = new Shader(ref vst, ref fst, target); target.Shader = shaderTarget; target.Scale(3f); target.Bounding = new Bounding(target, 3f); target.Physic.Mass = 100000000f; target.RotateU(-MathHelper.PiOver3); target.TextureShadowMap = shadowMap.DepthTexture; target.ShadowMatrix = shadowMap.ShadowMatrix; //target.TextureBumpMap = bump_texture; //target.TexMatrix = texMatrix; target.Collision = true; target.IsShadowCaster = false; target.Load(); shapes3D.Add("target", target); string[] lines = File.ReadAllLines("levels\\" + gameLevel.Name + ".csv"); foreach (var item in lines) { string[] lineStrings = item.Split(';'); int xBlock = Convert.ToInt32(lineStrings[0]); int yBlock = Convert.ToInt32(lineStrings[1]); string blockName = lineStrings[2]; insertBlocks(xBlock, yBlock, blockName, shapes3D); } /* * Shape3D cube = new NRCGL.Shapes.Cube3D(new Vector3(-48f, 6f, 48f), Color4.AliceBlue, current_texture); * cube.Physic.Mass = 100; * cube.Physic.Vxyz = Vector3.Zero; * cube.Bounding = new Bounding(cube, 20, 2, 20); * cube.Scale(2, 6, 2); * cube.TextureShadowMap = shadowMap.DepthTexture; * cube.TexMatrix = texMatrix; * cube.Load(); * shapes3D.Add("cube", cube); */ Shape3D skyBox = new NRCGL.Shapes.SkyBox(new Vector3(-30f, 50f, 30f), Color4.AliceBlue, sky_texture); skyBox.Scale(500); skyBox.Collision = false; skyBox.Load(); shapes3D.Add("skyBox", skyBox); /* * Shape3D shpereEnvCubeMap = new Sphere3DEnvCubeMap(new Vector3(-45f, 1f, -45f), 1f); * shpereEnvCubeMap.Physic.Mass = 10f; * shpereEnvCubeMap.Physic.Vxyz = Vector3.Zero; * shpereEnvCubeMap.ShadowMatrix = shadowMap.ShadowMatrix; * shpereEnvCubeMap.Load(); * shapes3D.Add("sphereEnvCubeMap", shpereEnvCubeMap); */ Shape3D sphere1 = new Sphere3D(new Vector3(-45f, 1.5f, -45f), 1.5f, Color4.Gold, sphere_texture); sphere1.Physic.Mass = 10f; sphere1.Physic.Vxyz = Vector3.Zero; sphere1.ShadowMatrix = shadowMap.ShadowMatrix; sphere1.TextureShadowMap = shadowMap.DepthTexture; sphere1.Bounding.R = 1.5f; sphere1.Load(); shapes3D.Add("sphereEnvCubeMap", sphere1); //Shape3D sphere2 = new Sphere3D(new Vector3(-30f, 5f, -30f), 1.5f, new Color4(1f, 1f, 0.3f, 1f)); //string vs2 = File.ReadAllText("Shaders\\vShader_Color_Normal1.txt"); //string fs2 = File.ReadAllText("Shaders\\fShader_Color_Normal1.txt"); //Shader Shader2 = new Shader(ref vs, ref fs, sphere2); //sphere2.Shader = Shader2; //sphere2.Collision = false; //sphere2.IsShadowCaster = false; //sphere2.Physic.Mass = 10f; //sphere2.Physic.Vxyz = Vector3.Zero; //sphere2.ShadowMatrix = shadowMap.ShadowMatrix; //sphere2.TextureShadowMap = shadowMap.DepthTexture; //sphere2.Bounding.R = 1.5f; //sphere2.Load(); //shapes3D.Add("pointLight", sphere2); //Shape3D shpereEnvCubeMap = new Sphere3DEnvCubeMap(new Vector3(0f, 30f, 0f), 10f); //shpereEnvCubeMap.Collision = false; //shpereEnvCubeMap.IsShadowCaster = false; //shpereEnvCubeMap.Physic.Mass = 10f; //shpereEnvCubeMap.Physic.Vxyz = Vector3.Zero; //shpereEnvCubeMap.ShadowMatrix = shadowMap.ShadowMatrix; ////shpereEnvCubeMap.TextureShadowMap = shadowMap.DepthTexture; //shpereEnvCubeMap.Load(); //shapes3D.Add("sphereEnvM", shpereEnvCubeMap); //Shape3D torus = new Torus3D(new Vector3(0f, 40f, 0f), 10f, Color4.Green); //torus.Collision = false; //torus.IsShadowCaster = true; //torus.Physic.Mass = 10f; //torus.Physic.Vxyz = Vector3.Zero; //torus.ShadowMatrix = shadowMap.ShadowMatrix; //torus.Load(); //torus.VertexBuffer.DrawMode = OpenTK.Graphics.OpenGL4.BeginMode.Lines; //shapes3D.Add("pointSprites", torus); //Shape3D torus = new Torus3D(new Vector3(0f, 40f, 0f), 10f, Color4.Green); //torus.Collision = false; //torus.IsShadowCaster = true; //torus.Physic.Mass = 10f; //torus.Physic.Vxyz = Vector3.Zero; //torus.ShadowMatrix = shadowMap.ShadowMatrix; //torus.Load(); //torus.VertexBuffer.DrawMode = OpenTK.Graphics.OpenGL4.BeginMode.Lines; //shapes3D.Add("pointSprites", torus); // point sprites //Shape3D pointSprites = // new PointSprites("pointSprites", new Vector3(0, 40, 0), 0, // gameLevel.Textures["pointsprites_texture"]); //pointSprites.IsShadowCaster = false; //pointSprites.ShadowMatrix = shadowMap.ShadowMatrix; //pointSprites.Collision = false; //pointSprites.Load(); //shapes3D.Add("pointSprites", pointSprites); Shape3D torus = new Torus3D(new Vector3(0f, 40f, 0f), 10f, Color4.Green); torus.Collision = false; torus.IsShadowCaster = true; torus.Physic.Mass = 10f; torus.Physic.Vxyz = Vector3.Zero; torus.ShadowMatrix = shadowMap.ShadowMatrix; torus.Load(); torus.VertexBuffer.DrawMode = OpenTK.Graphics.OpenGL4.BeginMode.Lines; torus.LifeTime = new LifeTime(400); // actions torus.ShapeActions = new Queue <ShapeAction>(); torus.ShapeActions.Enqueue(new ShapeAction( new Action <Shape3D, LifeTime>( (shape, lifeTime) => { shape.RotateY(0.1f); shape.Scale(5 + Tween.Solve( Tween.Function.Cubic, Tween.Ease.InOut, 0f, 5f, lifeTime.Max, lifeTime.Counter)); }), new LifeTime(200))); torus.ShapeActions.Enqueue(new ShapeAction( new Action <Shape3D, LifeTime>( (shape, lifeTime) => { shape.RotateX(Tween.Solve( Tween.Function.Elastic, Tween.Ease.Out, 0f, 0.08f, lifeTime.Max, lifeTime.Counter)); shape.Scale(10 - Tween.Solve( Tween.Function.Quadratic, Tween.Ease.Out, 0f, 5f, lifeTime.Max, lifeTime.Counter)); }), new LifeTime(200))); torus.Name = "notTableTorus"; shapes3D.Add(torus.Name, torus); Shape3D pointSprites = new PointSprites("pointSprites", new Vector3(0, 50, 0), 0, gameLevel.Textures["pointsprites_texture"]); pointSprites.IsShadowCaster = false; pointSprites.ShadowMatrix = shadowMap.ShadowMatrix; pointSprites.Collision = false; pointSprites.IsVisible = false; pointSprites.Load(); shapes3D.Add("pointSprites", pointSprites); return(shapes3D); }