WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)

 new_horizon 02-25-2011 08:47 AM

Hi All,

Another question regarding lighting :-) I am trying to create motorcycle headlights that illuminate the road as they travel forward - I have created the following, which seems to work - but with a slightly strange effect...

(Please note, you can insert any image in place of "tarmac.jpg"

import viz
import vizact
import math
import random
from numpy import *
viz.go()

#Set the viewpoint's position and orientation so that we'll be able to see our scene.
viz.MainView.setPosition( [0,0.8,20 ] )
viz.MainView.setEuler( [-180,4, 0] )

sun_light.position(0,100,-70,1)
# Give light sunish color and intensity
sun_light.color ([1,1,1])
sun_light.intensity(-1)

ball.appearance(viz.TEXMODULATE)

ball.setPosition([ 0 , 10.75 , 0 ])

#Add a model of a torch and place it in the scene.
viz.startlayer(viz.POLY_FILL)
viz.vertexcolor(1,1,1)
NUM_DOTS = 10000.0
for i in range(0, NUM_DOTS):
angle= 360.0*(i/NUM_DOTS)
# Put a vertex at each of these, but jump back to zero in between
viz.vertex(0,0)
viz.vertex(x,y)
headlight1.setPosition( [ 0 , 0 , -20 ])
#Add a light for the torch.
#Make the light positional.
flash_light.position(0,0,0,1)
flash_light.intensity(100)
#Make this positional light a spot light by limiting its spread.
#flash_light.spotexponent( 10 )
flash_light.constantattenuation(0)
flash_light.linearattenuation(1)

#Link the light source to the torch.

Can anyone shed any light on what is happening here?

Best wishes!

 Jeff 02-25-2011 03:25 PM

In the future please insert your code within code tags to preserve the indentation.

I think what you are seeing is that the whole texture quad appears lighted rather than just the small area near the light. Is that correct?

A surface has to be tessellated to have differentiated lighting. So you would need to have many smaller texture quads to get that effect.

 new_horizon 03-01-2011 09:34 AM

Thanks for the reply Jeff - I decided to try to use the Inifinite Terrain and coat it in a tarmac image in order to increase the tesselation...

#Add a texture and set it to repeat mode.
grass.wrap(viz.WRAP_S,viz.REPEAT)
grass.wrap(viz.WRAP_T,viz.REPEAT)

#Add the terrain using the infinte terrain plug-in.

#Texture the terrain.
terrain.texture(grass)
terrain.command(1,'',0,0)
terrain.appearance(viz.TEXMODULATE)

However, I am still getting this jagged light effect - almost as if it is passing the light onto one object and then another - just at a faster pace. Is there anyway of smoothing this? Any increase in tesselation value (over 8) for the terrain results in my PC crashing - if an increase is likely to improve this effect, I can find another PC.

Thanks - I appreciate your help!

1 Attachment(s)
For headlights, using the projector plugin will give the best effect. Check out this code and the attached .jpg

Code:

```import viz viz.go() model = viz.add('tankmaze.wrl') import projector left = projector.add(viz.add('spotlight.bmp')) left.border(0.3,0.3,0.3) left.translate(-1,1.8,0) left.affect(model) right = projector.add(viz.add('spotlight.bmp')) right.border(0.3,0.3,0.3) right.translate(1,1.8,0) right.affect(model,2) viz.link(viz.MainView, left) viz.link(viz.MainView, right)```

 new_horizon 03-04-2011 03:43 AM

3 Attachment(s)
Thanks for the reply, I really do appreciate it - that effect is really quite cool, but sadly, it isn't the viewpoint I was looking for.

The basic paradigm here is that I want individuals to make judgements based on the speed at which vehicles are travelling in night-time conditions.

In the attachments, you will see that in Screen Shot 1 - the car appears in full light (although the scene should actually be dark) and in Screen Shot 2, the car appears to be dark (which is correct) - but that is a different issue.

Basically (as Screen Shot 3 demonstrates) as the vehicles are approaching the observation point (they are only visible for 0.75s) the light eminating from the headlights onto the group seems to flicker - as if it is lighting up a particular square and then not the next and then coming back on again.

Is there a way that I can use this plug in here?

Once again, thanks for your time.

```light.setPosition([0, 3, 0]) light.setEuler([0, 90, 0])```