コード例 #1
0
 def move_along_view(self, camera, distance):
     px, py, pz = gh_camera.get_position(camera._id)
     vx, vy, vz = gh_camera.get_view_vector(camera._id)
     px = px + (vx * distance)
     py = py + (vy * distance)
     pz = pz + (vz * distance)
     gh_camera.set_position(camera._id, px, py, pz)
コード例 #2
0
def init_camera_ortho():
    global _camera_ortho
    global _winW
    global _winH
    _camera_ortho = gh_camera.create_ortho(-_winW / 2, _winW / 2, -_winH / 2,
                                           _winH / 2, 1.0, -1.0)
    gh_camera.set_viewport(_camera_ortho, 0, 0, _winW, _winH)
    gh_camera.set_position(_camera_ortho, 0, 0, 1)
    _old_camera_ortho = _camera_ortho
コード例 #3
0
def ftgl_init():
    global _ftgl_initialized, _ftgl_camera_ortho
    if (_ftgl_initialized == 0):
        ftgl_init_font_gpu_program()
        winW, winH = gh_window.getsize(0)
        _ftgl_camera_ortho = gh_camera.create_ortho(-winW / 2, winW / 2,
                                                    -winH / 2, winH / 2, 1.0,
                                                    10.0)
        gh_camera.set_viewport(_ftgl_camera_ortho, 0, 0, winW, winH)
        gh_camera.set_position(_ftgl_camera_ortho, 0, 0, 4)
        gh_camera.set_lookat(_ftgl_camera_ortho, 0, 0, 0, 1)
        _ftgl_initialized = 1
コード例 #4
0
def init_camera_perspective():
    global _camera_persp
    global _winW
    global _winH
    global _camera_persp_fov
    global _old_camera_persp
    aspect = _winW / _winH
    _camera_persp = gh_camera.create_persp(_camera_persp_fov, aspect, 0.1,
                                           1000.0)
    gh_camera.set_viewport(_camera_persp, 0, 0, _winW, _winH)
    gh_camera.set_position(_camera_persp, 0, 10, 50)
    gh_camera.set_lookat(_camera_persp, 0, 0, 0, 1)
    gh_camera.setupvec(_camera_persp, 0, 1, 0, 0)
    _old_camera_persp = _camera_persp
コード例 #5
0
    def strafe_h_xz(self, camera, dist, update_lookat):
        v = vec3()
        u = vec3()
        v.x, v.y, v.z = gh_camera.get_view_vector(camera._id)
        v.neg()
        u.x, u.y, u.z = gh_camera.get_up_vector(camera._id)
        xvec = v.cross(u)
        p = vec3()
        p.x, p.y, p.z = gh_camera.get_position(camera._id)
        p.x = p.x + (xvec.x * dist)
        p.z = p.z + (xvec.z * dist)
        gh_camera.set_position(camera._id, p.x, p.y, p.z)

        if (update_lookat == 1):
            lookat_x = camera._lookat_x + (xvec.x * dist)
            lookat_y = camera._lookat_y + (xvec.y * dist)
            lookat_z = camera._lookat_z + (xvec.z * dist)
            self.set_orbit_lookat(camera, lookat_x, lookat_y, lookat_z)
コード例 #6
0
 def create_perspective(self, fov, is_vertical_fov, viewport_x, viewport_y,
                        viewport_width, viewport_height, znear, zfar):
     camera = self._create()
     camera._viewport.x = viewport_x
     camera._viewport.y = viewport_y
     camera._viewport.width = viewport_width
     camera._viewport.height = viewport_height
     camera._fov = fov
     camera._znear = znear
     camera._zfar = zfar
     aspect = float(viewport_width) / float(viewport_height)
     #camera._id = gh_camera.create_persp_v2(fov, is_vertical_fov, aspect, znear, zfar)
     camera._id = gh_camera.create_persp(fov, aspect, znear, zfar)
     gh_camera.set_viewport(camera._id, viewport_x, viewport_y,
                            viewport_width, viewport_height)
     gh_camera.set_position(camera._id, 0, 0, 20)
     gh_camera.set_lookat(camera._id, 0, 0, 0, 1)
     gh_camera.setupvec(camera._id, 0, 1, 0, 0)
     return camera
コード例 #7
0
 def _rotate_camera_position_around_point(self, camera, lookat_point_x,
                                          lookat_point_y, lookat_point_z,
                                          pitch, yaw, roll):
     cam_pos_x, cam_pos_y, cam_pos_z = gh_object.get_position(camera._id)
     vx = cam_pos_x - lookat_point_x
     vy = cam_pos_y - lookat_point_y
     vz = cam_pos_z - lookat_point_z
     angX = pitch * math.pi / 180.0
     angY = yaw * math.pi / 180.0
     angZ = roll * math.pi / 180.0
     mag = math.sqrt(vx * vx + vy * vy + vz * vz)
     new_cam_pos_x = lookat_point_x + mag * math.cos(angY) * math.cos(angX)
     new_cam_pos_y = lookat_point_y + mag * math.sin(angX)
     new_cam_pos_z = lookat_point_z + mag * math.sin(angY) * math.cos(angX)
     gh_camera.set_position(camera._id, new_cam_pos_x, new_cam_pos_y,
                            new_cam_pos_z)
     camera._lookat_x = lookat_point_x
     camera._lookat_y = lookat_point_y
     camera._lookat_z = lookat_point_z
     gh_camera.set_lookat(camera._id, lookat_point_x, lookat_point_y,
                          lookat_point_z, 1)
コード例 #8
0
    def initialize(self):
        self._last_time = gh_utils.get_elapsed_time()
        lib_dir = gh_utils.get_scripting_libs_dir()
        #self._font_title_default = ftgl_load_font_v2(lib_dir + "common/Vampire Raves.otf", 30, 0, 0)
        self._font_title_default = ftgl_load_font_v2(
            lib_dir + "common/coolvetica rg.ttf", 30, 0, 0)
        self._font_default = ftgl_load_font_v2(
            lib_dir + "common/BebasNeue.otf", 20, 0, 0)
        self._font_default_user = ftgl_load_font_v2(
            lib_dir + "common/coolvetica rg.ttf", 20, 0, 0)
        self._gl_version = gh_renderer.get_api_version()
        self._gl_renderer = gh_renderer.get_renderer_model()
        self._GL_SAMPLES, y, z, w = gh_renderer.get_capability_4i("GL_SAMPLES")
        self._client_width, self._client_height = gh_window.getsize(0)
        if (gh_utils.get_platform() == 1):
            self._main_title = "GLSL Hacker (Windows 64-bit)"
        elif (gh_utils.get_platform() == 2):
            self._main_title = "GLSL Hacker (Mac OS X 64-bit)"
        elif (gh_utils.get_platform() == 3):
            self._main_title = "GLSL Hacker (Linux 64-bit)"
        elif (gh_utils.get_platform() == 4):
            self._main_title = "GLSL Hacker (Raspberry Pi x32)"

        PF_U8_RGBA = 3
        self._tex_mouse = gh_texture.create_from_file(
            lib_dir + "common/mouse-pointer-md.png", PF_U8_RGBA, 1)

        color_program_vs_gl3 = " \
    #version 150\
    in vec4 gxl3d_Position;\
    uniform mat4 gxl3d_ModelViewProjectionMatrix; \
    void main() \
    { \
      gl_Position = gxl3d_ModelViewProjectionMatrix * gxl3d_Position;\
    }"

        color_program_ps_gl3 = " \
    #version 150\
    uniform vec4 color;\
    out vec4 gl_FragColor;\
    void main() \
    { \
      gl_FragColor = color;  \
    }"

        color_program_vs_gles2 = " \
    attribute vec4 gxl3d_Position;\
    uniform mat4 gxl3d_ModelViewProjectionMatrix; \
    void main() \
    { \
      gl_Position = gxl3d_ModelViewProjectionMatrix * gxl3d_Position;\
    }"

        color_program_ps_gles2 = " \
    uniform vec4 color;\
    void main() \
    { \
      gl_FragColor = color;  \
    }"

        if (gh_utils.get_platform() == 4):
            self._color_program = gh_gpu_program.create_v2(
                "gfx_color_program", color_program_vs_gles2,
                color_program_ps_gles2)
        else:
            self._color_program = gh_gpu_program.create(
                "gfx_color_program", color_program_vs_gl3,
                color_program_ps_gl3)

        texture_program_vs_gl3 = " \
    #version 150\
    in vec4 gxl3d_Position;\
    in vec4 gxl3d_TexCoord0;\
    uniform mat4 gxl3d_ModelViewProjectionMatrix; \
    out vec4 Vertex_UV;\
    void main() \
    { \
      gl_Position = gxl3d_ModelViewProjectionMatrix * gxl3d_Position;\
      Vertex_UV = gxl3d_TexCoord0;\
    }"

        texture_program_ps_gl3 = " \
    #version 150\
    uniform sampler2D tex0;\
    uniform vec4 color;\
    varying vec4 Vertex_UV;\
    out vec4 gl_FragColor;\
    void main() \
    { \
      vec2 uv = Vertex_UV.xy;\
      uv.y *= -1.0;\
      vec4 t = texture(tex0,uv);\
      if ((t.r == 1.0) && (t.g < 1.0) && (t.g < 1.0))\
        gl_FragColor = color;  \
      else \
       discard;\
    }"

        texture_program_vs_gles2 = " \
    attribute vec4 gxl3d_Position;\
    attribute vec4 gxl3d_TexCoord0;\
    uniform mat4 gxl3d_ModelViewProjectionMatrix; \
    varying vec4 Vertex_UV;\
    void main() \
    { \
      gl_Position = gxl3d_ModelViewProjectionMatrix * gxl3d_Position;\
      Vertex_UV = gxl3d_TexCoord0;\
    }"

        texture_program_ps_gles2 = " \
    uniform sampler2D tex0;\
    uniform vec4 color;\
    varying vec4 Vertex_UV;\
    void main() \
    { \
      vec2 uv = Vertex_UV.xy;\
      uv.y *= -1.0;\
      vec4 t = texture2D(tex0,uv);\
      if ((t.r == 1.0) && (t.g < 1.0) && (t.b < 1.0))\
        gl_FragColor = color;  \
      else \
       discard;\
    }"

        if (gh_utils.get_platform() == 4):
            self.texture_program = gh_gpu_program.create_v2(
                "gfx_texture_program", texture_program_vs_gles2,
                texture_program_ps_gles2)
        else:
            self.texture_program = gh_gpu_program.create(
                "gfx_texture_program", texture_program_vs_gl3,
                texture_program_ps_gl3)

        gh_gpu_program.uniform1i(self.texture_program, "tex0", 0)

        winW, winH = gh_window.getsize(0)
        self._camera_ortho = gh_camera.create_ortho(-winW / 2.0, winW / 2.0,
                                                    -winH / 2.0, winH / 2.0,
                                                    1.0, 10.0)
        gh_camera.set_viewport(self._camera_ortho, 0, 0, winW, winH)
        gh_camera.set_position(self._camera_ortho, 0, 0, 4)

        self._mouse_quad = gh_mesh.create_quad(self._mouse_quad_width,
                                               self._mouse_quad_height)
コード例 #9
0
 def setPosition(self, cam, x, y, z):
     gh_camera.set_position(cam, x, y, z)
     gh_camera.set_lookat(cam, self._lookat_x, self._lookat_y,
                          self._lookat_z, 1)