PDA

View Full Version : Creating on the fly objects and projecting them on texture


Johannes
01-11-2005, 03:13 PM
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)

farshizzo
01-11-2005, 03:40 PM
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.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]

Johannes
01-11-2005, 03:55 PM
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?!




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)

farshizzo
01-11-2005, 04:02 PM
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.

Johannes
01-11-2005, 04:42 PM
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



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)

farshizzo
01-11-2005, 04:49 PM
Hi,

Change the following line:pointListe.append(startPoint)topointListe.app end(startPoint+[0])The viz.vertex command expects 3 values.

Johannes
01-11-2005, 04:55 PM
This works fine, thank you very much.
Time to go home, have a great evening,
Johannes