WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 07-18-2008, 08:38 AM
fc2008 fc2008 is offline
Member
 
Join Date: Jul 2008
Posts: 6
object in information box

Heya, I have an object - draft_text

I want to be included within an information box that pops up, how would I do this?

This is so when a user types a message it appears within that box

Also, how would I get the information box to follow an avatar around the screen?


The code i am using to create a networked chat box is below

Thanks in advance, FC

Code:
sent_message.visible(0)
typing_message.visible(0)


#Use a prompt to ask the user the network name of the other computer.
target_machine = viz.input('Enter the name of the other machine').upper()

#Add a mailbox from which to send messages. This is your outbox.
target_mailbox = viz.addNetwork(target_machine) 

 

#Start with sending_text as a blank space.
out_text = ''


def SendData(): 
    #Retrieve current transform of viewpoint
    mat = viz.MainView.getMatrix()
    
    #Apply offsets so duck model matches viewpoint
    mat.preEuler(180,0,0)
    mat.preTrans(0,-1,0)
 
 #Send position/rotation to target network object
    target_mailbox.send(quat=mat.getQuat(),pos=mat.getPosition(),message=out_text)

# Start a timer that sends out data over the network every frame
vizact.ontimer(0,SendData) 

# Listens for any incomming messages
def onNetwork(e):
    avatar.setPosition(e.pos)
    avatar.setQuat(e.quat)
    inbox.message(e.message)

# Register network to listen from incoming messages
viz.callback(viz.NETWORK_EVENT, onNetwork) 


#Create a variable for the draft of the outgoing message.
draft_text = ' '

def mykeyboard(key):
    global out_text, draft_text
    #If the length of the key is 1 then
    #add the character to the string.
    if draft_text == '':
        sent_message.visible(0)
        typing_message.visible(0)

    if len(key) == 1:
        draft_text += key
        sent_message.visible(0)
        typing_message.visible(1)
#If the key is a character return, end the line, make the 
#outgoing message equal to the draft message, and set the draft equal 
    # to a blank space.
    elif key == viz.KEY_RETURN:
        out_text = draft_text
        sent_message.visible(1)
        typing_message.visible(0)
        
    #If the key is the backspace key then remove the last character of the string.
    elif key == viz.KEY_BACKSPACE: 
        draft_text = draft_text[:-1]
    #Update the input text field so that you can see what you're typing.
    outbox.message(draft_text)
    print draft_text

Last edited by fc2008; 07-18-2008 at 08:44 AM.
Reply With Quote
  #2  
Old 07-22-2008, 12:25 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
You can use the vizinfo module to display an information box. You can use the viz.MainWindow.worldToScreen command to convert world coordinates to screen coordinates, in order to position the info box near the avatar. Here is some sample code that shows how to accomplish this:
Code:
import viz
viz.go()

#Create avatar
female = viz.add('vcc_female.cfg',euler=(180,0,0),pos=(0,0,6))

#Create info box that is aligned to lower left corner
import vizinfo
info = vizinfo.add('')
info.alignment(vizinfo.LOWER_LEFT)

#Setup timer to position info box near avatar head
def UpdateInfoPosition():
	m = female.getBone('Bip01 Head').getMatrix(viz.AVATAR_WORLD)
	m.preTrans(0,0.2,0)
	x,y,z = viz.MainWindow.worldToScreen(m.getPosition())
	info.translate(x+0.03,y+0.02)
	info.visible(z>0)
vizact.ontimer(0,UpdateInfoPosition)

#Use the following code to change the message of the box
info.message('hello')
Reply With Quote
  #3  
Old 06-11-2013, 07:35 AM
CompSci CompSci is offline
Member
 
Join Date: Jun 2013
Posts: 28
Hello,

Can you please add the code that enables real-time editing to this message box??

Thanks


Quote:
Originally Posted by farshizzo View Post
You can use the vizinfo module to display an information box. You can use the viz.MainWindow.worldToScreen command to convert world coordinates to screen coordinates, in order to position the info box near the avatar. Here is some sample code that shows how to accomplish this:
Code:
import viz
viz.go()

#Create avatar
female = viz.add('vcc_female.cfg',euler=(180,0,0),pos=(0,0,6))

#Create info box that is aligned to lower left corner
import vizinfo
info = vizinfo.add('')
info.alignment(vizinfo.LOWER_LEFT)

#Setup timer to position info box near avatar head
def UpdateInfoPosition():
	m = female.getBone('Bip01 Head').getMatrix(viz.AVATAR_WORLD)
	m.preTrans(0,0.2,0)
	x,y,z = viz.MainWindow.worldToScreen(m.getPosition())
	info.translate(x+0.03,y+0.02)
	info.visible(z>0)
vizact.ontimer(0,UpdateInfoPosition)

#Use the following code to change the message of the box
info.message('hello')
Reply With Quote
  #4  
Old 06-11-2013, 10:17 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
You can change the content of a info box using the info.message command. Register a callback function for key events and in that function change the message value based on keys pressed.
Reply With Quote
  #5  
Old 06-12-2013, 05:09 AM
CompSci CompSci is offline
Member
 
Join Date: Jun 2013
Posts: 28
I will give this a try, thank you.
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
retrieve Object names Geoffrey Vizard 11 12-11-2009 04:26 AM
Child Object Rotation paulgoldberg Vizard 5 09-05-2006 11:33 AM
when collision mode is on, can i "turn it off" for an individual object? Vdoug Vizard 1 09-22-2005 12:14 PM
rotate to object jargon Vizard 1 08-08-2005 12:20 PM
Moving view with object Xliben Vizard 2 07-25-2005 05:36 PM


All times are GMT -7. The time now is 02:17 AM.


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