コード例 #1
0
    def teclado(self, direction):
        # Condicion para adelante
        if direction == "ADELANTE":
            self.posicion -= self.frontal * 0.1
            # debug ---->print(self.posicion)
            # Condicion para evitar de que el modelo desaparesca
            if self.posicion.z < 2:
                self.posicion = Vector3([0.0, 0.0, 30.0])

        # Condicion para atras
        if direction == "ATRAS":
            self.posicion += self.frontal * 0.1
            # debug ---->print(self.posicion)
            # Ciclo para evitar que desaparesca el modelo
            if self.posicion.z > 85:
                self.posicion = Vector3([0.0, 0.0, 30.0])

        # Condicion para la izquierda
        if direction == "IZQUIERDA":
            # Condicion para evitar de que el modelo desaparesca
            self.posicion += self.derecha * 0.1
            # debug ----> print(self.posicion)
            if self.posicion.x > 28:
                self.posicion = Vector3([0.0, 0.0, 30.0])

        # Condcion para la derecha
        if direction == "DERECHA":
            self.posicion -= self.derecha * 0.1
            # debug ---> print(self.posicion)
            # Condicion para evitar de que el modelo desaparesca
            if self.posicion.x < -25:
                self.posicion = Vector3([0.0, 0.0, 30.0])
コード例 #2
0
    def mouseMovimiento(self, xoffset, yoffset, detector=True):
        # Valores del mouse
        xoffset = xoffset * self.sensibilidad
        yoffset = yoffset * self.sensibilidad

        self.dataX = self.dataX + xoffset
        self.dataY = self.dataY + yoffset

        # Si detecta un mouse que tome los siguientes datos
        if detector:
            # Si el dato es mayor o menor al dato en y que tome los datos
            if (self.dataY > 45.0):
                self.dataY = 45.0
            if (self.dataY < -45.0):
                self.dataY = -45.0

        # Vector para la camara frontal
        front = Vector3([0.0, 0.0, 0.0])
        # Encontramos cada uno de los datos de la camara front tanto en x, y e z
        front.x = cos(radians(self.dataX)) * cos(radians(self.dataY))
        front.y = sin(radians(self.dataY))
        front.z = sin(radians(self.dataX)) * cos(radians(self.dataY))

        # Normalizamos el vector, para obtener datos cercanos
        # debug ---> print(self.frontal)
        self.frontal = vector.normalise(front)
        # debug ---> print(self.derecha)
        # debug ---> print(self.arriba)
        self.derecha = vector.normalise(
            vector3.cross(self.frontal, Vector3([0.0, 1.0, 0.0])))
        self.arriba = vector.normalise(
            vector3.cross(self.derecha, self.frontal))
コード例 #3
0
ファイル: test_examples.py プロジェクト: spprabhu/Pyrr
    def test_oo_examples(self):
        from pyrr import Quaternion, Matrix44, Vector3
        import numpy as np

        point = Vector3([1., 2., 3.])
        orientation = Quaternion()
        translation = Vector3()
        scale = Vector3([1., 1., 1.])

        # translate along X by 1
        translation += [1.0, 0.0, 0.0]

        # rotate about Y by pi/2
        rotation = Quaternion.from_y_rotation(np.pi / 2.0)
        orientation = rotation * orientation

        # create a matrix
        # start our matrix off using the scale
        matrix = Matrix44.from_scale(scale)

        # apply our orientation
        # we can multiply matricies and quaternions directly!
        matrix = matrix * orientation

        # apply our translation
        translation = Matrix44.from_translation(translation)
        matrix = matrix * translation

        # transform our point by the matrix
        # vectors are transformable by matrices and quaternions directly
        point = matrix * point
コード例 #4
0
 def __init__(self, window, inputEvents, shaderList, player):
     self.__position = Vector3((0.0, 4.0, 4.0))
     self.__front = Vector3((0.0, 0.0, -1.0))
     self.__up = Vector3((0.0, 1.0, 0.0))
     self.__FOV = self.__FOV_LIMIT
     self.__width = window.width
     self.__height = window.height
     self.__inputEvents = inputEvents
     self.__shaderList = shaderList
     self.__pitch = 20  # Rotation around X axis: look up and down
     self.__yaw = 0  # Rotation around Y axis: look left and right. yaw is initalized to -90 since a yaw of 0.0 results in a direction vector pointing to the right
     self.__distanceFromPlayer = self.__STARTING_DISTANCE_FROM_PLAYER
     self.__angleAroundPlayer = 0
     self.__viewMatrix = None
     self.__projectionMatrix = None
     self.__previousMouseMovement = False
     self.__lastCursorPosition = None
     self.__startingCoordinate = None
     self.__screen = Gdk.Screen.get_default()
     self.initialized = False
     self.__setWarp = False
     self.__warpCounter = 0
     self.__player = player
     self.__playerRunSpeed = player.getRunSpeed()
     self.__updatePlayerYaw = False
     self.__playerPosition = Vector3((0, 0, 0))
コード例 #5
0
ファイル: stepping.py プロジェクト: nanicalabs/Hexapod-IK
    def tick(self):
        # If we are not moving, check if we need to begin:
        if self.fr < 0 or self.step_pattern is None:
            return; 
            # We don't need to start, return doing nothing.
        
        # Yep, we still need keyframe based animation.
        ee_pos = self.leg.getEndEffectorPosition();
        if self.fr < self.liftoff_frame:
            if self.step_ee_pos is None:
                self.step_ee_pos = Vector3([ee_pos[0], ee_pos[1], 0.0]);
            self.mp.updateTarget({self.leg.getId(): {"schedule":"snapto", "target":self.step_ee_pos, "ref":worldRefFrame, "frames": 1}});
        elif self.fr == self.liftoff_frame:
            self.step_ee_pos = None;
            ee_pos = ee_pos + Vector3([0., 0., self.step_height]);
            self.mp.updateTarget({self.leg.getId(): {"schedule":"snapto", "target":ee_pos, "ref":worldRefFrame, "frames": 1}});
        elif self.fr > self.liftoff_frame:
            self.step_ee_pos = None;
            ee_pos = self.heuristicStep(self.step_pattern) + Vector3([0., 0., self.step_height]);
            self.mp.updateTarget({self.leg.getId(): {"schedule":"linear", "target":ee_pos, "ref":self.leg.world_ref, "frames": self.frames - self.fr}});
        else:
            print "Unreachable state";

        if not self.started and self.fr == 0:
            self.fr = -1;
        
        # Advance the clock:
        self.fr += 1;
        if self.fr == self.frames:
            self.fr = 0;
コード例 #6
0
    def __init__(
        self,
        position=Vector3([(0.0, 0.0, 4.0)]),
        front=Vector3([(0.0, 0.0, -4.0)]),
        up=Vector3([(0.0, 1.0, 0.0)]),
        dolly_step_size=0.5,
        pedestal_step_size=0.8,
        truck_step_size=0.8,
        mouse_sensitivity=0.3,
    ):

        self._position = position
        self._front = front
        self._up = up

        # keyboard control ### TODO: move into a keyboard camera class
        self._mouse_sensitivity = mouse_sensitivity

        self._first_mouse = True

        self._pitch = 0.0
        self._yaw = 0.0

        self._dolly_step_size = dolly_step_size
        self._pedestal_step_size = pedestal_step_size
        self._truck_step_size = truck_step_size
コード例 #7
0
 def generate_shapes(self, nodes):
   nodes = [Vector3(aNode) for aNode in nodes]
   theta = math.pi / 2
   quaternions = {}
   for i in range(4):
     quaternions[(i, 0, 0)] = Quaternion.from_x_rotation(i * theta)
     quaternions[(0, i, 0)] = Quaternion.from_y_rotation(i * theta)
     quaternions[(0, 0, i)] = Quaternion.from_z_rotation(i * theta)
   shapes = {}
   for x_rot in (3, 2, 1, 0):
     new_rotation = quaternions[(x_rot, 0, 0)]
     rotated_nodes_x = self.shape_constrained([new_rotation * aNode for aNode in nodes], zero_align=True)
     for y_rot in (3, 2, 1, 0):
       new_rotation = quaternions[(0, y_rot, 0)]
       rotated_nodes_y = self.shape_constrained([new_rotation * aNode for aNode in rotated_nodes_x], zero_align=True)
       for z_rot in (3, 2, 1, 0):
         new_rotation = quaternions[(0, 0, z_rot)]
         rotated_nodes = self.shape_constrained([new_rotation * aNode for aNode in rotated_nodes_y], zero_align=True)
         for x_shift in (2, 1, 0):
           for y_shift in (2, 1, 0):
             for z_shift in (-2, -1, 0):
               new_shift = Vector3([float(x_shift), float(y_shift), float(z_shift)])
               shifted_nodes = [new_shift + aNode for aNode in rotated_nodes]
               shape = self.shape_constrained(shifted_nodes)
               shape = frozenset([Cube(int(round(aNode.x)), int(round(aNode.y)), int(round(aNode.z))) for aNode in shape])
               shapes[shape] = (x_rot, y_rot, z_rot, x_shift, y_shift, z_shift)
   return shapes
コード例 #8
0
 def test_init_world_position(self):
     self.root.world_position = Vector3([1, 0, 0])
     child = Node3D()
     child.local_position = Vector3([1, 0, 0])
     self.root.add(child)
     # Child local position is now relative to parent
     self.assertEqual(0, child.local_position[0])
コード例 #9
0
    def __init__(self,
                 aspect_ratio,
                 fov_degrees=45,
                 near=1.0,
                 far=1000.0,
                 position=Vector3([(0.0, 0.0, 70.0)]),
                 front=Vector3([(0.0, 0.0, -4.0)]),
                 up=Vector3([(0.0, 1.0, 0.0)]),
                 dolly_step_size=0.5,
                 pedestal_step_size=0.8,
                 truck_step_size=0.8,
                 zoom_step_size=0.8):
        super().__init__(
            position,
            front,
            up,
            dolly_step_size,
            pedestal_step_size,
            truck_step_size,
        )

        # TODO check input
        self._fov_degrees = fov_degrees
        self._aspect_ratio = aspect_ratio
        self._near = near
        self._far = far

        self._zoom_step_size = zoom_step_size
コード例 #10
0
    def __init__(self,
                 width=1280,
                 height=720,
                 name='OpenGL Window',
                 cameraSpeed=0.1,
                 mouseSpeed=0.3,
                 invertMouse=False,
                 resizable=False,
                 vsync=False):
        super().__init__(width, height, name, resizable=resizable, vsync=vsync)
        self.cameraSpeed = cameraSpeed
        self.mouseSpeed = mouseSpeed
        self.invertMouse = invertMouse
        self.cameraPos = Vector3([0.0, 0.0, 0.0])
        self.cameraTarget = Vector3([0.0, 0.0, -1.0])
        self.cameraUp = Vector3([0.0, 1.0, 0.0])
        self.worldUp = Vector3([0.0, 1.0, 0.0])
        self.yaw = -90.0
        self.pitch = 0.0
        self.pressedKeys = []

        self.set_mouse_visible(False)
        self.set_exclusive_mouse(True)

        # Matrices
        self.projection = Matrix44.perspective_projection(
            45.0, width / height, 0.1, 1000.0)
        self.view = Matrix44.look_at(self.cameraPos, self.cameraTarget,
                                     self.cameraUp)
コード例 #11
0
 def generate_twig_from_file(self, filepath):
     f = open(filepath, 'r')
     for line in f:
         if line.startswith("sphere"):
             arr = line.split(" ")
             if len(arr) > 10:
                 self.needle_num += 1
                 zenith_rotation_angle = degree_to_rad(float(arr[13]))
                 azimuth_rotation_angle = degree_to_rad(float(arr[18]))
                 translate_vector = Vector3([float(arr[20]), float(arr[21]), float(arr[22])])
                 matrix = Matrix44.from_y_rotation(zenith_rotation_angle)
                 matrix = matrix * Matrix44.from_z_rotation(azimuth_rotation_angle)
                 matrix = matrix * Matrix44.from_translation(translate_vector)
                 # applying rotation
                 newNeedle_vertexes = list(map(lambda x: matrix * Vector3(x), self.prim_needle.vertexes))
                 self.vertexes += newNeedle_vertexes
     f.close()
     # generate twig
     r = math.pi * self.twig_diameter / 6.0
     lower_plane, upper_plane = [], []
     for i in range(0, 360, 60):
         angle_rad = degree_to_rad(i)
         x = r * math.cos(angle_rad)
         y = r * math.sin(angle_rad)
         lower_plane.append([x, y, 0])
         upper_plane.append([x, y, self.twig_length])
     self.twig_vertexes = lower_plane + upper_plane
コード例 #12
0
ファイル: camera.py プロジェクト: PlumpMath/demosys-py
    def __init__(self, fov=60, aspect=1.0, near=1, far=100):
        """
        Initialize camera using a specific projection

        :param fov: Field of view
        :param aspect: Aspect ratio
        :param near: Near plane
        :param far: Far plane
        """
        self.position = Vector3([0.0, 0.0, 0.0])
        # Default camera placement
        self.up = Vector3([0.0, 1.0, 0.0])
        self.right = Vector3([1.0, 0.0, 0.0])
        self.dir = Vector3([0.0, 0.0, -1.0])
        # Yaw and Pitch
        self.yaw = -90.0
        self.pitch = 0.0

        # World up vector
        self._up = Vector3([0.0, 1.0, 0.0])

        # Projection attributes
        self.projection = None
        self.fov = fov
        self.aspect = aspect
        self.near = near
        self.far = far
        self.set_projection()
コード例 #13
0
 def processData(data):
     if isinstance(data, Vector3):
         return data
     elif isinstance(data, list) and len(data) == 3:
         return Vector3(data)
     else:
         return Vector3()
コード例 #14
0
 def create_translations():
     InitShader.model_loc = glGetUniformLocation(InitShader.shader, b"model")
     # translation for the monkey, flattening on the second line because the rotation
     InitShader.monkey_model = matrix44.create_from_translation(Vector3([-2.0, 0.0, -3.0]))
     # translation for the cube
     InitShader.cube_model = matrix44.create_from_translation(Vector3([2.0, 0.0, -3.0])).flatten().astype("float32")
     InitShader.c_cube_model = numpy.ctypeslib.as_ctypes(InitShader.cube_model)
コード例 #15
0
ファイル: camera.py プロジェクト: zzf-technion/nn_vis
    def __init__(self,
                 width: float,
                 height: float,
                 base: Vector3,
                 move_speed: float = 0.1,
                 rotation: bool = False,
                 rotation_speed: float = -0.25):
        self.base: Vector3 = base
        self.camera_pos: Vector3 = self.base + Vector3([-3.0, 0.0, 0.0])
        self.camera_front: Vector3 = Vector3([1.0, 0.0, 0.0])
        self.camera_up: Vector3 = Vector3([0.0, 1.0, 0.0])
        self.camera_right: Vector3 = Vector3([0.0, 0.0, 1.0])

        self.move_vector: Vector3 = Vector3([0, 0, 0])
        self.move_speed: float = move_speed

        self.yaw: float = 0.0
        self.pitch: float = 0.0
        self.rotation_speed: float = rotation_speed

        self.projection: Matrix44 = pyrr.matrix44.create_perspective_projection_matrix(
            45, width / height, 0.1, 100)
        self.view: Matrix44 = self.generate_view_matrix()
        self.rotate_around_base: bool = rotation
        self.yaw_offset: float = 0.0
コード例 #16
0
    def __init__(self, ratio):
        # Camera speeds
        self._zoom_step = 0.2
        self._move_vertically = 0.001
        self._move_horizontally = 0.001
        self._rotate_horizontally = -0.02
        self._rotate_vertically = 0.02

        # Angle of rotation
        self.angle = 0

        # Distance back the camera moves
        self.dist = 0.1

        # Projection? In my camera? It's more likely than you think
        self._field_of_view_degrees = 60.0
        self._z_near = 0.01
        self._z_far = 35
        self._ratio = ratio
        self.build_projection()

        # What are you looking at? Huh?
        # I'm looking at a zebra
        self.camera_position = Vector3([-.1, 0.03,
                                        -.06])  #Default camera values
        self.camera_front = Vector3([0.0, 1.0, 0.0])
        self._camera_up = Vector3([0.0, 0.0, -1.0])
        self._cameras_target = (self.camera_position + self.camera_front)
        self.build_look_at()
コード例 #17
0
ファイル: flythrough.py プロジェクト: kkyong77/pyvistas
 def __init__(self,
              position=Vector3(),
              direction=Vector3(),
              up=Vector3([0, 1, 0])):
     self.position = position
     self.direction = direction
     self.up = up
コード例 #18
0
ファイル: camera.py プロジェクト: jsa4000/OpenGL-Python
    def __init__(self,
                 position=[0.0, 0.0, -3.0],
                 fov=70.0,
                 aspect=1.33,
                 near=0.01,
                 far=1000.0,
                 rect=None,
                 speed=0.05,
                 sensitivity=0.1):
        """

            orthorect is an array with the following values  [left, right, bottom, top]
        """
        # Create private members for the setters (properties)
        self._speed = speed
        self._sensitivity = sensitivity
        self._zoom = 0
        # View Matrix
        self.__position = Vector3(nparray(position))
        self.__target = Vector3(nparray([0.0, 0.0, 0.0]))
        self._forward = normalize(nparray([0.0, 0.0, 1.0]))
        self._up = normalize(nparray([0.0, 1.0, 0.0]))
        # Projection Matrix (Perspective and orthographic)
        self._fov = fov
        self._aspect = aspect
        self._rect = rect
        self._zNear = near
        self._zFar = far
        # Initiali<e variables
        self._initialize()
コード例 #19
0
def drawBox():
    vbo = ctx.buffer(vertices.astype('f4').tobytes())
    vao = ctx.simple_vertex_array(box_prog, vbo, 'in_vert', 'in_norm',
                                  'in_UVs')

    model = buildTransMatrix(rot=[0, time.clock() * 25,
                                  0])  # slowly rotate the cube
    box_prog['projection'].write(proj.astype('f4').tobytes())
    box_prog['view'].write(view.astype('f4').tobytes())
    box_prog['model'].write(model.astype('f4').tobytes())
    box_prog['viewPos'].write(cameraPos.astype('f4').tobytes())

    # light properties
    pos = lightPos
    amb = Vector3([0.2, 0.2, 0.2])
    diff = Vector3([0.7, 0.7, 0.7])
    spec = lightCol
    box_prog['light.position'].write(pos.astype('f4').tobytes())
    box_prog['light.ambient'].write(amb.astype('f4').tobytes())
    box_prog['light.diffuse'].write(diff.astype('f4').tobytes())
    box_prog['light.specular'].write(spec.astype('f4').tobytes())

    # material properties
    diff = Vector3([1.0, 0.5, 0.31])
    spec = Vector3([0.5, 0.5, 0.5])
    shine = 32.0
    box_prog['material.diffuse'].value = 0  # texture unit 0
    box_prog['material.specular'].value = 1  # texture unit 1
    box_prog['material.shininess'].value = shine

    vao.render()
コード例 #20
0
 def __init__(self):
     width = self.WINDOW_SIZE[0]
     height = self.WINDOW_SIZE[1]
     self.camera = PerspectiveCamera(fov=45,
                                     aspect=width / height,
                                     near=0.01,
                                     far=1000)
     scene = Scene(background_color=color.rgb["white"],
                   ambient_light=(0.2, 0.2, 0.2))
     light = PointLight(color=(0.8, 0.8, 0.8))
     light.world_position = Vector3([2, 2, 2])
     scene.add(light)
     self.cube_1 = CubeObject3D(1,
                                1,
                                1,
                                name="Cube_1",
                                color=(0.9, 0.5, 0.4))
     self.cube_2 = CubeObject3D(1,
                                1,
                                1,
                                name="Cube_2",
                                color=(0.5, 0.9, 0.4))
     self.cube_3 = CubeObject3D(1,
                                1,
                                1,
                                name="Cube_3",
                                color=(0.4, 0.5, 0.9))
     self.cube_1.add(self.cube_2)
     self.cube_2.add(self.cube_3)
     self.cube_2.local_position = Vector3([5., 0, 0])
     self.cube_3.local_position = Vector3([0, 3, 0])
     self.camera.local_position = Vector3([0, 0, 30])
     scene.add(self.cube_1)
     self.renderer = GLRenderer(scene, self.camera)
コード例 #21
0
 def shape_constrained(self, shape_nodes, zero_align=False):
   min_box = Vector3([100., 100., 100.])
   max_box = Vector3([-100., -100., -100.])
   for aNode in shape_nodes:
     min_box.x = round(min(min_box.x, aNode.x))
     min_box.y = round(min(min_box.y, aNode.y))
     min_box.z = round(min(min_box.z, aNode.z))
     max_box.x = round(max(max_box.x, aNode.x))
     max_box.y = round(max(max_box.y, aNode.y))
     max_box.z = round(max(max_box.z, aNode.z))
   
   offset = Vector3()
   if not zero_align:
     if min_box.x < 0: offset.x = float(min_box.x)
     elif max_box.x > 2: offset.x = float(max_box.x - 2.)
     if min_box.y < -6: offset.y = float(min_box.y + 6.)
     elif max_box.y > -4: offset.y = float(max_box.y + 4.)
     if min_box.z < -2: offset.z = float(min_box.z + 2.)
     elif max_box.z > 0: offset.z = float(max_box.z)
   else:
     offset.x = float(min_box.x)
     offset.y = float(min_box.y + 6.)
     offset.z = float(max_box.z)
     
   return [aNode - offset for aNode in shape_nodes]
コード例 #22
0
def from_spherical(r, t, p):
    """Creating cartesian coord. vector (r:[float] radius ; t:[float] theta(radians) ; p:[float] phi (radians))  return: vector3"""
    if not r: return Vector3()
    sin_p = np.sin(p)
    x = r * np.cos(t) * sin_p
    y = r * np.sin(t) * sin_p
    z = r * np.cos(p)
    return Vector3([x, y, z])
コード例 #23
0
ファイル: test_opengl.py プロジェクト: jsa4000/OpenGL-Python
 def _initialize(self):
     # Create default transformations: position, rotation and scale
     if self.position is None:
         self.position = Vector3([0.0, 0.0, 0.0])
     if self.rotation is None:
         self.rotation = Vector3([0.0, 0.0, 0.0])
     if self.scale is None:
         self.scale = Vector3([1.0, 1.0, 1.0])
コード例 #24
0
    def test_parameters_as_angles_deg_to_rad_array(self):
        @parameters_as_angles_deg_to_rad('angle')
        def test(angle, result):
            np.testing.assert_almost_equal(np.array(angle),
                                           np.array(result),
                                           decimal=5)

        test(Vector3([45, 0, -280]), Vector3([0.785398, 0, -4.88692]))
コード例 #25
0
    def __init__(self):

        mesh = ObjLoader()
        mesh.load_model("../models/monkey.obj")

        num_verts = len(mesh.model_vertices) // 3

        self.batch = pyglet.graphics.Batch()
        self.verts = self.batch.add(num_verts, GL_TRIANGLES, None,
                                    ('v3f', mesh.model_vertices),
                                    ('t2f', mesh.model_textures))

        shader = ShaderLoader.compile_shader("shaders/video_13_vert.glsl",
                                             "shaders/video_13_frag.glsl")

        glUseProgram(shader)

        # vertices
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, self.verts.vertices)
        glEnableVertexAttribArray(0)
        # textures
        glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0,
                              self.verts.tex_coords)
        glEnableVertexAttribArray(1)

        projection = matrix44.create_perspective_projection_matrix(
            45.0, 1280 / 720, 0.1, 100.0).flatten().astype("float32")
        view = matrix44.create_from_translation(Vector3(
            [0.0, 0.0, -2.0])).flatten().astype("float32")
        self.translation = matrix44.create_from_translation(
            Vector3([0.0, 0.0, -2.0]))

        c_projection = numpy.ctypeslib.as_ctypes(projection)
        c_view = numpy.ctypeslib.as_ctypes(view)

        view_loc = glGetUniformLocation(shader, b"view")
        proj_loc = glGetUniformLocation(shader, b"projection")
        self.model_loc = glGetUniformLocation(shader, b"model")

        glUniformMatrix4fv(view_loc, 1, GL_FALSE, c_view)
        glUniformMatrix4fv(proj_loc, 1, GL_FALSE, c_projection)

        # region texture settings and loading
        texture = GLuint(0)
        glGenTextures(1, texture)
        glBindTexture(GL_TEXTURE_2D, texture)
        # set the texture wrapping
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
        # set the texture filtering
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
        # endregion

        image = pyglet.image.load('../models/monkey.jpg')
        image_data = image.get_data('RGB', image.pitch)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.width, image.height, 0,
                     GL_RGB, GL_UNSIGNED_BYTE, image_data)
コード例 #26
0
    def compute_bbox_coords(self, model, mesh, view):
        center = mesh['center']
        world_corners = {
            'top_left': model * Vector3([
                center[0] - mesh['width']/2,
                center[1],
                center[2] + mesh['height']/2
            ]),
            'top_right': model * Vector3([
                center[0] + mesh['width']/2,
                center[1],
                center[2] + mesh['height']/2
            ]),
            'bottom_right': model * Vector3([
                center[0] + mesh['width']/2,
                center[1],
                center[2] - mesh['height']/2
            ]),
            'bottom_left': model * Vector3([
                center[0] - mesh['width']/2,
                center[1],
                center[2] - mesh['height']/2
            ])
        }
        hidden_corners = 0
        left = right = top = bottom = None

        for key, value in world_corners.items():
            img_coords = self.project_to_img_frame(value, view)
            if (img_coords[0] < 10 or img_coords[0] > (self.width-10)
                    or img_coords[1] < 10 or img_coords[1] > (self.height-10)):
                hidden_corners += 1
            if left is None or (img_coords[0] < left['x']):
                left = {'x': img_coords[0], 'y': img_coords[1]}
            if top is None or (img_coords[1] < top['y']):
                top = {'x': img_coords[0], 'y': img_coords[1]}
            if bottom is None or (img_coords[1] > bottom['y']):
                bottom = {'x': img_coords[0], 'y': img_coords[1]}
            if right is None or (img_coords[0] > right['x']):
                right = {'x': img_coords[0], 'y': img_coords[1]}

        image_corners = {
            'min': [int(left['x']), int(top['y'])],
            'max': [int(right['x']), int(bottom['y'])]
        }

        if hidden_corners > 3:
            return {}
        elif hidden_corners > 0:
            for key, img_coords in image_corners.items():
                for i in range(0,2):
                    if img_coords[i] < 0:
                        img_coords[i] = 0
                    elif img_coords[i] > (self.width if i == 0 else self.height):
                        img_coords[i] = self.width if i == 0 else self.height
                image_corners[key] = img_coords

        return image_corners
コード例 #27
0
 def __init__(self,
              Position=Vector3([0, 0, 0]),
              Velocity=Vector3([0, 0, 0]),
              Color=Vector4([1., 1., 1., 1.]),
              Life=0.):
     self.Position = Position
     self.Velocity = Velocity
     self.Color = Color
     self.Life = Life
コード例 #28
0
ファイル: Camera.py プロジェクト: sdevkota007/SolarSystem
    def update_camera_vectors(self):
        front = Vector3([0.0, 0.0, 0.0])
        front.x = cos(radians(self.yaw)) * cos(radians(self.pitch))
        front.y = sin(radians(self.pitch))
        front.z = sin(radians(self.yaw)) * cos(radians(self.pitch))

        self.camera_front = vector.normalise(front)
        self.camera_right = vector.normalise(vector3.cross(self.camera_front, Vector3([0.0, 1.0, 0.0])))
        self.camera_up = vector.normalise(vector3.cross(self.camera_right, self.camera_front))
コード例 #29
0
    def __init__(self):
        self.camera_pos = Vector3([0.0, 0.0, 3.0])
        self.camera_front = Vector3([0.0, 0.0, -1.0])
        self.camera_up = Vector3([0.0, 1.0, 0.0])
        self.camera_right = Vector3([1.0, 0.0, 0.0])

        self.mouse_sensitivity = 0.25
        self.yaw = -90.0
        self.pitch = 0.0
コード例 #30
0
    def __init__(self, data):
        self.pos = Vector3([0.0, 8.0, 2.0])
        self.right = Vector3([1.0, 0.0, 0.0])
        self.up = Vector3([0.0, 0.0, 1.0])
        self.front = Vector3([0.0, 1.0, 0.0])

        self.mouse_sensitivity = 0.1
        self.jaw = -90
        self.pitch = 0