2012-08-17 3 views
1

프레임 객체를 현재 위치와 비교하여 회전하는 방법을 알아 내려고합니다.vpython "relative"프레임 회전

객체가 북쪽을 가리키고 있고 y 축을 중심으로 180도 회전합니다. 그 후에 저는 90도 기울이기 때문에 그것을 "세계"관점에서 기울입니다. 그래서 그것은 아래쪽으로 향하고 있습니다. (이 혼란스러운 이야기로 유감스럽게도, 아래 코드를 시도하고 상하 좌우 키를 사용하면 의미하는 것을 볼 수 있습니다.)

도움이 될 것입니다.

import time 
    import numpy 
    from visual import * 

    # initialize variables 
    pitch_degrees = 0 
    roll_degrees = 0 
    yaw_degrees = 0 

    xangle = 0.0 
    yangle = 0.0 
    zangle = 0.0 

    # create the airplane frame. this will be our working object. 
    airplane = frame(make_trail=True) 
    # below are the elements that create the airplane 
    body = cone(frame=airplane, pos=(50,0,0), axis=(-150,0,0), radius=10) 
    body2 = cone(frame=airplane, pos=(50,0,0), axis=(50,0,0), radius=10) 
    wing = box(frame=airplane, pos=(35,0,0), size=(30,3,180)) 
    tail = box(frame=airplane, pos=(-75,0,0), size=(20,3,50)) 
    aileron = box(frame=airplane, pos=(-75,12,0), size=(20,24,3)) 
    cabin = ellipsoid(frame=airplane, pos=(30,5,0), axis=(1,0,0),size=(45,24,12)) 
    #painting 
    for obj in airplane.objects: 
     obj.color = color.red 

    body.color = color.white 
    cabin.color = (0.5, 0.5, 0.5) 
    cabin.opacity = 0.8 

    # I'm experiencing some jitter in my screen when starting up (yay ati....) 
    time.sleep(2) 

    # loop forever 
    while True: 
      # are there any keys pressed? if so, act on them. 
      if scene.kb.keys: # event waiting to be processed? 
        s = scene.kb.getkey() # get keyboard info 
        if (s == 'up'): 
          pitch_degrees = pitch_degrees - 1 
        if (s == 'down'): 
          pitch_degrees = pitch_degrees + 1 
        if (s == 'left'): 
          roll_degrees = roll_degrees - 1 
        if (s == 'right'): 
          roll_degrees = roll_degrees + 1 

      # convert degrees to radians 
      zangle = numpy.radians(pitch_degrees) 
      xangle = numpy.radians(roll_degrees) 

      # execute the actual rotation. 
      # but this should be relative to its current rotation :(
      airplane.rotate(angle=zangle,axis=(0,0,1)) 
      airplane.rotate(angle=xangle,axis=(1,0,0)) 

      # some delay because i'm a dirty boy 
      time.sleep(0.005) 

답변

0

비행기가 아닌 비행기 인 사용자 지정 클래스를 만듭니다. 이렇게하면 비행기의 위치와 방향에 따라 클래스의 모든 항목 (날개, 꼬리 등)을 회전시키는 비행기 클래스에 대한 메서드를 가질 수 있습니다. 따라서 클래스에는 방향 벡터뿐 아니라 위치 벡터 인 벡터가 포함됩니다. 그런 다음 회전 수학을 사용하여 각 항목을 비행기의 방향 벡터에 대해 개별적으로 회전합니다.

죄송합니다. 댓글에 게시하지만 평판이 충분하지 않습니다.