예제 #1
0
파일: kc.go 프로젝트: toophy/vu
// Create is the startup asset creation.
func (kc *kctag) Create(eng vu.Eng, s *vu.State) {
	top := eng.Root().NewPov()
	view := top.NewView()
	view.SetUI()
	kc.ui = view.Cam()
	kc.positions = kc.keyPositions()

	// Create the keyboard image.
	kc.kb = top.NewPov().SetScale(900, 255, 0).SetLocation(450, 100+85, 0)
	kc.kb.NewModel("uv").LoadMesh("icon").AddTex("keyboard")

	// Pressed key focus
	kc.focus = top.NewPov().SetScale(50, 50, 0)
	kc.focus.NewModel("uv").LoadMesh("icon").AddTex("particle")

	// Place the key symbols over the keys.
	font := "lucidiaSu18"
	fontColour := "lucidiaSu18Black"
	for code, key := range kc.positions { // map key is key code, map value is key struct
		if char := vu.Keysym(code); char > 0 {
			cx, cy := key.location()
			letter := top.NewPov().SetLocation(cx, cy, 0)
			model := letter.NewModel("uv")
			model.AddTex(fontColour).LoadFont(font).SetPhrase(string(char))
		}
	}

	// Have a lighter default background.
	eng.SetColor(0.45, 0.45, 0.45, 1)
	kc.resize(s.W, s.H)
}
예제 #2
0
파일: rl.go 프로젝트: skyview059/vu
// Create is the engine callback for initial asset creation.
func (rl *rltag) Create(eng vu.Eng, s *vu.State) {
	rl.ww, rl.wh = 800, 600
	rl.floors = make(map[int]*floor)
	rl.setLevel(eng, vu.K_1)
	eng.SetColor(0.15, 0.15, 0.15, 1)
	return
}
예제 #3
0
파일: sg.go 프로젝트: skyview059/vu
// Create is the engine callback for initial asset creation.
func (sg *sgtag) Create(eng vu.Eng, s *vu.State) {
	sg.run = 10   // move so many cubes worth in one second.
	sg.spin = 270 // spin so many degrees in one second.
	sg.cam = eng.Root().NewCam()
	sg.cam.SetPerspective(60, float64(800)/float64(600), 0.1, 50)
	sg.cam.SetLocation(0, 0, 6)
	sg.tr = newTrooper(eng, 1)

	// initialize the reactions
	sg.reacts = map[int]inputHandler{
		vu.K_W:     sg.forward,
		vu.K_A:     sg.left,
		vu.K_S:     sg.back,
		vu.K_D:     sg.right,
		vu.K_Equal: sg.attach,
		vu.K_Minus: sg.detach,
		vu.K_0:     func(i *vu.Input, down int) { sg.setTr(down, 0) },
		vu.K_1:     func(i *vu.Input, down int) { sg.setTr(down, 1) },
		vu.K_2:     func(i *vu.Input, down int) { sg.setTr(down, 2) },
		vu.K_3:     func(i *vu.Input, down int) { sg.setTr(down, 3) },
		vu.K_4:     func(i *vu.Input, down int) { sg.setTr(down, 4) },
		vu.K_5:     func(i *vu.Input, down int) { sg.setTr(down, 5) },
		vu.K_P:     sg.stats,
	}
	eng.SetColor(0.1, 0.1, 0.1, 1.0)
}
예제 #4
0
파일: rl.go 프로젝트: toophy/vu
// Create is the engine callback for initial asset creation.
func (rl *rltag) Create(eng vu.Eng, s *vu.State) {
	rl.run = 5    // move so many cubes worth in one second.
	rl.spin = 270 // spin so many degrees in one second.
	rl.ww, rl.wh = 800, 600
	rl.floors = make(map[int]*floor)
	rl.setLevel(eng, vu.K_1)
	eng.SetColor(0.15, 0.15, 0.15, 1)
	return
}
예제 #5
0
파일: cr.go 프로젝트: toophy/vu
// Create is the engine callback for initial asset creation.
func (cr *crtag) Create(eng vu.Eng, s *vu.State) {
	cr.run = 10   // move so many cubes worth in one second.
	cr.spin = 270 // spin so many degrees in one second.
	cr.top = eng.Root().NewPov()
	sun := cr.top.NewPov().SetLocation(0, 10, 10)
	sun.NewLight().SetColour(0.8, 0.8, 0.8)
	cr.view = cr.top.NewView()
	cr.cam = cr.view.Cam()
	cr.cam.SetPerspective(60, float64(800)/float64(600), 0.1, 500)
	cr.cam.SetLocation(0, 10, 25)

	// load the static slab.
	slab := cr.top.NewPov().SetScale(50, 50, 50).SetLocation(0, -25, 0)
	slab.NewBody(vu.NewBox(25, 25, 25))
	slab.SetSolid(0, 0.4)
	slab.NewModel("gouraud").LoadMesh("cube").LoadMat("floor")

	// create a single moving body.
	useBalls := true // Flip to use boxes instead of spheres.
	cr.striker = cr.top.NewPov()
	cr.striker.SetLocation(15, 15, 0) // -5, 15, -3
	if useBalls {
		cr.getBall(cr.striker)
	} else {
		cr.getBox(cr.striker)
		cr.striker.SetRotation(&lin.Q{X: 0.1825742, Y: 0.3651484, Z: 0.5477226, W: 0.7302967})
	}
	cr.striker.Model().SetColour(rand.Float64(), rand.Float64(), rand.Float64())

	// create a block of physics bodies.
	cubeSize := 3
	startX := -5 - cubeSize/2
	startY := -5
	startZ := -3 - cubeSize/2
	for k := 0; k < cubeSize; k++ {
		for i := 0; i < cubeSize; i++ {
			for j := 0; j < cubeSize; j++ {
				bod := cr.top.NewPov()
				lx := float64(2*i + startX)
				ly := float64(20 + 2*k + startY)
				lz := float64(2*j + startZ)
				bod.SetLocation(lx, ly, lz)
				if useBalls {
					cr.getBall(bod)
				} else {
					cr.getBox(bod)
				}
			}
		}
	}

	// set non default engine state.
	eng.SetColor(0.15, 0.15, 0.15, 1)
	rand.Seed(time.Now().UTC().UnixNano())
}
예제 #6
0
파일: bampf.go 프로젝트: kissthink/bampf
// create the game screens before the main action/update loop is started.
func (mp *bampf) Create(eng vu.Eng, s *vu.State) {
	rand.Seed(time.Now().UnixNano())
	mp.eng = eng
	mp.ani = &animator{}
	mp.setMute(mp.mute)
	mp.eventq = list.New()
	mp.createScreens(s.W, s.H)
	mp.state = mp.choosing
	mp.active = mp.launch
	mp.active.activate(screenActive)
	eng.SetColor(1, 1, 1, 1) // White as default background.
}
예제 #7
0
파일: fm.go 프로젝트: toophy/vu
// Create is the engine callback for initial asset creation.
func (fm *fmtag) Create(eng vu.Eng, s *vu.State) {
	fm.view = eng.Root().NewView()
	fm.view.SetUI()
	eng.SetColor(0.95, 0.95, 0.95, 1)

	// create the panel layout examples.
	fm.layouts = append(fm.layouts, fm.simpleLayout(eng, s.W, s.H))
	fm.layouts = append(fm.layouts, fm.spanLayout(eng, s.W, s.H))
	fm.layouts = append(fm.layouts, fm.grabLayout(eng))
	fm.layouts = append(fm.layouts, fm.largeLayout(eng, s.W, s.H))
	fm.layouts = append(fm.layouts, fm.doubleLayout(eng))
	fm.layouts[fm.example].setVisible(true)

	// set non default engine state.
	fm.resize(s.W, s.H)
}
예제 #8
0
파일: ma.go 프로젝트: toophy/vu
// Create is the engine callback for initial asset creation.
func (ma *matag) Create(eng vu.Eng, s *vu.State) {
	ma.run = 10   // move so many cubes worth in one second.
	ma.spin = 270 // spin so many degrees in one second.
	ma.top = eng.Root().NewPov()
	ma.view = ma.top.NewView()
	ma.cam = ma.view.Cam()
	ma.cam.SetPerspective(60, float64(800)/float64(600), 0.1, 50)
	ma.cam.SetLocation(0, 3, 10)

	// load any available IQM/E models. The loaded model data is fed to
	// the animation capable shader "anim".
	for _, modelFile := range ma.modelFiles() {
		pov := ma.top.NewPov()
		pov.SetScale(-1, 1, 1)
		if modelFile == "runner" {
			pov.SetScale(-3, 3, 3) // Runner is a bit small.
		}
		pov.Spin(-90, 0, 0)   // Have the model face the camera.
		pov.SetVisible(false) // Hide initially.

		// Most IQ* files are expected to be animated.
		// Use a "uv" shader to handle IQ* files without animations.
		pov.NewModel("anim").LoadAnim(modelFile)
		ma.models = append(ma.models, pov)
		ma.names = append(ma.names, modelFile)
	}
	ma.model = ma.models[ma.index] // should always have at least one.
	ma.model.SetVisible(true)

	// Have a lighter default background.
	eng.SetColor(0.15, 0.15, 0.15, 1)

	// Create a banner to show the model name.
	top2D := eng.Root().NewPov()
	view2D := top2D.NewView()
	view2D.SetUI()
	ma.ui = view2D.Cam()
	ma.ui.SetOrthographic(0, float64(s.W), 0, float64(s.H), 0, 10)
	title := top2D.NewPov()
	title.SetLocation(10, 5, 0)
	ma.title = title.NewModel("uv").AddTex("lucidiaSu22White").LoadFont("lucidiaSu22")
	ma.title.SetPhrase(" ")
}
예제 #9
0
파일: ff.go 프로젝트: toophy/vu
// Create is the engine callback for initial asset creation.
func (ff *fftag) Create(eng vu.Eng, s *vu.State) {
	rand.Seed(time.Now().UTC().UnixNano())

	// create the overlay
	ff.top = eng.Root().NewPov()
	view := ff.top.NewView()
	view.SetUI()
	ff.cam = view.Cam()
	ff.mmap = ff.top.NewPov().SetScale(10, 10, 0)
	ff.mmap.SetLocation(30, 30, 0)

	// populate the map
	ff.msize = 69
	ff.plan = grid.New(grid.ROOMS_SKIRMISH)
	ff.plan.Generate(ff.msize, ff.msize)
	width, height := ff.plan.Size()
	for x := 0; x < width; x++ {
		for y := 0; y < height; y++ {
			if ff.plan.IsOpen(x, y) {
				block := ff.mmap.NewPov()
				block.SetLocation(float64(x), float64(y), 0)
				block.NewModel("uv").LoadMesh("icon").AddTex("wall")
				ff.spots = append(ff.spots, ff.id(x, y))
			}
		}
	}

	// populate chasers and a goal.
	numChasers := 30
	for cnt := 0; cnt < numChasers; cnt++ {
		chaser := ff.mmap.NewPov()
		chaser.NewModel("uv").LoadMesh("icon").AddTex("token")
		ff.chasers = append(ff.chasers, chaser)
	}
	ff.goal = ff.mmap.NewPov()
	ff.goal.NewModel("uv").LoadMesh("icon").AddTex("goal")
	ff.flow = grid.NewFlow(ff.plan) // flow field for the given plan.
	ff.resetLocations()

	// set non default engine state.
	eng.SetColor(0.15, 0.15, 0.15, 1)
	ff.resize(s.W, s.H)
}
예제 #10
0
파일: rc.go 프로젝트: toophy/vu
// Create is the engine callback for initial asset creation.
func (rc *rctag) Create(eng vu.Eng, s *vu.State) {
	top := eng.Root().NewPov()
	view := top.NewView()
	rc.cam = view.Cam()
	rc.cam.SetPitch(45)            // Tilt the camera and
	rc.cam.SetLocation(0, -14, 14) // ...point directly at 0, 0, 0
	rc.gsize = 32                  // 4x8 ie. image is 4x4 grid, tile.obj is oversampled by 8.

	// The ray cast target is a plane displaying the image of a 32x32 grid.
	rc.fsize = 10.0                               // 2x2 plane to 20x20 plane.
	rc.floor = top.NewPov()                       // create the floor.
	rc.floor.NewBody(vu.NewPlane(0, 0, -1))       // the floors ray intersect shape.
	rc.floor.SetScale(rc.fsize, rc.fsize, 0)      // scale the model to fsize.
	m := rc.floor.NewModel("uv").LoadMesh("tile") // put the image on the floor.
	m.AddTex("tile").SetTexMode(0, vu.TEX_REPEAT)

	// create a selected tile tracker.
	rc.hilite = top.NewPov().SetScale(0.625, 0.625, 0.001) // scale to cover a single tile.
	rc.hilite.NewModel("uv").LoadMesh("icon").AddTex("image")

	// Put spheres at the floor corners.
	rc.s0 = rc.makeSphere(top, 10, 10, 0, 1, 0, 0)
	rc.s1 = rc.makeSphere(top, -10, 10, 0, 0, 1, 0)
	rc.s2 = rc.makeSphere(top, 10, -10, 0, 0, 0, 1)
	rc.s3 = rc.makeSphere(top, -10, -10, 0, 1, 1, 0)

	// Add a banner to show the currently selected grid location.
	top2D := eng.Root().NewPov()
	view2D := top2D.NewView()
	view2D.SetUI()
	rc.ui = view2D.Cam()
	rc.banner = top2D.NewPov()
	rc.banner.SetLocation(100, 100, 0)
	rc.banner.SetVisible(false)
	m = rc.banner.NewModel("uv").AddTex("lucidiaSu22White")
	m.LoadFont("lucidiaSu22").SetPhrase("Overlay Text")

	// set non default engine state.
	eng.SetColor(0.2, 0.2, 0.2, 1.0)
	rc.resize(s.W, s.H)
}
예제 #11
0
파일: ps.go 프로젝트: toophy/vu
// Create is the engine callback for initial asset creation.
func (ps *pstag) Create(eng vu.Eng, s *vu.State) {
	ps.run = 10   // move so many cubes worth in one second.
	ps.spin = 270 // spin so many degrees in one second.
	ps.live = []*vu.EffectParticle{}
	ps.random = rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
	view := eng.Root().NewView()
	ps.cam = view.Cam()
	ps.cam.SetPerspective(60, float64(800)/float64(600), 0.1, 50)
	ps.cam.SetLocation(0, 0, 2.5)

	// A GPU/shader based particle example using a particle shader.
	gpu := eng.Root().NewPov()
	gpu.SetVisible(false)
	m := gpu.NewModel("particle").AddTex("particle")
	m.NewMesh("gpu").SetDrawMode(vu.POINTS).SetDepth(false)
	ps.makeParticles(m)
	ps.effects = append(ps.effects, gpu)

	// A CPU/shader based particle example using an effect shader.
	cpu := eng.Root().NewPov()
	cpu.SetVisible(false)
	m = cpu.NewModel("effect").AddTex("particle").SetDrawMode(vu.POINTS)
	m.SetEffect(ps.fall, 250)
	ps.effects = append(ps.effects, cpu)

	// A jet engine exhaust attempt.
	// FUTURE: update textures to look like engine exhaust.
	jet := eng.Root().NewPov().SetLocation(0, -1, 0)
	jet.SetVisible(false)
	m = jet.NewModel("exhaust").AddTex("exhaust").SetDrawMode(vu.POINTS)
	m.SetEffect(ps.vent, 40)
	ps.effects = append(ps.effects, jet)

	// Make the first particle effect visible to kick things off.
	ps.effect = ps.effects[ps.index]
	ps.effect.SetVisible(true)

	// Non default engine state. Have a lighter default background.
	eng.SetColor(0.15, 0.15, 0.15, 1)
}