Пример #1
0
func (self *Inventory) DrawItem(t int64, quantity uint16, itemid ItemId, x float64, y float64) {
	gl.PushMatrix()
	gl.LoadIdentity()

	// angle := -90.0
	const blocksize = float32(0.3)

	gl.Translated(x, y, 0)

	//gl.Rotated(angle, 1.0, 0.0, 0.0)
	gl.Rotated(90, 1.0, 0.0, 0.0)
	gl.Rotated(30*math.Sin(float64(t)/1e9+float64(itemid)/2), 0.0, 1.0, 0.0)
	gl.Scalef(blocksize, blocksize, blocksize)
	self.drawBuffer.Reset()

	if itemid < 256 {
		TerrainCube(self.drawBuffer, Vectori{}, [18]BlockId{BLOCK_DIRT, BLOCK_DIRT, BLOCK_DIRT, BLOCK_DIRT, BLOCK_AIR, BLOCK_DIRT, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR}, NewBlockDefault(BlockId(itemid)), FACE_NONE)
	} else {
		RenderItemFlat(self.drawBuffer, Vectori{}, BlockId(itemid))
	}
	self.drawBuffer.RenderDirect(false)

	gl.LoadIdentity()
	gl.Translated(x+2*PIXEL_SCALE-48*PIXEL_SCALE*float64(blocksize), y-7*PIXEL_SCALE-48*PIXEL_SCALE*float64(blocksize), 0)
	inventoryItemFont.Print(fmt.Sprintf("%d", quantity))

	gl.PopMatrix()

}
Пример #2
0
func (vbox vbox) Render(w, h, d float64) {
	l := len(vbox.renderers)
	dh := h / float64(l)
	gl.Translated(0, h, 0)
	for _, a := range vbox.renderers {
		gl.Translated(0, -dh, 0)
		a.Render(w, dh, d)
	}
}
Пример #3
0
func (hbox hbox) Render(w, h, d float64) {
	l := len(hbox.renderers)
	dw := w / float64(l)
	for _, a := range hbox.renderers {
		a.Render(dw, h, d)
		gl.Translated(dw, 0, 0)
	}
	gl.Translated(-w, 0, 0)
}
Пример #4
0
func renderPortrait(r Renderer, w, h, d float64) {
	gl.PushMatrix()
	ww := h / math.Phi
	if ww <= w {
		gl.Translated((w-ww)/2.0, 0, 0)
		r.Render(ww, h, d)
	} else {
		hh := w * math.Phi
		gl.Translated(0, (h-hh)/2.0, 0)
		r.Render(w, hh, d)
	}
	gl.PopMatrix()
}
Пример #5
0
func renderLandscape(r Renderer, w, h, d float64) {
	gl.PushMatrix()
	hh := w / math.Phi
	if hh <= h {
		gl.Translated(0, (h-hh)/2.0, 0)
		r.Render(w, hh, d)
	} else {
		ww := h * math.Phi
		gl.Translated((w-ww)/2.0, 0, 0)
		r.Render(ww, h, d)
	}
	gl.PopMatrix()
}
Пример #6
0
func (self *Pause) Draw(t int64) {
	gl.MatrixMode(gl.MODELVIEW)
	gl.PushMatrix()
	gl.LoadIdentity()

	gl.Disable(gl.DEPTH_TEST)
	gl.Disable(gl.LIGHTING)
	gl.Disable(gl.LIGHT0)
	gl.Disable(gl.LIGHT1)

	gl.Color4ub(0, 0, 0, 240)

	gl.Begin(gl.QUADS)
	gl.Vertex2f(float32(viewport.lplane), float32(viewport.bplane))
	gl.Vertex2f(float32(viewport.rplane), float32(viewport.bplane))
	gl.Vertex2f(float32(viewport.rplane), float32(viewport.tplane))
	gl.Vertex2f(float32(viewport.lplane), float32(viewport.tplane))
	gl.End()

	str := "paused"
	h, w := pauseFont.Measure(str)

	// x := (viewport.rplane - viewport.lplane - w) / 2
	// y := (viewport.tplane - viewport.bplane - h) / 2
	gl.Translated(-w/2, -h/2, 0)
	pauseFont.Print(str)

	gl.PopMatrix()

}
Пример #7
0
func Draw() {
	gl.Clear(gl.COLOR_BUFFER_BIT)

	gl.PushMatrix()
	defer gl.PopMatrix()

	gl.Color4f(0, 1, 0, .5)
	DrawCircle(vect.Vect{ScreenSize.X / 2, ScreenSize.Y / 2}, ScreenSize.Y/2.0-5.0, false)

	if Settings.Paused {
		gl.Color3f(1, 1, 1)
		RenderFontAt("Paused", 20, 30)
	}

	//draw collision objects

	gl.PushMatrix()

	gl.Translated(ScreenSize.X/2, ScreenSize.Y/2, 0)
	gl.Scaled(Settings.Scale, Settings.Scale, 1)

	DrawDebugData(space)

	gl.PopMatrix()
}
Пример #8
0
func (c cube) Render(w, h, d float64) {
	x := math.Min(math.Min(w, h), d)
	gl.PushMatrix()
	gl.Translated((w-x)/2.0, (h-x)/2.0, (d-x)/2.0)
	c.child.Render(x, x, x)
	gl.PopMatrix()
}
Пример #9
0
func positionCamera() {
	gl.LoadIdentity()
	x, y, z := player.Position()
	gl.Translated(-x, -y+4, -z)

	gl.Lightfv(gl.LIGHT1, gl.POSITION, []float32{float32(x), float32(y), float32(z) + 0.5, 1})
}
Пример #10
0
// OpenWindow opens a new window with the given size.
func OpenWindow(w, h int) error {
	glfw.OpenWindowHint(glfw.WindowNoResize, 1)

	r, g, b := 0, 0, 0 // defaults
	a := 8             // 8-bit alpha channel
	d, s := 0, 0       // no depth or stencil buffers
	m := glfw.Windowed
	if err := glfw.OpenWindow(w, h, r, g, b, a, d, s, m); err != nil {
		return err
	}

	if gl.Init() != 0 {
		return errors.New("Failed to initialize OpenGL")
	}

	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.ClearColor(0.0, 0.0, 0.0, 0.0)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, float64(w), 0, float64(-h), -1, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Translated(0, float64(-h), 0)
	return nil
}
Пример #11
0
// Handle the window being resized.
func reshape(width int, height int) {
	// Render into the entire window.
	gl.Viewport(0, 0, width, height)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()

	// Configure the Frustrum so the front face of the rendering
	// volume fills the screen.

	w := float64(width)
	h := float64(height)
	depth := (w + h) / 2
	near := depth / 2.0
	right := w / 4.0
	top := h / 4.0
	far := 4 * depth
	gl.Frustum(-right, right, -top, top, near, far)

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

	// Center the rendering volume in the viewport.  Its origin
	// is at the far lower left corner.

	gl.Translated(-w/2, -h/2, -2*depth)
}
Пример #12
0
func (x *wiggler) Render(w, h, d float64) {
	gl.PushMatrix()
	t := time.Now().Sub(x.start).Seconds()
	dx := w / 10.0 * math.Sin(t)
	gl.Translated(dx, 0, 0)
	x.child.Render(w, h, d)
	gl.PopMatrix()
}
Пример #13
0
func (s square) Render(w, h, d float64) {
	gl.PushMatrix()
	dim := w
	if dim > h {
		dim = h
	}
	gl.Translated((w-dim)/2.0, (h-dim)/2.0, 0)
	gl.PopMatrix()
}
Пример #14
0
func draw() {

	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.PushMatrix()
	gl.Rotated(view_rotx, 1.0, 0.0, 0.0)
	gl.Rotated(view_roty, 0.0, 1.0, 0.0)
	gl.Rotated(view_rotz, 0.0, 0.0, 1.0)

	gl.PushMatrix()
	gl.Translated(-3.0, -2.0, 0.0)
	gl.Rotated(angle, 0.0, 0.0, 1.0)
	gl.CallList(gear1)
	gl.PopMatrix()

	gl.PushMatrix()
	gl.Translated(3.1, -2.0, 0.0)
	gl.Rotated(-2.0*angle-9.0, 0.0, 0.0, 1.0)
	gl.CallList(gear2)
	gl.PopMatrix()

	gl.PushMatrix()
	gl.Translated(-3.1, 4.2, 0.0)
	gl.Rotated(-2.0*angle-25.0, 0.0, 0.0, 1.0)
	gl.CallList(gear3)
	gl.PopMatrix()

	gl.PopMatrix()

	sdl.GL_SwapBuffers()

	Frames++
	{
		t := sdl.GetTicks()
		if t-T0 >= 5000 {
			seconds := (t - T0) / 1000.0
			fps := Frames / seconds
			print(Frames, " frames in ", seconds, " seconds = ", fps, " FPS\n")
			T0 = t
			Frames = 0
		}
	}
}
Пример #15
0
func (s stack) Render(w, h, d float64) {
	l := len(s.renderers)
	dw := d / float64(l)
	gl.PushMatrix()
	for _, r := range s.renderers {
		r.Render(w, h, dw)
		gl.Translated(0, 0, dw)
	}
	gl.PopMatrix()
}
Пример #16
0
func draw() {

	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.PushMatrix()
	gl.Rotated(view_rotx, 1.0, 0.0, 0.0)
	gl.Rotated(view_roty, 0.0, 1.0, 0.0)
	gl.Rotated(view_rotz, 0.0, 0.0, 1.0)

	gl.PushMatrix()
	gl.Translated(-3.0, -2.0, 0.0)
	gl.Rotated(angle, 0.0, 0.0, 1.0)
	gl.CallList(gear1)
	gl.PopMatrix()

	gl.PushMatrix()
	gl.Translated(3.1, -2.0, 0.0)
	gl.Rotated(-2.0*angle-9.0, 0.0, 0.0, 1.0)
	gl.CallList(gear2)
	gl.PopMatrix()

	gl.PushMatrix()
	gl.Translated(-3.1, 4.2, 0.0)
	gl.Rotated(-2.0*angle-25.0, 0.0, 0.0, 1.0)
	gl.CallList(gear3)
	gl.PopMatrix()

	gl.PopMatrix()

	glfw.SwapBuffers()

	Frames++
	{
		t := glfw.Time()
		if t-T0 >= 5 {
			seconds := (t - T0)
			fps := float64(Frames) / seconds
			print(Frames, " frames in ", int(seconds), " seconds = ", int(fps), " FPS\n")
			T0 = t
			Frames = 0
		}
	}
}
Пример #17
0
func drawCircle(s CircleShape) {
	center := s.Center()
	radius := s.Radius()
	angle := s.Body().Angle()

	gl.VertexPointer(2, 0, circleVerts)
	gl.PushMatrix()
	gl.Translated(center.X, center.Y, 0.0)
	gl.Rotated(angle*180.0/math.Pi, 0.0, 0.0, 1.0)
	gl.Scaled(radius, radius, 1.0)
	gl.DrawArrays(gl.LINE_STRIP, 0, len(circleVerts)/2)
	gl.PopMatrix()
}
Пример #18
0
func (self *Inventory) DrawItem(t int64, quantity uint16, blockid uint16, r Rect) {
	gl.PushMatrix()
	gl.LoadIdentity()

	const blocksize = float32(0.3)

	i := 1
	gl.Translated(r.x+r.sizex/2, r.y+r.sizey/2+4*PIXEL_SCALE, 0)

	gl.Rotatef(360*float32(math.Sin(float64(t)/1e10+float64(i))), 1.0, 0.0, 0.0)
	gl.Rotatef(360*float32(math.Cos(float64(t)/1e10+float64(i))), 0.0, 1.0, 0.0)
	gl.Rotatef(360*float32(math.Sin(float64(t)/1e10+float64(i))), 0.0, 0.0, 1.0)
	gl.Scalef(blocksize, blocksize, blocksize)
	gVertexBuffer.Reset()
	TerrainCube(gVertexBuffer, Vectori{}, [18]uint16{}, blockid, FACE_NONE)
	gVertexBuffer.RenderDirect(false)

	gl.LoadIdentity()
	gl.Translated(r.x+5*PIXEL_SCALE, r.y+2*PIXEL_SCALE, 0)
	inventoryItemFont.Print(fmt.Sprintf("%d", quantity))

	gl.PopMatrix()

}
Пример #19
0
func plot_list(list uint) {
	gl.Enable(gl.BLEND)
	gl.Enable(gl.POINT_SMOOTH)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	gl.PointSize(1.0)
	gl.LoadIdentity()
	gl.Rotated(xrot, 1, 0, 0)
	gl.Rotated(yrot, 0, 1, 0)
	gl.Rotated(zrot, 0, 0, 1)
	gl.Scaled(scale, scale, scale)
	gl.Translated(xoff, yoff, zoff)
	gl.CallList(list)
	gl.Flush()
}
Пример #20
0
func onResize(w, h int) {
	if h == 0 {
		h = 1
	}

	gl.Viewport(0, 0, w, h)

	scale := math.Min(float64(w)/640.0, float64(h)/480.0)
	hw := float64(w) * (0.5 / scale)
	hh := float64(h) * (0.5 / scale)

	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(-hw, hw, -hh, hh, -1.0, 1.0)
	gl.Translated(0.5, 0.5, 0.0)

	Width = w
	Height = h
}
Пример #21
0
func (self *Inventory) ShowTooltip(x, y float64, str string) {
	h, w := inventoryItemFont.Measure(str)

	pad := 4 * PIXEL_SCALE
	gl.PushMatrix()

	gl.LoadIdentity()
	gl.Color4ub(0, 0, 0, 255)
	gl.Begin(gl.QUADS)
	gl.Vertex2d(x, y)
	gl.Vertex2d(x+w+pad, y)
	gl.Vertex2d(x+w+pad, y+h)
	gl.Vertex2d(x, y+h)
	gl.End()

	gl.Translated(x+pad/2, y+pad/2, 0)
	inventoryItemFont.Print(str)

	gl.PopMatrix()
}
Пример #22
0
func (player *Player) Draw(center Vectorf, selectedBlockFace *BlockFace) {

	pos := Vectorf{player.position[XAXIS], player.position[YAXIS], player.position[ZAXIS]}
	gl.PushMatrix()

	gl.Translatef(float32(player.position[XAXIS]), float32(player.position[YAXIS]), float32(player.position[ZAXIS]))
	//stepHeight := float32(math.Sin(player.Bounce * piover180)/10.0)
	gl.Rotated(player.Heading(), 0.0, 1.0, 0.0)

	// Translate to top of ground block
	gl.Translatef(0.0, -0.5, 0.0)
	pos[YAXIS] += -0.5

	// From http://www.realcolorwheel.com/human.htm
	headHeight := float64(0.25)
	hatHeight := headHeight
	brimHeight := 0.15 * headHeight
	brimWidth := 1.5 * headHeight
	brimDepth := 1.5 * headHeight
	neckHeight := 0.25 * headHeight
	torsoWidth := 2 * headHeight
	torsoHeight := 3.25 * headHeight
	torsoDepth := 1 * headHeight
	legHeight := 8*headHeight - torsoHeight - neckHeight - headHeight
	legWidth := (torsoWidth - 0.25*headHeight) / 2
	legDepth := legWidth
	armHeight := 2.75 * headHeight
	armWidth := 0.75 * torsoDepth
	armDepth := 0.75 * torsoDepth
	// lowerArmHeight := 1.25 * headHeight
	// handHeight := 0.75 * headHeight

	var legAngle, torsoAngle, leftArmAngle, rightArmAngle, step float64

	// if player.velocity[YAXIS] != 0 {
	// 	legAngle = 20
	// 	leftArmAngle = 120
	// 	rightArmAngle = 120
	// } else {
	legAngle = 40 * (math.Abs(player.velocity[XAXIS]) + math.Abs(player.velocity[ZAXIS])) / player.walkingSpeed * math.Sin(player.walkSequence)
	torsoAngle = -math.Abs(legAngle / 6)
	leftArmAngle = -legAngle * 1.2
	rightArmAngle = legAngle * 1.2
	step = headHeight * 0.1 * math.Pow(math.Sin(player.walkSequence), 2)
	// }

	gl.Translated(0.0, step, 0)
	pos[YAXIS] += step

	// Translate to top of leg
	gl.Translated(0.0, legHeight, 0)
	pos[YAXIS] += legHeight

	// Translate to centre of leg
	gl.Rotated(legAngle, 0.0, 0.0, 1.0)
	gl.Translated(0.0, -legHeight/2, (legWidth+0.25*headHeight)/2)
	pos[YAXIS] += -legHeight / 2
	pos[ZAXIS] += (legWidth + 0.25*headHeight) / 2
	Cuboid(pos, legWidth, legHeight, legDepth, textures[TEXTURE_LEG], textures[TEXTURE_LEG], textures[TEXTURE_LEG_SIDE], textures[TEXTURE_LEG_SIDE], textures[32], textures[32], FACE_NONE)
	gl.Translated(0.0, legHeight/2, -(legWidth+0.25*headHeight)/2)
	pos[YAXIS] += legHeight / 2
	pos[ZAXIS] += -(legWidth + 0.25*headHeight) / 2
	gl.Rotated(-legAngle, 0.0, 0.0, 1.0)

	gl.Rotated(-legAngle, 0.0, 0.0, 1.0)
	gl.Translated(0.0, -legHeight/2, -(legWidth+0.25*headHeight)/2)
	pos[YAXIS] += -legHeight / 2
	pos[ZAXIS] += -(legWidth + 0.25*headHeight) / 2
	Cuboid(pos, legWidth, legHeight, legDepth, textures[TEXTURE_LEG], textures[TEXTURE_LEG], textures[TEXTURE_LEG_SIDE], textures[TEXTURE_LEG_SIDE], textures[32], textures[32], FACE_NONE)
	gl.Translated(0.0, legHeight/2, (legWidth+0.25*headHeight)/2)
	pos[YAXIS] += legHeight / 2
	pos[ZAXIS] += (legWidth + 0.25*headHeight) / 2
	gl.Rotated(+legAngle, 0.0, 0.0, 1.0)

	gl.Rotated(torsoAngle, 0.0, 0.0, 1.0)
	// Translate to centre of torso
	gl.Translated(0.0, torsoHeight/2, 0.0)
	pos[YAXIS] += torsoHeight / 2
	Cuboid(pos, torsoWidth, torsoHeight, torsoDepth, textures[TEXTURE_TORSO_FRONT], textures[TEXTURE_TORSO_BACK], textures[TEXTURE_TORSO_LEFT], textures[TEXTURE_TORSO_RIGHT], textures[TEXTURE_TORSO_TOP], textures[TEXTURE_TORSO_TOP], FACE_NONE)

	// Translate to shoulders
	gl.Translated(0.0, torsoHeight/2, 0.0)
	pos[YAXIS] += torsoHeight / 2

	gl.Rotated(leftArmAngle, 0.0, 0.0, 1.0)
	gl.Translated(0.0, -armHeight/2, torsoWidth/2+armWidth/2)
	pos[YAXIS] += -armHeight / 2
	pos[ZAXIS] += torsoWidth/2 + armWidth/2
	Cuboid(pos, armWidth, armHeight, armDepth, textures[TEXTURE_ARM], textures[TEXTURE_ARM], textures[TEXTURE_ARM], textures[TEXTURE_ARM], textures[TEXTURE_ARM_TOP], textures[TEXTURE_HAND], FACE_NONE)
	gl.Translated(0.0, armHeight/2, -torsoWidth/2-armWidth/2)
	pos[YAXIS] += armHeight / 2
	pos[ZAXIS] += -torsoWidth/2 + armWidth/2
	gl.Rotated(-leftArmAngle, 0.0, 0.0, 1.0)

	gl.Rotated(rightArmAngle, 0.0, 0.0, 1.0)
	gl.Translated(0.0, -armHeight/2, -torsoWidth/2-armWidth/2)
	pos[YAXIS] += -armHeight / 2
	pos[ZAXIS] += -torsoWidth/2 + armWidth/2
	Cuboid(pos, armWidth, armHeight, armDepth, textures[TEXTURE_ARM], textures[TEXTURE_ARM], textures[TEXTURE_ARM], textures[TEXTURE_ARM], textures[TEXTURE_ARM_TOP], textures[TEXTURE_HAND], FACE_NONE)
	gl.Translated(0.0, armHeight/2, torsoWidth/2+armWidth/2)
	pos[YAXIS] += armHeight / 2
	pos[ZAXIS] += torsoWidth/2 + armWidth/2
	gl.Rotated(-rightArmAngle, 0.0, 0.0, 1.0)

	// Translate to centre of head
	gl.Translated(0.0, neckHeight+headHeight/2, 0.0)
	pos[YAXIS] += neckHeight + headHeight/2

	if selectedBlockFace != nil {
		blockPos := selectedBlockFace.pos.Vectorf()
		headPos := player.position.Add(Vectorf{0, headHeight * 9, 0})

		blockDir := blockPos.Minus(headPos)
		if player.Facing(blockDir) {
			yrot := (math.Atan2(blockDir[XAXIS], blockDir[ZAXIS]) - math.Pi/2) * 180 / math.Pi
			zrot, xrot := -12.0, -12.0
			gl.Rotated(-player.Heading(), 0.0, 1.0, 0.0)
			gl.Rotated(yrot, 0.0, 1.0, 0.0)
			gl.Rotated(zrot, 0.0, 0.0, 1.0)
			gl.Rotated(xrot, 1.0, 0.0, 0.0)
		}
	}

	Cuboid(pos, headHeight, headHeight, headHeight, textures[TEXTURE_HEAD_FRONT], textures[TEXTURE_HEAD_BACK], textures[TEXTURE_HEAD_LEFT], textures[TEXTURE_HEAD_RIGHT], nil, textures[TEXTURE_HEAD_BOTTOM], FACE_NONE)

	// Translate to hat brim
	gl.Translated(0.0, headHeight/2+brimHeight/2, 0.0)
	pos[YAXIS] += headHeight/2 + brimHeight/2
	Cuboid(pos, brimWidth, brimHeight, brimDepth, textures[TEXTURE_BRIM], textures[TEXTURE_BRIM], textures[TEXTURE_BRIM], textures[TEXTURE_BRIM], textures[TEXTURE_BRIM], textures[TEXTURE_BRIM], FACE_NONE)

	gl.Translated(0.0, brimHeight/2+hatHeight/2, 0.0)
	pos[YAXIS] += headHeight/2 + brimHeight/2
	Cuboid(pos, hatHeight, hatHeight, hatHeight, textures[TEXTURE_HAT_FRONT], textures[TEXTURE_HAT_BACK], textures[TEXTURE_HAT_LEFT], textures[TEXTURE_HAT_RIGHT], textures[TEXTURE_HAT_TOP], nil, FACE_NONE)

	gl.PopMatrix()
}
Пример #23
0
func (self *Inventory) Draw(t int64) {
	gl.MatrixMode(gl.MODELVIEW)
	gl.PushMatrix()
	gl.LoadIdentity()

	gl.Disable(gl.DEPTH_TEST)
	gl.Disable(gl.LIGHTING)
	gl.Disable(gl.LIGHT0)
	gl.Disable(gl.LIGHT1)

	gl.Color4ub(0, 0, 0, 208)

	gl.Begin(gl.QUADS)
	gl.Vertex2f(float32(viewport.lplane), float32(viewport.bplane))
	gl.Vertex2f(float32(viewport.rplane), float32(viewport.bplane))
	gl.Vertex2f(float32(viewport.rplane), float32(viewport.tplane))
	gl.Vertex2f(float32(viewport.lplane), float32(viewport.tplane))
	gl.End()

	picker.DrawItemHighlight(t, 3)
	picker.DrawItemHighlight(t, 4)
	picker.DrawItemHighlight(t, 5)
	picker.DrawItemHighlight(t, 6)
	picker.DrawItemHighlight(t, 7)
	picker.DrawPlayerItems(t, false)

	const blocksize = float64(0.3)
	const COLSIZE = 12

	slotsize := blocksize * 2.4
	slotstep := slotsize + float64(4)*PIXEL_SCALE
	slotsInRow := len(self.componentRects)

	xtools := float64(viewport.lplane) + 10.0*PIXEL_SCALE
	ytools := float64(viewport.tplane) - 10.0*PIXEL_SCALE - slotstep

	gl.PushMatrix()
	gl.LoadIdentity()
	gl.Translated(xtools, ytools+4*PIXEL_SCALE, 0)
	inventoryItemFont.Print("Inventory")
	gl.PopMatrix()
	for i := range self.inventoryRects {
		x := xtools + float64(i%slotsInRow)*slotstep
		y := ytools - float64(i/slotsInRow)*slotstep
		self.inventoryRects[i] = Rect{x, y - slotsize, slotsize, slotsize}
		self.DrawItemSlot(t, self.inventoryRects[i])
	}

	for i := range self.inventorySlots {
		if self.inventorySlots[i].item != 0 && self.inventorySlots[i].quantity > 0 {
			self.DrawItemInSlot(t, self.inventorySlots[i].quantity, self.inventorySlots[i].item, self.inventoryRects[i])
		}
	}

	xtools += slotstep * (1.0 + float64(slotsInRow))

	gl.PushMatrix()
	gl.LoadIdentity()
	gl.Translated(xtools, ytools+4*PIXEL_SCALE, 0)

	if self.currentCrafting == nil {
		inventoryItemFont.Print("Handcrafting")
	} else {
		inventoryItemFont.Print(self.currentCrafting.Label())
	}
	gl.PopMatrix()

	for i := range self.componentSlots {
		x := xtools + float64(i)*slotstep
		y := ytools
		self.componentRects[i] = Rect{x, y - slotsize, slotsize, slotsize}

		self.DrawItemSlot(t, self.componentRects[i])
	}

	for i, cs := range self.componentSlots {
		if cs.item != 0 {
			self.DrawItemInSlot(t, cs.quantity, cs.item, self.componentRects[i])
		}
	}

	ytools -= slotstep * 2
	for i := range self.productSlots {
		x := xtools + slotstep*float64(i%slotsInRow)
		y := ytools - slotstep*float64(i/slotsInRow)
		self.productRects[i] = Rect{x, y - slotsize, slotsize, slotsize}

		self.DrawItemSlot(t, self.productRects[i])
	}

	for i, ps := range self.productSlots {
		if ps != nil {
			self.DrawItemInSlot(t, ps.product.quantity, ps.product.item, self.productRects[i])
		}
	}

	ytools -= slotstep * float64(1+len(self.productRects)/slotsInRow)
	if self.currentContainer != nil {

		gl.PushMatrix()
		gl.LoadIdentity()
		gl.Translated(xtools, ytools+4*PIXEL_SCALE, 0)
		inventoryItemFont.Print(self.currentContainer.Label())
		gl.PopMatrix()

		for i := range self.containerRects {
			x := xtools + slotstep*float64(i%slotsInRow)
			y := ytools - slotstep*float64(i/slotsInRow)
			self.containerRects[i] = Rect{x, y - slotsize, slotsize, slotsize}

			self.DrawItemSlot(t, self.containerRects[i])
		}

		for i := 0; i < self.currentContainer.Slots(); i++ {
			if self.currentContainer.Item(i).item != 0 {
				self.DrawItemInSlot(t, self.currentContainer.Item(i).quantity, self.currentContainer.Item(i).item, self.containerRects[i])
			}
		}

	}

	var mousex, mousey int
	mousestate := sdl.GetMouseState(&mousex, &mousey)

	if self.selectedItem != nil {
		x, y := viewport.ScreenCoordsToWorld2D(uint16(mousex), uint16(mousey))
		self.DrawItem(t, self.selectedItem.quantity, self.selectedItem.item, x, y)
	}

	self.HandleMouse(mousex, mousey, mousestate)

	gl.PopMatrix()
}
Пример #24
0
func (f flat) Render(w, h, d float64) {
	gl.PushMatrix()
	gl.Translated(0, 0, d)
	f.child.Render(w, h, 0)
	gl.PopMatrix()
}
Пример #25
0
func (self *Wolf) Draw(center Vectorf, selectedBlockFace *BlockFace) {
	pos := Vectorf{self.position[XAXIS], self.position[YAXIS], self.position[ZAXIS]}
	gl.PushMatrix()

	gl.Translated(self.position[XAXIS], self.position[YAXIS], self.position[ZAXIS])
	gl.Rotated(self.Heading(), 0.0, 1.0, 0.0)

	// Translate to top of ground block
	gl.Translatef(0.0, -0.5, 0.0)
	pos[YAXIS] += -0.5

	headHeight := 0.25
	headWidth := headHeight
	headDepth := headHeight * 2.0
	neckHeight := 0.0
	torsoWidth := 1.5 * headHeight
	torsoHeight := 1.5 * headHeight
	torsoDepth := 5 * headHeight
	legHeight := 5*headHeight - torsoHeight - neckHeight - headHeight
	legWidth := (torsoWidth - 0.25*headHeight) / 2
	legDepth := legWidth

	var legAngle, step float64

	horzSpeed := self.velocity[XAXIS]*self.velocity[XAXIS] + self.velocity[ZAXIS]*self.velocity[ZAXIS]
	legAngle = math.Sin(self.walkSequence) * (15 + 55*horzSpeed/(self.sprintSpeed*self.sprintSpeed))
	headAngle := 30.0
	// torsoAngle = -math.Abs(legAngle / 6)
	step = headHeight * 0.3 * math.Pow(math.Sin(self.walkSequence), 2)

	gl.Translated(0.0, step, 0)
	pos[YAXIS] += step

	// Translate to top of leg
	// Translate to centre of front left leg
	gl.Translated(0.0, legHeight, 0)
	pos[YAXIS] += legHeight

	legDepthOffset := torsoDepth/2 - legWidth/2
	legHeightOffset := -legHeight / 2
	legWidthOffset := (legWidth + 0.25*headHeight) / 2

	// Translate to centre of front left leg
	gl.Translated(legDepthOffset, 0, legWidthOffset)
	gl.Rotated(legAngle, 0.0, 0.0, 1.0)
	gl.Translated(0, legHeightOffset, 0)
	pos[XAXIS] += legDepthOffset
	pos[YAXIS] += legHeightOffset
	pos[ZAXIS] += legWidthOffset
	Cuboid(pos, legWidth, legHeight, legDepth, textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], FACE_NONE)
	pos[XAXIS] -= legDepthOffset
	pos[YAXIS] -= legHeightOffset
	pos[ZAXIS] -= legWidthOffset
	gl.Translated(0, -legHeightOffset, 0)
	gl.Rotated(-legAngle, 0.0, 0.0, 1.0)
	gl.Translated(-legDepthOffset, 0, -legWidthOffset)

	legWidthOffset = -legWidthOffset
	if horzSpeed <= self.walkingSpeed*self.walkingSpeed {
		legAngle = -legAngle
	}

	gl.Translated(legDepthOffset, 0, legWidthOffset)
	gl.Rotated(legAngle, 0.0, 0.0, 1.0)
	gl.Translated(0, legHeightOffset, 0)
	pos[XAXIS] += legDepthOffset
	pos[YAXIS] += legHeightOffset
	pos[ZAXIS] += legWidthOffset
	Cuboid(pos, legWidth, legHeight, legDepth, textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], FACE_NONE)
	pos[XAXIS] -= legDepthOffset
	pos[YAXIS] -= legHeightOffset
	pos[ZAXIS] -= legWidthOffset
	gl.Translated(0, -legHeightOffset, 0)
	gl.Rotated(-legAngle, 0.0, 0.0, 1.0)
	gl.Translated(-legDepthOffset, 0, -legWidthOffset)

	legDepthOffset = -legDepthOffset
	legWidthOffset = -legWidthOffset

	if horzSpeed > self.walkingSpeed*self.walkingSpeed {
		legAngle = -legAngle
	}

	gl.Translated(legDepthOffset, 0, legWidthOffset)
	gl.Rotated(legAngle, 0.0, 0.0, 1.0)
	gl.Translated(0, legHeightOffset, 0)
	pos[XAXIS] += legDepthOffset
	pos[YAXIS] += legHeightOffset
	pos[ZAXIS] += legWidthOffset
	Cuboid(pos, legWidth, legHeight, legDepth, textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], FACE_NONE)
	pos[XAXIS] -= legDepthOffset
	pos[YAXIS] -= legHeightOffset
	pos[ZAXIS] -= legWidthOffset
	gl.Translated(0, -legHeightOffset, 0)
	gl.Rotated(-legAngle, 0.0, 0.0, 1.0)
	gl.Translated(-legDepthOffset, 0, -legWidthOffset)

	legWidthOffset = -legWidthOffset
	if horzSpeed <= self.walkingSpeed*self.walkingSpeed {
		legAngle = -legAngle
	}

	gl.Translated(legDepthOffset, 0, legWidthOffset)
	gl.Rotated(legAngle, 0.0, 0.0, 1.0)
	gl.Translated(0, legHeightOffset, 0)
	pos[XAXIS] += legDepthOffset
	pos[YAXIS] += legHeightOffset
	pos[ZAXIS] += legWidthOffset
	Cuboid(pos, legWidth, legHeight, legDepth, textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], FACE_NONE)
	pos[XAXIS] -= legDepthOffset
	pos[YAXIS] -= legHeightOffset
	pos[ZAXIS] -= legWidthOffset
	gl.Translated(0, -legHeightOffset, 0)
	gl.Rotated(-legAngle, 0.0, 0.0, 1.0)
	gl.Translated(-legDepthOffset, 0, -legWidthOffset)

	//gl.Rotated(torsoAngle, 0.0, 0.0, 1.0)
	// Translate to centre of torso
	gl.Translated(0.0, torsoHeight/2, 0.0)
	pos[YAXIS] += torsoHeight / 2
	Cuboid(pos, torsoWidth, torsoHeight, torsoDepth, textures[TEXTURE_WOLF_TORSO_FRONT], textures[TEXTURE_WOLF_TORSO_BACK], textures[TEXTURE_WOLF_TORSO_SIDE], textures[TEXTURE_WOLF_TORSO_SIDE], textures[TEXTURE_WOLF_TORSO_TOP], textures[TEXTURE_WOLF_TORSO_TOP], FACE_NONE)

	// Translate to shoulders
	gl.Translated(0.0, torsoHeight/2, 0.0)
	pos[YAXIS] += torsoHeight / 2

	// Translate to centre of head
	gl.Translated(torsoDepth/2+headDepth*0.5, 0.0, 0.0)
	pos[XAXIS] += torsoDepth/2 + headDepth*0.5
	pos[YAXIS] += 0.0

	gl.Rotated(-headAngle, 0.0, 0.0, 1.0)
	Cuboid(pos, headWidth, headHeight, headDepth, textures[TEXTURE_WOLF_HEAD_FRONT], textures[TEXTURE_WOLF_HEAD_BACK], textures[TEXTURE_WOLF_HEAD_SIDE], textures[TEXTURE_WOLF_HEAD_SIDE], textures[TEXTURE_WOLF_HEAD_TOP], textures[TEXTURE_WOLF_HEAD_BOTTOM], FACE_NONE)

	gl.PopMatrix()

}
Пример #26
0
func (s *Scatter) Render(w, h, d float64) {
	gl.PushMatrix()
	min, max := s.points.Bounds()
	dim := max.Sub(min)
	gl.Scaled(w/dim.X, h/dim.Y, d/dim.Z)
	gl.Translated(-min.X, -min.Y, -min.Z)

	// Draw axes: red X, green Y, blue Z.

	gl.Begin(gl.LINES)
	gl.LineWidth(1.5)
	gl.Color3ub(255, 0, 0)
	gl.Vertex3d(min.X, min.Y, min.Z)
	gl.Vertex3d(max.X, min.Y, min.Z)
	gl.Color3ub(0, 255, 0)
	gl.Vertex3d(min.X, min.Y, min.Z)
	gl.Vertex3d(min.X, max.Y, min.Z)
	gl.Color3ub(0, 0, 255)
	gl.Vertex3d(min.X, min.Y, min.Z)
	gl.Vertex3d(min.X, min.Y, max.Z)
	gl.End()

	// Draw 2d plots on the XY, YZ, and XZ planes.

	gl.PointSize(10.0)
	gl.Begin(gl.POINTS)

	// X plot
	gl.Color4ub(255, 0, 0, 31)
	for _, p := range s.points {
		gl.Vertex3d(p.X, min.Y, min.Z)
	}
	// Y plot
	gl.Color4ub(0, 255, 0, 31)
	for _, p := range s.points {
		gl.Vertex3d(min.X, p.Y, min.Z)
	}
	// Z plot
	gl.Color4ub(0, 0, 255, 31)
	for _, p := range s.points {
		gl.Vertex3d(min.X, min.Y, p.Z)
	}

	// XY plot
	gl.Color4ub(255, 255, 0, 63)
	for _, p := range s.points {
		gl.Vertex3d(p.X, p.Y, min.Z)
	}
	// YZ plot
	gl.Color4ub(0, 255, 255, 63)
	for _, p := range s.points {
		gl.Vertex3d(min.X, p.Y, p.Z)
	}
	// XZ plot
	gl.Color4ub(255, 0, 255, 63)
	for _, p := range s.points {
		gl.Vertex3d(p.X, min.Y, p.Z)
	}

	// XYZ plot
	gl.Color4ub(255, 255, 255, 128)
	for _, p := range s.points {
		gl.Vertex3d(p.X, p.Y, p.Z)
	}
	gl.End()
	gl.PopMatrix()
}
Пример #27
0
func testPlot(dimension, order int) {
	var (
		iterations float64   = 0
		start_t              = time.Now()
		split      time.Time = start_t
		total      time.Duration
		fps        float64 = 1.0

		new_attractor, redraw bool = true, true
		npoints               int  = 1e5

		coeffs []float64
		//offsets, offset_coeffs []float64
		start Matrix = MakeMatrix(1, int(math.Max(3, float64(dimension))))
		points, points2/*, points3*/ Matrix

	//attractor = gl.GenLists(1);
	)

	//offsets = make([]float64, ncoeffs(order))
	//offset_coeffs = make([]float64, ncoeffs(order))
	//coeffs = make([]float64, dimension + nCoeffs(order, dimension) * dimension)

	//for i := range offsets { offsets[i] += rand.Float64() }

	for handleEvents(&new_attractor, &redraw, &npoints) {

		xoff += xvel / fps
		yoff += yvel / fps
		zoff += zvel / fps
		xrot += xrotvel / fps
		yrot += yrotvel / fps
		zrot += zrotvel / fps
		scale += svel / fps

		if new_attractor {
			coeffs, start = find_map_with_L(dimension, order, 0.1, 0.4)
			redraw = true
			new_attractor = false
		}
		if redraw {
			points = MakePointMatrix(makeMapFn(dimension, order, coeffs), start, 500, npoints)
			points2 = MakeMatrix(npoints, points.Height())
			//points3 = MakeMatrix(npoints, points.Height())
			redraw = false
			fmt.Println("Redraw", npoints, "points")
		}

		//points2 = points
		//RotationXW(xwrot).Apply(points, points2)
		//RotationYW(xwrot + 0.25).Apply(points2, points3)
		//RotationZW(xwrot + 0.50).Apply(points3, points2)

		if dimension == 4 {
			RotationZW(xwrot).Apply(points, points2)
			xwrot += 0.05
			ApplyW(points2, points2)
		} else {
			points2 = points
		}

		gl.Enable(gl.BLEND)
		gl.Enable(gl.POINT_SMOOTH)
		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

		gl.PointSize(1.0)
		gl.LoadIdentity()
		gl.Rotated(xrot, 1, 0, 0)
		gl.Rotated(yrot, 0, 1, 0)
		gl.Rotated(zrot, 0, 0, 1)
		gl.Scaled(scale, scale, scale)
		gl.Translated(xoff, yoff, zoff)

		gl.Color4d(1, 1, 1, 0.25)

		gl.EnableClientState(gl.VERTEX_ARRAY)
		if dimension > 3 {
			gl.VertexPointer(3, (dimension-3)*32, points2.FlatCols())
		} else {
			gl.VertexPointer(3, 0, points2.FlatCols())
		}
		gl.DrawArrays(gl.POINTS, 0, points2.Width())
		gl.DisableClientState(gl.VERTEX_ARRAY)

		sdl.GL_SwapBuffers()
		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

		iterations++
		if time.Since(split).Seconds() > 1.0 {
			total = time.Since(start_t)
			fps = iterations / total.Seconds()
			fmt.Println(iterations, "iterations in", total.Seconds(), "gives",
				fps, "fps")
			split = time.Now()
		}
	}
}
Пример #28
0
func (self *Inventory) Draw(t int64) {
	gl.MatrixMode(gl.MODELVIEW)
	gl.PushMatrix()
	gl.LoadIdentity()

	gl.Disable(gl.DEPTH_TEST)
	gl.Disable(gl.LIGHTING)
	gl.Disable(gl.LIGHT0)
	gl.Disable(gl.LIGHT1)

	gl.Color4ub(0, 0, 0, 208)

	gl.Begin(gl.QUADS)
	gl.Vertex2f(float32(viewport.lplane), float32(viewport.bplane))
	gl.Vertex2f(float32(viewport.rplane), float32(viewport.bplane))
	gl.Vertex2f(float32(viewport.rplane), float32(viewport.tplane))
	gl.Vertex2f(float32(viewport.lplane), float32(viewport.tplane))
	gl.End()

	picker.DrawItemHighlight(t, 3)
	picker.DrawItemHighlight(t, 4)
	picker.DrawItemHighlight(t, 5)
	picker.DrawItemHighlight(t, 6)
	picker.DrawItemHighlight(t, 7)
	picker.DrawPlayerItems(t)

	const blocksize = float64(0.3)
	const COLSIZE = 12

	diam := blocksize * 2.4

	offset := diam + float64(4)*PIXEL_SCALE

	for i := range self.inventoryRects {
		x := float64(viewport.lplane) + float64(10)*PIXEL_SCALE + float64(i/COLSIZE)*offset
		y := float64(viewport.tplane) - float64(10)*PIXEL_SCALE - float64(i%COLSIZE)*offset
		self.inventoryRects[i] = Rect{x, y - diam, diam, diam}
		self.DrawItemSlot(t, self.inventoryRects[i])
	}

	slot := 0
	for i := 1; i < len(ThePlayer.inventory); i++ {
		if ThePlayer.inventory[i] > 0 {
			self.inventorySlots[slot] = uint16(i)
			self.DrawItem(t, ThePlayer.inventory[i], uint16(i), self.inventoryRects[slot])
			slot++
		}
	}

	for i := range self.componentSlots {
		x := float64(viewport.lplane) + offset*float64(2+len(self.inventoryRects)/COLSIZE) + float64(i)*offset
		y := float64(viewport.tplane) - (10.0 * PIXEL_SCALE)
		self.componentRects[i] = Rect{x, y - diam, diam, diam}

		self.DrawItemSlot(t, self.componentRects[i])
	}

	for i, cs := range self.componentSlots {
		if cs != 0 {
			self.DrawItem(t, ThePlayer.inventory[cs], cs, self.componentRects[i])
		}
	}

	for i := range self.productSlots {
		x := float64(viewport.lplane) + offset*float64(2+len(self.inventoryRects)/COLSIZE) + offset*float64(i%len(self.componentRects))
		y := float64(viewport.tplane) - (10.0 * PIXEL_SCALE) - offset*float64(2+float64(i/len(self.componentRects)))
		self.productRects[i] = Rect{x, y - diam, diam, diam}

		self.DrawItemSlot(t, self.productRects[i])
	}

	for i, ps := range self.productSlots {
		if ps != nil {
			self.DrawItem(t, ps.product.quantity, ps.product.item, self.productRects[i])
		}
	}

	if self.currentContainer != nil {

		for i := range self.containerRects {
			x := float64(viewport.lplane) + offset*float64(2+len(self.inventoryRects)/COLSIZE) + float64(i)*offset
			y := float64(viewport.tplane) - (10.0 * PIXEL_SCALE) - offset*float64(2+float64(len(self.productRects)/len(self.componentRects))) - offset*float64(2+float64(i/len(self.componentRects)))
			self.containerRects[i] = Rect{x, y - diam, diam, diam}

			self.DrawItemSlot(t, self.containerRects[i])
		}

		for i := uint16(0); i < self.currentContainer.Slots(); i++ {
			item := self.currentContainer.Item(i)
			if item != nil {
				self.DrawItem(t, item.quantity, item.item, self.containerRects[i])
			}
		}

		gl.PushMatrix()
		gl.LoadIdentity()
		gl.Translated(self.containerRects[0].x, self.containerRects[0].y+diam, 0)
		inventoryItemFont.Print(self.currentContainer.Label())
		gl.PopMatrix()

	}

	var mousex, mousey int
	mousestate := sdl.GetMouseState(&mousex, &mousey)
	self.HandleMouse(mousex, mousey, mousestate)

	gl.PopMatrix()
}