예제 #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
파일: 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
}
예제 #3
0
파일: cr.go 프로젝트: krattai/monoflow
// getBox creates a visible box physics body.
func (cr *crtag) getBox(bod vu.Part) {
	bod.SetScale(2, 2, 2)
	bod.SetFacade("cube", "gouraud").SetMaterial("sphere")
	bod.SetBody(vu.Box(1, 1, 1), 1, 0)
}