def normalize(self): normal = self.normal() if vector3.magnitude(normal) != 0: scale = 1 / vector3.magnitude(normal) normal = vector3.scale(normal, scale) d = self.factors[3] * scale self.factors = (normal[0], normal[1], normal[2], d)
def world_to_screen_point(point, camera): """Get view of the point on screen""" tr = camera.transform.get_global_transform() screen_plane = Plane.From_normal(tr.forward, point) screen_middle_point = Ray(tr.position, tr.forward).intersect_plane(screen_plane) screen_width = math.tan(math.radians(camera.FOV / 2)) * vector3.magnitude( vector3.subtract(screen_middle_point, tr.position)) * 2 screen_height = screen_width / camera.aspect_ratio point_in_camera_space = convert_to_different_space( vector3.subtract(point, screen_middle_point), tr.right, tr.down, tr.forward) point_right_vector = vector3.add( vector3.scale(tr.right, screen_width / 2), vector3.scale(tr.right, point_in_camera_space[0])) point_down_vector = vector3.add( vector3.scale(tr.down, screen_height / 2), vector3.scale(tr.down, point_in_camera_space[1])) point_right = vector3.magnitude(point_right_vector) / screen_width point_down = vector3.magnitude(point_down_vector) / screen_height scale_right = vector3.scale_div(point_right_vector, tr.right) if scale_right < 0: point_right = -point_right scale_down = vector3.scale_div(point_down_vector, tr.down) if scale_down < 0: point_down = -point_down return (point_right * camera.resolution[0], point_down * camera.resolution[1])
def Dist_from_ground(self): ray = Ray( Local_to_world_space(self.parent.collider.center, self.parent.transform), (0, 0, -1)) if ray.Collide(self.parent).point and ray.Collide().point: dist_vector = vector3.subtract(ray.Collide().point, ray.Collide(self.parent).point) return vector3.magnitude(dist_vector) else: return None
def Axis_view(point, axis): k = vector3.dot(point, axis) / vector3.magnitude(point)**2 return k
move_speed = run_speed elif not crouching: move_speed = walk_speed else: move_speed = crouch_speed right_move_vec = vector3.scale(cam.transform.right, player_move[0]) forward_move_vec = vector3.scale(cam.transform.forward, player_move[1]) move_vec = (vector3.add(right_move_vec, forward_move_vec)[0], vector3.add(right_move_vec, forward_move_vec)[1], 0) move_vec = vector3.normalize(move_vec) move_vec = vector3.scale(move_vec, move_speed) player.rigidbody.Move(vector3.scale(move_vec, Other.delta_time)) if vector3.magnitude(move_vec) > 0 and step_timer <= 0: if player.rigidbody.Dist_from_ground( ) and player.rigidbody.Dist_from_ground() <= 0.05: if move_speed == walk_speed: step_channel.play(footstep) step_timer = walk_step_time elif move_speed == run_speed: step_channel.play(footstep) step_timer = run_step_time if step_timer > 0: step_timer -= Other.delta_time if Input.Get_key_down('escape'): game_exit = True