Esempio n. 1
0
func (self *DefaultRenderer) drawPlaneLabels(renderList *renderList, cullInfo *cullInfo, labelDist float32) {
	var vp [4]float32
	gl.GetFloatv(gl.VIEWPORT, &vp[0])

	gl.MatrixMode(gl.PROJECTION)
	gl.PushMatrix()
	gl.LoadIdentity()
	gl.Ortho(0, float64(vp[2]), 0, float64(vp[3]), -1, 1)

	gl.MatrixMode(gl.MODELVIEW)
	gl.PushMatrix()
	gl.LoadIdentity()

	c := []float32{1, 1, 0, 1}
	for _, plane := range renderList.GetAllPlanes() {
		if plane.dist < labelDist {
			x, y := cullInfo.convertTo2d(vp, plane.x, plane.y, plane.z, 1.0)
			rat := 1.0 - (plane.dist / MAX_LABEL_DIST)
			c[0] = 0.5 + 0.5*rat
			c[1] = c[0]
			c[2] = 0.5 - 0.5*rat // gray -> yellow - no alpha in the SDK - foo!
			graphics.DrawString(color.RGBA{uint8(255.0 * c[0]), uint8(255.0 * c[1]), uint8(255.0 * c[2]), 0}, int(x), int(y+10), plane.plane.PositionData.Label, []int32{}, graphics.Font_Basic)
		}
	}
	gl.MatrixMode(gl.PROJECTION)
	gl.PopMatrix()
	gl.MatrixMode(gl.MODELVIEW)
	gl.PopMatrix()
}
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()
}
Esempio n. 3
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()
}