当前位置: 首页>>代码示例>>Python>>正文


Python Scene.set_ratio方法代码示例

本文整理汇总了Python中scene.Scene.set_ratio方法的典型用法代码示例。如果您正苦于以下问题:Python Scene.set_ratio方法的具体用法?Python Scene.set_ratio怎么用?Python Scene.set_ratio使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scene.Scene的用法示例。


在下文中一共展示了Scene.set_ratio方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: App

# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import set_ratio [as 别名]
class App(object):
	"""Application main class"""

	def __init__(self):

		self.button = {}
		self.move = [0,0,0]

		self.dirskeys = ( ( ['w'] , ['s'] ) , ( ['a'] , ['d'] ) , ( ['e'] , ['q'] ) )

		for d in self.dirskeys :
			for e in d :
				for i in range(len(e)) : e[i] = ( gtk.gdk.unicode_to_keyval(ord(e[i])) , False )

		self.near = 1
		self.far = 1000
		self.fov  = 60

		builder = gtk.Builder()
		builder.add_from_file(ui_file)

		glconfig = self.init_glext()

		self.drawing_area = GLDrawingArea(glconfig)
		self.drawing_area.set_events( gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.BUTTON1_MOTION_MASK | gtk.gdk.BUTTON2_MOTION_MASK |gtk.gdk.BUTTON3_MOTION_MASK )
		self.drawing_area.set_size_request(320,240)

		builder.get_object("vbox1").pack_start(self.drawing_area)

		win_main = builder.get_object("win_main")

		win_main.set_events( gtk.gdk.KEY_PRESS_MASK | gtk.gdk.KEY_RELEASE_MASK )

		win_main.connect('key-press-event'  , self._on_key_pressed  )
		win_main.connect('key-release-event', self._on_key_released )

		self.scene = Scene( self.fov , .01 , self.near , self.far )
		self.drawing_area.add( self.scene , ( 0,0,.5,1) )
		self.drawing_area.add( self.scene , (.5,0,.5,1) )

		print 'Scene added'

		win_main.show_all()

		width = self.drawing_area.allocation.width / 2.0
		height = self.drawing_area.allocation.height
		ratio = float(width)/float(height)

		self.scene.set_ratio( ratio )

		builder.connect_signals(self)

#        self.statbar = builder.get_object('statbar')

		self.drawing_area.connect('motion_notify_event',self._on_mouse_motion)
		self.drawing_area.connect('button_press_event',self._on_button_pressed)
		self.drawing_area.connect('button_release_event',self._on_button_released)
		self.drawing_area.connect('configure_event',self._on_reshape)
		self.drawing_area.connect_after('expose_event',self._after_draw)

		gtk.timeout_add( 1 , self._refresh )

	def _refresh( self ) :
		self.drawing_area.queue_draw()
		return True

	def _after_draw( self , widget , data=None ) :
		self.update_statusbar()

	def update_statusbar( self ) :
		pass

	def _on_reshape( self , widget , data=None ) :
		width = self.drawing_area.allocation.width / 2.0
		height = self.drawing_area.allocation.height

		ratio = float(width)/float(height)

		self.scene.set_screen_size( width , height )

	def _on_button_pressed( self , widget , data=None ) :
		if data.button == 1 or data.button == 2 or data.button == 3 :
			self.mouse_pos = data.x , data.y
		self.button[data.button] = True
		self.drawing_area.queue_draw()

	def _on_button_released( self , widget , data=None ) :
		self.button[data.button] = False


	def _on_mouse_motion( self , widget , data=None ) :
		diff = map( op.sub , self.mouse_pos , (data.x , data.y) )

		self.scene.mouse_move( diff , self.button )

		self.mouse_pos = data.x , data.y
		self.drawing_area.queue_draw()

	def _on_key_pressed( self , widget , data=None ) :
		if not any(self.move) :
#.........这里部分代码省略.........
开发者ID:jkotur,项目名称:empty_pyglgtk,代码行数:103,代码来源:empty.py

示例2: App

# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import set_ratio [as 别名]

#.........这里部分代码省略.........
        self.scene.key_pressed(self.move)
        self.drawing_area.queue_draw()
        return any(self.move)

    def _after_draw(self, widget, data=None):
        self.update_statusbar()

    def update_statusbar(self):
        cid = self.statbar.get_context_id("cursor")
        self.statbar.pop(cid)
        self.statbar.push(cid, str(self.scene.get_cursor_pos()) + "  " + str(self.scene.get_cursor_screen_pos()))

    def toggle_tbuts(self, omit=None):
        for t in self.tbuts:
            if t == omit:
                continue
            t.set_active(False)

    def on_tbut_add_toggled(self, widget, data=None):
        if widget.get_active():
            self.toggle_tbuts(widget)

    def on_sp_draw_surf_value_changed(self, widget, data=None):
        self.scene.set_surf_density((self.sp_draw_surf_x.get_value_as_int(), self.sp_draw_surf_y.get_value_as_int()))
        self.drawing_area.queue_draw()

    def _on_reshape(self, widget, data=None):
        width = self.drawing_area.allocation.width
        height = self.drawing_area.allocation.height

        ratio = float(width) / float(height)

        self.scene.set_screen_size(width, height)
        self.scene.set_ratio(ratio)

    def _on_button_pressed(self, widget, data=None):
        surfdata = (
            (self.sp_surf_x.get_value_as_int(), self.sp_surf_y.get_value_as_int()),
            (self.sp_draw_surf_x.get_value_as_int(), self.sp_draw_surf_y.get_value_as_int()),
        )
        if data.button == 1:
            self.mouse_pos = -data.x, data.y
        elif data.button == 3:
            if self.tbut_add_c0.get_active():
                self.scene.new_curve_c0()
                self.tbut_add_c0.set_active(False)
            elif self.tbut_add_c2.get_active():
                self.scene.new_curve_c2()
                self.tbut_add_c2.set_active(False)
            elif self.tbut_add_surf_c0.get_active():
                self.scene.new_surface_c0(surfdata)
                self.tbut_add_surf_c0.set_active(False)
            elif self.tbut_add_surf_c2.get_active():
                self.scene.new_surface_c2(surfdata)
                self.tbut_add_surf_c2.set_active(False)
            elif self.tbut_add_pipe.get_active():
                self.scene.new_pipe(surfdata)
                self.tbut_add_pipe.set_active(False)
            elif self.tbut_add_gregory.get_active():
                self.scene.new_gregory(surfdata)
                self.tbut_add_gregory.set_active(False)
            elif self.tbut_add_inter.get_active():
                self.scene.new_curve_interpolation()
                self.tbut_add_inter.set_active(False)
            elif self.tbut_del_curve.get_active():
                self.scene.delete_curve()
开发者ID:jkotur,项目名称:Torrusador,代码行数:70,代码来源:torrusador.py

示例3: App

# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import set_ratio [as 别名]
class App(object):
	"""Application main class"""

	def __init__(self):

		self._init_keyboard()

		self.near = .01 
		self.far  = 10
		self.fov  = 60

		builder = gtk.Builder()
		builder.add_from_file(ui_file)

		glconfig = self.init_glext()

		self.drawing_area = GLDrawingArea(glconfig)
		self.drawing_area.set_events( gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.BUTTON3_MOTION_MASK )
		self.drawing_area.set_size_request(800, 800)

		builder.get_object("vbox1").pack_start(self.drawing_area)

		self.scene = Scene( self.fov , 1 , self.near , self.far , self._load_cube_img(skybox_files) , self._load_img(duck_file) )
		self.drawing_area.add( self.scene )

		win_main = builder.get_object("win_main")

		win_main.connect('key-press-event'  , self._on_key_pressed  )
		win_main.connect('key-release-event', self._on_key_released )

		win_main.show_all()

		width = self.drawing_area.allocation.width
		height = self.drawing_area.allocation.height
		ratio = float(width)/float(height)

		self.scene.set_ratio( ratio )

		builder.connect_signals(self)

		self.statbar = builder.get_object('statbar')

		self.drawing_area.connect('motion_notify_event',self._on_mouse_motion)
		self.drawing_area.connect('button_press_event',self._on_button_pressed)
		self.drawing_area.connect('configure_event',self._on_reshape)
		self.drawing_area.connect_after('expose_event',self._after_draw)

		gtk.timeout_add( 1 , self._refresh )

	def _init_keyboard( self ) :
		self.move = [0,0,0]
		self.dirskeys = ( ( ['w'] , ['s'] ) , ( ['a'] , ['d'] ) , ( ['e'] , ['q'] ) )

		for d in self.dirskeys :
			for e in d : 
				for i in range(len(e)) : e[i] = ( gtk.gdk.unicode_to_keyval(ord(e[i])) , False )

	def _on_key_pressed( self , widget , data=None ) :
		if not any(self.move) :
			gtk.timeout_add( 20 , self._move_callback )
						  
		for i in range(len(self.dirskeys)) :
			if (data.keyval,False) in self.dirskeys[i][0] :
				self.dirskeys[i][0][ self.dirskeys[i][0].index( (data.keyval,False) ) ] = (data.keyval,True)
				self.move[i]+= 1
			elif (data.keyval,False) in self.dirskeys[i][1] :
				self.dirskeys[i][1][ self.dirskeys[i][1].index( (data.keyval,False) ) ] = (data.keyval,True)
				self.move[i]-= 1

	def _on_key_released( self , widget , data=None ) :
		for i in range(len(self.dirskeys)) :
			if (data.keyval,True) in self.dirskeys[i][0] :
				self.dirskeys[i][0][ self.dirskeys[i][0].index( (data.keyval,True) ) ] = (data.keyval,False)
				self.move[i]-= 1
			elif (data.keyval,True) in self.dirskeys[i][1] :
				self.dirskeys[i][1][ self.dirskeys[i][1].index( (data.keyval,True) ) ] = (data.keyval,False)
				self.move[i]+= 1

	def _move_callback( self ) :
		self.scene.key_pressed( self.move )
		self.drawing_area.queue_draw()
		return any(self.move)

	def _refresh( self ) :            
		self.drawing_area.queue_draw()
		return True    

	def _after_draw( self , widget , data=None ) :
		self.update_statusbar()

	def update_statusbar( self ) :
		pass

	def _on_reshape( self , widget , data=None ) :
		width = self.drawing_area.allocation.width
		height = self.drawing_area.allocation.height

		ratio = float(width)/float(height)

		self.scene.set_screen_size( width , height )
#.........这里部分代码省略.........
开发者ID:jkotur,项目名称:duck,代码行数:103,代码来源:duck.py


注:本文中的scene.Scene.set_ratio方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。