示例#1
0
文件: model.go 项目: mantyr/mol
func (m *Molecule) Paths(width, height float64) ln.Paths {
	scene := ln.Scene{}

	nodes := make([]ln.Vector, len(m.Atoms))
	for i, atom := range m.Atoms {
		nodes[i] = ln.Vector{atom.X, atom.Y, atom.Z}
	}

	mid := ln.BoxForVectors(nodes).Center()
	for i, node := range nodes {
		nodes[i] = node.Sub(mid)
	}

	eye := CameraPosition(nodes)
	center := ln.Vector{}
	fov := CameraFOV(nodes, eye, center)
	up := ln.Vector{0, 0, 1}

	for i, node := range nodes {
		atom := m.Atoms[i]
		radius := float64(AtomicRadii[atom.Symbol]) / 100
		scene.Add(ln.NewOutlineSphere(eye, up, node, radius*0.5))
	}

	for _, bond := range m.Bonds {
		v0 := nodes[bond.I]
		v1 := nodes[bond.J]
		r := float64(bond.Type) / 16
		scene.Add(ln.NewTransformedOutlineCylinder(eye, up, v0, v1, r))
	}

	return scene.Render(eye, center, up, width, height, fov, 0.1, 100, 0.01)
}
示例#2
0
文件: model.go 项目: fogleman/mol
func (m *Molecule) Paths(width, height float64) ln.Paths {
	scene := ln.Scene{}

	camera := m.Camera()
	eye := camera.Eye.ln()
	center := camera.Center.ln()
	up := camera.Up.ln()
	fovy := camera.Fovy

	spheres, cylinders := m.Solids()

	for _, s := range spheres {
		scene.Add(ln.NewOutlineSphere(eye, up, s.Center.ln(), s.Radius*0.5))
	}

	for _, c := range cylinders {
		scene.Add(ln.NewTransformedOutlineCylinder(eye, up, c.A.ln(), c.B.ln(), c.Radius))
	}

	return scene.Render(eye, center, up, width, height, fovy, 0.1, 100, 0.01)
}