PDA

View Full Version : Using on-the-fly with objects


vr_boyko
10-01-2004, 08:57 PM
Hi-

Is it possible to create on-the-fly objects using another object? Say I have a soccer ball object, and I want to create a string of them using on-the-fly. Is that allowed, or is OTF restricted to simple points and vertexes?

- thanks

farshizzo
10-04-2004, 09:51 AM
Hi,

Do you just want to make a copy of an existing object? If this is the case then you can use the either the clone or copy command. Example:ball = viz.add('ball.wrl')
ball2 = ball.clone()
ball3 = ball.clone()Let me know if I misunderstood your question.

vr_boyko
10-05-2004, 02:27 PM
Thanks for the reply.

Sorry about the vagueness - I was thinking more on the lines of using on-the-fly to create a sort of "3D paint" world. I'm tracking a second light for this world, which the user holds in his/her hand, and theoretically a stream of paint appears wherever the user moves the light.

My problem now is deciding on the implementation. I thought about creating small "paint pellet" spheres where the hand is every second, but I was concerned about clogging vizard with too many objects and polygons. Instead, I was wondering if I could use on-the-fly to create a kind of "paint tube" object. Theoretically, on-the-fly will constantly update the shape of this tube compared to the user's hand movements.

Is that possible?

farshizzo
10-05-2004, 02:37 PM
Hi,

This is definitely possible. Here's a sample script I wrote a while back which creates a fading trail coming from the mouse position:import viz
viz.go()

TRAIL_SIZE = 40

TRAIL_COLOR = viz.RED

history = []

viz.startlayer(viz.LINE_STRIP)
viz.vertexcolor(0,0,0,0)
viz.linewidth(2)
for x in range(TRAIL_SIZE):
viz.vertex(x,0.5,0)
trail = viz.endlayer(viz.SCREEN)

trail.dynamic()
trail.enable(viz.BLEND)

def mytimer(num):
history.append(viz.mousepos())
if len(history) > TRAIL_SIZE:
del history[0]

histsize = len(history)

for i in range(histsize):
trail.vertexcolor(i,TRAIL_COLOR+[i/float(histsize)])
trail.vertex(i,history[i][0],history[i][1])

viz.callback(viz.TIMER_EVENT,mytimer)
viz.starttimer(0,0.001,viz.FOREVER)This probably doesn't do exactly what you want, but I think it should definitely be a good starting point.

vsully
10-08-2004, 12:11 AM
Thanks, the code works beautifully.

One question left: can I change the alpha level for a particular vertex to be transparent? Right now the code draws the line in one big circle, connecting the end of the line (where the mouse is) with the beginning of the line. I need a way to turn off that last segment, so the line appears to have a beginning and end.

I was looking at the .alpha function, but it seems to work only on the object as a whole. Any suggestions?

Thanks again.

vsully
10-08-2004, 04:27 AM
One more question:

Vizard seems to have trouble creating on-the-fly objects within the constructor of a class. Whenever I try (simply initializing all the vertex points) in the class, vizard complains that the type 'x' in viz.vertex(x, 0.3,0) must be of type float instead of type ([]).

I'm using code pretty close to what you provided, simply tailored a bit to a class constructor.

Thanks much for all your help.

farshizzo
10-08-2004, 09:49 AM
Hi,

The code I gave you should already be setting the alpha value at each vertex. The alpha fades from 1 to 0 from the beginning of the trail to the end. The vertexcolor command has an optional fourth argument which represents the alpha value at that vertex. Be sure to enable viz.BLEND on the object in order for the alpha to work correctly.

Also, the trail should not be a loop. I've attached a screen shot of what the program above should look like when you run it.

There should be no problem with creating an OTF object in a class constructor. How are you initializing the value x?

vsully
10-08-2004, 03:50 PM
Here's a section of the code I'm running in the constructor:

---
viz.startlayer(viz.LINE_STRIP)
viz.vertexcolor(Color)
viz.linewidth(Size)

for x in range(trailSize):
viz.vertex(x,0.3,0)
self.trail = viz.endlayer(viz.SCREEN)
---

Spot anything?

Secondly, I can't seem to get the transparency working right.
With this line of code:

---
trail.vertexcolor((cur_vertex+1)%TRAIL_SIZE, viz.YELLOW, 0)
---

The line still shows up bright yellow. viz.BLEND has been enabled. Spot anything here?

Sorry for the spam, and thanks for your help.

-Aaron

farshizzo
10-08-2004, 03:55 PM
Hi,

In the following code:for x in range(trailSize):
viz.vertex(x,0.3,0) How is the variable trailSize initialized?

Also, for the vertex color try doing the following:trail.vertexcolor((cur_vertex+1)%TRAIL_S IZE, viz.YELLOW+[0])

vsully
10-08-2004, 04:29 PM
Vertex code works now - thanks. That's kind of random syntax though... :)

trailSize is passed in as a parameter. Right now I'm passing in the integer 400 for this field.

farshizzo
10-08-2004, 04:37 PM
Hi,

Yeah, it is kind of weird. I've fixed it so that your previous code will work in future versions.

Regarding your other problem, the following code works fine over here:class TrailClass:
def __init__(self):

viz.startlayer(viz.LINE_STRIP)
viz.vertexcolor(viz.RED)
viz.linewidth(1)

for x in range(400):
viz.vertex(x,0.3,0)
self.trail = viz.endlayer(viz.SCREEN)

lines = TrailClass()In the for loop where you declare each vertex will you try printing out the value of x and let me know what the output is?

vsully
10-12-2004, 05:48 PM
Hi farshizzo,

Thanks for all your help - I've managed to use the on-the-fly functionality like you've described and so far it shows potential. It's tempermental, but it works. :]

Now, however, I seem to be having openGL drawing errors with the on-the-fly. In VR the line draws exactly as it should, but occasionally a slight movement of the head will cause the line to disappear altogether, only to reappear when the head is moved back to it's original position. We're talking about a cm of movement here.

Any ideas?

Thanks,

Aaron

farshizzo
10-13-2004, 10:16 AM
Hi,

What position do you initialize the vertices to? Are the vertices attached to the screen?

vsully
10-13-2004, 10:32 AM
They're initialized to viz.WORLD

farshizzo
10-13-2004, 10:37 AM
Hi,

That's what I figured. This is definitely a bug. In the meantime, initialize at least 2 of the vertices to a large range of values, like (100,100,100) to (-100,-100,-100). After they are initialized you can change their positions back to the original values.

I know this sounds weird, but it will take care of the disappearing problem. Is this the only problem you are having?

vsully
10-14-2004, 06:54 PM
OK, that worked - pretty weird hack. :]

I believe that's the last of the problems. Thanks for all your help; I should be set for a while.

-Aaron