close enough
parent
c88442072c
commit
3dcc3bd3e7
|
@ -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
|
52
src/model.rs
52
src/model.rs
|
@ -21,57 +21,41 @@ 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, opt: Option<(std::ops::Range<i32>,Transform, &Camera, cgmath::Matrix4<f32> )>) {
|
||||
if opt.is_some()
|
||||
{
|
||||
let (range, transform, camera, model) = opt.unwrap();
|
||||
for (i, mesh) in self.meshes.iter().enumerate() {
|
||||
pub fn Draw(&self, shader: &shader, modelpass: Option<(cgmath::Matrix4<f32>, cgmath::Matrix4<f32>, cgmath::Matrix4<f32>)>) {
|
||||
|
||||
// run all meshes as normal
|
||||
if !range.contains(&(i as i32))
|
||||
{
|
||||
unsafe {mesh.Draw(shader); }
|
||||
}
|
||||
|
||||
}
|
||||
// run the special Transforms for the meshes specified
|
||||
|
||||
let translation = cgmath::Matrix4::from_translation(transform.Position);
|
||||
let rotation = cgmath::Matrix4::from(transform.Rotation);
|
||||
let scale = cgmath::Matrix4::from_scale(transform.Scale);
|
||||
let finalmod = model * (translation * rotation * scale);
|
||||
|
||||
let projection = cgmath::perspective(cgmath::Deg(camera.Zoom), 1600.0 /900.0, 0.1, 100.0);
|
||||
let view = camera.GetViewMatrix();
|
||||
shader.Use();
|
||||
shader.setMat4("projection", &projection);
|
||||
shader.setMat4("view", &view);
|
||||
shader.setMat4("model", &finalmod);
|
||||
|
||||
for i in range
|
||||
{
|
||||
|
||||
unsafe {self.meshes[i as usize].Draw(shader)}
|
||||
}
|
||||
} else {
|
||||
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>) {
|
||||
|
|
|
@ -16,7 +16,7 @@ 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>,
|
||||
|
@ -49,6 +49,7 @@ pub struct Texture {
|
|||
pub path: String,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Mesh {
|
||||
/* Mesh Data */
|
||||
pub vertices: Vec<Vertex>,
|
||||
|
|
|
@ -155,7 +155,7 @@ impl Scene{
|
|||
for (id, window) in windows
|
||||
{
|
||||
match window {
|
||||
debug::OpenWindows::ModelInfo => Callbacks.push(debug::ModelInfo(&self.Car.Model)),
|
||||
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)),
|
||||
|
||||
|
@ -169,7 +169,7 @@ 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::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) =>
|
||||
|
|
|
@ -34,6 +34,23 @@ pub struct Transform {
|
|||
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
|
||||
{
|
||||
|
@ -41,7 +58,7 @@ 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,
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -57,14 +74,52 @@ impl Transform {
|
|||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,6 +147,7 @@ impl Player {
|
|||
let forward = self.Transform.Rotation.rotate_vector(cgmath::Vector3::unit_z());
|
||||
let distance = forward * amount;
|
||||
self.Transform.Position += distance;
|
||||
self.distance += amount * 1000.0;
|
||||
|
||||
}
|
||||
|
||||
|
@ -101,31 +157,38 @@ 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);
|
||||
|
||||
let turned = Transform {
|
||||
let current = Transform {
|
||||
Scale: 1.0,
|
||||
..Transform::default()
|
||||
Rotation: self.Transform.Rotation * Quaternion::from_angle_x(Deg(self.distance)),
|
||||
..self.Transform
|
||||
};
|
||||
|
||||
let model = current.getMatModel();
|
||||
|
||||
|
||||
self.Model.Draw(shader, Some((1..3, turned, camera, model)));
|
||||
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);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue