Rotate spider
@@ -45,7 +45,7 @@ impl Spider
let program = program::Program::from_resource(&gl, "examples/assets/shaders/standard")?;
let model = surface::TriangleSurface::create(gl, &mesh, &program)?;
- Ok(Spider { program, model, position: vec3(0.0, 0.0, 0.0), view_direction: vec3(0.0, 0.0, -1.0), local2world: Matrix4::one(),
+ Ok(Spider { program, model, position: vec3(0.0, 0.0, 5.0), view_direction: vec3(0.0, 0.0, -1.0), local2world: Matrix4::one(),
is_moving_backward: false, is_moving_forward: false, is_rotating_left: false, is_rotating_right: false, is_jumping: false})
}
@@ -86,16 +86,18 @@ impl Spider
}
let spider_translation;
+ let spider_rotation;
{
// Get world position and view direction
let world_position = self.get_position(terrain);
let world_view_direction = self.get_view_direction(terrain);
// Compute spider model matrix
+ spider_rotation = ext::look_at(vec3(0., 0., 0.), *world_view_direction, vec3(0., 1., 0.));
//let spider_rotation_yaw = orientation(normalize(vec3(world_view_direction.x, 0.0, world_view_direction.z)), vec3(0.0, 0.0, 1.0));
//let spider_rotation_pitch = orientation(normalize(vec3(0.0, world_view_direction.y, 1.0)), vec3(0.0, 0.0, 1.0));
spider_translation = translate(&Matrix4::one(), *world_position);
}
- self.local2world = spider_translation;// * spider_rotation_yaw * spider_rotation_pitch;
+ self.local2world = spider_translation * spider_rotation;// * spider_rotation_yaw * spider_rotation_pitch;
}
}
