PDA

View Full Version : manipulating viewpoint


jaylocco
09-13-2009, 10:08 PM
Hi,

I wish to create a simulation of tank movement. as it move forward, the turret will be able to turn right and left when the correspondent key is being pressed.
But how do I make the turret to slowly return back to body_ori (facing in front back again) when I release the key? what I have here in the code, makes the turret to reappear to original position in a flash. also, why my turret does not turn smoothly like in TIME_EVENT? Is it normal in KEYDOWN_EVENT and KEYUP_EVENT?


def onkeydown(key):
if key == viz.KEY_RIGHT:
view.rotate(0,1,0,turn_speed*viz.elapsed(),viz.BOD Y_ORI,viz.REL_PARENT)
elif key == viz.KEY_LEFT:
view.rotate(0,1,0,-turn_speed*viz.elapsed(),viz.BODY_ORI,viz.REL_PARE NT)

viz.callback(viz.KEYDOWN_EVENT,onkeydown)

def onKeyUp(key):
if key == viz.KEY_RIGHT:
view.reset(viz.HEAD_ORI | viz.BODY_ORI)
elif key == viz.KEY_LEFT:
view.reset(viz.HEAD_ORI | viz.BODY_ORI)

viz.callback(viz.KEYUP_EVENT,onKeyUp)

jaylocco
09-14-2009, 01:51 AM
Also how do we animate view to fly like a bird? How do we set the view, if I want to animate a rollercoaster, how to make the camera view follows him on top of the head..

Thanks

jaylocco
09-15-2009, 02:00 AM
Just wana share

I have just discovered the way to make the viewpoint move like roller coaster.
First we need to animate the path using control points then set the move mode as Cubic Bezier. in order to get the view moves as well, link pos the view with the car

link = viz.link(car, viz.MainView)
link.setMask(viz.LINK_POS)

for reference check the animatepath.py in the Help section :rolleyes:

BUT does anyone have any idea how to do the Tank turret problem I sent earlier? :confused:

Jeff
09-17-2009, 11:10 AM
<viewpoint>.reset will not animate the view spinning back to its original orientation.

You could use <viewpoint>.spinto and give the orientation to spin to and the speed or time it will take.

jaylocco
09-22-2009, 06:35 PM
Thanks for the tip..never thought of it... good one ;)

jaylocco
09-22-2009, 08:20 PM
ahah...just encounter this...by using the spinto, how do I determine the degree of angle for it to animate back to the original position? because the amount of degree depends on how long I press the Right or Left button. Which mean, it is not fix to an amount of degree.Or, is there anyway that I can calculate the angle based on how long I press the button? so that I could assign the value to a variable which later to be applied in spinto

Degree = 'amount of degree'

<viewpoint>.spinto([x,y,z,Degree],value)