示例#1
0
文件: main.go 项目: nobonobo/go-three
func main() {
	runtime.LockOSThread()

	settings := three.WindowSettings{
		Width:      width,
		Height:     height,
		Title:      "Example - Wireframe Cube",
		Fullscreen: false,
		ClearColor: &three.Color{0., 0., 0.4},
	}

	window, err := three.NewWindow(settings)
	if err != nil {
		log.Fatal(err)
	}

	renderer, err := three.NewRenderer(window)
	if err != nil {
		log.Fatal(err)
	}

	scene := three.NewScene()
	camera := three.NewPerspectiveCamera(fov, width/height, near, far)
	camera.Transform.SetPosition(4.0, 3.0, 4.0)
	camera.Transform.LookAt(0, 0, 0)

	box := geometries.NewCube(1)
	red := three.NewBasicMaterial()
	red.SetColor(&three.Color{1.0, 0.0, 0.0})
	red.SetWireframe(true)

	mesh := three.NewMesh(box, red)

	scene.Add(mesh)

	var rotX float32 = 0.01
	var rotY float32 = 0.02
	transform := mesh.Transform()
	for !window.ShouldClose() {
		transform.RotateX(rotX)
		transform.RotateY(rotY)

		renderer.Render(scene, camera)
	}

	renderer.Unload(scene)

	renderer.OpenGLSentinel()
}
示例#2
0
文件: main.go 项目: nobonobo/go-three
func main() {
	runtime.LockOSThread()

	settings := three.WindowSettings{
		Width:      width,
		Height:     height,
		Title:      "Example - Textured Cube",
		Fullscreen: false,
	}

	window, err := three.NewWindow(settings)
	if err != nil {
		log.Fatal(err)
	}

	renderer, err := three.NewRenderer(window)
	if err != nil {
		log.Fatal(err)
	}

	scene := three.NewScene()
	camera := three.NewPerspectiveCamera(fov, width/height, near, far)
	camera.Transform.TranslateZ(1000)

	box := geometries.NewCube(200)
	texture := three.NewBasicMaterial()
	t, err := three.NewTexture("textures/uvgrid01.dds")
	if err != nil {
		log.Panic(err)
	}
	texture.SetTexture(t)

	mesh := three.NewMesh(box, texture)

	scene.Add(mesh)

	transform := mesh.Transform()
	for !window.ShouldClose() {
		transform.RotateX(0.01)
		transform.RotateY(0.02)

		renderer.Render(scene, camera)
	}

	renderer.Unload(scene)

	renderer.OpenGLSentinel()
}