예제 #1
0
	def addCar(self,carAppearance,isPlayerCar):

		newVisualCar=Factory.Car(carAppearance)

		newVisualCar.reparentTo(self.carsAndSceneryNode)
		newVisualCar.setPos(self.segments[100].getMidPoint().getX(),self.segments[100].getMidPoint().getY(),0)
		newVisualCar.setH(270)

		constantOneStencil = StencilAttrib.make(1,StencilAttrib.SCFEqual,StencilAttrib.SOZero,StencilAttrib.SOKeep,StencilAttrib.SOReplace,1,0,1)

		bob=ShadowGeometry('models/f1carshadow')
		newVisualCarShadowGeomNode=bob.getSnode()
		lightSourceX,lightSourceY,lightSourceZ=self.getLightSourcePosition()
		bob.setLightPos(lightSourceX,lightSourceY,lightSourceZ)
		newVisualCarShadow=render.attachNewNode(newVisualCarShadowGeomNode)
		newVisualCarShadow.setTwoSided(True)
		newVisualCarShadow.node().setAttrib(constantOneStencil)
		newVisualCarShadow.node().setAttrib(ColorWriteAttrib.make(0))
		newVisualCarShadow.setBin('fixed',40)
		newVisualCarShadow.setDepthWrite(0)

		self.createdNodes.append(newVisualCar)
		self.createdNodes.append(newVisualCarShadow)
		visualCarRepresentation=VisualCarRepresentation(newVisualCar,bob,newVisualCarShadow)
		self.cars.append(visualCarRepresentation)
		if isPlayerCar:
			self.setPlayerCar(visualCarRepresentation)

		return visualCarRepresentation
예제 #2
0
	def addStaticScenery(self,xpos,ypos,rotation,modelFilename):

		modelFilenameElements=modelFilename.split('-')
		modelFilename=modelFilenameElements[0]
		textureFilename=modelFilenameElements[1]
		if modelFilename=='lowsign':
			textureFilename="alt-"+textureFilename+"low"
		if modelFilename=='highsign':
			textureFilename="alt-"+textureFilename

		m = loader.loadModel("models/"+modelFilename)
		m.reparentTo(self.carsAndSceneryNode)

		n=m.find("**/SignLogoAdvert")
		t=loader.loadTexture("models/"+textureFilename+".png")
		t.setMinfilter(Texture.FTLinearMipmapLinear)
		n.setTexture(t,1)

		m.setPos(xpos,ypos,0)
		m.setH(rotation)

		self.createdNodes.append(m)

		lightSourceX,lightSourceY,lightSourceZ=self.getLightSourcePosition()
		shadowGeomNode=ShadowGeometry.makeModelShadow('models/'+modelFilename+'shadow',xpos,ypos,0,lightSourceX,lightSourceY,lightSourceZ,rotation)
		shadow=render.attachNewNode(shadowGeomNode)
		shadow.setTwoSided(True)
		self.createdNodes.append(shadow)
		shadow.setPos(xpos,ypos,0)

		constantOneStencil = StencilAttrib.make(1,StencilAttrib.SCFAlways,StencilAttrib.SOZero,StencilAttrib.SOKeep,StencilAttrib.SOReplace,1,0,1)
		shadow.node().setAttrib(constantOneStencil)
		shadow.node().setAttrib(ColorWriteAttrib.make(0))
		shadow.setBin('fixed',40)
		shadow.setDepthWrite(0)
예제 #3
0
	def addPuddle(self,xpos,ypos,rotation):

		stencilWriter=self.getStencilWriter(4)
		puddleStencil = loader.loadModel("models/puddlestencil")
		puddleStencil.reparentTo(self.carsAndSceneryNode)
		puddleStencil.setPos(xpos,ypos,0)
		puddleStencil.setH(rotation)
		puddleStencil.node().setAttrib(stencilWriter)
		puddleStencil.node().setAttrib(ColorWriteAttrib.make(0))
		puddleStencil.setDepthWrite(False)
		puddleStencil.setDepthTest(False)
		self.createdNodes.append(puddleStencil)

		stencilReader = self.getStencilReader(4)
		puddle = loader.loadModel("models/puddle")
		puddle.reparentTo(self.carsAndSceneryNode)
		puddle.setPos(xpos,ypos,0)
		puddle.setH(rotation)
		puddle.setDepthWrite(False)
		puddle.node().setAttrib(stencilReader)
		puddle.setBin('fixed',40)
		self.createdNodes.append(puddle)
예제 #4
0
	def __init__(self,parent,segments,timeOfDay):

		super(VisualTrackSession, self).__init__()

		self.parent=parent
		self.ticks=0
		self.cars=[]
		self.events=[]
		self.timerDependentObjects=[]
		self.segments=segments
		self.createdNodes=[]
		self.stencilReaders={}
		self.stencilWriters={}
		self.carShadowRefreshIndex=0

		self.speed=-1
		self.lapTimeSeconds=-1
		self.lapTimeMilliseconds=-1
		self.secondsRemaining=-1
		self.topScore=-1

		self.correctAspectRatio()
		base.setBackgroundColor(0.262,0.615,0.054)
		base.accept('aspectRatioChanged',self.correctAspectRatio )

		self.carsAndSceneryNode=render.attachNewNode("CarsAndSceneryNode")
		self.carsAndSceneryNode.setColorScale(1.0,1.0,1.0,1.0)

		self.sunEffectsEnabled=False
		if timeOfDay==TimeOfDay.dusk:
			self.setBackgroundTexture('textures/mountains4x2blurredblended.png')
			self.setLightSourcePosition([12000,-800,1200])
			self.addSunEffects()
		else:
			self.setBackgroundTexture('textures/mountainsx2blurredblended.png')
			self.setLightSourcePosition([-4000,-1800,2400])

		m = loader.loadModel("models/newstartline")
		m.reparentTo(self.carsAndSceneryNode)
		m.setPos(self.segments[0].getMidPoint().getX(),self.segments[0].getMidPoint().getY(),0)
		m.setH(270)
		self.lights=m
		self.lightsIlluminated=False
		for i in range(1,5):
			self.setStartingLight(i,False)
		self.createdNodes.append(m)

		trackGeomNodes=TrackVisualGeometry.makeTrack(self.segments)

		track=render.attachNewNode(trackGeomNodes['tarmac'])
		texture=loader.loadTexture("textures/track256.png")
		texture.setAnisotropicDegree(4)
		texture.setMagfilter(Texture.FTNearest)
		texture.setMinfilter(Texture.FTLinearMipmapLinear)
		texture.setWrapU(Texture.WMRepeat)
		texture.setWrapV(Texture.WMRepeat)
		track.setTexture(texture)
		track.setTwoSided(False)
		track.setDepthWrite(False)
		track.setDepthTest(False)
		track.setBin("background",10)
		self.createdNodes.append(track)

		constantTwoStencil = StencilAttrib.make(1,StencilAttrib.SCFEqual,StencilAttrib.SOZero,StencilAttrib.SOKeep,StencilAttrib.SOReplace,2,0,2)
		track.node().setAttrib(constantTwoStencil)

		startLine=render.attachNewNode(trackGeomNodes['startline'])
		texture=loader.loadTexture("textures/startline.png")
		texture.setAnisotropicDegree(4)
		texture.setMagfilter(Texture.FTNearest)
		texture.setMinfilter(Texture.FTLinearMipmapLinear)
		texture.setWrapU(Texture.WMRepeat)	
		texture.setWrapV(Texture.WMRepeat)
		startLine.setTexture(texture)
		startLine.setTwoSided(False)
		startLine.setDepthWrite(False)
		startLine.setDepthTest(False)
		startLine.setBin("background",11);
		self.createdNodes.append(startLine)

		backgroundGeomNodes=MountainsGeometry.makeMountains()

		mountainsGeomNode=backgroundGeomNodes['mountains']
		mountains=render.attachNewNode(mountainsGeomNode)
		texture=loader.loadTexture(self.getBackgroundTexture())
		texture.setAnisotropicDegree(4)
		texture.setWrapU(Texture.WMRepeat)	
		texture.setWrapV(Texture.WMClamp)
		mountains.setTexture(texture)
		mountains.setTwoSided(False)
		mountains.setDepthWrite(False)
		mountains.setDepthTest(False)
		mountains.setBin("background",10);
		self.createdNodes.append(mountains)

		skyGeomNode=backgroundGeomNodes['sky']
		sky=render.attachNewNode(skyGeomNode)
		sky.setDepthWrite(False)
		sky.setDepthTest(False)
		sky.setBin("background",11)
		self.createdNodes.append(sky)

		constantOneStencil = StencilAttrib.make(1,StencilAttrib.SCFEqual,StencilAttrib.SOZero,StencilAttrib.SOKeep,StencilAttrib.SOReplace,1,0,1)
		shadowX=self.segments[0].getMidPoint().getX()
		shadowY=self.segments[0].getMidPoint().getY()
		lightSourceX,lightSourceY,lightSourceZ=self.getLightSourcePosition()
		shadowGeomNode=ShadowGeometry.makeModelShadow("models/newstartlineshadow",shadowX,shadowY,0,lightSourceX,lightSourceY,lightSourceZ,270)
		shadow=render.attachNewNode(shadowGeomNode)
		shadow.setTwoSided(True)
		self.createdNodes.append(shadow)
		shadow.setPos(shadowX,shadowY,0)
		shadow.node().setAttrib(constantOneStencil)
		shadow.node().setAttrib(ColorWriteAttrib.make(0))
		shadow.setBin('fixed',40)
		shadow.setDepthWrite(0)
		self.createdNodes.append(shadow)

		stencilReader = StencilAttrib.make(1,StencilAttrib.SCFEqual,StencilAttrib.SOKeep, StencilAttrib.SOKeep,StencilAttrib.SOKeep,1,1,0) 
		cm2d = CardMaker('card')
		cm2d.setFrameFullscreenQuad()
		card = render2d.attachNewNode(cm2d.generate())
		card.node().setAttrib(stencilReader)
		card.setDepthTest(False)
		card.setTransparency(TransparencyAttrib.MAlpha)
		card.setColor(0,0,0,0.40)
		self.createdNodes.append(card)

		trafficLightCm=CardMaker('card')
		trafficLightCm.setFrame(-0.20,0.20,0.20,-0.20)
		trafficLight = render.attachNewNode(trafficLightCm.generate())
		trafficLight.reparentTo(self.lights)
		trafficLight.setDepthTest(True)
		trafficLight.setDepthWrite(False)
		trafficLight.setColor(1.0,0.0,0.0,1.0)
		trafficLight.setBin("unsorted",50)
		trafficLight.setBillboardAxis()
		trafficLight.setTwoSided(True)
		tex = loader.loadTexture('textures/roadhighlight.png')
		trafficLight.setTexture(tex)
		trafficLight.setTransparency(TransparencyAttrib.MAlpha)
		trafficLight.hide()
		self.trafficLight=trafficLight
		self.createdNodes.append(trafficLight)

		colour = (45.0/255.0,81.0/255.0,98.0/255.0)
		expfog = Fog("Scene-wide exponential Fog object")
		expfog.setColor(*colour)
		expfog.setExpDensity(0.002)
		self.carsAndSceneryNode.setFog(expfog)

		self.qualifyingEndBlimpFlightComplete=False
		self.qualifyingResultsDisplayComplete=False	

		self.gearIndicator=GearIndicator()
		self.gearIndicator.setGear(Gearbox.low)