WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-11-2005, 03:13 PM
Johannes Johannes is offline
Member
 
Join Date: Jan 2005
Posts: 143
Creating on the fly objects and projecting them on texture

Hi,
to add a graph to my 3d World (e.g. show velocity vs. time) I thought to create on-the-fly points and then add them to a texquad.

The advantage of this "projection" would be, that as it seems the texquad stays on the same place of the monitor.

Generating points works fine, but I don't get my points on the texquad. Or is the whole idea no good?

This wil be my last question for today

Thank you, Johannes

ExampleProgram

import viz

viz.go()

quad = viz.add(viz.TEXQUAD,viz.SCREEN)
quad.translate(0.5,0.5, 0.5)
quad.scale(3,3, 1)
quad.visible(viz.OFF)


RADIUS=1

viz.startlayer(viz.LINE_LOOP)
viz.vertexcolor(2, 4, 4)
viz.vertex(-RADIUS, -RADIUS, RADIUS)
viz.vertex(-RADIUS, RADIUS, RADIUS)
line = viz.endlayer()

viz.startlayer(viz.LINE_LOOP)
viz.vertexcolor(2, 4, 4)
viz.vertex(-RADIUS, -RADIUS, RADIUS)
viz.vertex(RADIUS, -RADIUS, RADIUS)
line2 = viz.endlayer()
#line.translate(3,2,4)

SPIsSet,EPIsSet=0,0
startPoint=[0,0,0]
endPoint=[0,0,0]
show=1
pointListe=[]

def mousedown(button):
#
if button == viz.MOUSEBUTTON_LEFT:
global startPoint,SPIsSet
global endPoint,EPIsSet, pointListe
if SPIsSet==0:
startPoint=viz.screentoworld(viz.mousepos())
#print 'startPoint:',startPoint
#SPIsSet=1
pointListe.append(startPoint)
drawPoints()
else:
print 'forgot option 3'
if button == viz.MOUSEBUTTON_RIGHT:
show=1
drawPoints()

def drawPoints():
viz.startlayer(viz.POINTS)
viz.vertexcolor(0,12,1)
viz.pointsize(2)
for object in pointListe:
print 'pointliste',pointListe
viz.vertex(object)
points = viz.endlayer()
quad.texture(points)
quad.visible(viz.ON)



#Create callbacks for timer events and mouse click events
viz.callback(viz.MOUSEDOWN_EVENT,mousedown)
Reply With Quote
  #2  
Old 01-11-2005, 03:40 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

I'm not exactly clear on what you are trying to do. Do you just want to attach an On-The-Fly object to the screen? On-The-Fly objects are not the same as Texture objects, so you cannot apply them as textures. The following code sample will draw a red square outline on the screen. Let me know if I misunderstood your question.
Code:
viz.startlayer(viz.LINE_LOOP)
viz.vertexcolor(viz.RED)
viz.linewidth(2)
viz.vertex(0.3,0.3)
viz.vertex(0.3,0.7)
viz.vertex(0.7,0.7)
viz.vertex(0.7,0.3)
line = viz.endlayer(viz.SCREEN)
P.S. Whenever you want to insert code into your post simply surround the code with the following tags: [ code ] some code [/code]
Reply With Quote
  #3  
Old 01-11-2005, 03:55 PM
Johannes Johannes is offline
Member
 
Join Date: Jan 2005
Posts: 143
Yes, good and easy idea, that's what I want to do but your approach does not seem to work with this code. (Code below works but if I change the line to points = viz.endlayer(viz.SCREEN) it does not work right. The screen does not seem to actualize itself on runtime?!


Code:
import viz

viz.go()


RADIUS=1

viz.startlayer(viz.LINE_LOOP)
viz.vertexcolor(2, 4, 4)
viz.vertex(-RADIUS, -RADIUS, RADIUS)
viz.vertex(-RADIUS,  RADIUS, RADIUS)
line = viz.endlayer()

viz.startlayer(viz.LINE_LOOP)
viz.vertexcolor(2, 4, 4)
viz.vertex(-RADIUS, -RADIUS, RADIUS)
viz.vertex(RADIUS,  -RADIUS, RADIUS) 
line2 = viz.endlayer()
#line.translate(3,2,4)

SPIsSet,EPIsSet=0,0
startPoint=[0,0,0]
endPoint=[0,0,0]
show=1
pointListe=[]

def mousedown(button):
	# 
	if button == viz.MOUSEBUTTON_LEFT:
		global startPoint,SPIsSet
		global endPoint,EPIsSet, pointListe
		if SPIsSet==0:
			startPoint=viz.screentoworld(viz.mousepos())
			#print 'startPoint:',startPoint
			#SPIsSet=1
			pointListe.append(startPoint)
			drawPoints()
		else:
			print 'forgot option 3'
	if button == viz.MOUSEBUTTON_RIGHT:
		show=1
		drawPoints()
			
def drawPoints():
	viz.startlayer(viz.POINTS)
	viz.vertexcolor(0,12,1)
	viz.pointsize(2)
	for object in pointListe:
		print 'pointliste',pointListe
		viz.vertex(object)
	points = viz.endlayer()



	
#Create callbacks for timer events and mouse click events
viz.callback(viz.MOUSEDOWN_EVENT,mousedown)
Reply With Quote
  #4  
Old 01-11-2005, 04:02 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

When you create an On-The-Fly object for the screen, the vertex positions need to be in screen coordinates. Screen coordinates range from 0 to 1. (0,0) is the bottom left corner of the screen and (1,1) is the top right corner. So in your case you don't need to bother with the viz.screentoworld function since the points are already in screen coordinates.
Reply With Quote
  #5  
Old 01-11-2005, 04:42 PM
Johannes Johannes is offline
Member
 
Join Date: Jan 2005
Posts: 143
Changed it and got the following exception: pointliste [[0.6171875, 0.60208332538604736], [0.7421875, 0.42916667461395264], [0.29843750596046448, 0.55833333730697632], [0.48906248807907104, 0.54583334922790527], [0.74531251192092896, 0.44374999403953552]]
Traceback (most recent call last):
File "050110_DrawPointProblem_forum.py", line 99, in mousedown
drawPoints()
File "050110_DrawPointProblem_forum.py", line 137, in drawPoints
viz.vertex(object)
File "C:\Program Files\Vizard25\viz.py", line 3692, in vertex
_ipcSend(_VIZ_VERTEX,0,0,'',x[0],x[1],x[2],0)
IndexError: list index out of range


Code:
import viz




viz.go()






RADIUS=1




viz.startlayer(viz.LINE_LOOP)


viz.vertexcolor(2, 4, 4)


viz.vertex(-RADIUS, -RADIUS, RADIUS)


viz.vertex(-RADIUS,  RADIUS, RADIUS)


line = viz.endlayer()




viz.startlayer(viz.LINE_LOOP)


viz.vertexcolor(2, 4, 4)


viz.vertex(-RADIUS, -RADIUS, RADIUS)


viz.vertex(RADIUS,  -RADIUS, RADIUS) 


line2 = viz.endlayer()


#line.translate(3,2,4)




SPIsSet,EPIsSet=0,0


startPoint=[0,0]


show=1


pointListe=[]




def mousedown(button):


	# 


	if button == viz.MOUSEBUTTON_LEFT:


		global startPoint,SPIsSet


		global endPoint,EPIsSet, pointListe


		if SPIsSet==0:


			startPoint=viz.mousepos()


			#print 'startPoint:',startPoint


			#SPIsSet=1


			pointListe.append(startPoint)


			drawPoints()


		else:


			print 'forgot option 3'


	if button == viz.MOUSEBUTTON_RIGHT:


		show=1


		drawPoints()


			

def drawPoints():


	viz.startlayer(viz.POINTS)


	viz.vertexcolor(0,12,1)


	viz.pointsize(2)


	for object in pointListe:


		print 'pointliste',pointListe


		viz.vertex(object)


	points = viz.endlayer(viz.SCREEN)
Reply With Quote
  #6  
Old 01-11-2005, 04:49 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

Change the following line:
Code:
pointListe.append(startPoint)
to
Code:
pointListe.append(startPoint+[0])
The viz.vertex command expects 3 values.
Reply With Quote
  #7  
Old 01-11-2005, 04:55 PM
Johannes Johannes is offline
Member
 
Join Date: Jan 2005
Posts: 143
This works fine, thank you very much.
Time to go home, have a great evening,
Johannes
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 03:16 AM.


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