我從一個跳躍運動控制器發送位置數據並將該位置數據設置爲3d軟件來移動一個對象。但是我需要該對象記住它以前的位置,並將其添加到由跳躍饋送的數據中。Python:將新值添加到來自飛躍控制器的以前值
因此,如果第一位置值是206.901,第二位置將先前的位置加上196.799等
這是飛躍控制器內收到我3dsoftware的UDP位置數據:
received message: 206.901992798
received message: 196.799606323
received message: 218.851989746
received message: 206.74659729
received message: 217.411819458
這是設定目標的位置的三維軟件代碼:
while(True):
try:
rightswipe_x = hou.session.sock.recv(1024)
rightswipe_x = float(rightswipe_x) #string to float
print "received message:", rightswipe_x
# x coordinate
effector = hou.node('/obj/geo1/transform1') # get object from scene
x2 = effector.parm('tx') # get value of current x position of effector
x2.set(rightswipe_x/500) #set tx parameter to value
x2 = effector.evalParm('tx') # re-evaluate parameter for x position
print 'x position:',x2
因此,也許我真的很厚,但它是來自飛躍傳感器的數字的實時流,我發出,所以我沒有範圍做我? 進口插座 UDP_IP = '本地主機' UDP_PORT = 7864 襪子= socket.socket(socket.AF_INET,socket.SOCK_DGRAM)sock.bind((UDP_IP,UDP_PORT)),而正確: rightswipe_x,ADDR =襪子。 recvfrom的(1024) #PRINT 「接收到的消息:」,rightswipe_x rightswipe_x = #string浮子(rightswipe_x)漂浮 位置=在範圍rightswipe_x #for I(0,位置): #打印我 # position = position + i #打印位置 – 212A