|
| 1 | +using System; |
| 2 | +using OpenTK; |
| 3 | + |
| 4 | +namespace OpenTK_RTExample |
| 5 | +{ |
| 6 | + class Cube : Volume |
| 7 | + { |
| 8 | + public Cube() |
| 9 | + { |
| 10 | + VertCount = 8; |
| 11 | + IndiceCount = 36; |
| 12 | + ColorDataCount = 8; |
| 13 | + } |
| 14 | + |
| 15 | + public override Vector3[] GetVerts() |
| 16 | + { |
| 17 | + return new Vector3[] {new Vector3(-0.5f, -0.5f, -0.5f), |
| 18 | + new Vector3(0.5f, -0.5f, -0.5f), |
| 19 | + 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 | + }; |
| 26 | + } |
| 27 | + |
| 28 | + public override int[] GetIndices(int offset = 0) |
| 29 | + { |
| 30 | + int[] inds = new int[] { |
| 31 | + //left |
| 32 | + 0, 2, 1, |
| 33 | + 0, 3, 2, |
| 34 | + //back |
| 35 | + 1, 2, 6, |
| 36 | + 6, 5, 1, |
| 37 | + //right |
| 38 | + 4, 5, 6, |
| 39 | + 6, 7, 4, |
| 40 | + //top |
| 41 | + 2, 3, 6, |
| 42 | + 6, 3, 7, |
| 43 | + //front |
| 44 | + 0, 7, 3, |
| 45 | + 0, 4, 7, |
| 46 | + //bottom |
| 47 | + 0, 1, 5, |
| 48 | + 0, 5, 4 |
| 49 | + }; |
| 50 | + |
| 51 | + if (offset != 0) |
| 52 | + { |
| 53 | + for (int i = 0; i < inds.Length; i++) |
| 54 | + { |
| 55 | + inds[i] += offset; |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + return inds; |
| 60 | + } |
| 61 | + |
| 62 | + public override Vector3[] GetColorData() |
| 63 | + { |
| 64 | + Random r = new Random(42); |
| 65 | + |
| 66 | + Vector3[] colors = new Vector3[VertCount]; |
| 67 | + |
| 68 | + for (int i = 0; i < colors.Length; i++) |
| 69 | + { |
| 70 | + colors[i] = new Vector3((float)r.NextDouble(), (float)r.NextDouble(), (float)r.NextDouble()); |
| 71 | + } |
| 72 | + |
| 73 | + return colors; |
| 74 | + } |
| 75 | + |
| 76 | + public override void CalculateModelMatrix() |
| 77 | + { |
| 78 | + ModelMatrix = Matrix4.CreateScale(Scale) * Matrix4.CreateRotationX(Rotation.X) * Matrix4.CreateRotationY(Rotation.Y) * Matrix4.CreateRotationZ(Rotation.Z) * Matrix4.CreateTranslation(Position); |
| 79 | + } |
| 80 | + |
| 81 | + public override Vector2[] GetTextureCoords() |
| 82 | + { |
| 83 | + return new Vector2[] { }; |
| 84 | + } |
| 85 | + } |
| 86 | +} |
0 commit comments