#1
|
|||
|
|||
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) |
#2
|
|||
|
|||
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) |
#3
|
|||
|
|||
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) |
#4
|
|||
|
|||
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. |
#5
|
|||
|
|||
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) |
#6
|
|||
|
|||
Hi,
Change the following line: Code:
pointListe.append(startPoint) Code:
pointListe.append(startPoint+[0]) |
#7
|
|||
|
|||
This works fine, thank you very much.
Time to go home, have a great evening, Johannes |
|
|