View Single Post
  #5  
Old 10-17-2008, 01:28 AM
Sandro Holzer Sandro Holzer is offline
Member
 
Join Date: Jul 2008
Posts: 19
Hi

The following is a small test code that should show a little bit what i like to do.
You just need the attached objects from the .zip file.

The "bar2" should represents a vehicle, and the "bar" should represent a arm, that is attached to the vehicle and can rotate (something like a lift arm).
The vehicle should be able to "steer" and drive, so it can change its direction on the world plane. This is simulated with the key´s "f" and "g".
The lift arm is controlled with "t" and "b".

In the small test code the Problem occurs just with the lift arm.
In my real code it occurs also for the vehicle when I try to drive around and steer. Then the vehicle changes its direction from one step to the next by 180 or 90 degrees.

I hope someone can point me in the right direction, how to do this in the right way.

Sandro


Code:
import viz
viz.go()
viz.clearcolor(0.1,0.1,1)
ground = viz.add('tut_ground.wrl')
ANCHOR_POS= (0.5,1.8005,6)
bar2 = viz.add('bar.obj',pos=ANCHOR_POS)
bar = bar2.add('bar.obj')

a = 0
b = 0

def mytimer(num):
	global a,b
	if viz.iskeydown('t'):
		a = a + 1
		move()
	if viz.iskeydown('b'):
		a = a - 1
		move()
		
	if viz.iskeydown('f'):
		b = b + 1
		move()
	if viz.iskeydown('h'):
		b = b - 1
		move()

def move():
	euler = bar.getEuler(viz.ABS_PARENT)
	print euler
	euler[1]=a
	bar.setEuler(euler,viz.ABS_PARENT)
	
	euler = bar2.getEuler(viz.ABS_GLOBAL)
	print euler
	euler[0]=b
	bar2.setEuler(euler,viz.ABS_GLOBAL)
	

viz.callback(viz.TIMER_EVENT,mytimer)
viz.starttimer(0,0.02,viz.FOREVER)
Attached Files
File Type: zip bar.zip (1.4 KB, 1207 views)
Reply With Quote