Advertisement
Chronos_Ouroboros

Untitled

Jan 11th, 2018
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.75 KB | None | 0 0
  1.             shader.Use ();
  2.            
  3.             Vector3 cameraPos = localCamera.Position.ToGLVec3 ();
  4.  
  5.             float yaw = MathHelper.DegreesToRadians ((float) localCamera.Angle), pitch = MathHelper.DegreesToRadians (MathHelper.Clamp ((float) localCamera.Pitch, -89.9f, 89.9f));
  6.             Matrix4 cameraFrontMatrix = Matrix4.Identity;
  7.             cameraFrontMatrix *= Matrix4.CreateRotationZ (pitch);
  8.             cameraFrontMatrix *= Matrix4.CreateRotationY (yaw);
  9.  
  10.             Vector3 cameraFront = Vector3.Transform (new Vector3 (1.0f, 0.0f, 0.0f), cameraFrontMatrix).Normalized ();
  11.             Vector3 cameraUp = new Vector3 (0.0f, 1.0f, 0.0f);
  12.             Matrix4 view = Matrix4.LookAt (cameraPos, cameraPos + cameraFront, cameraUp);
  13.  
  14.             GL.ActiveTexture (TextureUnit.Texture0);
  15.             tex.Bind ();
  16.            
  17.             Matrix4 model;
  18.  
  19.             shader.Use ();
  20.             shader.SetMatrix ("view", view, false);
  21.             shader.SetMatrix ("projection", projectionMatrix, false);
  22.             shader.SetVector3 ("viewPos", cameraPos);
  23.  
  24.             shader.SetInt ("matDiffuse", 0);
  25.             shader.SetInt ("matSpecular", 1);
  26.             shader.SetFloat ("material.shininess", 32.0f);
  27.  
  28.             shader.SetVector3 ("light.position", cameraPos);
  29.             shader.SetVector3 ("light.direction", cameraFront.Normalized ());
  30.             shader.SetFloat ("light.cutOff", (float) Math.Cos (MathHelper.DegreesToRadians (12.5)));
  31.             shader.SetFloat ("light.outerCutOff", (float) Math.Cos (MathHelper.DegreesToRadians (17.5)));
  32.  
  33.             shader.SetVector3 ("light.ambient", 0.2f, 0.2f, 0.2f);
  34.             shader.SetVector3 ("light.diffuse", 0.5f, 0.5f, 0.5f);
  35.             shader.SetVector3 ("light.specular", 1.0f, 1.0f, 1.0f);
  36.  
  37.             shader.SetFloat ("light.constant", 1.0f);
  38.             shader.SetFloat ("light.linear", 0.0014f);
  39.             shader.SetFloat ("light.quadratic", 0.000007f);
  40.  
  41.             GL.ActiveTexture (TextureUnit.Texture0);
  42.             tex.Bind ();
  43.             GL.ActiveTexture (TextureUnit.Texture1);
  44.             specTex.Bind ();
  45.             GL.BindVertexArray (VAO);
  46.  
  47.             var axis = new Vector3 (1.0f, 0.3f, 0.5f);
  48.             for (int i = 0; i < 10; i++) {
  49.                 model = Matrix4.Identity;
  50.                 model *= Matrix4.CreateTranslation (cubePositions [i]);
  51.                 model *= Matrix4.CreateScale (8.0f);
  52.                 float angle = 20.0f * i;
  53. #pragma warning disable CS0618 // Type or member is obsolete
  54.                 model *= Matrix4.Rotate (axis, angle);
  55. #pragma warning restore CS0618 // Type or member is obsolete
  56.                 shader.SetMatrix ("model", model, false);
  57.  
  58.                 GL.DrawArrays (PrimitiveType.Triangles, 0, 36);
  59.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement