44using System . Numerics ;
55using System . Runtime . CompilerServices ;
66using OpenGL_VR_Demo . OpenXR ;
7+ using Silk . NET . Maths ;
78using Silk . NET . OpenGL ;
89using Silk . NET . OpenXR ;
910using Shader = Silk . NET . OpenGL . Shader ;
@@ -19,6 +20,7 @@ public class Game : OpenGLXRGame
1920 private static VertexArrayObject < float , uint > VaoCube ;
2021 private static Shader LightingShader ;
2122 private static Shader LampShader ;
23+ private static Vector3 CubePosition = new ( 0.2f , 0.0f , 1.0f ) ;
2224 private static Vector3 LampPosition = new ( 1.2f , 1.0f , 2.0f ) ;
2325
2426 private static Camera Camera ;
@@ -84,7 +86,7 @@ public Game(bool forceNoDebug = false, bool useMinimumVersion = false)
8486
8587 protected override void Load ( )
8688 {
87- Gl = Renderer . Gl ;
89+ Gl = Renderer ! . Gl ;
8890
8991 Ebo = new ( Gl , Indices , BufferTargetARB . ElementArrayBuffer ) ;
9092 Vbo = new ( Gl , Vertices , BufferTargetARB . ArrayBuffer ) ;
@@ -99,7 +101,7 @@ protected override void Load()
99101 LampShader = new ( Gl , "shader.vert" , "shader.frag" ) ;
100102
101103 //Start a camera at position 3 on the Z axis, looking at position -1 on the Z axis
102- Camera = new ( Vector3 . UnitZ * 6 , Vector3 . UnitZ * - 1 , Vector3 . UnitY , ( float ) EyeWidth / EyeHeight ) ;
104+ Camera = new ( Vector3 . UnitZ * 6 * 6 , Renderer ) ;
103105 }
104106
105107 protected override void Update ( double delta )
@@ -110,26 +112,29 @@ protected override void Update(double delta)
110112
111113 protected override void Render ( int eye , double delta )
112114 {
113- var position = Unsafe . As < Vector3f , Vector3 > ( ref Renderer . ViewStates [ 0 ] . Pose . Position ) ;
114- var orientation = Unsafe . As < Quaternionf , Quaternion > ( ref Renderer . ViewStates [ 0 ] . Pose . Orientation ) ;
115- Camera . ModifyDirection ( orientation ) ;
116-
117115 Gl . Enable ( EnableCap . DepthTest ) ;
118116 Gl . Clear ( ( uint ) ( ClearBufferMask . ColorBufferBit | ClearBufferMask . DepthBufferBit ) ) ;
119117
120118 VaoCube . Bind ( ) ;
121119 LightingShader . Use ( ) ;
120+
121+ // Define the matrix for our cube
122+ var cubeMatrix = Matrix4x4 . Identity ;
123+ cubeMatrix *= Matrix4x4 . CreateTranslation ( CubePosition ) ;
122124
123- //Slightly rotate the cube to give it an angled face to look at
124- LightingShader . SetUniform ( "uModel" , Matrix4x4 . CreateRotationY ( MathHelper . DegreesToRadians ( 25f ) ) ) ;
125- LightingShader . SetUniform ( "uView" , Renderer . Views [ eye ] ) ;
126- LightingShader . SetUniform ( "uProjection" , Renderer . Projections [ eye ] ) ;
125+ // Slightly rotate the cube to give it an angled face to look at
126+ cubeMatrix *= Matrix4x4 . CreateRotationY ( Scalar . DegreesToRadians ( 25f ) ) ;
127+
128+ //LightingShader.SetUniform("uModel", Matrix4x4.CreateRotationY(MathHelper.DegreesToRadians(25f)));
129+ LightingShader . SetUniform ( "uModel" , cubeMatrix ) ;
130+ LightingShader . SetUniform ( "uView" , Camera . GetViewMatrix ( eye ) ) ;
131+ LightingShader . SetUniform ( "uProjection" , Camera . GetProjectionMatrix ( eye ) ) ;
127132 LightingShader . SetUniform ( "objectColor" , new Vector3 ( 1.0f , 0.5f , 0.31f ) ) ;
128133 LightingShader . SetUniform ( "lightColor" , Vector3 . One ) ;
129134 LightingShader . SetUniform ( "lightPos" , LampPosition ) ;
130135 LightingShader . SetUniform ( "viewPos" , Camera . Position ) ;
131136
132- //We're drawing with just vertices and no indicies, and it takes 36 verticies to have a six-sided textured cube
137+ // We're drawing with just vertices and no indicies, and it takes 36 verticies to have a six-sided textured cube
133138 Gl . DrawArrays ( PrimitiveType . Triangles , 0 , 36 ) ;
134139
135140 LampShader . Use ( ) ;
@@ -140,8 +145,8 @@ protected override void Render(int eye, double delta)
140145 lampMatrix *= Matrix4x4 . CreateTranslation ( LampPosition ) ;
141146
142147 LampShader . SetUniform ( "uModel" , lampMatrix ) ;
143- LampShader . SetUniform ( "uView" , Renderer . Views [ eye ] ) ;
144- LampShader . SetUniform ( "uProjection" , Renderer . Projections [ eye ] ) ;
148+ LampShader . SetUniform ( "uView" , Camera . GetViewMatrix ( eye ) ) ;
149+ LampShader . SetUniform ( "uProjection" , Camera . GetProjectionMatrix ( eye ) ) ;
145150
146151 Gl . DrawArrays ( PrimitiveType . Triangles , 0 , 36 ) ;
147152 }
0 commit comments