當前位置: 首頁>>代碼示例>>Python>>正文


Python Camera.rotate方法代碼示例

本文整理匯總了Python中pi3d.Camera.Camera.rotate方法的典型用法代碼示例。如果您正苦於以下問題:Python Camera.rotate方法的具體用法?Python Camera.rotate怎麽用?Python Camera.rotate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pi3d.Camera.Camera的用法示例。


在下文中一共展示了Camera.rotate方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ShadowCaster

# 需要導入模塊: from pi3d.Camera import Camera [as 別名]
# 或者: from pi3d.Camera.Camera import rotate [as 別名]
class ShadowCaster(OffScreenTexture):
  """For creating a depth-of-field blurring effect on selected objects"""
  def __init__(self, position, light, scale=10.0):
    """ calls Texture.__init__ but doesn't need to set file name as
    texture generated from the framebuffer
    """
    super(ShadowCaster, self).__init__("shadow_caster")

    self.LIGHT_CAM = Camera(is_3d=False, scale=scale)
    l_p = light.lightpos
    l_len = (l_p[0]**2 + l_p[1]**2 + l_p[2]**2)**0.5
    self.OFFSET = [200.0 * i / l_len for i in l_p]
    self.LIGHT_CAM.position([position[i] - o for i, o in enumerate(self.OFFSET)])
    self.tilt, self.rot = self.LIGHT_CAM.point_at(position)
    self.cast_shader = Shader("shadowcast")


  def move_light(self, position):
    self.LIGHT_CAM.reset()
    self.LIGHT_CAM.rotate(self.tilt, self.rot, 0)
    self.LIGHT_CAM.position([position[i] - o for i, o in enumerate(self.OFFSET)])


  def start_cast(self, position=None):
    if position is not None:
      self.move_light(position)
    super(ShadowCaster, self)._start()


  def cast_shadow(self, shape):
    shape.draw(shader=self.cast_shader, light_camera=self.LIGHT_CAM)


  def end_cast(self):
    super(ShadowCaster, self)._end()

    
  def draw_shadow(self):
    self.emap.draw(shader=self.dshader)


  def draw_tree(self, tree, shader):
    tree.draw(shader, [self])
開發者ID:Clever-Boy,項目名稱:pi3d,代碼行數:45,代碼來源:ShadowCaster.py

示例2: StereoCam

# 需要導入模塊: from pi3d.Camera import Camera [as 別名]
# 或者: from pi3d.Camera.Camera import rotate [as 別名]
class StereoCam(object):
    """For creating an apparatus with two sprites to hold left and right
  eye views.

  This Class is used to hold the 3D Camera which should be used to draw
  the 3D objects. It also holds a 2D Camera for drawing the Sprites"""

    def __init__(self, shader="uv_flat", mipmap=False, separation=0.4, interlace=0):
        """ calls Texture.__init__ but doesn't need to set file name as
    texture generated from the framebuffer. Keyword Arguments:

      *shader*
        to use when drawing sprite, defaults to post_base, a simple
        3x3 convolution that does basic edge detection. Can be copied to
        project directory and modified as required.

      *mipmap*
        can be set to True with slight cost to speed, or use fxaa shader

      *separation*
        distance between the two camera positions - how wide apart the
        eye views are.

      *interlace*
        if interlace > 0 then the images are not taken with glScissor and
        must be drawn with a special interlacing shader.
    """
        # load shader
        if interlace <= 0:
            self.shader = Shader(shader)
        else:
            self.shader = Shader(
                vshader_source="""
precision mediump float;
attribute vec3 vertex;
attribute vec2 texcoord;
uniform mat4 modelviewmatrix[2];
varying vec2 texcoordout;
void main(void) {
  texcoordout = texcoord;
  gl_Position = modelviewmatrix[1] * vec4(vertex,1.0);
}
    """,
                fshader_source="""
precision mediump float;
uniform sampler2D tex0;
uniform sampler2D tex1;
varying vec2 texcoordout;
void main(void) {{
  vec4 texc0 = texture2D(tex0, texcoordout);
  vec4 texc1 = texture2D(tex1, texcoordout);
  vec2 coord = vec2(gl_FragCoord);
  gl_FragColor = mix(texc0, texc1, step(0.5, fract(coord.x / {:f})));
}}
    """.format(
                    interlace * 2.0
                ),
            )
            # self.shader = Shader("2d_flat")
        self.camera_3d = Camera()
        self.forMtrx = np.identity(4, dtype="float32")  # initially not rotated
        self.position = [0.0, 0.0, 0.0]
        self.camera_2d = Camera(is_3d=False)
        self.offs = separation / 2.0
        self.interlace = interlace
        self.textures = []
        self.sprites = []
        self.tex_list = []
        for i in range(2):
            self.textures.append(OffScreenTexture(name="stereo"))
            ix, iy = self.textures[i].ix, self.textures[i].iy
            # two sprites full width but moved so that they are centred on the
            # left and right edges. The offset values then move the uv mapping
            # so the image is on the right of the left sprite and left of the
            # right sprite
            self.sprites.append(Sprite(z=20.0, w=ix, h=iy, flip=True))
            if interlace <= 0:
                self.sprites[i].positionX(-ix / 2.0 + i * ix)
                self.sprites[i].set_offset((i * 0.5 - 0.25, 0.0))
            else:
                self.sprites[i].set_2d_size(w=ix, h=iy)
            self.textures[i].blend = True
            self.textures[i].mipmap = mipmap
            self.tex_list.append(self.textures[i])
        opengles.glColorMask(1, 1, 1, 1)

    def move_camera(self, position, rot, tilt, roll=0.0, absolute=True):
        """ Arguments:
    
      *position*
        array [x,y,z]

      *rot, tilt, roll*
        rotations about y, x, z axis (yes it's not entirely logical for position
        to be an array and orientation three values but it's too late to change!)

      *absolute*
        if set to False then the rotations are treated as relative to the
        rotated frame of reference i.e. as if signals from VR headset 3
        axis gyro.
#.........這裏部分代碼省略.........
開發者ID:swehner,項目名稱:pi3d,代碼行數:103,代碼來源:StereoCam.py

示例3: StereoCam

# 需要導入模塊: from pi3d.Camera import Camera [as 別名]
# 或者: from pi3d.Camera.Camera import rotate [as 別名]
class StereoCam(object):
  """For creating an apparatus with two sprites to hold left and right
  eye views.

  This Class is used to hold the 3D Camera which should be used to draw
  the 3D objects. It also holds a 2D Camera for drawing the Sprites"""
  def __init__(self, shader="uv_flat", mipmap=False, separation=0.4):
    """ calls Texture.__init__ but doesn't need to set file name as
    texture generated from the framebuffer. Keyword Arguments:

      *shader*
        to use when drawing sprite, defaults to post_base, a simple
        3x3 convolution that does basic edge detection. Can be copied to
        project directory and modified as required.

      *mipmap*
        can be set to True with slight cost to speed, or use fxaa shader

      *separation*
        distance between the two camera positions - how wide apart the
        eye views are.
    """
    # load shader
    self.shader = Shader(shader)
    self.camera_3d = Camera()
    self.camera_2d = Camera(is_3d=False)
    self.offs = separation / 2.0
    self.textures = []
    self.sprites = []
    self.tex_list = []
    for i in range(2):
      self.textures.append(OffScreenTexture(name="bin"))
      ix, iy = self.textures[i].ix, self.textures[i].iy
      #two sprites full width but moved so that they are centred on the
      #left and right edges. The offset values then move the uv mapping
      #so the image is on the right of the left sprite and left of the
      #right sprite
      self.sprites.append(Sprite(z=20.0, x=-ix/2.0 + i*ix, w=ix, h=iy, flip=True))
      self.sprites[i].set_offset((i * 0.5 - 0.25, 0.0))
      self.textures[i].alpha = False
      self.textures[i].blend = True
      self.textures[i].mipmap = mipmap
      self.tex_list.append([self.textures[i]])

  def move_camera(self, position, rot, tilt):
    self.camera_3d.reset()
    self.camera_3d.rotate(tilt, rot, 0)
    self.camera_3d.position(position)

  def start_capture(self, side):
    """ after calling this method all object.draw()s will rendered
    to this texture and not appear on the display.

      *side*
        Either 0 or 1 to determine stereoscopic view
    """
    offs = -self.offs if side == 0 else self.offs
    self.camera_3d.position((self.camera_3d.mtrx[2,3] * offs, 0,
                            -self.camera_3d.mtrx[0,3] * offs))
    tex = self.textures[side]
    tex._start()
    xx = tex.ix / 4.0 # draw the middle only - half width
    yy = 0
    ww = tex.ix / 2.0
    hh = tex.iy
    opengles.glEnable(GL_SCISSOR_TEST)
    opengles.glScissor(ctypes.c_int(int(xx)), ctypes.c_int(int(yy)),
                  ctypes.c_int(int(ww)), ctypes.c_int(int(hh)))

  def end_capture(self, side):
    """ stop capturing to texture and resume normal rendering to default
    """
    self.textures[side]._end()
    opengles.glDisable(GL_SCISSOR_TEST)

  def draw(self):
    """ draw the shape using the saved texture
    """
    for i in range(2):
     self.sprites[i].draw(self.shader, self.tex_list[i], 0.0, 0.0, self.camera_2d)
開發者ID:kostyll,項目名稱:pi3d,代碼行數:82,代碼來源:StereoCam.py


注:本文中的pi3d.Camera.Camera.rotate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。