示例#1
0
文件: cr.go 项目: krattai/monoflow
// Create is the engine intialization callback. Create the physics objects.
func (cr *crtag) Create(eng vu.Engine) {
	cr.scene = eng.AddScene(vu.VP)
	cr.scene.SetPerspective(60, float64(800)/float64(600), 0.1, 50)
	cr.scene.SetLightLocation(0, 5, 0)
	cr.scene.SetLightColour(0.4, 0.7, 0.9)
	cr.scene.SetViewLocation(0, 10, 25)

	// load the static slab.
	slab := cr.scene.AddPart()
	slab.SetFacade("cube", "gouraud").SetMaterial("floor")
	slab.SetScale(50, 50, 50)
	slab.SetBody(vu.Box(25, 25, 25), 0, 0.4)
	slab.SetLocation(0, -25, 0)

	// create a single moving body.
	useBalls := true
	cr.bod = cr.scene.AddPart()
	cr.bod.SetLocation(15, 15, 0) // -5, 15, -3
	if useBalls {
		cr.getBall(cr.bod)
	} else {
		cr.getBox(cr.bod)
		cr.bod.SetRotation(0.1825742, 0.3651484, 0.5477226, 0.7302967)
	}

	// Box can be used as a ball replacement.

	// 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.scene.AddPart()
				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 some constant state.
	rand.Seed(time.Now().UTC().UnixNano())
	cr.eng.Enable(vu.BLEND, true)
	cr.eng.Enable(vu.CULL, true)
	cr.eng.Enable(vu.DEPTH, true)
	cr.eng.Color(0.1, 0.1, 0.1, 1.0)
	return
}
示例#2
0
文件: bb.go 项目: krattai/monoflow
// Create is the engine intialization callback.
func (bb *bbtag) Create(eng vu.Engine) {
	bb.scene = eng.AddScene(vu.VP)
	bb.scene.SetPerspective(60, float64(800)/float64(600), 0.1, 50)
	bb.scene.SetLightLocation(0, 10, 0)
	bb.scene.SetLightColour(0.4, 0.7, 0.9)
	bb.scene.SetViewLocation(0, 0, 4)
	bb.scene.Set2D()

	// load the floor model.
	floor := bb.scene.AddPart()
	floor.SetLocation(0, 1, 0)
	floor.SetFacade("floor", "gouraud").SetMaterial("floor")

	// load the billboard and textures.
	b1 := bb.scene.AddPart()
	b1.SetFacade("billboard", "bbra").SetTexture("core", 3)
	b1.SetAlpha(0.2)
	b1.SetLocation(0, 0, -2)
	b1.SetScale(0.25, 0.25, 0.25)

	b2 := bb.scene.AddPart()
	b2.SetFacade("billboard", "bbra").SetTexture("core", -1)
	b2.SetAlpha(0.2)
	b2.SetLocation(0, 0, -2)
	b2.SetScale(0.25, 0.25, 0.25)

	b3 := bb.scene.AddPart()
	b3.SetFacade("billboard", "bbra").SetTexture("halo", -2)
	b3.SetAlpha(0.2)
	b3.SetLocation(0, 0, -2)
	b3.SetScale(0.25, 0.25, 0.25)

	b4 := bb.scene.AddPart()
	b4.SetFacade("billboard", "bbra").SetTexture("halo", 1)
	b4.SetAlpha(0.2)
	b4.SetLocation(0, 0, -2)
	b4.SetScale(0.25, 0.25, 0.25)

	// Add a banner overlay
	over := eng.AddScene(vu.VO)
	over.Set2D()
	_, _, w, h := bb.eng.Size()
	over.SetOrthographic(0, float64(w), 0, float64(h), 0, 10)
	over.SetLightLocation(1, 1, 1)
	over.SetLightColour(1, 1, 1)
	banner := over.AddPart()
	banner.SetBanner("Banner Text", "uv", "weblySleek22", "weblySleek22White")
	banner.SetLocation(100, 100, 0)

	// set some constant state.
	bb.eng.Enable(vu.BLEND, true)
	bb.eng.Enable(vu.CULL, true)
	bb.eng.Color(0.1, 0.1, 0.1, 1.0)
}
示例#3
0
文件: sg.go 项目: krattai/monoflow
// Create is the engine intialization callback.
func (sg *sgtag) Create(eng vu.Engine) {
	sg.scene = eng.AddScene(vu.VP)
	sg.scene.SetPerspective(60, float64(800)/float64(600), 0.1, 50)
	sg.scene.SetLightLocation(0, 10, 0)
	sg.scene.SetLightColour(0.4, 0.7, 0.9)
	sg.scene.SetViewLocation(0, 0, 6)
	sg.scene.Set2D()

	// load the floor model.
	floor := sg.scene.AddPart()
	floor.SetLocation(0, 0, 0)
	floor.SetFacade("floor", "gouraud").SetMaterial("floor")

	// load the trooper
	sg.tr = newTrooper(sg.eng, sg.scene, 1)

	// initialize the reactions
	sg.reacts = map[string]vu.Reaction{
		"W":   vu.NewReaction("Forward", func() { sg.forward() }),
		"A":   vu.NewReaction("Left", func() { sg.left() }),
		"S":   vu.NewReaction("Back", func() { sg.back() }),
		"D":   vu.NewReaction("Right", func() { sg.right() }),
		"KP+": vu.NewReaction("Attach", func() { sg.tr.attach() }),
		"KP-": vu.NewReaction("Detach", func() { sg.tr.detach() }),
		"0":   vu.NewReactOnce("SL0", func() { sg.setTr(0) }),
		"1":   vu.NewReactOnce("SL1", func() { sg.setTr(1) }),
		"2":   vu.NewReactOnce("SL2", func() { sg.setTr(2) }),
		"3":   vu.NewReactOnce("SL3", func() { sg.setTr(3) }),
		"4":   vu.NewReactOnce("SL4", func() { sg.setTr(4) }),
		"5":   vu.NewReactOnce("SL5", func() { sg.setTr(5) }),
		"P":   vu.NewReactOnce("Stats", func() { sg.stats() }),
	}

	// set some constant state.
	sg.eng.Enable(vu.BLEND, true)
	sg.eng.Enable(vu.CULL, true)
	sg.eng.Color(0.1, 0.1, 0.1, 1.0)
}
示例#4
0
文件: cm.go 项目: krattai/monoflow
// Create is the engine intialization callback. Create the physics objects.
func (cm *cmtag) Create(eng vu.Engine) {
	cm.holdoff, _ = time.ParseDuration("1000ms")
	cm.last = time.Now()
	cm.scene = eng.AddScene(vu.VF)
	cm.scene.SetPerspective(60, float64(800)/float64(600), 0.1, 50)
	cm.scene.SetLightLocation(0, 5, 0)
	cm.scene.SetLightColour(0.4, 0.7, 0.9)
	cm.scene.SetViewLocation(0, 10, 25)

	// add a base for the other physics bodies to rest on.
	slab := cm.scene.AddPart()
	slab.SetLocation(0, 1, 0)
	slab.SetFacade("cube", "gouraud").SetMaterial("floor")
	slab.SetScale(100, 50, 100)
	slab.SetBody(vu.Box(50, 25, 50), 0, 0.4)
	slab.SetLocation(0, -25, 0)

	// create a fixed part.
	box := cm.scene.AddPart()
	box.SetLocation(0, 1, 0)
	box.SetFacade("cube", "gouraud").SetMaterial("cube")
	box.SetScale(5, 5, 5)
	box.SetBody(vu.Box(2.5, 2.5, 2.5), 0, 0) // sized to match scaling.

	// create a physics body that can be associated with a camera,
	cm.bod = cm.scene.AddPart()
	cm.bod.SetFacade("sphere", "gouraud").SetMaterial("sphere")
	cm.bod.SetBody(vu.Sphere(1), 1, 0)
	cm.bod.SetLocation(-6, 2, -2)

	// set some constant state.
	cm.eng.Enable(vu.BLEND, true)
	cm.eng.Enable(vu.CULL, true)
	cm.eng.Enable(vu.DEPTH, true)
	cm.eng.Color(0.1, 0.1, 0.1, 1.0)
	return
}