WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Thread Tools Rate Thread Display Modes
Old 02-25-2011, 08:47 AM
new_horizon new_horizon is offline
Join Date: Apr 2010
Posts: 43
Headlight Question

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 viztask
import math
import random
from numpy import *

#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] )

#Disable the default head light.

# Add directional light source
# Give light sunish color and intensity
sun_light.color ([1,1,1])

ball = viz.add('ball.wrl')

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

# Create Road
ground = viz.addTexture('tarmac.jpg')
road = viz.addTexQuad(viz.WORLD,viz.MainScene,10) # 100m sq quad
road.setPosition(0,-0.6,0) #

#Add a model of a torch and place it in the scene.
# Create headlight shape
Radius = 0.1
NUM_DOTS = 10000.0
for i in range(0, NUM_DOTS):
angle= 360.0*(i/NUM_DOTS)
x = Radius*math.sin(angle)
y = Radius*math.cos(angle)
# Put a vertex at each of these, but jump back to zero in between
headlight1 = viz.endlayer()
headlight1.setPosition( [ 0 , 0 , -20 ])
#Add a light for the torch.
flash_light = viz.addLight()
#Make the light positional.
#Make this positional light a spot light by limiting its spread.
#flash_light.spotexponent( 10 )


torch = viz.add('art/flashlight.IVE')
#Link the light source to the torch. headlight1, flash_light) headlight1, torch)

headlight1.goto(0,0,15,8, viz.TIME)

#headlight1.addAction( vizact.spin( 10,1,0,90, viz.FOREVER ) )

Can anyone shed any light on what is happening here?

Best wishes!
Reply With Quote
Old 02-25-2011, 03:25 PM
Jeff Jeff is offline
WorldViz Team Member
Join Date: Aug 2008
Posts: 2,467
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.
Reply With Quote
Old 03-01-2011, 09:34 AM
new_horizon new_horizon is offline
Join Date: Apr 2010
Posts: 43
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 = viz.add('tarmac.jpg')

#Add the terrain using the infinte terrain plug-in.
terrain = viz.add('InfiniteTerrain.dlc',1,'456',8,1000,400,1 0000)

#Texture the terrain.

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!
Reply With Quote
Old 03-02-2011, 12:47 PM
Gladsomebeast Gladsomebeast is offline
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
For headlights, using the projector plugin will give the best effect. Check out this code and the attached .jpg

import viz

model = viz.add('tankmaze.wrl')

import projector

left = projector.add(viz.add('spotlight.bmp'))

right = projector.add(viz.add('spotlight.bmp'))
right.affect(model,2), left), right)
Attached Images
File Type: bmp spotlight.bmp (48.1 KB, 681 views)
Paul Elliott
WorldViz LLC
Reply With Quote
Old 03-04-2011, 03:43 AM
new_horizon new_horizon is offline
Join Date: Apr 2010
Posts: 43
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.
Attached Thumbnails
Click image for larger version

Name:	NIght Screen Shot 1.JPG
Views:	724
Size:	67.4 KB
ID:	411   Click image for larger version

Name:	NIght Screen Shot 2.JPG
Views:	727
Size:	66.4 KB
ID:	412   Click image for larger version

Name:	Night Screen Shot MC.JPG
Views:	721
Size:	63.1 KB
ID:	413  
Reply With Quote
Old 03-04-2011, 09:45 AM
Gladsomebeast Gladsomebeast is offline
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
Instead of linking the projector to the mainview, position it high and point it down.

light.setPosition([0, 3, 0])
light.setEuler([0, 90, 0])
Paul Elliott
WorldViz LLC
Reply With Quote

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Lighting Question new_horizon Vizard 12 02-24-2011 08:11 AM
question about NVIDIA 3D vision Weihua An Vizard 5 08-02-2010 06:49 AM
Stereoscopic view question atamasan Vizard 2 03-09-2010 09:13 PM
how to invoke command line question billjarrold Vizard 2 01-11-2010 08:51 AM
General question and question regarding arrays dan12345 Vizard 1 01-15-2008 10:15 AM

All times are GMT -7. The time now is 11:11 AM.

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