WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 05-08-2018, 05:21 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
Here's an example. Use the left and right arrow keys to move the box:

Code:
'''
Move the clip box left and right
with the arrow keys
'''

import viz
import vizact
import vizshape
import vizinfo
viz.go()

vizinfo.InfoPanel()

class MovingClipBox():
	def __init__(self,node,center,size):
		
		self.node = node
		self.x,self.y,self.z = center
		self.sx,self.sy,self.sz = [ v / 2.0 for v in size ]
		self.applyClipBox()	
		self.box = vizshape.addBox(size=size,pos=center,color=viz.RED,lighting=False)
		self.box.polyMode(viz.POLY_WIRE)

	def applyClipBox(self):
		
		self.node.clipPlane([1,0,0,self.x-self.sx],num=0)
		self.node.clipPlane([-1,0,0,-self.x-self.sx],num=1)
		self.node.clipPlane([0,1,0,self.y-self.sy],num=2)
		self.node.clipPlane([0,-1,0,-self.y-self.sy],num=3)
		self.node.clipPlane([0,0,1,self.z-self.sz],num=4)
		self.node.clipPlane([0,0,-1,-self.z-self.sz],num=5)
		
	def getBoxCenter(self):
		return [self.x,self.y,self.z]

	def setBoxCenter(self,center):
		self.x,self.y,self.z = center
		self.applyClipBox()
		self.box.setPosition(center)
		
viz.clearcolor(viz.GRAY)
vizshape.addGrid(color=[0.2]*3)
model = viz.add('logo.osgb')

expand = vizact.sizeTo([3,3,3],speed=0.5)
shrink = vizact.sizeTo([1,1,1],speed=0.5)
model.runAction(vizact.sequence(expand,shrink,viz.FOREVER))
model.runAction(vizact.spin(0,1,0,20,viz.FOREVER),pool=1)
				
BOX_CENTER = [0,2,0]
BOX_SIZE = [2,2,2]
movingClipBox = MovingClipBox(model,center=BOX_CENTER,size=BOX_SIZE)

import vizcam
vizcam.PivotNavigate(center = BOX_CENTER, distance = 10.0)

def updateClipBox():
	
	x_change = 0
	if viz.key.isDown(viz.KEY_LEFT):
		x_change -= 0.01
	elif viz.key.isDown(viz.KEY_RIGHT):
		x_change += 0.01
	if x_change != 0:
		center = movingClipBox.getBoxCenter()
		center[0] += x_change
		movingClipBox.setBoxCenter(center)

vizact.onupdate(0,updateClipBox)
Reply With Quote
 

Tags
box, clipping, move, plane, rotate


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a clipping box pswaney Vizard 1 03-01-2013 12:19 PM
Clipping Plane envisC Vizard 8 10-23-2012 12:36 PM
Can I make a moving clipping plane? Salvar Vizard 3 04-18-2012 12:32 PM
Near and far clipping on infinite terrain vijaykiran Vizard 2 01-21-2011 04:59 AM
Does the automatic clipping plane calculation work? Joran Vizard 4 07-10-2009 10:35 AM


All times are GMT -7. The time now is 07:37 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC