Compare commits
11 Commits
Author | SHA1 | Date |
---|---|---|
Milk.H | 8c75d1ee43 | |
Milk.H | 3dcc3bd3e7 | |
Milk.H | c88442072c | |
Milk.H | c17d5f8ce5 | |
Milk.H | f5253f16e8 | |
Milk.H | 7eb4ece49f | |
Milk.H | df9c5f387f | |
Milk.H | 9161af2b83 | |
Milk.H | 37b38694c5 | |
Milk.H | 397a86043a | |
Milk.H | 83d940b25b |
|
@ -15,3 +15,4 @@ sdl2 = "0.34.5"
|
|||
imgui = "0.10.0"
|
||||
imgui-glow-renderer = {path = "./imgui_glow_renderer"}
|
||||
imgui-sdl2-support = {path = "./imgui_sdl2_support"}
|
||||
mint = "0.5.9"
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
# Blender MTL File: 'Car.blend'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl Wheel_Mat
|
||||
Ns 225.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
||||
map_Kd Wheel_D.png
|
|
@ -0,0 +1,320 @@
|
|||
# Blender v3.0.1 OBJ File: 'Car.blend'
|
||||
# www.blender.org
|
||||
mtllib wheel.mtl
|
||||
o Wheel.FL_Circle.006
|
||||
v 0.087493 -0.000001 -0.267421
|
||||
v 0.087493 0.102337 -0.247065
|
||||
v 0.087493 0.189095 -0.189095
|
||||
v 0.087493 0.247064 -0.102337
|
||||
v 0.087493 0.267421 0.000001
|
||||
v 0.087493 0.247064 0.102338
|
||||
v 0.120491 0.000032 -0.000016
|
||||
v 0.087493 0.189095 0.189096
|
||||
v 0.087493 0.102337 0.247066
|
||||
v 0.087493 -0.000001 0.267422
|
||||
v 0.087493 -0.102339 0.247066
|
||||
v 0.087493 -0.189097 0.189096
|
||||
v 0.087493 -0.247066 0.102338
|
||||
v 0.087493 -0.267423 0.000000
|
||||
v 0.087493 -0.247066 -0.102337
|
||||
v 0.087493 -0.189097 -0.189095
|
||||
v 0.087493 -0.102339 -0.247065
|
||||
v 0.120490 0.089462 -0.215982
|
||||
v 0.120490 -0.000001 -0.233777
|
||||
v 0.120490 0.165305 -0.165305
|
||||
v 0.120490 0.215981 -0.089462
|
||||
v 0.120490 0.233777 0.000001
|
||||
v 0.120490 0.215981 0.089463
|
||||
v 0.120490 0.165305 0.165306
|
||||
v 0.120490 0.089462 0.215983
|
||||
v 0.120490 -0.000001 0.233778
|
||||
v 0.120490 -0.089464 0.215983
|
||||
v 0.120490 -0.165307 0.165306
|
||||
v 0.120490 -0.215983 0.089463
|
||||
v 0.120490 -0.233779 0.000000
|
||||
v 0.120490 -0.215983 -0.089462
|
||||
v 0.120490 -0.165307 -0.165305
|
||||
v 0.120490 -0.089464 -0.215982
|
||||
v -0.087493 -0.000001 -0.267421
|
||||
v -0.087493 0.102337 -0.247065
|
||||
v -0.087493 0.189095 -0.189095
|
||||
v -0.087493 0.247064 -0.102337
|
||||
v -0.087493 0.267421 0.000001
|
||||
v -0.087493 0.247064 0.102338
|
||||
v -0.120491 0.000032 -0.000016
|
||||
v -0.087493 0.189095 0.189096
|
||||
v -0.087493 0.102337 0.247066
|
||||
v -0.087493 -0.000001 0.267422
|
||||
v -0.087493 -0.102339 0.247066
|
||||
v -0.087493 -0.189097 0.189096
|
||||
v -0.087493 -0.247066 0.102338
|
||||
v -0.087493 -0.267423 0.000000
|
||||
v -0.087493 -0.247066 -0.102337
|
||||
v -0.087493 -0.189097 -0.189095
|
||||
v -0.087493 -0.102339 -0.247065
|
||||
v -0.120490 0.089462 -0.215982
|
||||
v -0.120490 -0.000001 -0.233777
|
||||
v -0.120490 0.165305 -0.165305
|
||||
v -0.120490 0.215981 -0.089462
|
||||
v -0.120490 0.233777 0.000001
|
||||
v -0.120490 0.215981 0.089463
|
||||
v -0.120490 0.165305 0.165306
|
||||
v -0.120490 0.089462 0.215983
|
||||
v -0.120490 -0.000001 0.233778
|
||||
v -0.120490 -0.089464 0.215983
|
||||
v -0.120490 -0.165307 0.165306
|
||||
v -0.120490 -0.215983 0.089463
|
||||
v -0.120490 -0.233779 0.000000
|
||||
v -0.120490 -0.215983 -0.089462
|
||||
v -0.120490 -0.165307 -0.165305
|
||||
v -0.120490 -0.089464 -0.215982
|
||||
vt 0.947129 0.746039
|
||||
vt 0.741723 0.746039
|
||||
vt 0.741723 0.623557
|
||||
vt 0.947129 0.623557
|
||||
vt 0.947129 0.624268
|
||||
vt 0.741723 0.624268
|
||||
vt 0.741723 0.501786
|
||||
vt 0.947129 0.501786
|
||||
vt 0.947129 0.746750
|
||||
vt 0.741723 0.746750
|
||||
vt 0.741723 0.501075
|
||||
vt 0.947129 0.501075
|
||||
vt 0.741723 0.379304
|
||||
vt 0.947129 0.379304
|
||||
vt 0.741723 0.378593
|
||||
vt 0.947129 0.378593
|
||||
vt 0.741723 0.256823
|
||||
vt 0.947129 0.256822
|
||||
vt 0.741723 0.256111
|
||||
vt 0.947129 0.256111
|
||||
vt 0.741723 0.134341
|
||||
vt 0.947129 0.134341
|
||||
vt 0.741724 0.133629
|
||||
vt 0.947129 0.133630
|
||||
vt 0.741723 0.011859
|
||||
vt 0.947129 0.011859
|
||||
vt 0.741724 0.011147
|
||||
vt 0.947129 0.011148
|
||||
vt 0.947129 0.991002
|
||||
vt 0.741723 0.991002
|
||||
vt 0.741723 0.868520
|
||||
vt 0.947129 0.868520
|
||||
vt 0.947129 0.991714
|
||||
vt 0.741724 0.991714
|
||||
vt 0.741724 0.869232
|
||||
vt 0.947129 0.869232
|
||||
vt 0.633313 0.736984
|
||||
vt 0.655743 0.624222
|
||||
vt 0.698148 0.624222
|
||||
vt 0.672491 0.753212
|
||||
vt 0.569439 0.832578
|
||||
vt 0.599424 0.862564
|
||||
vt 0.473844 0.896453
|
||||
vt 0.490072 0.935631
|
||||
vt 0.361082 0.918882
|
||||
vt 0.361082 0.961288
|
||||
vt 0.248320 0.896452
|
||||
vt 0.232092 0.935631
|
||||
vt 0.152726 0.832578
|
||||
vt 0.122740 0.862564
|
||||
vt 0.088851 0.736983
|
||||
vt 0.049673 0.753212
|
||||
vt 0.066422 0.624222
|
||||
vt 0.024016 0.624222
|
||||
vt 0.088851 0.511460
|
||||
vt 0.049673 0.495232
|
||||
vt 0.152726 0.415866
|
||||
vt 0.122740 0.385880
|
||||
vt 0.248321 0.351991
|
||||
vt 0.232092 0.312813
|
||||
vt 0.361082 0.329561
|
||||
vt 0.361082 0.287155
|
||||
vt 0.473844 0.351991
|
||||
vt 0.490072 0.312813
|
||||
vt 0.569439 0.415866
|
||||
vt 0.599424 0.385880
|
||||
vt 0.633313 0.511460
|
||||
vt 0.672491 0.495232
|
||||
vt 0.361103 0.624263
|
||||
vt 0.633313 0.736984
|
||||
vt 0.672491 0.753212
|
||||
vt 0.698148 0.624222
|
||||
vt 0.655743 0.624222
|
||||
vt 0.569438 0.832578
|
||||
vt 0.599424 0.862564
|
||||
vt 0.473844 0.896453
|
||||
vt 0.490072 0.935631
|
||||
vt 0.361082 0.918882
|
||||
vt 0.361082 0.961288
|
||||
vt 0.248320 0.896452
|
||||
vt 0.232092 0.935631
|
||||
vt 0.152726 0.832578
|
||||
vt 0.122740 0.862564
|
||||
vt 0.088851 0.736983
|
||||
vt 0.049673 0.753212
|
||||
vt 0.066422 0.624222
|
||||
vt 0.024016 0.624222
|
||||
vt 0.088851 0.511460
|
||||
vt 0.049673 0.495232
|
||||
vt 0.152726 0.415865
|
||||
vt 0.122740 0.385880
|
||||
vt 0.248321 0.351991
|
||||
vt 0.232092 0.312813
|
||||
vt 0.361082 0.329561
|
||||
vt 0.361082 0.287155
|
||||
vt 0.473844 0.351991
|
||||
vt 0.490072 0.312813
|
||||
vt 0.569439 0.415865
|
||||
vt 0.599424 0.385880
|
||||
vt 0.633313 0.511460
|
||||
vt 0.672491 0.495232
|
||||
vt 0.361103 0.624263
|
||||
vn 0.3710 -0.3554 0.8579
|
||||
vn -0.3710 -0.3554 0.8579
|
||||
vn -0.3710 -0.6566 0.6566
|
||||
vn 0.3710 -0.6566 0.6566
|
||||
vn 0.3710 0.6566 -0.6566
|
||||
vn -0.3710 0.6566 -0.6566
|
||||
vn -0.3710 0.8579 -0.3554
|
||||
vn 0.3710 0.8579 -0.3554
|
||||
vn 0.3710 0.3554 -0.8579
|
||||
vn -0.3710 0.3554 -0.8579
|
||||
vn -0.3710 -0.8579 0.3554
|
||||
vn 0.3710 -0.8579 0.3554
|
||||
vn -0.3710 0.9286 0.0000
|
||||
vn 0.3710 0.9286 0.0000
|
||||
vn -0.3710 -0.9286 0.0000
|
||||
vn 0.3710 -0.9286 0.0000
|
||||
vn -0.3710 0.8579 0.3554
|
||||
vn 0.3710 0.8579 0.3554
|
||||
vn -0.3710 -0.8579 -0.3554
|
||||
vn 0.3710 -0.8579 -0.3554
|
||||
vn -0.3710 0.6566 0.6566
|
||||
vn 0.3710 0.6566 0.6566
|
||||
vn -0.3710 -0.6566 -0.6566
|
||||
vn 0.3710 -0.6566 -0.6566
|
||||
vn -0.3710 0.3554 0.8579
|
||||
vn 0.3710 0.3554 0.8579
|
||||
vn -0.3710 -0.3554 -0.8579
|
||||
vn 0.3710 -0.3554 -0.8579
|
||||
vn -0.3710 0.0000 0.9286
|
||||
vn 0.3710 0.0000 0.9286
|
||||
vn -0.3710 0.0000 -0.9286
|
||||
vn 0.3710 0.0000 -0.9286
|
||||
vn 0.9088 0.1596 -0.3854
|
||||
vn 0.9088 0.0000 -0.4172
|
||||
vn 0.9088 0.2950 -0.2950
|
||||
vn 0.9088 0.3854 -0.1596
|
||||
vn 0.9088 0.4172 0.0000
|
||||
vn 0.9088 0.3854 0.1596
|
||||
vn 0.9088 0.2950 0.2950
|
||||
vn 0.9088 0.1596 0.3854
|
||||
vn 0.9088 0.0000 0.4172
|
||||
vn 0.9088 -0.1596 0.3854
|
||||
vn 0.9088 -0.2950 0.2950
|
||||
vn 0.9088 -0.3854 0.1596
|
||||
vn 0.9088 -0.4172 0.0000
|
||||
vn 0.9088 -0.3854 -0.1596
|
||||
vn 0.9088 -0.2950 -0.2950
|
||||
vn 0.9088 -0.1596 -0.3854
|
||||
vn 1.0000 0.0000 0.0000
|
||||
vn -0.9088 0.1596 -0.3854
|
||||
vn -0.9088 0.0000 -0.4172
|
||||
vn -0.9088 0.2950 -0.2950
|
||||
vn -0.9088 0.3854 -0.1596
|
||||
vn -0.9088 0.4172 0.0000
|
||||
vn -0.9088 0.3854 0.1596
|
||||
vn -0.9088 0.2950 0.2950
|
||||
vn -0.9088 0.1596 0.3854
|
||||
vn -0.9088 0.0000 0.4172
|
||||
vn -0.9088 -0.1596 0.3854
|
||||
vn -0.9088 -0.2950 0.2950
|
||||
vn -0.9088 -0.3854 0.1596
|
||||
vn -0.9088 -0.4172 0.0000
|
||||
vn -0.9088 -0.3854 -0.1596
|
||||
vn -0.9088 -0.2950 -0.2950
|
||||
vn -0.9088 -0.1596 -0.3854
|
||||
vn -1.0000 0.0000 0.0000
|
||||
usemtl Wheel_Mat
|
||||
s 1
|
||||
f 11/1/1 44/2/2 45/3/3 12/4/4
|
||||
f 3/5/5 36/6/6 37/7/7 4/8/8
|
||||
f 2/9/9 35/10/10 36/6/6 3/5/5
|
||||
f 12/4/4 45/3/3 46/11/11 13/12/12
|
||||
f 4/8/8 37/7/7 38/13/13 5/14/14
|
||||
f 13/12/12 46/11/11 47/15/15 14/16/16
|
||||
f 5/14/14 38/13/13 39/17/17 6/18/18
|
||||
f 14/16/16 47/15/15 48/19/19 15/20/20
|
||||
f 6/18/18 39/17/17 41/21/21 8/22/22
|
||||
f 15/20/20 48/19/19 49/23/23 16/24/24
|
||||
f 8/22/22 41/21/21 42/25/25 9/26/26
|
||||
f 16/24/24 49/23/23 50/27/27 17/28/28
|
||||
f 9/29/26 42/30/25 43/31/29 10/32/30
|
||||
f 17/33/28 50/34/27 34/35/31 1/36/32
|
||||
f 10/32/30 43/31/29 44/2/2 11/1/1
|
||||
f 18/37/33 19/38/34 1/39/32 2/40/9
|
||||
f 20/41/35 18/37/33 2/40/9 3/42/5
|
||||
f 21/43/36 20/41/35 3/42/5 4/44/8
|
||||
f 22/45/37 21/43/36 4/44/8 5/46/14
|
||||
f 23/47/38 22/45/37 5/46/14 6/48/18
|
||||
f 24/49/39 23/47/38 6/48/18 8/50/22
|
||||
f 25/51/40 24/49/39 8/50/22 9/52/26
|
||||
f 26/53/41 25/51/40 9/52/26 10/54/30
|
||||
f 27/55/42 26/53/41 10/54/30 11/56/1
|
||||
f 28/57/43 27/55/42 11/56/1 12/58/4
|
||||
f 29/59/44 28/57/43 12/58/4 13/60/12
|
||||
f 30/61/45 29/59/44 13/60/12 14/62/16
|
||||
f 31/63/46 30/61/45 14/62/16 15/64/20
|
||||
f 32/65/47 31/63/46 15/64/20 16/66/24
|
||||
f 33/67/48 32/65/47 16/66/24 17/68/28
|
||||
f 19/38/34 33/67/48 17/68/28 1/39/32
|
||||
f 7/69/49 19/38/34 18/37/33
|
||||
f 7/69/49 18/37/33 20/41/35
|
||||
f 7/69/49 20/41/35 21/43/36
|
||||
f 7/69/49 21/43/36 22/45/37
|
||||
f 7/69/49 22/45/37 23/47/38
|
||||
f 7/69/49 23/47/38 24/49/39
|
||||
f 7/69/49 24/49/39 25/51/40
|
||||
f 7/69/49 25/51/40 26/53/41
|
||||
f 7/69/49 26/53/41 27/55/42
|
||||
f 7/69/49 27/55/42 28/57/43
|
||||
f 7/69/49 28/57/43 29/59/44
|
||||
f 7/69/49 29/59/44 30/61/45
|
||||
f 7/69/49 30/61/45 31/63/46
|
||||
f 7/69/49 31/63/46 32/65/47
|
||||
f 7/69/49 32/65/47 33/67/48
|
||||
f 7/69/49 33/67/48 19/38/34
|
||||
f 51/70/50 35/71/10 34/72/31 52/73/51
|
||||
f 53/74/52 36/75/6 35/71/10 51/70/50
|
||||
f 54/76/53 37/77/7 36/75/6 53/74/52
|
||||
f 55/78/54 38/79/13 37/77/7 54/76/53
|
||||
f 56/80/55 39/81/17 38/79/13 55/78/54
|
||||
f 57/82/56 41/83/21 39/81/17 56/80/55
|
||||
f 58/84/57 42/85/25 41/83/21 57/82/56
|
||||
f 59/86/58 43/87/29 42/85/25 58/84/57
|
||||
f 60/88/59 44/89/2 43/87/29 59/86/58
|
||||
f 61/90/60 45/91/3 44/89/2 60/88/59
|
||||
f 62/92/61 46/93/11 45/91/3 61/90/60
|
||||
f 63/94/62 47/95/15 46/93/11 62/92/61
|
||||
f 64/96/63 48/97/19 47/95/15 63/94/62
|
||||
f 65/98/64 49/99/23 48/97/19 64/96/63
|
||||
f 66/100/65 50/101/27 49/99/23 65/98/64
|
||||
f 52/73/51 34/72/31 50/101/27 66/100/65
|
||||
f 40/102/66 51/70/50 52/73/51
|
||||
f 40/102/66 53/74/52 51/70/50
|
||||
f 40/102/66 54/76/53 53/74/52
|
||||
f 40/102/66 55/78/54 54/76/53
|
||||
f 40/102/66 56/80/55 55/78/54
|
||||
f 40/102/66 57/82/56 56/80/55
|
||||
f 40/102/66 58/84/57 57/82/56
|
||||
f 40/102/66 59/86/58 58/84/57
|
||||
f 40/102/66 60/88/59 59/86/58
|
||||
f 40/102/66 61/90/60 60/88/59
|
||||
f 40/102/66 62/92/61 61/90/60
|
||||
f 40/102/66 63/94/62 62/92/61
|
||||
f 40/102/66 64/96/63 63/94/62
|
||||
f 40/102/66 65/98/64 64/96/63
|
||||
f 40/102/66 66/100/65 65/98/64
|
||||
f 40/102/66 52/73/51 66/100/65
|
||||
f 1/36/32 34/35/31 35/10/10 2/9/9
|
|
@ -0,0 +1,14 @@
|
|||
#version 330 core
|
||||
|
||||
in vec2 v_texcoord;
|
||||
|
||||
out vec4 frag_color;
|
||||
|
||||
uniform sampler2D tex;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 tex_color = texture(tex, v_texcoord*60);
|
||||
|
||||
frag_color = tex_color;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
#version 330 core
|
||||
|
||||
layout(location = 0) in vec3 position;
|
||||
layout(location = 1) in vec2 texcoord;
|
||||
|
||||
out vec2 v_texcoord;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
uniform float tile_size;
|
||||
uniform float scroll_speed;
|
||||
|
||||
uniform vec3 camera_position;
|
||||
void main()
|
||||
{
|
||||
// Apply the model, view, and projection matrices
|
||||
gl_Position = projection * view * model * vec4(position, 1.0);
|
||||
|
||||
// Calculate the texture coordinate offset based on the camera position
|
||||
v_texcoord = texcoord;
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 9.2 KiB |
|
@ -68,6 +68,10 @@ impl Camera {
|
|||
Matrix4::look_at(self.Position, self.Position + self.Front, self.Up)
|
||||
}
|
||||
|
||||
pub fn follow(&mut self, pos: Vector3)
|
||||
{
|
||||
self.Position = Point3::new(0.0, 0.55, 1.0) + pos;
|
||||
}
|
||||
/// Processes input received from any keyboard-like input system. Accepts input parameter in the form of camera defined ENUM (to abstract it from windowing systems)
|
||||
pub fn ProcessKeyboard(&mut self, direction: Camera_Movement, deltaTime: f32) {
|
||||
let velocity = self.MovementSpeed * deltaTime;
|
||||
|
|
95
src/debug.rs
95
src/debug.rs
|
@ -8,13 +8,13 @@ const MODELS: [&str; 3]= ["resources/models/TestCarModel/CarW4.obj", "resources/
|
|||
|
||||
mod info;
|
||||
|
||||
|
||||
pub enum dEvent
|
||||
{
|
||||
loadModel(i32),
|
||||
setTest(f32, i32),
|
||||
getObj(i32),
|
||||
addWindow(OpenWindows),
|
||||
removeWindow(OpenWindows),
|
||||
setObj(cgmath::Vector3<f32>),
|
||||
exit,
|
||||
}
|
||||
|
||||
|
@ -22,15 +22,15 @@ pub enum dEvent
|
|||
pub enum Callback
|
||||
{
|
||||
ModelInfo(info::ModelI),
|
||||
TestWind(info::testI),
|
||||
ObjectInfo(info::ObjectI),
|
||||
MainMenu,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub enum OpenWindows {
|
||||
ModelInfo,
|
||||
TestWind,
|
||||
MainMenu,
|
||||
Object(i32),
|
||||
}
|
||||
|
||||
pub struct Debug {
|
||||
|
@ -43,6 +43,25 @@ pub struct Debug {
|
|||
}
|
||||
|
||||
|
||||
fn makeMint<T>(input: cgmath::Vector3<T>) -> mint::Vector3<T>
|
||||
{
|
||||
mint::Vector3{
|
||||
x: input.x,
|
||||
y: input.y,
|
||||
z: input.z
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn makeCG<T>(input: mint::Vector3<T>) -> cgmath::Vector3<T>
|
||||
{
|
||||
cgmath::Vector3
|
||||
{
|
||||
x: input.x,
|
||||
y: input.y,
|
||||
z: input.z
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug {
|
||||
pub fn new(gl: std::sync::Arc<glow::Context>) -> Debug
|
||||
|
@ -88,10 +107,10 @@ impl Debug {
|
|||
match call {
|
||||
Callback::ModelInfo(a) =>
|
||||
ret.append(&mut Debug::displayModel(ui, &a)),
|
||||
Callback::TestWind(mut a) =>
|
||||
ret.append(&mut Debug::displayTest(ui, &mut a)),
|
||||
Callback::MainMenu =>
|
||||
ret.append(&mut Debug::displayMain(ui)),
|
||||
Callback::ObjectInfo(mut a) =>
|
||||
ret.append(&mut Debug::displayObject(ui, &mut a))
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -146,35 +165,12 @@ impl Debug {
|
|||
}
|
||||
}
|
||||
|
||||
fn displayTest(ui: &mut imgui::Ui, testI: &mut info::testI) -> Vec<dEvent>
|
||||
{
|
||||
let mut ret = Vec::new();
|
||||
let mut selectedModel = testI.selectedModel;
|
||||
let mut spinSpeed = testI.spinSpeed;
|
||||
ui.window("POLY I WILL FUCKING")
|
||||
.size([500.0, 100.0], imgui::Condition::FirstUseEver)
|
||||
.build(|| {
|
||||
ui.text("you serve no purpose in life");
|
||||
ui.text("Your Purpose in life is to suck my dick");
|
||||
ui.slider("The Spin Speed", 0.1, 10.0, &mut spinSpeed);
|
||||
if ui
|
||||
.button("Close") {
|
||||
ret.push(dEvent::removeWindow(OpenWindows::TestWind));
|
||||
}
|
||||
if ui.list_box("Select Model to Load", &mut selectedModel, &MODELS, 5) {
|
||||
ret.push(dEvent::loadModel(selectedModel));
|
||||
}
|
||||
});
|
||||
ret.push(dEvent::setTest(spinSpeed, selectedModel
|
||||
));
|
||||
ret
|
||||
}
|
||||
|
||||
fn displayModel(ui: &mut imgui::Ui ,model: &info::ModelI) -> Vec<dEvent>
|
||||
{
|
||||
let mut ret = Vec::new();
|
||||
ui.window("Stats")
|
||||
.size([300.0, 500.0], imgui::Condition::Always)
|
||||
.always_auto_resize(true)
|
||||
.build(|| {
|
||||
ui.text("Model Information");
|
||||
ui.text(format!("count meshes: {}", model.meshesCount));
|
||||
|
@ -196,7 +192,7 @@ impl Debug {
|
|||
{
|
||||
let mut ret = Vec::new();
|
||||
ui.window("Welcome to the main Menu")
|
||||
.size([500.0, 500.0], imgui::Condition::Always)
|
||||
.always_auto_resize(true)
|
||||
.build(|| {
|
||||
ui.text("this is the main Debugger Menu, it's used to Debug the game");
|
||||
ui.text("although it isn't done yet");
|
||||
|
@ -204,8 +200,8 @@ impl Debug {
|
|||
if ui.button("Open the Model Info") {
|
||||
ret.push(dEvent::addWindow(OpenWindows::ModelInfo))
|
||||
}
|
||||
if ui.button("Open the Test Modifier"){
|
||||
ret.push(dEvent::addWindow(OpenWindows::TestWind))
|
||||
if ui.button("Open Object Modifier") {
|
||||
ret.push(dEvent::addWindow(OpenWindows::Object(0)))
|
||||
}
|
||||
if ui.button("Quit") {
|
||||
ret.push(dEvent::exit)
|
||||
|
@ -214,10 +210,23 @@ impl Debug {
|
|||
});
|
||||
ret
|
||||
}
|
||||
fn displayObject(ui: &mut imgui::Ui , object: &mut info::ObjectI ) -> Vec<dEvent>
|
||||
{
|
||||
let mut ret = Vec::new();
|
||||
let mut position = makeMint(object.Position);
|
||||
ui.window("ObjectInfo")
|
||||
.always_auto_resize(true)
|
||||
.build(|| {
|
||||
ui.text("Position");
|
||||
ui.input_float3("Position", &mut position).build();
|
||||
ui.text("WIP");
|
||||
|
||||
ret.push(dEvent::setObj(makeCG(position)));
|
||||
});
|
||||
ret
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
use crate::model;
|
||||
|
@ -234,10 +243,18 @@ pub fn ModelInfo(model: &model::Model) -> Callback
|
|||
})
|
||||
}
|
||||
|
||||
pub fn TestWind(spinSpeed: f32, selectedModel: i32) -> Callback
|
||||
use crate::scene::objects::Player;
|
||||
|
||||
pub fn ObjectInfo(object: &Player) -> Callback
|
||||
{
|
||||
Callback::TestWind(info::testI {
|
||||
spinSpeed,
|
||||
selectedModel,
|
||||
let Position = object.Transform.Position;
|
||||
let Rotation = object.Transform.Rotation;
|
||||
let Velocity = object.Transform.Velocity;
|
||||
let Scale = object.Transform.Scale;
|
||||
Callback::ObjectInfo(info::ObjectI {
|
||||
Position,
|
||||
Rotation,
|
||||
Velocity,
|
||||
Scale
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use cgmath::{Vector3, Quaternion};
|
||||
|
||||
pub struct ModelI
|
||||
{
|
||||
|
@ -10,3 +11,11 @@ pub struct testI
|
|||
pub spinSpeed: f32,
|
||||
pub selectedModel: i32,
|
||||
}
|
||||
|
||||
pub struct ObjectI
|
||||
{
|
||||
pub Position: Vector3<f32>,
|
||||
pub Rotation: Quaternion<f32>,
|
||||
pub Velocity: Vector3<f32>,
|
||||
pub Scale: f32
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ fn main() {
|
|||
|
||||
let mut State = gameState::Playing;
|
||||
|
||||
let mut scene = Scene::new(gl);
|
||||
let mut scene = Scene::new(gl);
|
||||
|
||||
println!("entering main loop");
|
||||
|
||||
|
|
36
src/model.rs
36
src/model.rs
|
@ -13,29 +13,49 @@ use tobj;
|
|||
mod mesh;
|
||||
use mesh::{ Mesh, Texture, Vertex };
|
||||
use crate::shader::shader;
|
||||
use crate::scene::objects::Transform;
|
||||
use crate::camera::Camera;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Model {
|
||||
/* Model Data */
|
||||
pub meshes: Vec<Mesh>,
|
||||
pub textures_loaded: Vec<Texture>, // stores all the textures loaded so far, optimization to make sure textures aren't loaded more than once.
|
||||
pub Transform: Transform, // Internal Transformation
|
||||
directory: String,
|
||||
}
|
||||
|
||||
impl Model {
|
||||
/// constructor, expects a filepath to a 3D model.
|
||||
pub fn new(path: &str, gl: std::sync::Arc<glow::Context>) -> Model {
|
||||
let mut model = Model::default();
|
||||
pub fn new(path: &str, gl: std::sync::Arc<glow::Context>, Transform: Option<Transform>) -> Model {
|
||||
let mut model = Model {
|
||||
Transform: Transform.unwrap_or(Transform::default()),
|
||||
..Model::default()
|
||||
};
|
||||
model.loadModel(path, Arc::clone(&gl));
|
||||
model
|
||||
}
|
||||
/// NOTE problem with this implementation is that only one range and transform could be specified
|
||||
pub fn Draw(&self, shader: &shader, modelpass: Option<(cgmath::Matrix4<f32>, cgmath::Matrix4<f32>, cgmath::Matrix4<f32>)>) {
|
||||
|
||||
pub fn Draw(&self, shader: &shader) {
|
||||
for mesh in &self.meshes {
|
||||
|
||||
unsafe { mesh.Draw(shader); }
|
||||
}
|
||||
}
|
||||
|
||||
let model;
|
||||
if let Some((translation, rotation, scale)) = modelpass
|
||||
{
|
||||
let (c_translation, c_rotation, c_scale) = self.Transform.getMatTuple(); //model = self.Transform.getMatModel();
|
||||
model = (translation ) * (rotation * c_rotation * c_translation) * (c_scale * scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
model = self.Transform.getMatModel();
|
||||
};
|
||||
shader.setMat4("model", &model);
|
||||
|
||||
for (i, mesh) in self.meshes.iter().enumerate() {
|
||||
unsafe { mesh.Draw(shader); }
|
||||
}
|
||||
}
|
||||
|
||||
// loads a model from file and stores the resulting meshes in the meshes vector.
|
||||
fn loadModel(&mut self, path: &str, gl: Arc<glow::Context>) {
|
||||
|
@ -110,7 +130,7 @@ impl Model {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe fn TextureFromFile(path: &str, directory: &str, gl: Arc<glow::Context>) -> glow::NativeTexture {
|
||||
pub unsafe fn TextureFromFile(path: &str, directory: &str, gl: Arc<glow::Context>) -> glow::NativeTexture {
|
||||
let filename = format!("{}/{}", directory, path);
|
||||
|
||||
let mut textureID = gl.create_texture().unwrap();
|
||||
|
|
|
@ -11,11 +11,13 @@ use cgmath::prelude::*;
|
|||
use glow::*;
|
||||
use field_offset::offset_of;
|
||||
|
||||
use crate::scene::objects;
|
||||
use crate::shader::shader;
|
||||
// NOTE: without repr(C) the compiler may reorder the fields or use different padding/alignment than C.
|
||||
// Depending on how you pass the data to OpenGL, this may be bad. In this case it's not strictly
|
||||
// necessary though because of the `offset!` macro used below in setupMesh()
|
||||
#[repr(C)]
|
||||
#[derive(Clone)]
|
||||
pub struct Vertex {
|
||||
// position
|
||||
pub Position: Vector3<f32>,
|
||||
|
@ -48,6 +50,7 @@ pub struct Texture {
|
|||
pub path: String,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Mesh {
|
||||
/* Mesh Data */
|
||||
pub vertices: Vec<Vertex>,
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
//! an Object Module for defining Objects
|
||||
|
||||
use crate::model::Model;
|
||||
|
||||
struct
|
121
src/scene.rs
121
src/scene.rs
|
@ -10,7 +10,7 @@ use glow::*;
|
|||
use imgui_glow_renderer::AutoRenderer;
|
||||
use imgui_sdl2_support::SdlPlatform;
|
||||
use crate::debug;
|
||||
mod objects;
|
||||
pub mod objects;
|
||||
use cgmath::{Matrix4, vec3, Point3, Deg, perspective};
|
||||
use cgmath::prelude::*;
|
||||
|
||||
|
@ -23,17 +23,6 @@ const SCR_HEIGHT: u32 = 900;
|
|||
const MODELS: [&str; 3]= ["resources/models/TestCarModel/CarW4.obj", "resources/models/TestCarModel/CarW1.obj",
|
||||
"resources/models/TestCarModel/CarW0.obj"];
|
||||
|
||||
/// XXX this is temporary, thus the name
|
||||
pub struct tempData {
|
||||
pub projection: Matrix4<f32>,
|
||||
pub spinSpeed: f32,
|
||||
pub current_rad: f32,
|
||||
pub currentFrame: f32,
|
||||
pub deltaTime: f32,
|
||||
pub lastFrame: f32,
|
||||
DebugMode: bool,
|
||||
selectedModel: i32
|
||||
}
|
||||
use crate::debug::Debug;
|
||||
|
||||
pub enum SceneEnum {
|
||||
|
@ -50,7 +39,9 @@ pub struct Scene {
|
|||
debug: Debug,
|
||||
shaders: Vec<Rc<shader>>,
|
||||
time: std::time::Instant,
|
||||
tempData: tempData,
|
||||
DebugMode: bool,
|
||||
input: objects::Input,
|
||||
plane: objects::plane
|
||||
}
|
||||
|
||||
impl Scene{
|
||||
|
@ -59,6 +50,7 @@ impl Scene{
|
|||
let Car = objects::Player::new(Arc::clone(&gl));
|
||||
|
||||
let shader = Rc::new(shader::new("model", Arc::clone(&gl)));
|
||||
let planeShader = Rc::new(shader::new("plane", Arc::clone(&gl)));
|
||||
|
||||
let time = std::time::Instant::now();
|
||||
|
||||
|
@ -67,18 +59,7 @@ impl Scene{
|
|||
Pitch: -20.0,
|
||||
..Camera::default()
|
||||
};
|
||||
|
||||
let tempData = tempData {
|
||||
projection: perspective(Deg(45.0), 1600.0/ 900.0, 0.1, 100.0),
|
||||
spinSpeed: 1.0,
|
||||
current_rad: 1.0,
|
||||
currentFrame: 0.0,
|
||||
deltaTime: 0.0,
|
||||
lastFrame: 0.0,
|
||||
DebugMode: false,
|
||||
selectedModel: 0,
|
||||
|
||||
};
|
||||
let plane = objects::plane::new(Arc::clone(&gl));
|
||||
|
||||
let debug = Debug::new(gl.clone());
|
||||
Scene{
|
||||
|
@ -86,51 +67,41 @@ impl Scene{
|
|||
Car,
|
||||
camera,
|
||||
debug,
|
||||
shaders: vec![shader],
|
||||
shaders: vec![shader, planeShader],
|
||||
time,
|
||||
tempData,
|
||||
DebugMode: false,
|
||||
input: objects::Input::default(),
|
||||
plane
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self ,events_loop: &mut sdl2::EventPump, window: &sdl2::video::Window) -> SceneEnum
|
||||
{
|
||||
self.tempData.currentFrame = self.time.elapsed().as_secs_f32();
|
||||
self.tempData.deltaTime = self.tempData.currentFrame - self.tempData.lastFrame;
|
||||
self.tempData.lastFrame = self.tempData.currentFrame;
|
||||
|
||||
|
||||
|
||||
|
||||
let mut ret = SceneEnum::Resume;
|
||||
|
||||
unsafe {
|
||||
self.gl.enable(glow::DEPTH_TEST);
|
||||
self.gl.clear(glow::COLOR_BUFFER_BIT | glow::DEPTH_BUFFER_BIT);
|
||||
}
|
||||
/*
|
||||
unsafe {
|
||||
|
||||
self.shaders[0].Use();
|
||||
self.tempData.projection = perspective(Deg(self.camera.Zoom), SCR_WIDTH as f32 /SCR_HEIGHT as f32, 0.1, 100.0);
|
||||
let view = self.camera.GetViewMatrix();
|
||||
self.shaders[0].setMat4("projection", &self.tempData.projection);
|
||||
self.shaders[0].setMat4("view", &view);
|
||||
|
||||
let mut model: Matrix4<f32> = Matrix4::from_axis_angle(vec3(0.0, -1.0, 0.0).normalize(),
|
||||
cgmath::Rad(1.0));
|
||||
|
||||
model = model * Matrix4::from_scale(0.2);
|
||||
self.shaders[0].setMat4("model", &model);
|
||||
}
|
||||
*/
|
||||
self.Car.update();
|
||||
self.Car.turn(self.tempData.spinSpeed);
|
||||
self.camera.follow(self.Car.Transform.Position);
|
||||
self.plane.draw(&self.shaders[1], &self.camera);
|
||||
self.Car.update(&self.input);
|
||||
self.Car.Draw(&self.shaders[0], &self.camera);
|
||||
|
||||
|
||||
if self.tempData.DebugMode{
|
||||
if self.DebugMode{
|
||||
self.handleDebug(events_loop, window, &mut ret)
|
||||
}
|
||||
|
||||
for event in events_loop.poll_iter() {
|
||||
if self.tempData.DebugMode {
|
||||
if self.DebugMode {
|
||||
self.debug.handle(&event);
|
||||
}
|
||||
|
||||
match event {
|
||||
Event::Quit {..} |
|
||||
Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
|
||||
|
@ -138,14 +109,36 @@ impl Scene{
|
|||
},
|
||||
Event::KeyDown {keycode: Some(Keycode::P), ..} => {
|
||||
},
|
||||
Event::KeyDown {keycode: Some(Keycode::D), ..} => {
|
||||
self.tempData.DebugMode = !self.tempData.DebugMode
|
||||
}
|
||||
Event::KeyDown {keycode: Some(Keycode::Q), ..} => {
|
||||
self.DebugMode = !self.DebugMode
|
||||
},
|
||||
Event::KeyDown {keycode: Some(Keycode::W), repeat: false, ..} => {
|
||||
self.input.Accel = true;
|
||||
},
|
||||
Event::KeyUp {keycode: Some(Keycode::W), ..} => {
|
||||
self.input.Accel = false;
|
||||
},
|
||||
Event::KeyDown {keycode: Some(Keycode::S), repeat: false, ..} => {
|
||||
self.input.Decel = true;
|
||||
},
|
||||
Event::KeyUp {keycode: Some(Keycode::S), ..} => {
|
||||
self.input.Decel = false;
|
||||
},
|
||||
Event::KeyDown {keycode: Some(Keycode::D), repeat: false, ..} => {
|
||||
self.input.Right = true;
|
||||
},
|
||||
Event::KeyUp {keycode: Some(Keycode::D), ..} => {
|
||||
self.input.Right = false;
|
||||
},
|
||||
|
||||
Event::KeyDown {keycode: Some(Keycode::A), repeat: false, ..} => {
|
||||
self.input.Left = true;
|
||||
},
|
||||
Event::KeyUp {keycode: Some(Keycode::A), ..} => {
|
||||
self.input.Left = false;
|
||||
},
|
||||
Event::KeyDown {keycode: Some(Keycode::M), ..} => {
|
||||
self.debug.addWindow(debug::OpenWindows::ModelInfo)
|
||||
},
|
||||
Event::KeyDown {keycode: Some(Keycode::W), ..} => {
|
||||
self.camera.ProcessKeyboard(Camera_Movement::FORWARD, self.tempData.deltaTime);
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
|
@ -162,9 +155,9 @@ impl Scene{
|
|||
for (id, window) in windows
|
||||
{
|
||||
match window {
|
||||
debug::OpenWindows::ModelInfo => Callbacks.push(debug::ModelInfo(&self.Car.Model)),
|
||||
debug::OpenWindows::TestWind => Callbacks.push(debug::TestWind(self.tempData.spinSpeed, self.tempData.selectedModel)),
|
||||
debug::OpenWindows::ModelInfo => Callbacks.push(debug::ModelInfo(&self.Car.Model[0])),
|
||||
debug::OpenWindows::MainMenu => Callbacks.push(debug::Callback::MainMenu),
|
||||
debug::OpenWindows::Object(a) => Callbacks.push(debug::ObjectInfo(&self.Car)),
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -176,13 +169,15 @@ impl Scene{
|
|||
match command
|
||||
{
|
||||
dEvent::exit => *ret = SceneEnum::Exit,
|
||||
dEvent::loadModel(i) => self.Car.Model = Model::new(MODELS[i as usize], Arc::clone(&self.gl)),
|
||||
dEvent::setTest(a, b) => {
|
||||
self.tempData.spinSpeed = a;
|
||||
self.tempData.selectedModel = b;
|
||||
},
|
||||
dEvent::loadModel(i) => self.Car.Model = vec!(Model::new(MODELS[i as usize], Arc::clone(&self.gl), None)),
|
||||
dEvent::addWindow(a) => self.debug.addWindow(a),
|
||||
dEvent::removeWindow(a) => self.debug.removeWindow(a),
|
||||
dEvent::setObj(p) =>
|
||||
{
|
||||
self.Car.Transform.Position = p;
|
||||
}
|
||||
// TODO
|
||||
dEvent::getObj(_a) => ()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,18 +2,55 @@
|
|||
const SCR_WIDTH: u32 = 1600;
|
||||
const SCR_HEIGHT: u32 = 900;
|
||||
|
||||
use cgmath::{Vector3, Quaternion, Rotation3};
|
||||
use cgmath::{Vector3, Quaternion, Rotation3, Deg, perspective, Matrix4};
|
||||
use cgmath::prelude::*;
|
||||
use crate::model::Model;
|
||||
use crate::camera::Camera;
|
||||
use glow::HasContext;
|
||||
|
||||
pub struct Transform {
|
||||
Position: Vector3<f32>,
|
||||
Rotation: Quaternion<f32>,
|
||||
Velocity: Vector3<f32>,
|
||||
Scale: f32,
|
||||
pub struct Input {
|
||||
pub Accel: bool,
|
||||
pub Decel: bool,
|
||||
pub Left: bool,
|
||||
pub Right: bool
|
||||
}
|
||||
|
||||
// TODO make a struct to pass info
|
||||
|
||||
impl Default for Input {
|
||||
fn default() -> Input {
|
||||
Input {
|
||||
Accel: false,
|
||||
Decel: false,
|
||||
Left: false,
|
||||
Right: false
|
||||
}
|
||||
}
|
||||
}
|
||||
pub struct Transform {
|
||||
pub Position: Vector3<f32>,
|
||||
pub Rotation: Quaternion<f32>,
|
||||
pub Velocity: Vector3<f32>,
|
||||
pub Scale: f32,
|
||||
}
|
||||
|
||||
impl Transform {
|
||||
pub fn getMatModel(&self) -> cgmath::Matrix4<f32> {
|
||||
let translation = cgmath::Matrix4::from_translation(self.Position);
|
||||
let rotation = cgmath::Matrix4::from(self.Rotation);
|
||||
let scale = cgmath::Matrix4::from_scale(self.Scale);
|
||||
|
||||
translation * rotation * scale
|
||||
}
|
||||
|
||||
pub fn getMatTuple(&self) -> (cgmath::Matrix4<f32>, cgmath::Matrix4<f32>, cgmath::Matrix4<f32>)
|
||||
{
|
||||
let translation = cgmath::Matrix4::from_translation(self.Position);
|
||||
let rotation = cgmath::Matrix4::from(self.Rotation);
|
||||
let scale = cgmath::Matrix4::from_scale(self.Scale);
|
||||
(translation, rotation, scale)
|
||||
}
|
||||
}
|
||||
impl Default for Transform {
|
||||
fn default() -> Transform
|
||||
{
|
||||
|
@ -21,31 +58,98 @@ impl Default for Transform {
|
|||
Position: Vector3::<f32>::new(0.0, 0.0, 0.0),
|
||||
Rotation: Quaternion::from_angle_y(cgmath::Deg(0.0)),
|
||||
Velocity: Vector3::<f32>::new(0.0, 0.0, 0.0),
|
||||
Scale: 0.2,
|
||||
Scale: 0.1,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Transform {
|
||||
pub fn setPos(&mut self, input: Vector3<f32>)
|
||||
{
|
||||
self.Position = input;
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Player {
|
||||
pub Transform: Transform,
|
||||
pub Model: Model
|
||||
pub Model: Vec<Model>,
|
||||
distance: f32
|
||||
}
|
||||
|
||||
impl Player {
|
||||
pub fn new(gl: std::sync::Arc<glow::Context>) -> Self {
|
||||
|
||||
Player {
|
||||
Transform: Transform::default(),
|
||||
Model: Model::new("resources/models/TestCarModel/CarW4.obj", gl),
|
||||
Transform: Transform {
|
||||
Position: cgmath::vec3(0.0, 0.150, 0.0),
|
||||
Scale: 1.0,
|
||||
..Transform::default()
|
||||
},
|
||||
|
||||
|
||||
Model: vec!(
|
||||
// Car
|
||||
Model::new("resources/models/TestCarModel/CarW0.obj", gl.clone(), Some(Transform {
|
||||
Position: cgmath::vec3(0.0, 0.0, 0.0),
|
||||
..Transform::default()
|
||||
})),
|
||||
|
||||
// left Front Wheel
|
||||
Model::new("resources/models/TestCarModel/wheel.obj", gl.clone(), Some(Transform {
|
||||
Position: cgmath::vec3(0.070,-0.020, 0.135),
|
||||
..Transform::default()
|
||||
})),
|
||||
|
||||
// right Front Wheel
|
||||
Model::new("resources/models/TestCarModel/wheel.obj", gl.clone(), Some(Transform {
|
||||
Position: cgmath::vec3(-0.085,-0.020, 0.135),
|
||||
..Transform::default()
|
||||
})),
|
||||
// left back Wheel
|
||||
Model::new("resources/models/TestCarModel/wheel.obj", gl.clone(), Some(Transform {
|
||||
Position: cgmath::vec3(0.070,-0.020, -0.12),
|
||||
..Transform::default()
|
||||
})),
|
||||
// right Back Wheel
|
||||
Model::new("resources/models/TestCarModel/wheel.obj", gl.clone(), Some(Transform {
|
||||
Position: cgmath::vec3(-0.085,-0.020, -0.12),
|
||||
..Transform::default()
|
||||
})),
|
||||
),
|
||||
|
||||
distance: 0.0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self)
|
||||
pub fn update(&mut self, input: &Input)
|
||||
{
|
||||
if input.Accel {
|
||||
self.forward(0.01);
|
||||
}
|
||||
if input.Decel {
|
||||
self.forward(-0.01)
|
||||
}
|
||||
|
||||
if input.Left {
|
||||
self.turn(1.5)
|
||||
}
|
||||
if input.Right {
|
||||
self.turn(-1.5)
|
||||
}
|
||||
|
||||
self.Transform.Position += self.Transform.Velocity;
|
||||
self.Transform.Rotation = self.Transform.Rotation.normalize();
|
||||
}
|
||||
pub fn forward(&mut self, amount: f32)
|
||||
{
|
||||
let forward = self.Transform.Rotation.rotate_vector(cgmath::Vector3::unit_z());
|
||||
let distance = forward * amount;
|
||||
self.Transform.Position += distance;
|
||||
self.distance += amount * 1000.0;
|
||||
|
||||
}
|
||||
|
||||
pub fn turn(&mut self, amount: f32)
|
||||
{
|
||||
|
@ -53,22 +157,125 @@ impl Player {
|
|||
let delta_rotation = Quaternion::from_axis_angle(up, cgmath::Deg(amount));
|
||||
self.Transform.Rotation = self.Transform.Rotation * delta_rotation;
|
||||
}
|
||||
pub fn Draw(&self, shader: &crate::shader::shader, camera: &Camera)
|
||||
pub fn Draw(&mut self, shader: &crate::shader::shader, camera: &Camera)
|
||||
{
|
||||
shader.Use();
|
||||
|
||||
let translation = cgmath::Matrix4::from_translation(self.Transform.Position);
|
||||
let rotation = cgmath::Matrix4::from(self.Transform.Rotation);
|
||||
let scale = cgmath::Matrix4::from_scale(self.Transform.Scale);
|
||||
let model = translation * rotation * scale;
|
||||
|
||||
let projection = cgmath::perspective(cgmath::Deg(camera.Zoom), SCR_WIDTH as f32 /SCR_HEIGHT as f32, 0.1, 100.0 );
|
||||
let view = camera.GetViewMatrix();
|
||||
shader.setMat4("projection", &projection);
|
||||
shader.setMat4("view", &view);
|
||||
|
||||
shader.setMat4("model", &model);
|
||||
|
||||
self.Model.Draw(shader);
|
||||
let current = Transform {
|
||||
Scale: 1.0,
|
||||
Rotation: self.Transform.Rotation * Quaternion::from_angle_x(Deg(self.distance)),
|
||||
..self.Transform
|
||||
};
|
||||
|
||||
let model = current.getMatModel();
|
||||
|
||||
|
||||
let model = current.getMatTuple();
|
||||
for models in &self.Model
|
||||
{
|
||||
models.Draw(shader, Some(model));
|
||||
|
||||
}
|
||||
/*
|
||||
for i in 1..5
|
||||
{
|
||||
shader.setMat4("model", &turned.getMatModel());
|
||||
self.Model[i].0.Draw(shader);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
pub struct plane {
|
||||
pub texture: glow::NativeTexture,
|
||||
pub VAO: glow::VertexArray,
|
||||
|
||||
VBO: glow::Buffer,
|
||||
EBO: glow::Buffer,
|
||||
}
|
||||
|
||||
impl plane {
|
||||
pub fn new(gl: std::sync::Arc<glow::Context>) -> plane
|
||||
{
|
||||
let vertices: [f32; 20] = [
|
||||
10.5, 10.5, 0.0, 1.0, 1.0,
|
||||
10.5, -10.5, 0.0, 1.0, 0.0,
|
||||
-10.5, -10.5, 0.0, 0.0, 0.0,
|
||||
-10.5, 10.5, 0.0, 0.0, 1.0
|
||||
];
|
||||
let indices: [u32; 6] = [
|
||||
0, 1, 3,
|
||||
1, 2, 3
|
||||
];
|
||||
unsafe {
|
||||
let VAO = gl.create_vertex_array().unwrap();
|
||||
let VBO = gl.create_buffer().unwrap();
|
||||
let EBO = gl.create_buffer().unwrap();
|
||||
|
||||
gl.bind_vertex_array(Some(VAO));
|
||||
|
||||
gl.bind_buffer(glow::ARRAY_BUFFER, Some(VBO));
|
||||
let data = core::slice::from_raw_parts(
|
||||
vertices.as_ptr() as *const u8,
|
||||
vertices.len() * core::mem::size_of::<f32>(),
|
||||
);
|
||||
gl.named_buffer_data_u8_slice(VBO, data, glow::STATIC_DRAW);
|
||||
|
||||
gl.bind_buffer(glow::ELEMENT_ARRAY_BUFFER, Some(EBO));
|
||||
let data = core::slice::from_raw_parts(
|
||||
indices.as_ptr() as *const u8,
|
||||
indices.len() * core::mem::size_of::<u32>(),
|
||||
);
|
||||
gl.named_buffer_data_u8_slice(EBO, data, glow::STATIC_DRAW);
|
||||
|
||||
let stride = 5 * core::mem::size_of::<f32>() as i32;
|
||||
gl.enable_vertex_attrib_array(0);
|
||||
gl.vertex_attrib_pointer_f32(0, 3, glow::FLOAT, false, stride, 0);
|
||||
|
||||
gl.enable_vertex_attrib_array(1);
|
||||
gl.vertex_attrib_pointer_f32(1, 2, glow::FLOAT, false, stride, (3 * core::mem::size_of::<f32>()) as i32 );
|
||||
|
||||
gl.bind_vertex_array(None);
|
||||
|
||||
plane {
|
||||
texture: crate::model::TextureFromFile("texture.jpg", "resources", gl.clone()),
|
||||
VAO,
|
||||
VBO,
|
||||
EBO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw(&self, shader: &crate::shader::shader, camera: &Camera)
|
||||
{
|
||||
unsafe {
|
||||
shader.Use();
|
||||
|
||||
let model = cgmath::Matrix4::from_angle_x(cgmath::Deg(-90.0));
|
||||
let projection = cgmath::perspective(cgmath::Deg(camera.Zoom), SCR_WIDTH as f32 /SCR_HEIGHT as f32, 0.1, 100.0);
|
||||
let view = camera.GetViewMatrix();
|
||||
|
||||
shader.setMat4("model", &model);
|
||||
shader.setMat4("view", &view);
|
||||
shader.setMat4("projection", &projection);
|
||||
shader.setFloat("tile_size", 0.5);
|
||||
shader.setFloat("scroll_speed", 10.0);
|
||||
let camera_direction = (camera.Position - cgmath::Point3::new(0.0, 0.0, 0.0));
|
||||
shader.setVector3("camera_position", camera_direction);
|
||||
|
||||
shader.gl.bind_texture(glow::TEXTURE_2D, Some(self.texture));
|
||||
shader.gl.bind_vertex_array(Some(self.VAO));
|
||||
|
||||
shader.gl.draw_elements(glow::TRIANGLES, 6, glow::UNSIGNED_INT, 0);
|
||||
shader.gl.bind_vertex_array(None);
|
||||
|
||||
shader.gl.active_texture(glow::TEXTURE0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue