Introduction to Vizard: Loading Avatars, Random Walk, Character Actions, and Mouse Interaction
This article introduces Vizard, a C/C++‑based virtual‑reality development platform with Python bindings, and demonstrates how to load avatars and objects, implement a random‑walk pigeon, create talking characters, handle character movement via keyboard, capture mouse motion, and combine these techniques into a functional VR scene.
Vizard is a virtual‑reality development platform built on C/C++ and OpenGL, which can be scripted with Python; the Python layer compiles scripts to a byte‑code abstraction (LAXMI) that drives the rendering engine.
Loading avatars, objects, and backgrounds
avatar = viz.addAvatar('xxx.cfg', pos=(0,0,0), euler=(0,0,0)) viz.add('xxx.osgb', pos=(0,0,0), euler=(0,0,0)) viz.addChild('xxx.obj', pos=(-4,0,7.5))Pigeon random walk
pigeon = viz.addAvatar('pigeon.cfg', pos=(2,0,5)) random_walk = vizact.walkTo(pos=[vizact.randfloat(1.5,2.5),0,vizact.randfloat(4.5,5.5)]) random_animation = vizact.method.state(vizact.choice([1,3], vizact.RANDOM)) random_wait = vizact.waittime(vizact.randfloat(2.0,8.0)) pigeon_idle = vizact.sequence(random_walk, random_animation, random_wait, viz.FOREVER) pigeon.runAction(pigeon_idle)Talking characters
def PersonTalk(): female = viz.addAvatar('vcc_female.cfg', pos=(1,0,8), euler=(-90,0,0)) male = viz.addAvatar('vcc_male2.cfg', pos=(0,0,8), euler=(90,0,0)) female.state(14) male.state(4)Character movement via keyboard
def roleMove(): m1 = viz.Matrix.euler(0,0,0) dm = viz.getFrameElapsed() * speed temp = avatar.getEuler()[0] * math.pi / 180 if viz.key.isDown('w'): m1.preTrans([dm*math.sin(temp),0,dm*math.cos(temp)]) avatar.state(2) elif viz.key.isDown('s'): m1.preTrans([-dm*math.sin(temp),0,-dm*math.cos(temp)]) avatar.state(2) elif viz.key.isDown('a'): m1.preTrans([-dm*0.3*math.cos(temp),0,dm*0.3*math.sin(temp)]) avatar.state(12) elif viz.key.isDown('d'): m1.preTrans([dm*0.3*math.cos(temp),0,-dm*0.3*math.sin(temp)]) avatar.state(13) else: avatar.state(1) avatar.setPosition(m1.getPosition(), viz.REL_PARENT)Mouse movement capture
def onMouseMove(e): global mp_x, mp_y mp_x = e.dx mp_y = e.dy viz.callback(viz.MOUSE_MOVE_EVENT, onMouseMove)The final scene combines a system‑time clock, two animated talking avatars, a third‑person roaming pigeon, keyboard‑controlled character navigation, mouse‑driven rotation and pitch, and additional 3D objects such as a vase, sky, and grass backgrounds.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.