View Full Version : making doors open with clicking on them using a mouse
5ky1ine
04-09-2009, 04:51 AM
hi, i wanted to know if there is a way of making doors open with a mouse, for example when you click on the door, it should open. i know there is way for making doors open with a key but i have a lot of doors in my scene. help needed please.
Try using viz.pick or vizact.onpick. Here when the door object is clicked with the left mouse button the function door.addAction is called with the argument opendoor, your animating action.
vizact.onpick(door, door.addAction, opendoor)
5ky1ine
04-10-2009, 11:47 AM
is that all i have to add or is there a complete code to make this work?
Here is a box scaled to have the shape of a door. There is a spinning action that is added to the door when you click on it.
Another way of doing this would be to use the physics engine and add a hinge joint to the door. When you click on the door a force is applied making it swing open
import viz
viz.go()
import vizinfo
info = vizinfo.add("Click on the door")
viz.add('tut_ground.wrl')
door = viz.add('box.wrl', pos = [0,1,8], scale = [1,2,.05])
#change the origin and where door will rotate
door.center(-.5,0,0)
#show the rotation point
ball = viz.add('ball.wrl', pos = [-.5,1,8], scale = [.2,.2,.2])
#create a spinning action for the door
opendoor = vizact.spinto(0,1,0, 120, 30.0)
#add the action to the door when clicked on
vizact.onpick(door, door.addAction, opendoor)
#put someone behind the door
female = viz.add('vcc_female.cfg', pos = [0,0,10], euler = [180,0,0])
female.state(5)
#disable mouse navigation
viz.mouse(viz.OFF)
5ky1ine
04-12-2009, 10:03 AM
i've added the code but my doors seem to be opening in a strange direction, when i click on them they rotate and end up somewhere else, i've added my code below for you 2 have a look at.
one more thing i have exported baked textures from 3ds max and one of them comes with grey patches for some reason, the rest work fine.
import viz
viz.go()
viz.clearcolor (0.5,0.5,1)
myHUD = viz.addTexQuad(viz.SCREEN)
myImage = viz.add('myHud.png')
myHUD.setPosition(0.5,0.5,0)
myHUD.setScale(0.2,0.2,0)
myHUD.texture(myImage)
door1 = viz.add('door1.ive')
door2 = viz.add('door2.ive')
import vizinfo
info = vizinfo.add("Click on the door")
#Door1
#change the origin and where door will rotate
door1.center(1,1,0.1)
#create a spinning action for the door
opendoor = vizact.spinto(0,6,0,90,90)
#add the action to the door when clicked on
vizact.onpick(door1, door1.addAction, opendoor)
#Door2
#change the origin and where door will rotate
door2.center(1,1,0.1)
#create a spinning action for the door
opendoor = vizact.spinto(0,6,0,-90,90)
#add the action to the door when clicked on
vizact.onpick(door2, door2.addAction, opendoor)
MOVE_SPEED = 5
TURN_SPEED = 60
view = viz.get(viz.MAIN_VIEWPOINT)
def mytimer (num):
if viz.iskeydown(viz.KEY_UP):
view.move(0,0,MOVE_SPEED*viz.elapsed(),viz.BODY_OR I)
elif viz.iskeydown(viz.KEY_DOWN):
view.move(0,0,-MOVE_SPEED*viz.elapsed(),viz.BODY_ORI)
elif viz.iskeydown(viz.KEY_RIGHT):
view.rotate(0,1,0,TURN_SPEED*viz.elapsed(),viz.BOD Y_ORI,viz.REL_PARENT)
elif viz.iskeydown(viz.KEY_LEFT):
view.rotate(0,1,0,-TURN_SPEED*viz.elapsed(),viz.BODY_ORI,viz.REL_PARE NT)
viz.callback(viz.TIMER_EVENT,mytimer)
viz.starttimer(0,0.01,viz.FOREVER)
def mousemove(e):
euler = view.getEuler(viz.HEAD_ORI)
euler[0] += e.dx*0.1
euler[1] += -e.dy*0.1
euler[1] = viz.clamp(euler[1],-95.0,85.0)
view.rotate(euler,viz.HEAD_ORI)
viz.callback(viz.MOUSE_MOVE_EVENT,mousemove)
viz.mouse(viz.OFF)
viz.cursor(viz.OFF)
viz.restrictmouse(viz.ON)
Perhaps the door was offset from the origin in your modeling software. If you just spin the model without changing it's center in Vizard and its moving all over the place then that would be the case.
If you set the origin of the door in your modeling software to the point that you want the door to rotate around then you don't have to change it's center in Vizard
bloswald
03-15-2010, 08:00 AM
Another way of doing this would be to use the physics engine and add a hinge joint to the door. When you click on the door a force is applied making it swing open
Can you please post some sample code of the physics way of doing this?
-
bloswald :)
VelvetElvis
03-29-2010, 06:30 AM
You need to rotate the door based on the GEODE of the door. I used the example of the hierarchical animation, the one with the rotating teapots on the main page.
http://kb.worldviz.com/articles/1157
You also need to make sure that your pivot point is where you want it on the door, as well as your objects xForm is reset (if you use Max.)
vBulletin® v3.8.7, Copyright ©2000-2025, vBulletin Solutions, Inc.