View Single Post
  #1  
Old 02-25-2011, 08:47 AM
new_horizon new_horizon is offline
Member
 
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 *
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] )

#Disable the default head light.
viz.MainView.getHeadLight().disable()

# Add directional light source
sun_light=viz.addLight()
sun_light.position(0,100,-70,1)
# Give light sunish color and intensity
sun_light.color ([1,1,1])
sun_light.intensity(-1)
sun_light.quadraticattenuation(0)

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

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.texture(ground)
road.setPosition(0,-0.6,0) #
road.rotate(90,90,0)
road.appearance(viz.TEXGEN)
road.appearance(viz.TEXMODULATE)
road2=road.copy()
road2.rotate(90,90,0)
road2.setPosition(0,-0.6,10)

#Add a model of a torch and place it in the scene.
# Create headlight shape
viz.startlayer(viz.POLY_FILL)
viz.vertexcolor(1,1,1)
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
viz.vertex(0,0)
viz.vertex(x,y)
headlight1 = viz.endlayer()
headlight1.color(1,1,1)
headlight1.setPosition( [ 0 , 0 , -20 ])
#Add a light for the torch.
flash_light = viz.addLight()
#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.spread(80)
#flash_light.spotexponent( 10 )
flash_light.constantattenuation(0)
flash_light.linearattenuation(1)

#flash_light.quadraticattenuation(0)


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

headlight1.setEuler(0,0,0)
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