示例#1
0
        public void SphereAABBTest()
        {
            Point3d  p  = new Point3d(0, 0, 0);
            Sphere   e  = new Sphere(p, 5);
            Rotation r  = new Rotation(new Vector3d(1, 2, 3), PI / 4);
            Coord3d  cs = new Coord3d(new Point3d(1, 2, 4), r.ToRotationMatrix.Transpose());

            Box3d b = e.BoundingBox(cs);

            Plane3d s = new Plane3d(b.P1, b.P2, b.P3);

            Assert.IsTrue(e.IntersectionWith(s).GetType() == typeof(Point3d));

            s = new Plane3d(b.P8, b.P7, b.P6);
            Assert.IsTrue(e.IntersectionWith(s).GetType() == typeof(Point3d));

            s = new Plane3d(b.P1, b.P2, b.P5);
            Assert.IsTrue(e.IntersectionWith(s).GetType() == typeof(Point3d));

            s = new Plane3d(b.P2, b.P3, b.P6);
            Assert.IsTrue(e.IntersectionWith(s).GetType() == typeof(Point3d));

            s = new Plane3d(b.P3, b.P4, b.P7);
            Assert.IsTrue(e.IntersectionWith(s).GetType() == typeof(Point3d));

            s = new Plane3d(b.P1, b.P4, b.P8);
            Assert.IsTrue(e.IntersectionWith(s).GetType() == typeof(Point3d));
        }
示例#2
0
 public void Apply(Coord3d scale)
 {
     if (_enabled)
     {
         GL.MatrixMode(MatrixMode.Modelview);
         GL.LoadIdentity();
         GL.Translate(_position.x * scale.x, _position.y * scale.y, _position.z * scale.z);
         // Light position representation (cube)
         if ((_representationDisplayed))
         {
             GL.Disable(EnableCap.Lighting);
             GL.Color3(0.0, 1.0, 1.0);
             GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
             Glut.Glut.SolidCube(10);
             GL.Enable(EnableCap.Lighting);
         }
         // Actual light source setting	TODO: check we really need to define @ each rendering
         LightSwitch.Enable(_lightId);
         GL.Light(LightName.Light0, LightParameter.Position, _positionZero);
         GL.Light(LightName.Light0, LightParameter.Ambient, _ambiantColor.OpenTKColor4);
         GL.Light(LightName.Light0, LightParameter.Diffuse, _diffuseColor.OpenTKColor4);
         GL.Light(LightName.Light0, LightParameter.Specular, _specularColor.OpenTKColor4);
     }
     else
     {
         GL.Disable(EnableCap.Lighting);
     }
 }
示例#3
0
        public List <Coord3d> getDecimatedVertices(double dstep)
        {
            List <Coord3d> steps   = new List <Coord3d>();
            int            num     = vertices.Count;
            int            i       = 0;
            double         segLen  = 0;
            Coord3d        a       = default(Coord3d);
            Coord3d        dir     = default(Coord3d);
            Coord3d        stepDir = default(Coord3d);
            Coord3d        b       = vertices[0];
            Coord3d        curr    = b.Clone();

            while (i < num - 1)
            {
                a       = b;
                b       = vertices[i + 1];
                dir     = b.substract(a);
                segLen  = 1 / dir.magSquared();
                stepDir = dir.normalizeTo(dstep);
                curr    = a.interpolateTo(b, curr.substract(a).dot(dir) * segLen);
                while (curr.substract(a).dot(dir) / segLen <= 1)
                {
                    steps.Add(curr.Clone());
                    curr.addSelf(stepDir);
                }
                i += 1;
            }
            return(steps);
        }
示例#4
0
        public static object Generate(Coord3d center, double radius, int steps, bool half)
        {
            List <Coord3d> coords = new List <Coord3d>();
            double         inc    = Math.PI / steps;
            double         i      = 0;
            int            jrat   = (half ? 1 : 2);

            while (i < (2 * Math.PI))
            {
                double j = 0;
                while (j < (jrat * Math.PI))
                {
                    Coord3d c = (new Coord3d(i, j, radius)).cartesian();
                    if ((center != null))
                    {
                        c.x += center.x;
                        c.y += center.y;
                        c.z += center.z;
                    }
                    coords.Add(c);
                    j += inc;
                }
                i += inc;
            }
            return(coords);
        }
示例#5
0
        public BoundingBox3d computeScaling()
        {
            //-- Scale the scene's view -------------------
            if (Squared)
            {
                _scaling = Squarify();
            }
            else
            {
                _scaling = (Coord3d)Coord3d.IDENTITY.Clone();
            }
            // Compute the bounds for computing cam distance, clipping planes, etc ...
            if ((_targetBox == null))
            {
                _targetBox = new BoundingBox3d(0, 1, 0, 1, 0, 1);
            }
            BoundingBox3d boundsScaled = new BoundingBox3d();

            boundsScaled.Add(_targetBox.scale(_scaling));
            if (MAINTAIN_ALL_OBJECTS_IN_VIEW)
            {
                boundsScaled.Add(Scene.Graph.Bounds.scale(_scaling));
            }
            return(boundsScaled);
        }
示例#6
0
        /// <summary>
        /// Selects the closest displayable Z axe from camera
        /// </summary>
        internal int findClosestZaxe(Camera cam)
        {
            int na = 4;

            double[] distAxeZ = new double[na];

            // keeps axes that are not at intersection of 2 quads
            for (int a = 0; a <= na - 1; a++)
            {
                if ((_quadIsHidden[_axeZquads[a, 0]] ^ _quadIsHidden[_axeZquads[a, 1]]))
                {
                    distAxeZ[a] = new Vector3d(_axeZx[a, 0], _axeZy[a, 0], _axeZz[a, 0], _axeZx[a, 1], _axeZy[a, 1], _axeZz[a, 1]).distance(cam.Eye);
                }
                else
                {
                    distAxeZ[a] = double.MaxValue;
                }
            }

            // prefers the lower one
            for (int a = 0; a <= na - 1; a++)
            {
                if ((distAxeZ[a] < double.MaxValue))
                {
                    Coord3d axeCEnter = new Coord3d((_axeZx[a, 0] + _axeZx[a, 1]) / 2, (_axeZy[a, 0] + _axeZy[a, 1]) / 2, (_axeZz[a, 0] + _axeZz[a, 1]) / 2);
                    if (!cam.side(axeCEnter))
                    {
                        distAxeZ[a] *= -1;
                    }
                }
            }

            return(min(distAxeZ));
        }
示例#7
0
 /// <summary>
 /// Initialize a point at <paramref name="xyz"/> coordinate, with a <paramref name="rgb"/> color and a width of <paramref name="width"/>.
 /// </summary>
 /// <param name="xyz">Point coordinates</param>
 /// <param name="rgb">Point color</param>
 /// <param name="width">Point width</param>
 /// <remarks></remarks>
 public Point(Coord3d xyz, Color rgb, float width)
 {
     _bbox  = new BoundingBox3d();
     _xyz   = xyz;
     _width = width;
     _rgb   = rgb;
     UpdateBounds();
 }
示例#8
0
 public Polygon() : base()
 {
     _points = new List <Point>();
     _bbox   = new BoundingBox3d();
     _center = new Coord3d();
     _polygonOffsetFillEnable = true;
     _polygonMode             = PolygonMode.FRONT_AND_BACK;
 }
示例#9
0
        public void RotationFromCoordTest()
        {
            Coord3d  coord = new Coord3d(new Point3d(2, 3, 1), new Vector3d(2, 1, 5), new Vector3d(1, 1, 1));
            Rotation r     = new Rotation(coord);

            Assert.AreEqual(r * Coord3d.GlobalCS.Xaxis, coord.Xaxis);
            Assert.AreEqual(r * Coord3d.GlobalCS.Yaxis, coord.Yaxis);
            Assert.AreEqual(r * Coord3d.GlobalCS.Zaxis, coord.Zaxis);
        }
示例#10
0
        public void VectorConvertToTest()
        {
            Coord3d coord1 = Coord3d.GlobalCS.Copy();
            Coord3d coord2 = Coord3d.GlobalCS.Copy();

            coord2.RotateDeg(new Vector3d(1, 1, 1), 120);

            Assert.IsTrue(new Vector3d(1, 2, 3, coord1) == new Vector3d(2, 3, 1, coord2));
        }
示例#11
0
        public void Rotate(Coord2d move, bool updateView)
        {
            Coord3d eye = this.ViewPoint;

            eye.x -= move.x;
            eye.y += move.y;
            setViewPoint(eye, updateView);
            //fireControllerEvent(ControllerType.ROTATE, eye);
        }
示例#12
0
        public void drawAxisTicks(Camera cam, AxeDirection direction, Color color, Halign hal, Valign val, float tickLength, BoundingBox3d ticksTxtBounds, float xpos,
                                  float ypos, float zpos, float xdir, float ydir, float zdir, float[] ticks)
        {
            double xlab;
            double ylab;
            double zlab;
            String tickLabel = "";

            for (int t = 0; t < ticks.Length; t++)
            {
                // Shift the tick vector along the selected axis
                // and set the tick length
                switch (direction)
                {
                case AxeDirection.AxeX:
                    xpos      = ticks[t];
                    xlab      = xpos;
                    ylab      = (_yrange / tickLength) * ydir + ypos;
                    zlab      = (_zrange / tickLength) * zdir + zpos;
                    tickLabel = _layout.XTickRenderer.Format(xpos);
                    break;

                case AxeDirection.AxeY:
                    ypos      = ticks[t];
                    xlab      = (_xrange / tickLength) * xdir + xpos;
                    ylab      = ypos;
                    zlab      = (_zrange / tickLength) * zdir + zpos;
                    tickLabel = _layout.YTickRenderer.Format(ypos);
                    break;

                case AxeDirection.AxeZ:
                    zpos      = ticks[t];
                    xlab      = (_xrange / tickLength) * xdir + xpos;
                    ylab      = (_yrange / tickLength) * ydir + ypos;
                    zlab      = zpos;
                    tickLabel = _layout.ZTickRenderer.Format(zpos);
                    break;

                default:
                    throw new Exception("Unsupported axe direction");
                }
                Coord3d tickPosition = new Coord3d(xlab, ylab, zlab);

                if (_layout.TickLineDisplayed)
                {
                    drawTickLine(color, xpos, ypos, zpos, xlab, ylab, zlab);
                }

                // Select the alignement of the tick label
                Halign hAlign = layoutHorizontal(direction, cam, hal, tickPosition);
                Valign vAlign = layoutVertical(direction, val, zdir);

                // Draw the text label of the current tick
                drawAxisTickNumericLabel(direction, cam, color, hAlign, vAlign, ticksTxtBounds, tickLabel, tickPosition);
            }
        }
示例#13
0
        public void DefaultBoxTest()
        {
            Rotation r      = new Rotation(new Vector3d(2, 1, 5), PI / 3);
            Coord3d  coord1 = new Coord3d(new Point3d(2, 3, 1), r.ToRotationMatrix.Transpose());
            Box3d    b      = new Box3d(coord1);

            Assert.AreEqual(b.Center, coord1.Origin);
            Assert.AreEqual(b.P1, new Point3d(-0.5, -0.5, -0.5, coord1));
            Assert.AreEqual(b.P7, new Point3d(0.5, 0.5, 0.5, coord1));
        }
示例#14
0
        public void CoordSystemTest()
        {
            Coord3d c1 = new Coord3d(new Point3d(), new[] { 2.0, 0.0, 0.0 }, new[] { 1.0, 1.0, 0.0 });

            Assert.IsTrue(c1.Axes == Matrix3d.Identity());

            c1 = new Coord3d(new Point3d(), new Vector3d(2, 0, 0), new Vector3d(0, 0, 5));
            c1.RotateDeg(new Vector3d(1, 0, 0), -90);
            Assert.IsTrue(c1.Axes == Matrix3d.Identity());
        }
示例#15
0
        /// <summary>
        /// Transform a 3d point coordinate into its screen position.
        /// </summary>
        /// <param name="point">3D model coordinate</param>
        /// <returns>2D screen coordinate</returns>
        public Coord3d ModelToScreen(Coord3d point)
        {
            Vector4d screencoord = default(Vector4d);

            if (!Glut.Glut.Project(new Vector4d(point.x, point.y, point.z, 0), getModelViewAsMatrix4d(), getProjectionAsMatrix4d(), getViewPortAsDouble(), ref screencoord))
            {
                FailedProjection("Could not retrieve model coordinates in screen " + point.ToString() + ".");
            }
            return(new Coord3d(screencoord.X, screencoord.Y, screencoord.Z));
        }
示例#16
0
        public Color Color(Coord3d coord)
        {
            Color @out = m_colormap.GetColor(this, coord.x, coord.y, coord.z);

            if ((m_factor != null))
            {
                @out.mul(m_factor);
            }
            return(@out);
        }
示例#17
0
        public void PointConvertToTest2()
        {
            Coord3d coord1 = new Coord3d(new Point3d(2, 3, 1), Matrix3d.RotationMatrix(new Vector3d(2, 1, 5), PI / 3));
            Coord3d coord2 = new Coord3d(new Point3d(1, -3, 4), Matrix3d.RotationMatrix(new Vector3d(3, 2, 1), PI / 2));

            Point3d p1 = new Point3d(1, 2, -2, coord1);
            Point3d p2 = p1.ConvertTo(coord2);

            Assert.IsTrue(p2 == p1);
        }
示例#18
0
        public Coord3d Compute(Coord3d input)
        {
            Coord3d output = (Coord3d)input.Clone();

            foreach (ITransformer nextT in _sequence)
            {
                output = nextT.Compute(output);
            }
            return(output);
        }
示例#19
0
        public void BoxOrientationTest()
        {
            Rotation r      = new Rotation(new Vector3d(0, 0, 1), PI / 4);
            Coord3d  coord1 = new Coord3d(new Point3d(2, 3, 1), r.ToRotationMatrix.Transpose());
            Box3d    b      = new Box3d(coord1);

            Assert.AreEqual(b.V1.Normalized, new Vector3d(1, 1, 0).Normalized);
            Assert.AreEqual(b.V2.Normalized, new Vector3d(-1, 1, 0).Normalized);
            Assert.AreEqual(b.V3.Normalized, new Vector3d(0, 0, 1).Normalized);
        }
示例#20
0
        /// <summary>
        /// Transform a 2d screen coordinate into a 3d coordinate.
        /// The z component of the screen coordinate indicates a depth value between the
        /// near and far clipping plane of the {@link Camera}.
        /// </summary>
        /// <param name="screen">2D screen coordinate</param>
        /// <returns>3D model coordinate</returns>
        public Coord3d ScreenToModel(Coord3d screen)
        {
            Vector4d worldcoord = default(Vector4d);
            bool     s          = Glut.Glut.UnProject(new Vector4d(screen.x, screen.y, screen.z, 0), getModelViewAsMatrix4d(), getProjectionAsMatrix4d(), getViewPortAsDouble(), ref worldcoord);

            if (!s)
            {
                FailedProjection("Could not retrieve screen coordinates in model.");
            }
            return(new Coord3d(worldcoord.X, worldcoord.Y, worldcoord.Z));
        }
示例#21
0
 public void setViewPoint(Coord3d polar, bool updateView)
 {
     _viewpoint   = polar;
     _viewpoint.y = (_viewpoint.y < -PI_div2 ? -PI_div2 : _viewpoint.y);
     _viewpoint.y = (_viewpoint.y > PI_div2 ? PI_div2 : _viewpoint.y);
     if (updateView)
     {
         Shoot();
     }
     fireViewPointChangedEvent(new ViewPointChangedEventArgs(this, polar));
 }
示例#22
0
        public void PointProjectionToPlaneTest()
        {
            Point3d p1 = new Point3d(-4, 3, 5);
            Plane3d s1 = new Plane3d(-1, 2, -2, 9);

            Assert.IsTrue(p1.ProjectionTo(s1) == new Point3d(-3, 1, 7));

            Coord3d coord1 = new Coord3d(new Point3d(2, 3, 1), Matrix3d.RotationMatrix(new Vector3d(2, 1, 5), PI / 3));

            p1 = p1.ConvertTo(coord1);
            Assert.IsTrue(p1.ProjectionTo(s1) == new Point3d(-3, 1, 7));
        }
示例#23
0
 /// <summary>
 /// Add a point to the polygon
 /// </summary>
 /// <param name="point">Point to add</param>
 public void Add(Point point)
 {
     _points.Add(point);
     _bbox.@add(point);
     // Recompute Center
     _center = new Coord3d();
     foreach (Point p in _points)
     {
         _center.addSelf(p.xyz);
     }
     _center.divideSelf(_points.Count);
 }
        private Polygon buildPolygonFrom(Triangle_dt triangle)
        {
            Coord3d c1      = triangle.p1.Coord3d;
            Coord3d c2      = triangle.p2.Coord3d;
            Coord3d c3      = triangle.p3.Coord3d;
            Polygon polygon = new Polygon();

            polygon.Add(new Point(c1));
            polygon.Add(new Point(c2));
            polygon.Add(new Point(c3));
            return(polygon);
        }
示例#25
0
        public void TranslatePointTest1()
        {
            Coord3d coord1 = Coord3d.GlobalCS.Copy();

            coord1.RotateDeg(new Vector3d(0, 0, 1), 90);
            coord1.Origin = new Point3d(1, 1, 1);

            Point3d  p1 = new Point3d(1, 2, 3, Coord3d.GlobalCS);
            Vector3d v1 = new Vector3d(1, 1, 1, coord1);

            Assert.IsTrue(p1.Translate(v1) == new Point3d(0, 3, 4));
        }
示例#26
0
        public void PlaneRotationTest()
        {
            Matrix3d r     = Matrix3d.RotationMatrix(new Vector3d(1, 1, 1), 2 * PI / 3);
            Coord3d  coord = new Coord3d(new Point3d(3, 2, 1), r);
            Point3d  p     = new Point3d(5, 0, 2, coord);
            Plane3d  s     = new Plane3d(1, 2, 3, 4);

            Assert.IsTrue(s.Rotate(r, p).Rotate(r, p).Rotate(r, p) == s);

            Rotation q = new Rotation(new Vector3d(1, 1, 1), 2 * PI / 3);

            Assert.IsTrue(s.Rotate(q, p).Rotate(q, p).Rotate(q, p) == s);
        }
示例#27
0
        public void drawAxisTickNumericLabel(AxeDirection direction, Camera cam, Color color, Halign hAlign, Valign vAlign, BoundingBox3d ticksTxtBounds, String tickLabel,
                                             Coord3d tickPosition)
        {
            GL.LoadIdentity();
            GL.Scale(_scale.x, _scale.y, _scale.z);

            BoundingBox3d tickBounds = _txt.drawText(cam, tickLabel, tickPosition, hAlign, vAlign, color);

            if (tickBounds != null)
            {
                ticksTxtBounds.Add(tickBounds);
            }
        }
示例#28
0
        public void PointProjectionToSphereTest()
        {
            Point3d p1 = new Point3d(1, 1, 1);
            Sphere  s  = new Sphere(p1, 2);
            Point3d p2 = new Point3d(5, 5, 5);

            Assert.IsTrue(p2.ProjectionTo(s) == new Point3d(1 + 2 / Sqrt(3), 1 + 2 / Sqrt(3), 1 + 2 / Sqrt(3)));

            Coord3d coord1 = new Coord3d(new Point3d(2, 3, 1), Matrix3d.RotationMatrix(new Vector3d(2, 1, 5), PI / 3));

            p2 = p2.ConvertTo(coord1);
            Assert.IsTrue(p2.ProjectionTo(s) == new Point3d(1 + 2 / Sqrt(3), 1 + 2 / Sqrt(3), 1 + 2 / Sqrt(3)));
        }
示例#29
0
        public void VectorConvertToTest2()
        {
            Coord3d coord1 = Coord3d.GlobalCS.Copy();
            Coord3d coord2 = Coord3d.GlobalCS.Copy();

            coord2.RotateDeg(new Vector3d(1, 1, 1), 120);

            Vector3d v1 = new Vector3d(2, 3, 4);
            Vector3d v2 = v1.ConvertTo(coord1);
            Vector3d v3 = v1.ConvertTo(coord2);

            Assert.IsTrue(v2 == v3);
        }
示例#30
0
        public void LineReflectInLineTest()
        {
            Coord3d coord1 = new Coord3d(new Point3d(2, 3, 1), Matrix3d.RotationMatrix(new Vector3d(2, 1, 5), PI / 3));
            Coord3d coord2 = new Coord3d(new Point3d(1, -3, 4), Matrix3d.RotationMatrix(new Vector3d(3, 2, 1), PI / 2));

            Line3d l1 = new Line3d(new Point3d(2, 3, 4, coord1), new Vector3d(2, 1, -3));
            Line3d l2 = new Line3d(new Point3d(2, 3, 4, coord2), new Vector3d(2, 1, -3));
            Line3d lt = l1.ReflectIn(l2);

            lt.Point = lt.Point.ConvertTo(coord2);

            Assert.IsTrue(lt.ReflectIn(l2) == l1);
        }