Exemplo n.º 1
0
func (node *Node) RelativePosition(n *Node) (mgl32.Vec3, error) {
	if node == n {
		return mgl32.Vec3{}, nil
	}
	for _, child := range node.children {
		if childNode, ok := child.(*Node); ok {
			if rPost, err := childNode.RelativePosition(n); err == nil {
				return mgl32.TransformCoordinate(rPost, childNode.Transform), nil
			}
		}
	}
	return mgl32.Vec3{}, fmt.Errorf("Node not found")
}
Exemplo n.º 2
0
func (geometry *Geometry) transformRange(transform mgl32.Mat4, from int) {
	for i := from; i < len(geometry.Verticies); i = i + VertexStride {
		v := mgl32.TransformCoordinate(mgl32.Vec3{
			geometry.Verticies[i],
			geometry.Verticies[i+1],
			geometry.Verticies[i+2],
		}, transform)
		n := mgl32.TransformNormal(mgl32.Vec3{
			geometry.Verticies[i+3],
			geometry.Verticies[i+4],
			geometry.Verticies[i+5],
		}, transform)
		geometry.Verticies[i] = v.X()
		geometry.Verticies[i+1] = v.Y()
		geometry.Verticies[i+2] = v.Z()
		geometry.Verticies[i+3] = n.X()
		geometry.Verticies[i+4] = n.Y()
		geometry.Verticies[i+5] = n.Z()
	}
	geometry.updateGeometry()
}
Exemplo n.º 3
0
func (sceneGraph *SceneGraph) sortBuckets(renderer Renderer, cameraLocation mgl32.Vec3) {
	for index, entry := range sceneGraph.transparentBucket {
		sceneGraph.transparentBucket[index].cameraDelta = mgl32.TransformCoordinate(entry.spatial.Centre(), entry.transform).Sub(cameraLocation).Len()
	}
	sort.Sort(sceneGraph.transparentBucket)
}