Example #1
0
 def __init__(self,
              color=Rgb(),
              pos=Vector([0, 0, 0]),
              axis=Vector([1.0, 0.0, 0.0]),
              radius=1.0,
              material=Material(),
              other=None):
     """
     :param radius: The sphere's radius.
     :type radius: float
     :param color: The object's color.
     :type color: pyglet_helper.util.Rgb
     :param pos: The object's position.
     :type pos: pyglet_helper.util.Vector
     :param axis: The cone points from the base to the point along the axis.
     :type axis: pyglet_helper.util.Vector
     :param material: The object's material
     :type material: pyglet_helper.util.Material
     :param other: another sphere object to copy properties from (optional)
     :type other: pyglet_helper.objects.Sphere
     """
     super(Sphere, self).__init__(color=color,
                                  pos=pos,
                                  radius=radius,
                                  material=material,
                                  axis=axis)
     # Construct a unit sphere at the origin.
     if other is not None:
         self.axial = other
     self.compiled = False
Example #2
0
def test_pyramid_center():
    from pyglet_helper.objects import Pyramid
    from pyglet_helper.util import Vector
    blo = Pyramid(pos=Vector([10, 0, 0]), axis=Vector([-1, 0, 0]), height=30)
    assert (blo.center[0] == 0)
    assert (blo.center[1] == 0)
    assert (blo.center[2] == 0)
    def __init__(self,
                 height=1.0,
                 width=1.0,
                 length=1.0,
                 color=Rgb(),
                 pos=Vector([0, 0, 0]),
                 axis=Vector([1.0, 0.0, 0.0])):
        """

        :param width: The ellipsoid's width.
        :type width: float
        :param height: The ellipsoid's height.
        :type height: float
        :param length: The ellipsoid's length.
        :type length: float
        :param color: The object's color.
        :type color: pyglet_helper.util.Rgb
        :param pos: The object's position.
        :type pos: pyglet_helper.util.Vector
        """
        super(Ellipsoid, self).__init__(color=color, pos=pos, axis=axis)
        self._height = None
        self._width = None
        self.height = height
        self.width = width
        self.length = length
Example #4
0
 def __init__(self,
              axis=Vector([1, 0, 0]),
              pos=Vector([0, 0, 0]),
              width=1.0,
              height=1.0,
              length=1.0,
              color=Rgb(),
              other=None):
     """
     :param color: The object's color.
     :type color: pyglet_helper.util.Rgb
     :param pos: The object's position.
     :type pos: pyglet_helper.util.Vector
     :param width: The object's width.
     :type width: float
     :param height: The object's height.
     :type height: float
     :param length: The object's length.
     :type length: float
     """
     super(Rectangular, self).__init__(color=color, pos=pos, axis=axis)
     self._height = None
     self._width = None
     if other is None:
         self.width = width
         self.height = height
     else:
         self.width = other.width
         self.height = other.height
     self.length = length
Example #5
0
    def __init__(self,
                 axis=Vector([1, 0, 0]),
                 radius=1.0,
                 color=Rgb(),
                 pos=Vector([0, 0, 0]),
                 material=Material(),
                 other=None):
        """

        :param other: another axial object to copy properties from (optional)
        :type other: pyglet_helper.objects.Axial
        :param axis: The axis for the orientation of the object.
        :type axis: pyglet_helper.util.Vector
        :param radius: The object's radius.
        :type radius: float
        :param color: The object's color.
        :type color: pyglet_helper.util.Rgb
        :param pos: The object's position.
        :type pos: pyglet_helper.util.Vector
        :param material: The object's material
        :type material: pyglet_helper.util.Material
        """
        super(Axial, self).__init__(color=color,
                                    pos=pos,
                                    axis=axis,
                                    material=material)
        self._radius = None
        if other is not None:
            self.radius = other.radius
        else:
            self.radius = radius
def test_arrow_center():
    from pyglet_helper.objects import Arrow
    from pyglet_helper.util import Vector
    blo = Arrow(pos=Vector([-10, -10, -10]), axis=Vector([10, 10, 10]))
    assert (blo.center[0] == 0)
    assert (blo.center[1] == 0)
    assert (blo.center[2] == 0)
Example #7
0
def test_pyramid_material_matrix():
    from pyglet_helper.objects import Pyramid
    from pyglet_helper.util import Vector
    blo = Pyramid(pos=Vector([10, 0, 0]), axis=Vector([-1, 0, 0]), height=40)
    assert (blo.material_matrix[0, 0] == 0.025)
    assert (blo.material_matrix[1, 1] == 0.025)
    assert (blo.material_matrix[2, 2] == 0.025)
    assert (blo.material_matrix[3, 3] == 1.0)
def test_vector_mult():
    from pyglet_helper.util import Vector
    vec1 = Vector([1.0, 0, 2.0])
    vec2 = Vector([0, 1.0, 0.5])
    vec3 = vec1 * vec2
    assert vec3[0] == 0
    assert vec3[1] == 0
    assert vec3[2] == 1.0
def test_vector_scale():
    from pyglet_helper.util import Vector
    vec1 = Vector([1.0, 0, 2.0])
    vec2 = Vector([0, 1.0, 1.0])
    vec3 = vec1.scale(vec2)
    print(vec3)
    assert vec3[0] == 0
    assert vec3[2] == 2.0
Example #10
0
def test_cylinder_center():
    from pyglet_helper.objects import Cylinder
    from pyglet_helper.util import Vector
    blo = Cylinder(radius=0.0,
                   pos=Vector([0, -0.5, 0]),
                   axis=Vector([0, 1, 0]))
    assert (abs(blo.center[0]) < 1e-7)
    assert (blo.center[1] == 0)
    assert (blo.center[2] == 0)
def test_vector_rotate():
    from pyglet_helper.util import Vector
    vec1 = Vector([1.0, 0, 2.0])
    vec2 = Vector([0, 1.0, 1.0])
    vec3 = vec1.rotate(angle=1.0, axis=vec2)
    assert abs(vec3[0] - 2.73032198493) < 0.01
    assert vec3[3] == 1.0
    vec3 = vec1.rotate(angle=1.0)
    assert vec3[2] == 3.0
    assert vec3[3] == 1.0
Example #12
0
 def material_matrix(self):
     """
     Creates a transformation matrix scaled to the size of the torus
     :return: the transformation matrix
     :return: pyglet_helper.util.Tmatrix
     """
     out = Tmatrix()
     out.translate(Vector([.5, .5, .5]))
     out.scale(Vector([self.radius, self.radius, self.radius]) *
               (.5 / (self.radius + self.thickness)))
     return out
def test_vector_diff_angle():
    from pyglet_helper.util import Vector
    vec1 = Vector([1.0, 1.0, 1.0])
    vec2 = Vector([1.0, 1.0, 1.0])
    result = vec1.diff_angle(vec2)
    print(result)
    assert result == 0.0
    vec1 = Vector([1.0, 1.0, 1.0])
    vec2 = Vector([-1.0, -1.0, -1.0])
    result = vec1.diff_angle(vec2)
    print(result)
    assert result == 3.141592653589793
Example #14
0
 def material_matrix(self):
     """
     Creates a transformation matrix for pyramid objects
     :return: the transformation matrix
     :rtype: pyglet_helper.util.Tmatrix
     """
     out = Tmatrix()
     out.translate(Vector([0, .5, .5]))
     scale = Vector([self.axis.mag(), self.height, self.width])
     out.scale(Vector([self.scale,self.scale,self.scale]) *
               (1.0 /max(scale.x_component, max(scale.y_component,
                                           scale.z_component))))
     return out
Example #15
0
 def material_matrix(self):
     """
     Creates a transformation matrix scaled to the size of the axial object
     :return: the transformation matrix
     :return: pyglet_helper.util.Tmatrix
     """
     out = Tmatrix()
     out.translate(Vector([.0005, .5, .5]))
     out.scale(
         self.scale *
         (.999 / max(self.scale.x_component, self.scale.y_component * 2)))
     out_vector = Vector([0, 1, 0])
     out_vector = out_vector.rotate(angle=.5 * pi)
     out = out * out_vector
     return out
Example #16
0
    def pixel_coverage(self, pos, radius):
        """ Compute the apparent diameter, in pixels, of a circle that is
        parallel to the screen, with a center at pos, and some radius.  If pos
        is behind the camera, it will return negative.

        :param pos: The position in the view to examine
        :type pos: pyglet_helper.util.Vector
        :param radius: The radius of coverage to examine
        :type radius: float
        :return: The diameter in pixels.
        :rtype: float
        """
        # The distance from the camera to this position, in the direction of 
        # the camera.  This is the distance to the viewing plane that the 
        # coverage circle lies in.

        pos = Vector(pos)
        dist = (pos - self.camera).dot(self.forward)
        # Half of the width of the viewing plane at this distance.
        apparent_hwidth = self.tan_hfov_x * dist
        # The fraction of the apparent width covered by the coverage circle.
        if apparent_hwidth == 0:
            coverage_fraction = 1
        else:
            coverage_fraction = radius / apparent_hwidth
        # Convert from fraction to pixels.
        return coverage_fraction * self.view_width
Example #17
0
def on_draw():
    global screennum
    scene.setup()
    spin = Vector([sin(rx) * cos(ry), sin(rx) * sin(ry), cos(rx)])
    _ellipsoid.axis = _ellipsoid.length * spin
    _ellipsoid.render(scene)

    # The sphere will look the same from all angles, so rotating it doesn't make sense
    _ball.render(scene)

    _pyramid.axis = _pyramid.length * spin
    _pyramid.render(scene)

    _box.axis = _box.length * spin
    _box.render(scene)

    _cylinder.axis = _cylinder.length * spin
    _cylinder.render(scene)

    _arrow.axis = _arrow.length * spin
    _arrow.render(scene)

    _cone.axis = _cone.length * spin
    _cone.render(scene)

    _ring.axis = spin
    _ring.render(scene)
    if screennum < 99:
        path = os.path.dirname(__file__)
        filename = os.path.join(path, 'screenshot%02d.png' % (screennum, ))
        get_buffer_manager().get_color_buffer().save(filename)
        screennum += 1
def test_arrow_shaft_width():
    from pyglet_helper.objects import Arrow
    from pyglet_helper.util import Vector
    blo = Arrow(shaft_width=0.75)
    assert (blo.shaft_width == 0.75)
    blo = Arrow(axis=Vector([10.0, 0, 0]))
    assert (blo.shaft_width == 1.0)
Example #19
0
def test_primitive_center():
    from pyglet_helper.objects import Primitive
    from pyglet_helper.util import Vector
    _primitive = Primitive(pos=Vector([-1, 0, 1]))
    assert _primitive.center[0] == -1
    assert _primitive.center[1] == 0
    assert _primitive.center[2] == 1
Example #20
0
 def scale(self):
     """
     Gets the scaling factor of the ellipsoid (1/2 of the size)
     :return: the scaling factors
     :rtype: pyglet_helper.util.Vector
     """
     return Vector([self.axis.mag(), self.height, self.width]) * 0.5
Example #21
0
 def size(self):
     """
     Gets a vector with the object's scale along the x, y, and z axes
     :return: a vector with the scales
     :rtype: pyglet_helper.util.Vector
     """
     return Vector([self.axis.mag(), self.height, self.width])
def test_vector_set_mag():
    from pyglet_helper.util import Vector
    vec1 = Vector([1.0, 0, 2.0])
    vec1.set_mag(0.1)
    print(vec1)
    assert vec1[0] == 0.044721359549995794
    assert vec1[1] == 0
Example #23
0
def test_view_pixel_coverage():
    from pyglet_helper.objects import View
    from pyglet_helper.util import Vector
    scene = View()
    pix_coverage = scene.pixel_coverage(pos=Vector([10, 0, 0]), radius=0.2)
    print(pix_coverage)
    assert (pix_coverage == 800.0)
def test_vector_clear():
    from pyglet_helper.util import Vector
    vec1 = Vector([1.0, 0, 2.0])
    vec1.clear()
    assert vec1[0] == 0.0
    assert vec1[1] == 0.0
    assert vec1[2] == 0.0
Example #25
0
    def render(self, scene):
        """Add the cone to the scene.

        :param scene: The view to render the model into
        :type scene: pyglet_helper.objects.View
        """
        if self.radius == 0:
            return

        self.init_model(scene)

        coverage_levels = [10, 30, 90, 250, 450]
        lod = self.lod_adjust(scene, coverage_levels, self.pos, self.radius)

        length = self.axis.mag()
        gl.glPushMatrix()
        self.model_world_transform(scene.gcf,
                                   Vector([length, self.radius,
                                           self.radius])).gl_mult()

        self.color.gl_set(self.opacity)
        if self.translucent:
            gl.glEnable(gl.GL_CULL_FACE)

            # Render the back half.
            gl.glCullFace(gl.GL_FRONT)
            scene.cone_model[lod].gl_render()

            # Render the front half.
            gl.glCullFace(gl.GL_BACK)
            scene.cone_model[lod].gl_render()
        else:
            scene.cone_model[lod].gl_render()
        gl.glPopMatrix()
Example #26
0
 def pos(self, n_pos):
     """
     Set the object's position with a Vector
     :param n_pos: a vector with the object's new position
     :type n_pos: pyglet_helper.util.Vector
     :return:
     """
     self._pos = Vector(n_pos)
Example #27
0
 def center(self):
     """
     Gets the light's center. Since the light is not a physical object,
     this will always be an empty vector
     :return: the light's center
     :rtype: pyglet_helper.util.Vector
     """
     return Vector()
def test_vector_set_index():
    from pyglet_helper.util import Vector
    vec1 = Vector([1.0, 0, 2.0])
    vec1[0] = -1.0
    vec1[1] = -2.0
    vec1[2] = -3.0
    assert vec1.x_component == -1.0
    assert vec1.y_component == -2.0
    assert vec1.z_component == -3.0
Example #29
0
 def __init__(self, axis=Vector([1, 0, 0]), pos=Vector([0, 0, 0]),
              width=1.0, height=1.0, length=1.0, color=Rgb()):
     """
     :param color: The object's color.
     :type color: pyglet_helper.util.Rgb
     :param pos: The object's position.
     :type pos: pyglet_helper.util.Vector
     :param width: The pyramid's width.
     :type width: float
     :param height: The pyramid's height.
     :type height: float
     :param length: The pyramid's length.
     :type length: float
     :return:
     """
     super(Pyramid, self).__init__(axis=axis, pos=pos, color=color,
                                   width=width, height=height,
                                   length=length)
     self.compiled = False
Example #30
0
    def __init__(self,
                 radius=1.0,
                 color=Rgb(),
                 pos=Vector([0, 0, 0]),
                 axis=Vector([1, 0, 0])):
        """

        :param radius: The cone's bottom radius.
        :type radius: float
        :param color: The object's color.
        :type color: pyglet_helper.util.Rgb
        :param pos: The object's position.
        :type pos: pyglet_helper.util.Vector
        :param axis: The cone points from the base to the point along the axis.
        :type axis: pyglet_helper.util.Vector
        :return:
        """
        super(Cone, self).__init__(radius=radius, color=color, pos=Vector(pos))
        self.axis = Vector(axis)