WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #7  
Old 05-17-2009, 12:47 PM
Jerry Jerry is offline
Member
 
Join Date: Jun 2004
Posts: 105
Since spinning balls is so much fun,
Let's try spinning more than one.

Code:
from viz import *

go()

clearcolor(.8,.8,.8)
ball1 = add('ball.wrl')
ball1.translate(.3,1.8,1.5)
ball2 = add('ball.wrl')
ball2.translate(-.3,1.8,1.5)

balls = []
balls.append(ball1)
balls.append(ball2)

INCREMENT = .5

mouse(OFF)
restrictmouse(OFF)

def mousemove(x,y):					
	
	object = pick() 

	if viz.mouse.getState() == viz.MOUSEBUTTON_LEFT:
		mousedown = 1
	else:
		mousedown = 0
		
	if object in balls and mousedown == 1:
		object.rotate(0,1,0,-x*INCREMENT,RELATIVE_WORLD)
		object.rotate(1,0,0,y*INCREMENT,RELATIVE_WORLD)

		
mousedata(RELATIVE,RELATIVE)
callback(MOUSEMOVE_EVENT,mousemove)

Or if you like the number three,
Let's try to make them all agree.

Code:
from viz import *

go()

clearcolor(.8,.8,.8)
ball1 = add('ball.wrl')
ball1.translate(0,2.1,2)
ball2 = add('ball.wrl')
ball2.translate(.4,1.5,2)
ball3 = add('ball.wrl')
ball3.translate(-.4,1.5,2)

balls = []
balls.append(ball1)
balls.append(ball2)
balls.append(ball3)

INCREMENT = .5

mouse(OFF)
restrictmouse(OFF)

def mousemove(x,y):					
	
	object = pick() 

	if viz.mouse.getState() == viz.MOUSEBUTTON_LEFT:
		mousedown = 1
	else:
		mousedown = 0
		
	if object in balls and mousedown == 1:
		for b in range(len(balls)):
			balls[b].rotate(0,1,0,-x*INCREMENT,RELATIVE_WORLD)
			balls[b].rotate(1,0,0,y*INCREMENT,RELATIVE_WORLD)

		
mousedata(RELATIVE,RELATIVE)
callback(MOUSEMOVE_EVENT,mousemove)

And here's the one you want the most,
Just like iPhone make it coast.

Code:
from viz import *

go()

clearcolor(.8,.8,.8)
ball1 = add('ball.wrl')
ball1.translate(.3,1.8,1.5)
ball2 = add('ball.wrl')
ball2.translate(-.3,1.8,1.5)

balls = []
balls.append(ball1)
balls.append(ball2)

increment = .5
COAST = 1
mx = 0
my = 0
object = []
spinning = 0

mouse(OFF)
restrictmouse(OFF)

def mousemove(x,y):					
	global mx,my,object,spinning,increment
	
	if spinning == 0:
		object = pick() 

	if mouse.getState() == MOUSEBUTTON_LEFT:
		object = pick() 
		mousedown = 1
		killtimer(COAST)
		spinning = 0
	else:
		mousedown = 0
		
	if object in balls and mousedown == 1:
		object.rotate(0,1,0,-x*increment,RELATIVE_WORLD)
		object.rotate(1,0,0,y*increment,RELATIVE_WORLD)
		mx = x
		my = y

	if mousedown == 1 and spinning == 0:
		increment = .5
		spinning = 1
		starttimer(COAST,.01,FOREVER)
		
mousedata(RELATIVE,RELATIVE)
callback(MOUSEMOVE_EVENT,mousemove)

def onTimer(num):
	global spinning,mx,my,object,increment
	
	if num == COAST:
	
		object.rotate(0,1,0,-mx*increment,RELATIVE_WORLD)
		object.rotate(1,0,0,my*increment,RELATIVE_WORLD)

		increment = increment - .01
		if abs(increment) < .01:
			spinning = 0
			increment = .5
			killtimer(COAST)
						
viz.callback(viz.TIMER_EVENT,onTimer)
Reply With Quote
 


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
retrieve Object names Geoffrey Vizard 11 12-11-2009 04:26 AM
reseting an object durf Vizard 3 03-17-2009 11:48 PM
Object rotating around world axis, not own axis tacbob Vizard 1 02-15-2007 09:12 AM
Child Object Rotation paulgoldberg Vizard 5 09-05-2006 11:33 AM
rotate to object jargon Vizard 1 08-08-2005 12:20 PM


All times are GMT -7. The time now is 08:53 AM.


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