예제 #1
0
파일: UtilTest.py 프로젝트: NCCA/NGL
 def testPerspectiveFOV(self) :
   fov=45.0
   near=0.02
   far=10.0
   aspect=1024.0/720.0
   width=1024
   height=720
   perspNGL=pyngl.perspectiveFov(fov,width,height,near,far)
   perspGLM=glm.perspectiveFov(pyngl.radians(fov),width,height,near,far)
   self.assertTrue(self.glmToNGL(perspGLM)==perspNGL)
예제 #2
0
 def testPerspectiveFOV(self):
     fov = 45.0
     near = 0.02
     far = 10.0
     aspect = 1024.0 / 720.0
     width = 1024
     height = 720
     perspNGL = pyngl.perspectiveFov(fov, width, height, near, far)
     perspGLM = glm.perspectiveFov(pyngl.radians(fov), width, height,
                                   near, far)
     self.assertTrue(self.glmToNGL(perspGLM) == perspNGL)
예제 #3
0
    def _calc_projection(self):
        asp = self.width / self.height

        if self._projection == "o":
            proj = glm.ortho(-3, 3, -3, 3, -30, 30)
        elif self._projection == "p":
            proj = glm.perspectiveFov(self.fov, self.width, self.height, 0.01,
                                      100.)

        proj = glm.translate(proj, glm.vec3(0, 0, -4))

        self.projection_matrix = proj
예제 #4
0
    def _calc_matrix(self):
        sc = 11
        asp = self.width / self.height

        # projection

        if self.projection in "it":
            ysc = sc / asp
            proj = glm.ortho(-sc, sc, -ysc, ysc, self._near, self._far)
        elif self.projection == "o":
            ysc = sc / asp * .75
            proj = glm.ortho(-sc, sc, -ysc, ysc, self._near, self._far)
        elif self.projection == "p":
            proj = glm.perspectiveFov(1., self.width, self.height, self._near,
                                      self._far)
            proj = glm.translate(proj, glm.vec3(0, 0, -5))
        else:  # "e"
            proj = glm.perspectiveFov(2., self.width, self.height, self._near,
                                      self._far)

        self._mat_project = proj

        # transformation

        trans = glm.rotate(glm.mat4(1), self._srotation[0], glm.vec3(1, 0, 0))
        trans = glm.rotate(trans, self._srotation[1], glm.vec3(0, 1, 0))
        trans = glm.rotate(trans, self._srotation[2], glm.vec3(0, 0, 1))
        trans = glm.translate(
            trans,
            glm.vec3(0, 0, [-3, -2, -4, -1,
                            0]["oipet".index(self.projection)]))

        trans = glm.scale(trans, glm.vec3(max(0.01, 1. + self.zoom / 10.)))

        if self.user_transformation is not None:
            trans = trans * self.user_transformation

        self._mat_transform = trans
예제 #5
0
    def _calc_projection_matrix(self):
        sc = 11
        asp = self.width / self.height

        # projection

        if self.projection == self.P_ORTHO:
            ysc = sc/asp * .75
            proj = glm.ortho(-sc,sc, -ysc,ysc, self._near, self._far)
        elif self.projection == self.P_PERSPECTIVE:
            proj = glm.perspectiveFov(1., self.width, self.height, self._near, self._far)
        else:
            raise ValueError(f"unknown projection type '{self.projection}'")

        self._mat_project = proj
예제 #6
0
    def render(self, rs, pass_num):
        time = rs.time * self.speed
        #proj = glm.ortho(-3, 3, -3, 3, -3, 3)
        proj = glm.perspectiveFov(0.7, rs.render_width, rs.render_height, 0.01, 5.)
        proj = glm.translate(proj, glm.vec3(0,0,-2))
        proj = glm.rotate(proj, time*.7, glm.vec3(0,0,1))
        proj = glm.rotate(proj, time*.8, glm.vec3(0,1,0))
        proj = glm.rotate(proj, time*.9, glm.vec3(1,0,0))
        self.drawable.shader.set_uniform("u_time", time)
        self.drawable.shader.set_uniform("u_tex1", 0)
        self.drawable.shader.set_uniform("u_tex2", 1)
        self.drawable.shader.set_uniform("u_projection", proj)

        glDisable(GL_CULL_FACE)
        glEnable(GL_DEPTH_TEST)
        #glEnable(GL_BLEND)
        #glDepthMask(True)
        #glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        self.drawable.draw()
예제 #7
0
 def calculate_projection(self):
     if self.ortho:
         if min(self.app.size) < 1:
             return glm.mat4(1)
         # ratio = self.app.size[0] / self.app.size[1]
         use_ratio = self._use_ratio()
         if use_ratio:
             ratio = self.app.aspect_ratio / 2
             return glm.ortho(-ratio, ratio, *self.ortho_bounds()[2:])
         else:
             return glm.ortho(*self.ortho_bounds())
     else:
         # ratio = self.app.size[0] / self.app.size[1]
         return glm.perspectiveFov(
             math.tau * self._fov(),
             self.app.aspect_ratio,  # float(self.app.size[0]),
             1,  # float(self.app.size[1]),
             0.01,
             1000.0,
         )
예제 #8
0
파일: graphics.py 프로젝트: bluddy/lean_rl
 def set_perspective(self, fov=45):
     self.proj_mat = glm.perspectiveFov(glm.radians(fov), float(self.res[0]), float(self.res[1]), -0.1, 100.)