![]() |
|
|
|
#1
|
|||
|
|||
|
If you are trying to modify an existing rotation, it is best to perform the changes using matrix multiplications. Manually changing a single component of an euler rotation is not very reliable, this is simply the nature of euler angles. What specific modification are you trying to perform on the rotation?
|
|
#2
|
|||
|
|||
|
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)
|
|
#3
|
|||
|
|||
|
I modified your script to work with the built-in relative transform modes. Hopefully this should work better:
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')
MOVE_SPEED = 60 # degrees/sec
def UpdateBars():
if viz.iskeydown('t'):
bar.setEuler([0,MOVE_SPEED*viz.elapsed(),0],viz.REL_LOCAL)
if viz.iskeydown('b'):
bar.setEuler([0,-MOVE_SPEED*viz.elapsed(),0],viz.REL_LOCAL)
if viz.iskeydown('f'):
bar2.setEuler([MOVE_SPEED*viz.elapsed(),0,0],viz.REL_PARENT)
if viz.iskeydown('h'):
bar2.setEuler([-MOVE_SPEED*viz.elapsed(),0,0],viz.REL_PARENT)
vizact.ontimer(0,UpdateBars)
|
|
#4
|
|||
|
|||
|
Hi
Thanks for answers. The relative transform mode is a bit a problem with my application, but I tryed to do it ABS with the transform-matrix and it looks very good. The code is the following, and it seems to work also in my big script. 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():
X = bar.getMatrix(viz.ABS_PARENT)
X.setAxisAngle(1,0,0,a)
bar.update(X)
X = bar2.getMatrix(viz.ABS_GLOBAL)
X.setAxisAngle(0,1,0,b)
bar2.update(X)
viz.callback(viz.TIMER_EVENT,mytimer)
viz.starttimer(0,0.02,viz.FOREVER)
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|