Пример #1
0
func (rv *RoomViewer) modelviewToBoard(mx, my float32) (x, y, dist float32) {
	mz := d2p(rv.mat, mathgl.Vec3{mx, my, 0}, mathgl.Vec3{0, 0, 1})
	//  mz := (my - float32(rv.Render_region.Y+rv.Render_region.Dy/2)) * float32(math.Tan(float64(rv.angle*math.Pi/180)))
	v := mathgl.Vec4{X: mx, Y: my, Z: mz, W: 1}
	v.Transform(&rv.imat)
	return v.X, v.Y, mz
}
Пример #2
0
func (rv *RoomViewer) modelviewToRightWall(mx, my float32) (x, y, dist float32) {
	mz := d2p(rv.right_wall_mat, mathgl.Vec3{mx, my, 0}, mathgl.Vec3{0, 0, 1})
	v := mathgl.Vec4{X: mx, Y: my, Z: mz, W: 1}
	v.Transform(&rv.right_wall_imat)
	if v.Y > float32(rv.room.Size.Dy) {
		v.Y = float32(rv.room.Size.Dy)
	}
	return v.X + float32(rv.room.Size.Dx), v.Y, mz
}
Пример #3
0
func (room *Room) renderFurniture(floor mathgl.Mat4, base_alpha byte, drawables []Drawable, los_tex *LosTexture) {
	board_to_window := func(mx, my float32) (x, y float32) {
		v := mathgl.Vec4{X: mx, Y: my, W: 1}
		v.Transform(&floor)
		x, y = v.X, v.Y
		return
	}

	var all []RectObject
	for _, d := range drawables {
		x, y := d.Pos()
		if x < room.X {
			continue
		}
		if y < room.Y {
			continue
		}
		if x >= room.X+room.Size.Dx {
			continue
		}
		if y >= room.Y+room.Size.Dy {
			continue
		}
		all = append(all, offsetDrawable{d, -room.X, -room.Y})
	}

	// Do not include temporary objects in the ordering, since they will likely
	// overlap with other objects and make it difficult to determine the proper
	// ordering.  Just draw the temporary ones last.
	var temps []RectObject
	for _, f := range room.Furniture {
		if f.temporary {
			temps = append(temps, f)
		} else {
			all = append(all, f)
		}
	}
	all = OrderRectObjects(all)
	for i := range all {
		temps = append(temps, all[i])
	}

	for i := len(temps) - 1; i >= 0; i-- {
		d := temps[i].(Drawable)
		fx, fy := d.FPos()
		near_x, near_y := float32(fx), float32(fy)
		idx, idy := d.Dims()
		dx, dy := float32(idx), float32(idy)
		leftx, _ := board_to_window(near_x, near_y+dy)
		rightx, _ := board_to_window(near_x+dx, near_y)
		_, boty := board_to_window(near_x, near_y)
		vis := visibilityOfObject(room.X, room.Y, d, los_tex)
		r, g, b, a := d.Color()
		r = alphaMult(r, vis)
		g = alphaMult(g, vis)
		b = alphaMult(b, vis)
		a = alphaMult(a, vis)
		a = alphaMult(a, base_alpha)
		gl.Color4ub(gl.Ubyte(r), gl.Ubyte(g), gl.Ubyte(b), gl.Ubyte(a))
		d.Render(mathgl.Vec2{leftx, boty}, rightx-leftx)
	}
}
Пример #4
0
func (hv *HouseViewer) boardToModelview(mx, my float32) (x, y, z float32) {
	v := mathgl.Vec4{X: mx, Y: my, W: 1}
	v.Transform(&hv.floor)
	x, y, z = v.X, v.Y, v.Z
	return
}
Пример #5
0
func (hv *HouseViewer) modelviewToBoard(mx, my float32) (x, y, dist float32) {
	mz := d2p(hv.floor, mathgl.Vec3{mx, my, 0}, mathgl.Vec3{0, 0, 1})
	v := mathgl.Vec4{X: mx, Y: my, Z: mz, W: 1}
	v.Transform(&hv.ifloor)
	return v.X, v.Y, mz
}
Пример #6
0
func drawFurniture(roomx, roomy int, mat mathgl.Mat4, zoom float32, furniture []*Furniture, temp_furniture *Furniture, extras []Drawable, cstack base.ColorStack, los_tex *LosTexture, los_alpha float64) {
	gl.Enable(gl.TEXTURE_2D)
	gl.Color4d(1, 1, 1, los_alpha)
	gl.PushMatrix()
	gl.LoadIdentity()

	board_to_window := func(mx, my float32) (x, y float32) {
		v := mathgl.Vec4{X: mx, Y: my, W: 1}
		v.Transform(&mat)
		x, y = v.X, v.Y
		return
	}

	g_stuff = g_stuff[0:0]
	for i := range furniture {
		g_stuff = append(g_stuff, furniture[i])
	}
	if temp_furniture != nil {
		g_stuff = append(g_stuff, temp_furniture)
	}
	for i := range extras {
		g_stuff = append(g_stuff, extras[i])
	}
	g_stuff = OrderRectObjects(g_stuff)

	for i := len(g_stuff) - 1; i >= 0; i-- {
		f := g_stuff[i]
		var near_x, near_y, dx, dy float32

		idx, idy := f.Dims()
		dx = float32(idx)
		dy = float32(idy)
		switch d := f.(type) {
		case *Furniture:
			ix, iy := d.Pos()
			near_x = float32(ix)
			near_y = float32(iy)

		case Drawable:
			fx, fy := d.FPos()
			near_x = float32(fx)
			near_y = float32(fy)
		}

		vis_tot := 1.0
		if los_tex != nil {
			vis_tot = 0.0

			// If we're looking at a piece of furniture that blocks Los then we
			// can't expect to have Los to all of it, so we will check the squares
			// around it.  Full visibility will mean that half of the surrounding
			// cells are visible.
			blocks_los := false
			// Also need to check if it is an enemy unit
			if _, ok := f.(*Furniture); ok {
				blocks_los = true
			}

			if blocks_los {
				for x := near_x - 1; x < near_x+dx+1; x++ {
					vis_tot += float64(los_tex.Pix()[int(x)+roomx][int(near_y-1)+roomy])
					vis_tot += float64(los_tex.Pix()[int(x)+roomx][int(near_y+dy+1)+roomy])
				}
				for y := near_y; y < near_y+dy; y++ {
					vis_tot += float64(los_tex.Pix()[int(near_x-1)+roomx][int(y)+roomy])
					vis_tot += float64(los_tex.Pix()[int(near_x+dx+1)+roomx][int(y)+roomy])
				}
				vis_tot /= float64((dx*2 + dy*2 + 4) * 255 / 2)
				if vis_tot > 1 {
					vis_tot = 1
				}
			} else {
				for x := near_x; x < near_x+dx; x++ {
					for y := near_y; y < near_y+dy; y++ {
						vis_tot += float64(los_tex.Pix()[int(x)+roomx][int(y)+roomy])
					}
				}
				vis_tot /= float64(dx * dy * 255)
			}
		}

		leftx, _ := board_to_window(near_x, near_y+dy)
		rightx, _ := board_to_window(near_x+dx, near_y)
		_, boty := board_to_window(near_x, near_y)
		if f == temp_furniture {
			cstack.Push(1, 0, 0, 0.4)
		} else {
			bot := (LosMinVisibility / 255.0)
			vis := (vis_tot - bot) / (1 - bot)
			vis = vis * vis
			vis = vis*(1-bot) + bot
			vis = vis * vis
			cstack.Push(vis, vis, vis, 1)
		}
		cstack.ApplyWithAlpha(los_alpha)
		cstack.Pop()
		switch d := f.(type) {
		case *Furniture:
			d.Render(mathgl.Vec2{leftx, boty}, rightx-leftx)

		case Drawable:
			gl.Enable(gl.TEXTURE_2D)
			x := (leftx + rightx) / 2
			d.Render(mathgl.Vec2{x, boty}, rightx-leftx)
		}
	}
	gl.PopMatrix()
}
Пример #7
0
func (rv *RoomViewer) boardToModelview(mx, my float32) (x, y, z float32) {
	v := mathgl.Vec4{X: mx, Y: my, W: 1}
	v.Transform(&rv.mat)
	x, y, z = v.X, v.Y, v.Z
	return
}
Пример #8
0
func (rv *RoomViewer) rightWallToModelview(bx, by float32) (x, y, z float32) {
	v := mathgl.Vec4{X: bx - float32(rv.room.Size.Dx), Y: by, W: 1}
	v.Transform(&rv.right_wall_mat)
	return v.X, v.Y, v.Z
}