public override void Init() { VSync = false; SetWindowSize(1280, 720); // Start the application in demo mode? demoMode = true; #region MeshImports _Geo = new Geometry(); _Geo.LoadAsset("Assets/Cube.obj.model"); //_Geo.LoadAsset("Assets/Cube_quads.obj.model"); //_Geo.LoadAsset("Assets/Sphere.obj.model"); //_Geo.LoadAsset("Assets/Sphere_quads.obj.model"); //_Geo.LoadAsset("Assets/SharedCorners.obj.model"); //_Geo.LoadAsset("Assets/Cylinder.obj.model"); //_Geo.LoadAsset("Assets/Cylinder_quads.obj.model"); //_Geo.LoadAsset("Assets/SharedCorners_pro.obj.model"); //_Geo.LoadAsset("Assets/Teapot.obj.model"); #endregion MeshImports // Set the smoothing angle for the edge based vertex normal calculation // Feel free to test around. _Geo._SmoothingAngle = 89.0; // The shader colors here are not supposed to be changed. They don't have an effect. If you want to change the shaders // then please change the values in the ShaderChanger() method. These ones are just for declaration. #region Shaders #region TextureShader _msDiffuse = Shaders.GetDiffuseTextureShader(RC); _vLightShaderParam = _msDiffuse.GetShaderParam("texture1"); //ImageData imgData = RC.LoadImage("Assets/Cube_Mat_uv.jpg"); ImageData imgData = RC.LoadImage("Assets/world_map.jpg"); //ImageData imgData = RC.LoadImage("Assets/Teapot_Texture.jpg"); // Due to copyright reasons, this file will not be delivered with the project. //ImageData imgData = RC.LoadImage("Assets/Hellknight.jpg"); _tex = RC.CreateTexture(imgData); #endregion TextureShader #region ColorShader _spColor = Shaders.GetDiffuseColorShader(RC); _colorParam = _spColor.GetShaderParam("color"); RC.SetShader(_spColor); RC.SetShaderParam(_colorParam, new float4(0f, 0f, 0f, 1f)); #endregion ColorShader #region LightPos RC.SetLightActive(0, 0f); RC.SetLightAmbient(0, new float4(0.0f, 0.0f, 0.0f, 1.0f)); RC.SetLightDiffuse(0, new float4(1.0f, 1.0f, 1.0f, 1.0f)); RC.SetLightDirection(0, new float3(0.0f, -1.0f, 0.0f)); RC.SetLightActive(1, 0f); RC.SetLightAmbient(1, new float4(0.0f, 0.0f, 0.0f, 1.0f)); RC.SetLightDiffuse(1, new float4(0.5f, 0.5f, 0.5f, 1.0f)); RC.SetLightDirection(1, new float3(1.0f, 0.0f, 0.0f)); #endregion LightPos #endregion // Convert the loaded lfg model to a fusee mesh the first time. _lfgmesh = _Geo.ToMesh(); RC.ClearColor = new float4(0.2f, 0.2f, 0.2f, 1f); // For Benchmarking only. _ShaderType = 1; runDemoAnimation = true; _Geo._DoCalcVertexNormals = true; }
// Pull the users input public void PullUserInput() { #region Mouse if (Input.Instance.IsButton(MouseButtons.Left)) { _angleVelHorz = RotationSpeed * Input.Instance.GetAxis(InputAxis.MouseX); _angleVelVert = RotationSpeed * Input.Instance.GetAxis(InputAxis.MouseY); if (Transformations.RotateY(_angleVelHorz * _InvertMouseAxis, ref _Geo)) { if (Transformations.RotateX(_angleVelVert * _InvertMouseAxis, ref _Geo)) { _Geo._Changes = true; } } } // Scale the model up with the middle mouse button if (Input.Instance.IsButton(MouseButtons.Middle)) { if (Transformations.Scale(1.1f, 1.1f, 1.1f, ref _Geo)) { _Geo._Changes = true; } } // Reset the model with the right mouse button if (Input.Instance.IsButton(MouseButtons.Right)) { if (_Geo.ResetGeometryToDefault()) { _Geo._Changes = true; } } #endregion Mouse #region Scaling if (Input.Instance.IsKey(KeyCodes.Q)) { if (Transformations.Scale(1.1f, 1.1f, 1.1f, ref _Geo)) { _Geo._Changes = true; } } else if (Input.Instance.IsKey(KeyCodes.A)) { if (Transformations.Scale(0.9f, 0.9f, 0.9f, ref _Geo)) { _Geo._Changes = true; } } // Scale only x direction if (Input.Instance.IsKey(KeyCodes.W)) { if (Transformations.Scale(1.1f, 1.0f, 1.0f, ref _Geo)) { _Geo._Changes = true; } } else if (Input.Instance.IsKey(KeyCodes.S)) { if (Transformations.Scale(0.9f, 1.0f, 1.0f, ref _Geo)) { _Geo._Changes = true; } } // Scale only y direction if (Input.Instance.IsKey(KeyCodes.E)) { if (Transformations.Scale(1.0f, 1.1f, 1.0f, ref _Geo)) { _Geo._Changes = true; } } else if (Input.Instance.IsKey(KeyCodes.D)) { if (Transformations.Scale(1.0f, 0.9f, 1.0f, ref _Geo)) { _Geo._Changes = true; } } // Scale only z direction if (Input.Instance.IsKey(KeyCodes.R)) { if (Transformations.Scale(1.0f, 1.0f, 1.1f, ref _Geo)) { _Geo._Changes = true; } } else if (Input.Instance.IsKey(KeyCodes.F)) { if (Transformations.Scale(1.0f, 1.0f, 0.9f, ref _Geo)) { _Geo._Changes = true; } } #endregion Scaling #region Translation if (Input.Instance.IsKey(KeyCodes.U)) { if (Transformations.Translate(0f, (_MovementSpeed * (float)Time.Instance.DeltaTime) * 20, 0f, ref _Geo)) { _Geo._Changes = true; } } else if (Input.Instance.IsKey(KeyCodes.J)) { if (Transformations.Translate(0f, (-_MovementSpeed * (float)Time.Instance.DeltaTime) * 20, 0f, ref _Geo)) { _Geo._Changes = true; } } if (Input.Instance.IsKey(KeyCodes.H)) { if (Transformations.Translate(-(_MovementSpeed * (float)Time.Instance.DeltaTime) * 20, 0f, 0f, ref _Geo)) { _Geo._Changes = true; } } else if (Input.Instance.IsKey(KeyCodes.K)) { if (Transformations.Translate((_MovementSpeed * (float)Time.Instance.DeltaTime) * 20, 0f, 0f, ref _Geo)) { _Geo._Changes = true; } } if (Input.Instance.IsKey(KeyCodes.Z)) { if (Transformations.Translate(0f, 0f, -(_MovementSpeed * (float)Time.Instance.DeltaTime) * 20, ref _Geo)) { _Geo._Changes = true; } } else if (Input.Instance.IsKey(KeyCodes.I)) { if (Transformations.Translate(0f, 0f, (_MovementSpeed * (float)Time.Instance.DeltaTime) * 20, ref _Geo)) { _Geo._Changes = true; } } #endregion Translation #region Rotation if (Input.Instance.IsKey(KeyCodes.Up)) { if (Transformations.RotateX(1f * (float)Time.Instance.DeltaTime, ref _Geo)) { _Geo._Changes = true; } } else if (Input.Instance.IsKey(KeyCodes.Down)) { if (Transformations.RotateX(-1f * (float)Time.Instance.DeltaTime, ref _Geo)) { _Geo._Changes = true; } } if (Input.Instance.IsKey(KeyCodes.Left)) { if (Transformations.RotateY(1f * (float)Time.Instance.DeltaTime, ref _Geo)) { _Geo._Changes = true; } } else if (Input.Instance.IsKey(KeyCodes.Right)) { if (Transformations.RotateY(-1f * (float)Time.Instance.DeltaTime, ref _Geo)) { _Geo._Changes = true; } } if (Input.Instance.IsKey(KeyCodes.O)) { if (Transformations.RotateZ(1f * (float)Time.Instance.DeltaTime, ref _Geo)) { _Geo._Changes = true; } } else if (Input.Instance.IsKey(KeyCodes.P)) { if (Transformations.RotateZ(-1f * (float)Time.Instance.DeltaTime, ref _Geo)) { _Geo._Changes = true; } } #endregion Rotation #region ActivateVertexNormals if (Input.Instance.IsKeyDown(KeyCodes.N)) { _Geo._DoCalcVertexNormals = true; } if (Input.Instance.IsKeyDown(KeyCodes.M)) { _Geo._DoCalcVertexNormals = false; } #endregion ActivateVertexNormals if (Input.Instance.IsKeyDown(KeyCodes.T)) { if (_Geo.ResetGeometryToDefault()) { _Geo._Changes = true; } } if (_Geo._Changes) { _lfgmesh = _Geo.ToMesh(); _Geo._Changes = false; } #region Shader Render Settings and demo if (Input.Instance.IsKeyDown(KeyCodes.F1) && Input.Instance.IsKey(KeyCodes.LControl)) { _ShaderChange = true; _ShaderType = 0; } else if (Input.Instance.IsKeyDown(KeyCodes.F2) && Input.Instance.IsKey(KeyCodes.LControl)) { _ShaderChange = true; _ShaderType = 1; } else if (Input.Instance.IsKeyDown(KeyCodes.F3) && Input.Instance.IsKey(KeyCodes.LControl)) { runDemoAnimation = !runDemoAnimation; } #endregion float4x4 mtxCam = float4x4.LookAt(0, 500, 500, 0, 0, 0, 0, 1, 0); RC.ModelView = float4x4.CreateTranslation(0, 0, 0) * mtxCam; }
public override void Init() { VSync = false; // Start the application in demo mode? demoMode = true; #region MeshImports _Geo = new Geometry(); //_Geo.LoadAsset("Assets/Cube.obj.model"); //_Geo.LoadAsset("Assets/Cube_quads.obj.model"); //_Geo.LoadAsset("Assets/Sphere.obj.model"); //_Geo.LoadAsset("Assets/Sphere_quads.obj.model"); //_Geo.LoadAsset("Assets/SharedCorners.obj.model"); //_Geo.LoadAsset("Assets/Cylinder.obj.model"); //_Geo.LoadAsset("Assets/Cylinder_quads.obj.model"); //_Geo.LoadAsset("Assets/SharedCorners_pro.obj.model"); _Geo.LoadAsset("Assets/Teapot.obj.model"); // Due to copyright reasons, this file will not be delivered with the project. //_Geo.LoadAsset("Assets/Hellknight.obj.model"); #endregion MeshImports // Set the smoothing angle for the edge based vertex normal calculation // Feel free to test around. _Geo._SmoothingAngle = 89.0; // The shader colors here are not supposed to be changed. They don't have an effect. If you want to change the shaders // then please change the values in the ShaderChanger() method. These ones are just for declaration. #region Shaders #region TextureShader _msDiffuse = MoreShaders.GetDiffuseTextureShader(RC); _vLightShaderParam = _msDiffuse.GetShaderParam("texture1"); //ImageData imgData = RC.LoadImage("Assets/Cube_Mat_uv.jpg"); ImageData imgData = RC.LoadImage("Assets/world_map.jpg"); //ImageData imgData = RC.LoadImage("Assets/Teapot_Texture.jpg"); // Due to copyright reasons, this file will not be delivered with the project. //ImageData imgData = RC.LoadImage("Assets/Hellknight.jpg"); _tex = RC.CreateTexture(imgData); #endregion TextureShader #region ColorShader _spColor = MoreShaders.GetDiffuseColorShader(RC); _colorParam = _spColor.GetShaderParam("color"); RC.SetShader(_spColor); RC.SetShaderParam(_colorParam, new float4(0f, 0f, 0f, 1)); #endregion ColorShader #region LightPos RC.SetLightActive(0, 0f); RC.SetLightAmbient(0, new float4(0.0f, 0.0f, 0.0f, 1.0f)); RC.SetLightDiffuse(0, new float4(1.0f, 1.0f, 1.0f, 1.0f)); RC.SetLightDirection(0, new float3(0.0f, -1.0f, 0.0f)); RC.SetLightActive(1, 0f); RC.SetLightAmbient(1, new float4(0.0f, 0.0f, 0.0f, 1.0f)); RC.SetLightDiffuse(1, new float4(0.5f, 0.5f, 0.5f, 1.0f)); RC.SetLightDirection(1, new float3(1.0f, 0.0f, 0.0f)); #endregion LightPos #endregion // Convert the loaded lfg model to a fusee mesh the first time. _lfgmesh = _Geo.ToMesh(); RC.ClearColor = new float4(0.2f, 0.2f, 0.2f, 1f); // TODO: For Benchmarking only. _ShaderType = 1; runDemoAnimation = true; _Geo._DoCalcVertexNormals = true; }