def Calculate_normal(self, inverted=False): plane_vector1 = vector3.subtract(self.vertex[0], self.vertex[1]) plane_vector2 = vector3.subtract(self.vertex[1], self.vertex[2]) normal = vector3.cross(plane_vector1, plane_vector2) normal = vector3.normalize(normal) if not inverted: return normal else: return vector3.scale(normal, -1)
def From_vectors(vector1, vector2, origin_point): normal = vector3.cross(vector1, vector2) normal = vector3.normalize(normal) a = normal[0] b = normal[1] c = normal[2] d = -normal[0] * origin_point[0] - normal[1] * origin_point[ 1] - normal[2] * origin_point[2] plane = Plane((a, b, c, d)) return plane
def From_points(vertex1, vertex2, vertex3): plane_vector1 = vector3.subtract(vertex1, vertex2) plane_vector2 = vector3.subtract(vertex2, vertex3) normal = vector3.cross(plane_vector1, plane_vector2) normal = vector3.normalize(normal) a = normal[0] b = normal[1] c = normal[2] d = -normal[0] * vertex1[0] - normal[1] * vertex1[1] - normal[ 2] * vertex1[2] plane = Plane((a, b, c, d)) return plane
def Ray_on_pixel(point2d): cam = camera.main_camera tr = cam.transform.get_global_transform() dist_from_mid = vector2.subtract(point2d, cam.middle_pixel) tg_alfa = math.tan(math.radians( cam.FOV / 2)) * dist_from_mid[0] / (cam.resolution[0] / 2) tg_beta = math.tan(math.radians( cam.FOV_vertical / 2)) * dist_from_mid[1] / (cam.resolution[1] / 2) direction = vector3.add( vector3.add(tr.forward, vector3.scale(tr.right, tg_alfa)), vector3.scale(tr.down, tg_beta)) direction = vector3.normalize(direction) ray = Ray(tr.position, direction) return ray
if Input.Get_key("lshift"): if crouching: crouching = False cam.transform.Translate((0, 0, 0.9)) 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:
def from_angle_axis(cls, angle, axis): axis = vector3.normalize(axis) v = vector3.scale(axis, math.radians(angle)) q = quaternion.from_rotation_vector(v) return cls.from_np_quaternion(q)