Форум сайта python.su
0
Установлен Blender 2.59.
Пытаюсь запустить простой скрипт движения камеры по движению мышки.
# Example Uses an L{SCA_MouseSensor}, and two L{KX_ObjectActuator}s to implement MouseLook::
# To use a mouse movement sensor "Mouse" and a
# motion actuator to mouse look:
import bge.render
import bge.logic
# scale sets the speed of motion
scale = 1.0, 0.5
co = bge.logic.getCurrentController()
obj = co.getOwner()
mouse = co.getSensor("Mouse")
lmotion = co.getActuator("LMove")
wmotion = co.getActuator("WMove")
# Transform the mouse coordinates to see how far the mouse has moved.
def mousePos():
x = (bge.render.getWindowWidth() / 2 - mouse.getXPosition()) * scale[0]
y = (bge.render.getWindowHeight() / 2 - mouse.getYPosition()) * scale[1]
return (x, y)
pos = mousePos()
# Set the amount of motion: X is applied in world coordinates...
lmotion.setTorque(0.0, 0.0, pos[0], False)
# ...Y is applied in local coordinates
wmotion.setTorque(-pos[1], 0.0, 0.0, True)
# Activate both actuators
bge.logic.addActiveActuator(lmotion, True)
bge.logic.addActiveActuator(wmotion, True)
# Centre the mouse
bge.render.setMousePosition(bge.render.getWindowWidth() / 2, bge.render.getWindowHeight() / 2)Отредактировано (Дек. 1, 2011 14:57:46)
Офлайн
0
Уверен, что апи в справке для 2.59?
Лучше спросить на сайте про блендер http://blender3d.org.ua/
Офлайн
0
Да я уже даже с родного сайта пример пробовал.
http://www.blender.org/documentation/blender_python_api_2_59_release/bge.render.html#
как раз справка по API моей версии. То же самое.
Я там уже спросил, но там в основном люди которые моделированием занимаются, а не API.
Попробую удалить Python 2.6.3, вдруг поможет.
Офлайн
18
Попробуйте просто
import bge
если не найдет модуль
import sys
sys.path.append(r'путь до bge')
Офлайн
0
Благодарю! Модуль нашел, теперь уже какие то более вменяемые ошибки выдает:
“KX_Camera object is not callable”, хотя почему он не может к камере обратится, странно. Большое вам спасибо за ответы.
Вдруг кому то пригодится: Вот тут решение, частичное.
http://blenderartists.org/forum/archive/index.php/t-165246.html
Как я понял теперь свойства хранятся и задаются в массивах а не так как в ранних версиях.
# Example Uses an L{SCA_MouseSensor}, and two L{KX_ObjectActuator}s to implement MouseLook::
# To use a mouse movement sensor "Mouse" and a
# motion actuator to mouse look:
import bge
# scale sets the speed of motion
scale = [1.0, 0.5]
cont = bge.logic.getCurrentController()
obj = cont.owner
mouse = cont.sensors["Mouse"]
lmotion = cont.actuators["LMove"]
wmotion = cont.actuators["WMove"]
# Transform the mouse coordinates to see how far the mouse has moved.
def mousePos():
x = (bge.render.getWindowWidth() / 2 - mouse.getXPosition()) * scale[0]
y = (bge.render.getWindowHeight() / 2 - mouse.getYPosition()) * scale[1]
return (x, y)
pos = mousePos()
# Set the amount of motion: X is applied in world coordinates...
lmotion.setTorque(0.0, 0.0, pos[0], False)
# ...Y is applied in local coordinates
wmotion.setTorque(-pos[1], 0.0, 0.0, True)
# Activate both actuators
bge.logic.addActiveActuator(lmotion, True)
bge.logic.addActiveActuator(wmotion, True)
# Centre the mouse
bge.render.setMousePosition(bge.render.getWindowWidth() / 2, bge.render.getWindowHeight() / 2)# Example Uses an L{SCA_MouseSensor}, and two L{KX_ObjectActuator}s to implement MouseLook::
# To use a mouse movement sensor "Mouse" and a
# motion actuator to mouse look:
import bge
# scale sets the speed of motion
scale = [1.0, 0.5]
cont = bge.logic.getCurrentController()
obj = cont.owner
mouse = cont.sensors["Mouse"]
lmotion = cont.actuators["LMove"]
wmotion = cont.actuators["WMove"]
# Transform the mouse coordinates to see how far the mouse has moved.
def mousePos():
x = (bge.render.getWindowWidth() / 2 - mouse.position[0] * scale[0]
y = (bge.render.getWindowHeight() / 2 - mouse.position[1] * scale[1]
return (x, y)
pos = mousePos()
# Set the amount of motion: X is applied in world coordinates...
lmotion.setTorque(0.0, 0.0, pos[0], False)
# ...Y is applied in local coordinates
wmotion.setTorque(-pos[1], 0.0, 0.0, True)
# Activate both actuators
bge.logic.addActiveActuator(lmotion, True)
bge.logic.addActiveActuator(wmotion, True)
# Centre the mouse
bge.render.setMousePosition(bge.render.getWindowWidth() / 2, bge.render.getWindowHeight() / 2)y = (bge.render.getWindowHeight() / 2 - mouse.position[1] * scale[1]
Отредактировано (Дек. 1, 2011 18:20:28)
Офлайн
18
У вас скобка не закрыта.
С bge незнаком, но думаю документацию смотреть лучше не любую, а к версии, которая у вас установлена.
Офлайн
0
Вот я слепошарый, простите. Благодарю. Да я как раз и смотрю документацию по моей версии, но они видимо файлы примеров поменяли везде, под версию 2.60 уже.
Офлайн