Example #1
0
def test_rgb_grayscale():
    from pyglet_helper.util import Rgb
    blo = Rgb(red=0.5, blue=0.9, green=0.1)
    blo.rgb = 0.2
    assert blo[0] == 0.2
    assert blo[1] == 0.2
    assert blo[2] == 0.2
Example #2
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 #3
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 __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 #5
0
def test_rgb_rgb():
    from pyglet_helper.util import Rgb
    blo = Rgb(color=[0.1, 0.2, 0.3])
    tup = blo.rgb
    assert(tup[0]==0.1)
    assert(tup[1]==0.2)
    assert(tup[2]==0.3)
Example #6
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 #7
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)
Example #8
0
    def __init__(self, width=1.0, height=1.0, length=1.0, color=Rgb(),
                 pos=Vector([0, 0, 0])):
        """

        :param width: The box's width.
        :type width: float
        :param height: The box's height.
        :type height: float
        :param length: The box'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(Box, self).__init__(width=width, height=height, color=color,
                                  length=length, pos=pos)
        self.initialized = False
        self.skip_right_face = False
Example #9
0
    def __init__(self,
                 fixed_width=False,
                 head_width=0.0,
                 head_length=0.0,
                 shaft_width=0.0,
                 color=Rgb(),
                 pos=Vector([0, 0, 0]),
                 axis=(1, 0, 0)):
        """

        :param fixed_width: if True, the arrow's head width and length will not
         be scaled in proportion to its length.
        :type fixed_width: bool
        :param head_width: The width of the arrow's head section.
        :type head_width: float
        :param head_length: The length of the arrow's length section
        :type head_length: float
        :param shaft_width: The length of the arrow's shaft section
        :type shaft_width: float
        :param color: The arrow's color.
        :type color: pyglet_helper.util.Rgb
        :param pos: The arrow's position
        :type pos: pyglet_helper.util.pos
        :param axis: The arrow's axis direction
        :type axis: pyglet_helper.util.Vector
        """
        super(Arrow, self).__init__(color=color, pos=pos, axis=axis)
        # True if the width of the point and shaft should not vary with the
        # length
        # of the arrow.
        self.fixed_width = fixed_width
        self._head_width = None
        self._head_length = None
        self._shaft_width = None
        self._fixed_width = None
        # If zero, then use automatic scaling for the width's of the parts of
        # the arrow.  If nonzero, they specify proportions for the arrow in
        # world space.
        self.head_width = head_width
        self.head_length = head_length
        self.shaft_width = shaft_width
        self.box = None
        self.pyramid = None
Example #10
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 #11
0
    def __init__(self,
                 pos=Vector([0, 0, 0]),
                 axis=Vector([1, 0, 0]),
                 radius=1.0,
                 color=Rgb(0, 0, 0)):
        """

        :param radius: The cylinder'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
        """
        super(Cylinder, self).__init__(pos=pos,
                                       radius=radius,
                                       color=color,
                                       axis=axis)
Example #12
0
 def __init__(self, color=Rgb(), mat=Material(), opacity=1.0,
              visible=False):
     """
     :param color: The object's color.
     :type color: pyglet_helper.util.Rgb
     :param material: The object's material
     :type material: pyglet_helper.util.Material
     :param opacity: The transparency value of the object
     :type opacity: float
     :param visible: If True, the object will be rendered on the screen
     :type visible: bool
     """
     # The base color of this body.  Ignored by the variable-color 
     # composites (curve, faces, frame).
     self.color = color
     # Fully opaque is 1.0, fully transparent is 0.0:
     self.opacity = opacity
     # True if the object should be rendered on the screen.
     self.visible = visible
     self.mat = mat
Example #13
0
    def __init__(self, color=Rgb(), specular=(.5, .5, 1, 0.5),
                 diffuse=(1, 1, 1, 1), position=(1, 0.5, 1, 0)):
        """

        :param color: The object's color.
        :type color: pyglet_helper.util.Rgb
        :param specular: The color of the specular reflections on the objects
        in the scene.
        :type specular: array_like
        :param diffuse: The color of the diffuse reflections of the objects in
        the scene.
        :type position: array_like
        :param position: The object's position.
        :type position: array_like
        """
        super(Light, self).__init__(color=color)
        self.color = None
        self.rgb = color
        self.specular = (gl.GLfloat * 4)(*specular)
        self.diffuse = (gl.GLfloat * 4)(*diffuse)
        self.position = (gl.GLfloat * 4)(*position)
Example #14
0
    def __init__(self, thickness=0.0, radius=1.0, color=Rgb(),
                 pos=Vector([0, 0, 0]), axis=Vector([1, 0, 0])):
        """

        :param thickness: The ring's thickness.
        :type thickness: float
        :param radius: The ring'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
        """
        super(Ring, self).__init__(radius=radius, color=color, pos=pos,
                                   axis=axis)
        self._thickness = None
        self.list = None
        self.axis = axis
        # The radius of the ring's body.  If not specified, it is set to 1/10
        # of the radius of the body.
        self.thickness = thickness
Example #15
0
    def __init__(self,
                 axis=Vector([1, 0, 0]),
                 up_vector=Vector([0, 1, 0]),
                 pos=Vector([0, 0, 0]),
                 obj_initialized=False,
                 color=Rgb(),
                 material=Material()):
        """

        :param axis: The orientation to use when drawing.
        :type axis: pyglet_helper.util.Vector
        :param up_vector: A vector that points to the current up direction in
        the view.
        :type up_vector: pyglet_helper.util.Vector
        :param pos: The object's position.
        :type pos: pyglet_helper.util.Vector
        :param obj_initialized: If True, the object has been initialized
        :type obj_initialized: bool
        :param color: The object's color.
        :type color: pyglet_helper.util.Rgb
        :param material: The object's material
        :type material: pyglet_helper.util.Material
        """
        super(Primitive, self).__init__(color=color, mat=material)
        self._axis = None
        self._pos = None
        self._up = None
        self._width = None
        self._height = None

        self.startup = True
        self.obj_initialized = obj_initialized

        # position must be defined first, before the axis
        self.up_vector = Vector(up_vector)
        self.pos = Vector(pos)
        self.axis = Vector(axis)
Example #16
0
def test_rgb_get_error():
    from pyglet_helper.util import Rgb
    blo = Rgb()
    print(blo[3])
Example #17
0
def test_rgb_set_error():
    from pyglet_helper.util import Rgb
    blo = Rgb()
    blo[3] = 1.0
Example #18
0
    def __init__(self, gcf=1.0, view_width=800, view_height=600,
                 anaglyph=False, coloranaglyph=False, forward_changed=False,
                 gcf_changed=False, lod_adjust=0, tan_hfov_x=0, tan_hfov_y=0,
                 enable_shaders=True, background_color=Rgb()):
        """
        :param gcf: The global scaling factor, a coefficient applied to all 
        objects in the view
        :type gcf: float
        :param view_width: The width of the viewport in pixels.
        :type view_width: int
        :param view_height: The height of the viewport in pixels.
        :type view_height: int
        :param anaglyph: If True, the scene will be rendered in anaglyph stereo
         mode.
        :type anaglyph: bool
        :param coloranaglyph: If True, the scene will be rendered in 
        coloranaglyph stereo mode.
        :type coloranaglyph: bool
        :param forward_changed: True if the forward vector changed since the 
        last rending operation.
        :type forward_changed: bool
        :param gcf_changed: True if the global scaling factor changed since 
        the last render cycle.
        :type gcf_changed: bool
        :param lod_adjust: The level-of-detail.
        :type lod_adjust: int
        :param tan_hfov_x: The tangent of half the horizontal field of view.
        :type tan_hfov_x: int
        :param tan_hfov_y: The tangent of half the vertical field of view.
        :type tan_hfov_y: int
        :param enable_shaders: If True, shader programs will be allowed
        :type enable_shaders: bool
        :param background_color: The scene's background color
        :type background_color: pyglet_helper.util.Rgb
        """
        # The position of the camera in world space.
        self.camera = Vector()
        # The direction the camera is pointing - a unit vector.
        self.forward = Vector()
        # The center of the scene in world space.
        self.center = Vector()
        # The true up direction of the scene in world space.
        self.up_vector = Vector()
        self.view_width = view_width
        self.view_height = view_height
        self.forward_changed = forward_changed
        self.gcf = gcf
        # The vector version of the Global Scaling Factor, for scene.uniform=0
        self.gcfvec = Vector()
        self.gcf_changed = gcf_changed
        self.lod_adjust = lod_adjust
        self.anaglyph = anaglyph
        self.coloranaglyph = coloranaglyph
        self.tan_hfov_x = tan_hfov_x
        self.tan_hfov_y = tan_hfov_y

        self.box_model = DisplayList()
        self.sphere_model = [DisplayList()] * 6
        self.cylinder_model = [DisplayList()] * 6
        self.cone_model = [DisplayList()] * 6
        self.pyramid_model = DisplayList()

        self.camera_world = Tmatrix()

        self.background_color = background_color
        self.lights = []

        self.enable_shaders = enable_shaders
        self.screen_objects = []
        self.is_setup = False
        self.setup()
Example #19
0
def test_rgb_str():
    from pyglet_helper.util import Rgb
    blo = Rgb(color=[0.5, 0.5, 0.5])
    assert str(blo) == 'color: r0.5 g0.5 b0.5'
Example #20
0
def test_rgb_get_set():
    from pyglet_helper.util import Rgb
    blo = Rgb(red=0.5, blue=0.9, green=0.1)
    assert blo[0] == 0.5
    assert blo[2] == 0.9
    assert blo[1] == 0.1
Example #21
0
def test_rgb_length_error():
    from pyglet_helper.util import Rgb
    Rgb(color=[1, 1, 1, 1, 1])