Skip to content

Commit 60e9668

Browse files
committed
"Complete" versions of tutorial 9
No reason to not have these available by now
1 parent 16e3891 commit 60e9668

File tree

103 files changed

+28364
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+28364
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.24720.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTKTutorial9-1", "OpenTKTutorial9-1\OpenTKTutorial9-1.csproj", "{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{ACBF192E-C0F1-4B53-958F-915EDD01BA71}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|x64 = Debug|x64
13+
Debug|x86 = Debug|x86
14+
Release|x64 = Release|x64
15+
Release|x86 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}.Debug|x64.ActiveCfg = Debug|x64
19+
{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}.Debug|x64.Build.0 = Debug|x64
20+
{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}.Debug|x86.ActiveCfg = Debug|x86
21+
{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}.Debug|x86.Build.0 = Debug|x86
22+
{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}.Release|x64.ActiveCfg = Release|x64
23+
{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}.Release|x64.Build.0 = Release|x64
24+
{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}.Release|x86.ActiveCfg = Release|x86
25+
{CE5CD75D-8626-4CD8-83FC-B7A4868DAEC0}.Release|x86.Build.0 = Release|x86
26+
EndGlobalSection
27+
GlobalSection(SolutionProperties) = preSolution
28+
HideSolutionNode = FALSE
29+
EndGlobalSection
30+
EndGlobal
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using OpenTK;
2+
using System;
3+
4+
namespace OpenTKTutorial9
5+
{
6+
class Camera
7+
{
8+
public Vector3 Position = Vector3.Zero;
9+
public Vector3 Orientation = new Vector3((float)Math.PI, 0f, 0f);
10+
public float MoveSpeed = 0.2f;
11+
public float MouseSensitivity = 0.01f;
12+
13+
/// <summary>
14+
/// Create a view matrix for this Camera
15+
/// </summary>
16+
/// <returns>A view matrix to look in the camera's direction</returns>
17+
public Matrix4 GetViewMatrix()
18+
{
19+
Vector3 lookat = new Vector3();
20+
21+
lookat.X = (float)(Math.Sin((float)Orientation.X) * Math.Cos((float)Orientation.Y));
22+
lookat.Y = (float)Math.Sin((float)Orientation.Y);
23+
lookat.Z = (float)(Math.Cos((float)Orientation.X) * Math.Cos((float)Orientation.Y));
24+
25+
return Matrix4.LookAt(Position, Position + lookat, Vector3.UnitY);
26+
}
27+
28+
/// <summary>
29+
/// Offset the position of the camera in coordinates relative to its current orientation
30+
/// </summary>
31+
/// <param name="x">Movement along the camera ground (left/right)</param>
32+
/// <param name="y">Movement along the camera axis (forward)</param>
33+
/// <param name="z">Height to move</param>
34+
public void Move(float x, float y, float z)
35+
{
36+
Vector3 offset = new Vector3();
37+
Vector3 forward = new Vector3((float)Math.Sin((float)Orientation.X), 0, (float)Math.Cos((float)Orientation.X));
38+
Vector3 right = new Vector3(-forward.Z, 0, forward.X);
39+
40+
offset += x * right;
41+
offset += y * forward;
42+
offset.Y += z;
43+
44+
offset.NormalizeFast();
45+
offset = Vector3.Multiply(offset, MoveSpeed);
46+
47+
Position += offset;
48+
}
49+
50+
/// <summary>
51+
/// Adds rotation from mouse movement to camera orientation
52+
/// </summary>
53+
/// <param name="x"></param>
54+
/// <param name="y"></param>
55+
public void AddRotation(float x, float y)
56+
{
57+
x = x * MouseSensitivity;
58+
y = y * MouseSensitivity;
59+
60+
Orientation.X = (Orientation.X + x) % ((float)Math.PI * 2.0f);
61+
Orientation.Y = Math.Max(Math.Min(Orientation.Y + y, (float)Math.PI / 2.0f - 0.1f), (float)-Math.PI / 2.0f + 0.1f);
62+
}
63+
}
64+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using OpenTK;
2+
3+
namespace OpenTKTutorial9
4+
{
5+
/// <summary>
6+
/// A rectangular prism with square sides (seriously, you know what a cube is)
7+
/// </summary>
8+
class Cube : Volume
9+
{
10+
public Cube()
11+
{
12+
VertCount = 8;
13+
IndiceCount = 36;
14+
ColorDataCount = 8;
15+
}
16+
17+
public override Vector3[] GetVerts()
18+
{
19+
return new Vector3[] {new Vector3(-0.5f, -0.5f, -0.5f),
20+
new Vector3(0.5f, -0.5f, -0.5f),
21+
new Vector3(0.5f, 0.5f, -0.5f),
22+
new Vector3(-0.5f, 0.5f, -0.5f),
23+
new Vector3(-0.5f, -0.5f, 0.5f),
24+
new Vector3(0.5f, -0.5f, 0.5f),
25+
new Vector3(0.5f, 0.5f, 0.5f),
26+
new Vector3(-0.5f, 0.5f, 0.5f),
27+
};
28+
}
29+
30+
public override int[] GetIndices(int offset = 0)
31+
{
32+
int[] inds = new int[] {
33+
//left
34+
0, 2, 1,
35+
0, 3, 2,
36+
//back
37+
1, 2, 6,
38+
6, 5, 1,
39+
//right
40+
4, 5, 6,
41+
6, 7, 4,
42+
//top
43+
2, 3, 6,
44+
6, 3, 7,
45+
//front
46+
0, 7, 3,
47+
0, 4, 7,
48+
//bottom
49+
0, 1, 5,
50+
0, 5, 4
51+
};
52+
53+
if (offset != 0)
54+
{
55+
for (int i = 0; i < inds.Length; i++)
56+
{
57+
inds[i] += offset;
58+
}
59+
}
60+
61+
return inds;
62+
}
63+
64+
public override Vector3[] GetColorData()
65+
{
66+
return new Vector3[] {
67+
new Vector3(1f, 0f, 0f),
68+
new Vector3( 0f, 0f, 1f),
69+
new Vector3( 0f, 1f, 0f),
70+
new Vector3( 1f, 0f, 0f),
71+
new Vector3( 0f, 0f, 1f),
72+
new Vector3( 0f, 1f, 0f),
73+
new Vector3( 1f, 0f, 0f),
74+
new Vector3( 0f, 0f, 1f)
75+
};
76+
}
77+
78+
public override void CalculateModelMatrix()
79+
{
80+
ModelMatrix = Matrix4.Scale(Scale) * Matrix4.CreateRotationX(Rotation.X) * Matrix4.CreateRotationY(Rotation.Y) * Matrix4.CreateRotationZ(Rotation.Z) * Matrix4.CreateTranslation(Position);
81+
}
82+
83+
public override Vector2[] GetTextureCoords()
84+
{
85+
return new Vector2[]{};
86+
}
87+
}
88+
}

0 commit comments

Comments
 (0)