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


Python OrthographicLens.setAspectRatio方法代码示例

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


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

示例1: __init__

# 需要导入模块: from panda3d.core import OrthographicLens [as 别名]
# 或者: from panda3d.core.OrthographicLens import setAspectRatio [as 别名]
class Camera_Controller:
	
	def __init__(self,base):

		self.base = base
		self.base.disableMouse()		

		x_win = self.base.win.getXSize()
		y_win = self.base.win.getYSize()
		aspect_win = float(x_win)/float(y_win)

		self.active_lens = 1

		self.ortho_lens = OrthographicLens()
		self.ortho_lens.setAspectRatio(aspect_win)
		self.ortho_lens.setNearFar(1.0,100.0)

		self.persp_lens = PerspectiveLens()
		self.persp_lens.setAspectRatio(aspect_win)
		self.persp_lens.setFov(5.0)
		self.persp_lens.setNearFar(1.0,100.0)

		self.lenses = [self.persp_lens, self.ortho_lens]

		self.set_lens(lens=self.active_lens)


		self.set_view(Vec3(50.0,50.0,50.0))

		self.old_x = None
		self.old_y = None

		self.zoom_speed = 0.05
		self.pan_speed = 0.005
		self.rotate_speed = 0.1

		#these are pointers
		self.keys = self.base.keyboard_reader.keys
		self.key_map = self.base.keyboard_reader.key_map

		#registering camera functions
		self.base.taskMgr.add(hold_caller_multikey(trigger=self.keys, indices=[self.key_map['shift'], self.key_map['mouse2']], values=[1,1], init_handle=None, loop_handle=self.pan_camera, cleanup_handle=self.mouse_delta_cleanup), 'pan_camera_task')
		self.base.taskMgr.add(hold_caller_multikey(trigger=self.keys, indices=[self.key_map['control'], self.key_map['shift'], self.key_map['mouse2']], values=[0, 0,1], init_handle=None, loop_handle=self.rotate_camera_fixed_pivot, cleanup_handle=self.mouse_delta_cleanup), 'rotate_camera_task')
		self.base.taskMgr.add(hold_caller_multikey(trigger=self.keys, indices=[self.key_map['control'], self.key_map['mouse2']], values=[1,1], init_handle=None, loop_handle=self.zoom_camera, cleanup_handle=self.mouse_delta_cleanup), 'rotate_camera_task')


		#register camera presets
		self.base.taskMgr.add( delta_caller(handle = self.set_viewpoint_front , trigger = self.keys, index = self.key_map['1'], value=1), 'camera_preset_front_task')
		self.base.taskMgr.add( delta_caller(handle = self.set_viewpoint_side , trigger = self.keys, index = self.key_map['2'], value=1), 'camera_preset_side_task')
		self.base.taskMgr.add( delta_caller(handle = self.set_viewpoint_top , trigger = self.keys, index = self.key_map['3'], value=1), 'camera_preset_top_task')

		#register switching perspective
		#TODO: currently disabled because perspective camera is stupid and should feel bad
		#self.base.taskMgr.add( delta_caller(handle = self.switch_perspective , trigger = self.keys, index = self.key_map['5'], value=1), 'camera_switch_perspective_task')

		#makes the zoom level of the orthographic camera more reasonable
		self.fixed_zoom_camera(10.0)


	def set_view(self, position):
		self.pos = Vec3(position)
		self.base.cam.setPos(self.pos)
		self.pivot = Vec3(0.0,0.0,0.0)
		self.base.cam.lookAt(0.0,0.0,0.0)
		self.hpr = self.base.cam.getHpr()


	def set_lens(self,lens):

		old_pos = self.base.cam.getPos()
		self.active_lens = lens
		self.base.cam.node().setLens(self.lenses[self.active_lens])
		self.base.cam.setPos(old_pos)

	def mouse_delta_cleanup(self):
			self.old_x = None
			self.old_y = None

	def get_mouse_delta(self):

			md = self.base.win.getPointer(0)
			x = md.getX()
			y = md.getY()

			d_x = None
			d_y = None

			if self.old_x == None or self.old_y == None:
				self.old_x = x
				self.old_y = y
			else:
				d_y = (y - self.old_y) 
				d_x = (x - self.old_x)
				self.old_x = x
				self.old_y = y

			return (d_x, d_y)

	def pan_camera(self):
		pan_speed = self.pan_speed
#.........这里部分代码省略.........
开发者ID:nkolkin13,项目名称:ProcEdit,代码行数:103,代码来源:camera_controller.py


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