WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 04-09-2009, 04:51 AM
5ky1ine 5ky1ine is offline
Member
 
Join Date: Mar 2009
Posts: 10
Smile making doors open with clicking on them using a mouse

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.
Reply With Quote
  #2  
Old 04-09-2009, 01:27 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,453
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.
Code:
vizact.onpick(door, door.addAction, opendoor)
Reply With Quote
  #3  
Old 04-10-2009, 11:47 AM
5ky1ine 5ky1ine is offline
Member
 
Join Date: Mar 2009
Posts: 10
is that all i have to add or is there a complete code to make this work?
Reply With Quote
  #4  
Old 04-10-2009, 02:01 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,453
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

Code:
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)
Reply With Quote
  #5  
Old 04-12-2009, 10:03 AM
5ky1ine 5ky1ine is offline
Member
 
Join Date: Mar 2009
Posts: 10
Unhappy

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)
Reply With Quote
  #6  
Old 04-13-2009, 11:01 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,453
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
Reply With Quote
  #7  
Old 03-15-2010, 08:00 AM
bloswald bloswald is offline
Member
 
Join Date: Jan 2010
Posts: 7
Quote:
Originally Posted by Jeff View Post
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
Reply With Quote
  #8  
Old 03-29-2010, 06:30 AM
VelvetElvis VelvetElvis is offline
Member
 
Join Date: Nov 2009
Posts: 5
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.)
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 08:54 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC