예제 #1
0
func (self *DefaultRenderer) drawObj7Lights(renderData *planeRenderData, fieldOfViewValue float32, cameraPos camera.CameraPosition) {
	if !renderData.lightStatus.BeaconLights && !renderData.lightStatus.StrobeLights && !renderData.lightStatus.LandingLights && !renderData.lightStatus.NavLights && !renderData.lightStatus.TaxiLights {
		//es ist kein Licht an --> nicht zeichnen
		return
	}
	lodInfo := calculateLOD(renderData.plane.CslAircraft.ObjInfo, renderData.dist)
	if lodInfo == nil {
		//keine LOD-Informationen --> nichts zeichnen
		return
	}
	gl.MatrixMode(gl.MODELVIEW)
	gl.PushMatrix()
	gl.Translatef(renderData.x, renderData.y, renderData.z)
	gl.Rotatef(renderData.plane.PositionData.Heading, 0.0, -1.0, 0.0)
	gl.Rotatef(renderData.plane.PositionData.Pitch, 1.0, 0.0, 0.0)
	gl.Rotatef(renderData.plane.PositionData.Roll, 0.0, 0.0, -1.0)

	lights := renderData.lightStatus

	offset := renderData.plane.SurfacesData.Lights.TimeOffset
	// flash frequencies
	baseTime := int(processing.GetElapsedTime()*1000.0) + offset
	lights.BeaconLights = calculateBeaconFlash(lights.BeaconLights, renderData.plane.SurfacesData.Lights.FlashPattern, baseTime)
	lights.StrobeLights = calculateStrobeFlash(lights.StrobeLights, renderData.plane.SurfacesData.Lights.FlashPattern, baseTime)

	// Find our distance from the camera
	dx := cameraPos.X - renderData.x
	dy := cameraPos.Y - renderData.y
	dz := cameraPos.Z - renderData.z
	distance := float32(math.Sqrt(float64((dx * dx) + (dy * dy) + (dz * dz))))

	// Convert to NM
	distance *= MetersToNM

	// Scale based on our FOV and Zoom. I did my initial
	// light adjustments at a FOV of 60 so thats why
	// I divide our current FOV by 60 to scale it appropriately.
	distance *= fieldOfViewValue / 60.0
	distance /= cameraPos.Zoom

	// Calculate our light size. This is piecewise linear. I noticed
	// that light size changed more rapidly when closer than 3nm so
	// I have a separate equation for that.
	var size float32
	if distance <= 3.6 {
		size = (10 * distance) + 1
	} else {
		size = (6.7 * distance) + 12
	}
	for _, currentLight := range lodInfo.Lights {
		if currentLight == nil {
			continue
		}
		gl.MatrixMode(gl.MODELVIEW)
		gl.PushMatrix()
		// First we translate to our coordinate system and move the origin
		// to the center of our lights.
		gl.Translatef(currentLight.XYZ[0], currentLight.XYZ[1], currentLight.XYZ[2])

		// Now we undo the rotation of the plane
		gl.Rotatef(-renderData.plane.PositionData.Pitch, 1.0, 0.0, 0.0)
		gl.Rotatef(-renderData.plane.PositionData.Heading, 0.0, -1.0, 0.0)
		gl.Rotatef(-renderData.plane.PositionData.Roll, 0.0, 0.0, -1.0)

		// Now we undo the rotation of the camera
		// NOTE: The order and sign of the camera is backwards
		// from what we'd expect (the plane rotations) because
		// the camera works backwards. If you pan right, everything
		// else moves left!
		gl.Rotatef(cameraPos.Pitch, 1.0, 0.0, 0.0)
		gl.Rotatef(cameraPos.Heading, 0.0, -1.0, 0.0)
		gl.Rotatef(cameraPos.Roll, 0.0, 0.0, -1.0)

		drawSingleLight(currentLight, size, distance, &lights)
		// Put OpenGL back how we found it
		gl.PopMatrix()
	}
	gl.PopMatrix()
}
예제 #2
0
func (self *DefaultRenderer) drawObj7Model(renderData *planeRenderData) {
	if renderData.plane.CslAircraft.ObjInfo == nil {
		//es wurde kein Objekt geladen --> nichts zeichnen
		return
	}
	// Find out what LOD we need to draw
	lodInfo := calculateLOD(renderData.plane.CslAircraft.ObjInfo, renderData.dist)
	if lodInfo == nil {
		//es wurde kein gutes LOD gefunden --> nichts zeichnen
		return
	}
	//PointPool ist leer
	if lodInfo.PointPool.Size() == 0 && lodInfo.Dl == 0 {
		return
	}
	gl.MatrixMode(gl.MODELVIEW)
	gl.PushMatrix()
	gl.Translatef(renderData.x, renderData.y, renderData.z)
	gl.Rotatef(renderData.plane.PositionData.Heading, 0.0, -1.0, 0.0)
	gl.Rotatef(renderData.plane.PositionData.Pitch, 1.0, 0.0, 0.0)
	gl.Rotatef(renderData.plane.PositionData.Roll, 0.0, 0.0, -1.0)

	textureId, litTextureId := renderData.plane.TextureNum, renderData.plane.LitTextureNum
	useNight := texture.TextureManagerInstance.UseLitTexture() && litTextureId != -1
	texUnits := 1
	if useNight {
		texUnits++
	} else {
		litTextureId = -1
	}
	graphics.SetGraphicsState(true, texUnits, true, true, true, true, true)
	graphics.BindTexture2d(textureId, 0)
	if litTextureId != -1 {
		graphics.BindTexture2d(litTextureId, 1)
	}
	gl.TexEnvi(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE)
	if litTextureId != -1 {
		gl.ActiveTextureARB(gl.TEXTURE1)
		gl.TexEnvi(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.ADD)
		gl.ActiveTextureARB(gl.TEXTURE0)
	}

	if lodInfo.Dl == 0 {
		lodInfo.Dl = gl.GenLists(1)

		var xpBuffer int32
		// See if the card even has VBO. If it does, save xplane's pointer
		// and bind to 0 for us.
		gl.GetIntegerv(gl.ARRAY_BUFFER_BINDING_ARB, &xpBuffer)
		gl.BindBufferARB(gl.ARRAY_BUFFER_ARB, 0)
		// Save XPlanes OpenGL state
		gl.PushClientAttrib(gl.CLIENT_ALL_ATTRIB_BITS)
		// Setup OpenGL pointers to our pool
		lodInfo.PointPool.PreparePoolToDraw()
		// Enable vertex data sucking
		gl.EnableClientState(gl.VERTEX_ARRAY)
		// Enable normal array sucking
		gl.EnableClientState(gl.NORMAL_ARRAY)
		// Enable texture coordinate data sucking
		gl.ClientActiveTextureARB(gl.TEXTURE1)
		gl.EnableClientState(gl.TEXTURE_COORD_ARRAY)
		gl.ClientActiveTextureARB(gl.TEXTURE0)
		gl.EnableClientState(gl.TEXTURE_COORD_ARRAY)
		// Disable colors - maybe x-plane left it around.
		gl.DisableClientState(gl.COLOR_ARRAY)

		gl.NewList(lodInfo.Dl, gl.COMPILE)
		// Kick OpenGL and draw baby!
		gl.DrawElements(gl.TRIANGLES, int32(len(lodInfo.TriangleList)), gl.UNSIGNED_INT, unsafe.Pointer(&(lodInfo.TriangleList[0])))
		gl.EndList()

		// Disable vertex data sucking
		gl.DisableClientState(gl.VERTEX_ARRAY)
		// Disable texture coordinate data sucking
		gl.DisableClientState(gl.TEXTURE_COORD_ARRAY)
		// Disable normal array sucking
		gl.DisableClientState(gl.NORMAL_ARRAY)

		// Restore Xplane's OpenGL State
		gl.PopClientAttrib()

		// If we bound before, we need to put xplane back where it was
		gl.BindBufferARB(gl.ARRAY_BUFFER_ARB, uint32(xpBuffer))

		lodInfo.TriangleList = make([]int32, 0)
		lodInfo.PointPool.Purge()
	}
	gl.CallList(lodInfo.Dl)
	gl.PopMatrix()
}