From 5ecdf0f8787b62b3f1b38d0c718fd3f52e2a19c0 Mon Sep 17 00:00:00 2001 From: Anders Gidenstam Date: Mon, 1 Nov 2010 22:44:10 +0100 Subject: [PATCH] Updated WalkView: Added a makePolylinePath convenience function. --- Aircraft/Generic/WalkView/walkview.nas | 49 +++++++++++++++++++------- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/Aircraft/Generic/WalkView/walkview.nas b/Aircraft/Generic/WalkView/walkview.nas index c329f88dc..b7bad57c1 100644 --- a/Aircraft/Generic/WalkView/walkview.nas +++ b/Aircraft/Generic/WalkView/walkview.nas @@ -221,6 +221,43 @@ var Walker = { # Constraint classes. Determines where the view can walk. # +# Convenience functions. + +# Build a UnionConstraint hierarchy from a list of constraints. +# cs - list of constraints : [constraint] +var makeUnionConstraint = func (cs) { + if (size(cs) < 2) return cs[0]; + + var ret = cs[0]; + for (var i = 1; i < size(cs); i += 1) { + ret = UnionConstraint.new(ret, cs[i]); + } + return ret; +} + +# Build a UnionConstraint hierachy that represents a polyline path +# with a certain width. Each internal point gets a circular surface. +# points - list of points : [position] ([[meter, meter, meter]]) +# width - width of the path : length (meter) +# round_ends - put a circle also on the first and last points : bool +var makePolylinePath = func (points, width, round_ends = 0) { + if (size(points) < 2) return nil; + var ret = LinePlane.new(points[0], points[1], width); + if (round_ends) { + ret = UnionConstraint.new(line, + CircularXYSurface.new(points[0], width/2)); + } + for (var i = 2; i < size(points); i += 1) { + var line = LinePlane.new(points[i-1], points[i], width); + if (i + 1 < size(points) or round_ends) { + line = UnionConstraint.new + (line, + CircularXYSurface.new(points[i], width/2)); + } + ret = UnionConstraint.new(line, ret); + } + return ret; +} # The union of two constraints. # c1, c2 - the constraints : constraint @@ -249,18 +286,6 @@ var UnionConstraint = { } }; -# Build a unionConstraint hierarchy from a list of constraints. -# cs - list of constraints : [constraint] -var makeUnionConstraint = func (cs) { - if (size(cs) < 2) return cs[0]; - - var ret = cs[0]; - for (var i = 1; i < size(cs); i += 1) { - ret = UnionConstraint.new(ret, cs[i]); - } - return ret; -} - # Rectangular plane defined by a straight line and a width. # The line is extruded horizontally on each side by width/2 into a # planar surface.