WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   object in information box (https://forum.worldviz.com/showthread.php?t=1573)

fc2008 07-18-2008 08:38 AM

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


farshizzo 07-22-2008 12:25 PM

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')


CompSci 06-11-2013 07:35 AM

Hello,

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

Thanks


Quote:

Originally Posted by farshizzo (Post 5988)
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')



Jeff 06-11-2013 10:17 AM

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.

CompSci 06-12-2013 05:09 AM

I will give this a try, thank you.


All times are GMT -7. The time now is 10:32 AM.

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