Ejemplo n.º 1
0
    def calculate(self):
        self.rays = []
        cone_normal_top, cone_norma_bottom = self.light.cone_normals()
        angle_top = math.atan2(cone_normal_top.y(), cone_norma_bottom.x())
        angle_bottom = math.atan2(cone_norma_bottom.y(), cone_norma_bottom.x())

        # get angle between vectors
        total_angle = math.acos(
            QVector2D.dotProduct(cone_normal_top, cone_norma_bottom))
        part = total_angle / self.segments

        for i in range(self.segments):
            rad = math.atan2(self.light.dir.y(), self.light.dir.x())
            angle_i = rad - total_angle / 2.0 + (part * i)
            vector_i = QVector2D(math.cos(angle_i), math.sin(angle_i))
            ray_i = Ray(self.light.get_focal_point_worldspace(), vector_i)
            first_i = True
            self.rays.append(ray_i)

            for line in self.lines:
                intersect_v = self.does_ray_intersect(ray_i, line)

                if intersect_v:

                    length_i = (intersect_v - ray_i.pos).length()
                    if first_i:
                        ray_i.length = length_i
                        first_i = False
                    if length_i < ray_i.length:
                        ray_i.length = length_i
Ejemplo n.º 2
0
 def _closest_point(self, line, point):
     d = QVector2D(line.p2() - line.p1())
     d.normalize()
     v = QVector2D(point - line.p1())
     return line.p1() + (d * QVector2D.dotProduct(d, v)).toPoint()
Ejemplo n.º 3
0
 def reflect(self, point, normal):
     v = point - (normal * QVector2D.dotProduct(point, normal) * 2)
     v.normalize()
     return v