Esempio n. 1
0
 public Triangle(Vect3 p1, Vect3 p2, Vect3 p3)
 {
     P1 = p1;
     P2 = p2;
     P3 = p3;
     //calc normal
 }
Esempio n. 2
0
 public SkyBox(int id, MessageBus bus)
 {
     Id = id;
     Bus = bus;
     Position = new Vect3(0, 0, 0);
     Rotation = new Quat(Math.Sqrt(0.5), 0, 0, Math.Sqrt(0.5));
 }
Esempio n. 3
0
 public AABB(Vect3 center, double size)
 {
     Center = center;
     Min = center - new Vect3(size / 2.0, size / 2.0, size / 2.0);
     Max = center + new Vect3(size / 2.0, size / 2.0, size / 2.0);
     Extent = new Vect3(size, size, size);
 }
Esempio n. 4
0
 public AABB(Vect3 min, Vect3 max)
 {
     Min = min;
     Max = max;
     Center = (Min + Max) * 0.5;
     Extent = Max - Min;
 }
Esempio n. 5
0
 public void Vect3DivideTest()
 {
     Vect3 vec = new Vect3(5.0, 8.0, 9.0) / 4.0;
     Assert.AreEqual<double>(1.25, vec.X);
     Assert.AreEqual<double>(2.0, vec.Y);
     Assert.AreEqual<double>(2.25, vec.Z);
 }
Esempio n. 6
0
 private void LoadASCII(string filename)
 {
     Vect3 normal = null;
     var points = new Vect3[3];
     int i = 0;
     const NumberStyles style = NumberStyles.AllowExponent | NumberStyles.AllowLeadingSign | NumberStyles.Number;
     foreach (var split in File.ReadLines(filename).Select(line => line.Trim().ToLower().Split(' ')))
     {
         switch (split[0])
         {
             case "solid":
                 break;
             case "facet":
                 normal = new Vect3(Double.Parse(split[2], style), Double.Parse(split[3], style),
                                    Double.Parse(split[4], style));
                 break;
             case "outer":
                 break;
             case "vertex":
                 points[i++] = new Vect3(Double.Parse(split[1], style), Double.Parse(split[2], style),
                                         Double.Parse(split[3], style));
                 break;
             case "endloop":
                 break;
             case "endfacet":
                 Elements.Add(new STLElement { P1 = points[0], P2 = points[1], P3 = points[2], Normal = normal });
                 i = 0;
                 break;
             case "endsolid":
                 break;
         }
     }
 }
Esempio n. 7
0
 public void Vect3InitValuesTest()
 {
     Vect3 vec = new Vect3(1.0, 2.0, 3.0);
     Assert.AreEqual<double>(1.0, vec.X);
     Assert.AreEqual<double>(2.0, vec.Y);
     Assert.AreEqual<double>(3.0, vec.Z);
 }
Esempio n. 8
0
 public Triangle(Vect3 p1, Vect3 p2, Vect3 p3, Vect3 normal)
 {
     P1 = p1;
     P2 = p2;
     P3 = p3;
     Normal = normal;
 }
Esempio n. 9
0
 public OctreeNode(Vect3 center, Double size, NodeState state, int level, int maxLevel)
 {
     Center = center;
     Size = size;
     State = state;
     Level = level;
     MaxLevel = maxLevel;
     Children = Enumerable.Empty<OctreeNode>();
     Color = Color.Purple;
 }
Esempio n. 10
0
 public void Vect3AddTest()
 {
     Vect3 vec = new Vect3(5.0, 8.0, 9.0) + new Vect3(5.0, 2.0,2.0);
     Assert.AreEqual<double>(10.0, vec.X);
     Assert.AreEqual<double>(10.0, vec.Y);
     Assert.AreEqual<double>(11.0, vec.Z);
     vec = new Vect3(5.0, 8.0, 9.0).Add(new Vect3(5.0, 2.0, 2.0));
     Assert.AreEqual<double>(10.0, vec.X);
     Assert.AreEqual<double>(10.0, vec.Y);
     Assert.AreEqual<double>(11.0, vec.Z);
 }
Esempio n. 11
0
 private static double SqDistPointAABB(this AABB b, Vect3 p)
 {
     var sqDist = 0.0;
     if (p.X < b.Min.X) sqDist += (b.Min.X - p.X) * (b.Min.X - p.X);
     if (p.X > b.Max.X) sqDist += (p.X - b.Max.X) * (p.X - b.Max.X);
     if (p.Y < b.Min.Y) sqDist += (b.Min.Y - p.Y) * (b.Min.Y - p.Y);
     if (p.Y > b.Max.Y) sqDist += (p.Y - b.Max.Y) * (p.Y - b.Max.Y);
     if (p.Z < b.Min.Z) sqDist += (b.Min.Z - p.Z) * (b.Min.Z - p.Z);
     if (p.Z > b.Max.Z) sqDist += (p.Z - b.Max.Z) * (p.Z - b.Max.Z);
     return sqDist;
 }
Esempio n. 12
0
 public void Vect3CrossProductTest()
 {
     Vect3 vec = new Vect3(3.0, -3.0, 1.0).CrossProduct(new Vect3(4.0, 9.0, 2.0));
     Assert.AreEqual<double>(-15.0, vec.X);
     Assert.AreEqual<double>(-2.0, vec.Y);
     Assert.AreEqual<double>(39.0, vec.Z);
     vec = new Vect3(4.0, 9.0, 2.0).CrossProduct(new Vect3(3.0, -3.0, 1.0));
     Assert.AreEqual<double>(15.0, vec.X);
     Assert.AreEqual<double>(2.0, vec.Y);
     Assert.AreEqual<double>(-39.0, vec.Z);
 }
Esempio n. 13
0
        public OrthographicCamera()
        {
            Near = 1;
            Far = 40.0;
            Target = Vect3.Zero;
            Up = Vect3.UnitY;
            Eye = new Vect3(0, 0, -_dist);
            Model = Mat4.Identity;

            View = Mat4.LookAt(Eye, Target, Up);

            Projection = Mat4.Identity;
            Scale = 1;
        }
Esempio n. 14
0
        public MainCamera()
        {

            Near = 1f;
            Far = 500f;
            Model = Mat4.Translate(0,0,0);
            Target = Vect3.Zero;
            Up = Vect3.UnitY;

            Eye = new Vect3(0,0,20);


            _view =Mat4.LookAt(Eye, Target, Up);

           // _view = Mat4.RotateX(Angle.FromRadians(Math.Atan(Math.Sin(Angle.FromDegrees(-45))))) * (Mat4.LookAt(Eye, Target, Up) * Mat4.RotateZ(Angle.FromDegrees(45)));
            //_view = Mat4.Identity;
        }
Esempio n. 15
0
 public STLFile(string filename)
 {
     Triangles = new List<STLTriangle>();
     using (var br = new BinaryReader(File.Open(filename, FileMode.Open)))
     {
         br.ReadBytes(80); //header
         var count = (int)br.ReadUInt32();
         for (var i = 0; i < count; i++)
         {
             var normal = new Vect3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
             var p1 = new Vect3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
             var p2 = new Vect3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
             var p3 = new Vect3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
             br.ReadUInt16(); //attrib
             Triangles.Add(new STLTriangle { P1 = p1, P2 = p2, P3 = p3, Normal = normal });
         }
     }
 }
Esempio n. 16
0
 private static void SubdivideSphere(ICollection<Vertex> vertices, Vect3 v1, Vect3 v2, Vect3 v3, int div, Double r, Color color)
 {
     if (div <= 0)
     {
         vertices.Add(new Vertex {Position = (v1*(float) r),Normal = v1, Color = color});
         vertices.Add(new Vertex {Position = (v2*(float) r),Normal = v2, Color = color});
         vertices.Add(new Vertex {Position = (v3*(float) r),Normal = v3, Color = color});
     }
     else
     {
         var v12 = new Vect3((v1.X + v2.X) / 2.0f, (v1.Y + v2.Y) / 2.0f, (v1.Z + v2.Z) / 2.0f).Normalize();
         var v23 = new Vect3((v2.X + v3.X) / 2.0f, (v2.Y + v3.Y) / 2.0f, (v2.Z + v3.Z) / 2.0f).Normalize();
         var v31 = new Vect3((v3.X + v1.X) / 2.0f, (v3.Y + v1.Y) / 2.0f, (v3.Z + v1.Z) / 2.0f).Normalize();
         SubdivideSphere(vertices, v1, v12, v31, div - 1, r, color);
         SubdivideSphere(vertices, v2, v23, v12, div - 1, r, color);
         SubdivideSphere(vertices, v3, v31, v23, div - 1, r, color);
         SubdivideSphere(vertices, v12, v23, v31, div - 1, r, color);
     }
 }
Esempio n. 17
0
        public void When_GetFace_Expect_CorrectFace()
        {
            Vertex    vertex1 = new Vertex(1, 2, 3);
            Vertex    vertex2 = new Vertex(2, 2, 2);
            Vertex    vertex3 = new Vertex(3, 8, 1);
            Component comp    = new Component();

            int[] vertices = new int[3];
            vertices[0] = comp.AddVertex(vertex1);
            vertices[1] = comp.AddVertex(vertex2);
            vertices[2] = comp.AddVertex(vertex3);

            Vect3 normal = Vect3.Cross(vertex1.coordinate - vertex2.coordinate,
                                       vertex1.coordinate - vertex3.coordinate);

            Face face      = new Face(normal, vertices);
            int  faceIndex = comp.AddFace(face);

            Assert.AreEqual(comp.GetFace(faceIndex), face);
        }
Esempio n. 18
0
 public STLFile(string filename)
 {
     Triangles = new List <STLTriangle>();
     using (var br = new BinaryReader(File.Open(filename, FileMode.Open)))
     {
         br.ReadBytes(80); //header
         var count = (int)br.ReadUInt32();
         for (var i = 0; i < count; i++)
         {
             var normal = new Vect3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
             var p1     = new Vect3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
             var p2     = new Vect3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
             var p3     = new Vect3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
             br.ReadUInt16(); //attrib
             Triangles.Add(new STLTriangle {
                 P1 = p1, P2 = p2, P3 = p3, Normal = normal
             });
         }
     }
 }
Esempio n. 19
0
        public void CreationFromListTooLong()
        {
            try
            {
                var v = new Vect2(new[] { 2.0, 3.0, 5.0 });
                Assert.Fail(); // If it gets to this line, no exception was thrown
            }
            catch (ArgumentException)
            {
            }
            catch (Exception)
            {
                Assert.Fail();
            }

            try
            {
                var v = new Vect3(new[] { 2.0, 3.0, 5.0, 7.0 });
                Assert.Fail(); // If it gets to this line, no exception was thrown
            }
            catch (ArgumentException)
            {
            }
            catch (Exception)
            {
                Assert.Fail();
            }

            try
            {
                var v = new Vect4(new[] { 2.0, 3.0, 5.0, 7.0, 7.0 });
                Assert.Fail(); // If it gets to this line, no exception was thrown
            }
            catch (ArgumentException)
            {
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
Esempio n. 20
0
        public static bool IsAreaIntersectingCone(Vect3 planeNormal, Vect3 planePoint, double areaWidthHalf,
                                                  Vect3 conePosition, Vect3 coneAxis, double coneAxisLength,
                                                  double coneCosPhi)
        {
            double len;

            //try "bending" axis towards plane normal
            Vect3 q  = conePosition + coneAxis * coneAxisLength;
            Vect3 qx = planeNormal.ProjectOn(coneAxis);
            Vect3 p  = qx - planeNormal;

            if (System.Math.Abs(p.QuadLength() - 0) < Constants.EPS)
            {
// axis equals plane normal
                p   = coneAxis;
                len = coneAxisLength;
            }
            else
            {
//bend axis towards plane normal as far as sinPhi allows
                p   = p.Normalize();
                q   = q + (p * coneAxisLength * System.Math.Sin(System.Math.Acos(coneCosPhi)));
                q  -= conePosition;
                len = q.Length();
                p   = q / len;
            }

            double d = RayPlane.GetHitPointRayPlaneDistance(conePosition, p, planePoint, planeNormal);

            if (d < len)
            {
                //check if Hitpoint is in the +/-width/2 - area of the plane
                p = conePosition + p * d;
                return
                    (System.Math.Abs(p.X - planePoint.X) < areaWidthHalf * 2 &&
                     System.Math.Abs(p.Y - planePoint.Y) < areaWidthHalf * 2 &&
                     System.Math.Abs(p.Z - planePoint.Z) < areaWidthHalf * 2);
            }

            return(false);
        }
Esempio n. 21
0
        /// <summary>
        /// Get the nearest intersection with the cube
        /// </summary>
        /// <param name="ray"></param>
        /// <param name="useBiggerX"></param>
        /// <param name="useBiggerY"></param>
        /// <param name="useBiggerZ"></param>
        /// <returns></returns>
        private double RayIntersectionDistance(Shapes.Ray ray, bool useBiggerX, bool useBiggerY, bool useBiggerZ)
        {
            if (PointCube.Encloses(_center, _halfWidth, ray.Origin))
            {
                return(0);
            }

            var normal = new Vect3 {
                X = useBiggerX ? _halfWidth : -_halfWidth
            };
            var    planeCenter = _center + normal;
            double distance    = SideRayIntersectionDistance(ray, normal, planeCenter);

            // we can return instantly as we only evaluate the hear side -> only one side should be hit at any time
            if (!double.IsInfinity(distance))
            {
                return(distance);
            }

            normal = new Vect3 {
                Y = useBiggerY ? _halfWidth : -_halfWidth
            };
            planeCenter = _center + normal;
            distance    = SideRayIntersectionDistance(ray, normal, planeCenter);
            if (!double.IsInfinity(distance))
            {
                return(distance);
            }

            normal = new Vect3 {
                Z = useBiggerZ ? _halfWidth : -_halfWidth
            };
            planeCenter = _center + normal;
            distance    = SideRayIntersectionDistance(ray, normal, planeCenter);
            if (!double.IsInfinity(distance))
            {
                return(distance);
            }

            return(double.PositiveInfinity);
        }
Esempio n. 22
0
        public void Vect3Equality()
        {
            var a = new Vect3(2.0, 3.0, 5.0);
            var b = new Vect3(2.0, 3.0, 5.0);
            var c = new Vect3(3.0, 3.0, 6.0);
            var d = a;

            Assert.IsTrue(a.Equals(b));
            Assert.IsFalse(a.Equals(c));
            Assert.IsTrue(a.Equals(d));

            Assert.AreEqual(a, b);
            Assert.AreNotEqual(a, c);
            Assert.AreEqual(a, d);

            Assert.IsTrue(a == b);
            Assert.IsTrue(a != c);

            Assert.IsTrue(a != null);
            Assert.IsTrue(a == a);
        }
Esempio n. 23
0
        public Component HelpFunctionForNeighbouringFaces()
        {
            Component comp    = new Component();
            Vertex    vertex0 = new Vertex(1, 2, 3);
            Vertex    vertex1 = new Vertex(8, 12, 3);
            Vertex    vertex2 = new Vertex(1, 5, 1);
            Vertex    vertex3 = new Vertex(4, 1, 3);
            Vertex    vertex4 = new Vertex(10, 11, 7);
            Vertex    vertex5 = new Vertex(8, 3, 5);
            Vertex    vertex6 = new Vertex(9, 7, 8);
            Vertex    vertex7 = new Vertex(5, 6, 2);
            Vertex    vertex8 = new Vertex(3, 4, 11);

            comp.AddVertex(vertex0);
            comp.AddVertex(vertex1);
            comp.AddVertex(vertex2);
            comp.AddVertex(vertex3);
            comp.AddVertex(vertex4);
            comp.AddVertex(vertex5);
            comp.AddVertex(vertex6);
            comp.AddVertex(vertex7);
            comp.AddVertex(vertex8);

            Vect3 normal0 = Vect3.Cross(vertex0.coordinate - vertex1.coordinate, vertex0.coordinate - vertex2.coordinate);
            Vect3 normal1 = Vect3.Cross(vertex3.coordinate - vertex4.coordinate, vertex3.coordinate - vertex5.coordinate);
            Vect3 normal2 = Vect3.Cross(vertex4.coordinate - vertex5.coordinate, vertex4.coordinate - vertex8.coordinate);
            Vect3 normal3 = Vect3.Cross(vertex4.coordinate - vertex6.coordinate, vertex4.coordinate - vertex8.coordinate);
            Vect3 normal4 = Vect3.Cross(vertex6.coordinate - vertex7.coordinate, vertex6.coordinate - vertex8.coordinate);
            Vect3 normal5 = Vect3.Cross(vertex5.coordinate - vertex7.coordinate, vertex5.coordinate - vertex8.coordinate);

            int face0 = comp.CreateFace(normal0, new int[] { 0, 1, 2 });
            int face1 = comp.CreateFace(normal1, new int[] { 3, 4, 5 });
            int face2 = comp.CreateFace(normal2, new int[] { 4, 5, 8 });
            int face3 = comp.CreateFace(normal3, new int[] { 4, 6, 8 });
            int face4 = comp.CreateFace(normal4, new int[] { 6, 7, 8 });
            int face5 = comp.CreateFace(normal5, new int[] { 5, 7, 8 });

            return(comp);
        }
Esempio n. 24
0
        protected virtual WideColor ShootRay(Shapes.Ray ray, int level)
        {
            if (level == MaxRecursionDepth)
            {
                return Color.Red.ToWide();
            }

            //Find nearest Hit
            CollisionDetails c = Scene.FindNearestHit(ray);

            //No hit
            if (c.Obj == null)
            {
                return Color.White.ToWide();
            }

            //Calculate hit point
            Vect3 hitPoint = ray.Origin + ray.Direction*c.Distance;

            //Return object's color at hit point
            return c.Obj.GetColorAt(hitPoint).ToWide();
        }
Esempio n. 25
0
        public void When_RotateCubeCenteredAroundY_Expect_NormalsRotated(Structure simpleCube)
        {
            Component cube       = simpleCube.components[0];
            Component offsetCube = cube.Transform(Vect3.Transforms.Translation(-0.5d, 0, -0.5d));

            //CW around Y =>
            // Front => Left
            // Left => Back
            // Back => Right
            // Right => Front
            // Top, Bottom unchanged
            Component translatedCube = offsetCube.Transform(Vect3.Transforms.Rotation(0, System.Math.PI / 2d, 0));

            var Front  = new Vect3(0, 0, -1);
            var Right  = new Vect3(1, 0, 0);
            var Left   = new Vect3(-1, 0, 0);
            var Bottom = new Vect3(0, -1, 0);
            var Back   = new Vect3(0, 0, 1);
            var Top    = new Vect3(0, 1, 0);

            // was Front
            Assert.AreEqual(Left, translatedCube.faces[0].normal);
            Assert.AreEqual(Left, translatedCube.faces[1].normal);
            // was Right
            Assert.AreEqual(Front, translatedCube.faces[2].normal);
            Assert.AreEqual(Front, translatedCube.faces[3].normal);
            // was Left
            Assert.AreEqual(Back, translatedCube.faces[4].normal);
            Assert.AreEqual(Back, translatedCube.faces[5].normal);
            // was Bottom
            Assert.AreEqual(Bottom, translatedCube.faces[6].normal);
            Assert.AreEqual(Bottom, translatedCube.faces[7].normal);
            // was Back
            Assert.AreEqual(Right, translatedCube.faces[8].normal);
            Assert.AreEqual(Right, translatedCube.faces[9].normal);
            // was Top
            Assert.AreEqual(Top, translatedCube.faces[10].normal);
            Assert.AreEqual(Top, translatedCube.faces[11].normal);
        }
Esempio n. 26
0
        private void buttonLoadAlignment_Click(object sender, EventArgs e)
        {
            OpenFileDialog openfile = new OpenFileDialog();

            openfile.InitialDirectory = Application.StartupPath + @"\";
            openfile.Filter           = "XML files (*.xml)|*.xml|All files (*.*)|*.*";
            openfile.FilterIndex      = 1;
            openfile.RestoreDirectory = true;

            try
            {
                DialogResult res = openfile.ShowDialog();
                if (res != DialogResult.OK)
                {
                    return;
                }

                XmlProfile  profile          = new XmlProfile(openfile.FileName);
                AlignStar[] stars            = (AlignStar[])profile.GetValue("entries", "AlignmentStars", null, typeof(AlignStar[]));
                Vect3       alignmentEquAxis = (Vect3)profile.GetValue("entries", "AlignmentEquAxis", new Vect3());
                if (stars != null)
                {
                    alignment_ = new DSCAlignment(alignmentEquAxis, Precisions.Default);
                    for (int i = 0; i < stars.Length; ++i)
                    {
                        alignment_.AddStar(stars[i]);
                    }

                    alignment_.ForceAlignment();
                    AlignmentChanged();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }
Esempio n. 27
0
        public static Camera CreateCamera(Vect3 position, Vect3 viewPaneCenter, Vect3 camUp, double viewPaneWidth,
                                          double viewPaneHeight)
        {
            var viewPaneHeightVector = camUp;

            viewPaneHeightVector *= -viewPaneHeight;

            Vect3 temp1 = position - viewPaneCenter;
            Vect3 viewPaneWidthVector = temp1.CrossProduct(viewPaneHeightVector);

            viewPaneWidthVector  = viewPaneWidthVector.Normalize();
            viewPaneWidthVector *= viewPaneWidth;

            viewPaneWidthVector.CopyDataTo(ref temp1);
            temp1 = temp1 / 2;
            Vect3 viewPaneEdge = viewPaneCenter - temp1;

            viewPaneHeightVector.CopyDataTo(ref temp1);
            temp1         = temp1 / 2;
            viewPaneEdge -= temp1;

            return(new Camera(position, viewPaneEdge, viewPaneWidthVector, viewPaneHeightVector));
        }
Esempio n. 28
0
    public static GameObject DrawLine(Vect3 startPos, Vect3 endPos, GameObject parent = null)
    {
        GameObject cylinder = GameObject.CreatePrimitive(PrimitiveType.Cylinder);

        if (parent)
        {
            cylinder.transform.parent = parent.transform;
        }

        Vect3 localVect = startPos - endPos;

        cylinder.transform.position   = GetVector3FromVect3(Vect3.MiddlePoint(startPos, endPos));
        cylinder.transform.localScale = new Vector3(0.05f, (float)localVect.Length() / 2, 0.05f);
        Vector3 crossedVector = Vector3.Cross(GetVector3FromVect3(localVect), cylinder.transform.right);

        if (crossedVector == Vector3.zero)
        {
            crossedVector = Vector3.Cross(GetVector3FromVect3(localVect), cylinder.transform.forward);
        }
        cylinder.transform.rotation = Quaternion.LookRotation(crossedVector,
                                                              GetVector3FromVect3(localVect));
        return(cylinder);
    }
Esempio n. 29
0
 void OnBallChange(List <Colyseus.Schema.DataChange> changes, string id)
 {
     for (int i = 0; i < changes.Count; i++)
     {
         if (changes[i].Field == "owner")
         {
             Debug.Log("Ball owner changed");
             gameManager.BallOwnerChanged(id, (string)changes[i].Value);
         }
         else if (changes[i].Field == "position")
         {
             Vect3 pos = (Vect3)changes[i].Value;
             //Debug.Log("Ball changed " + pos.x + " " + pos.y + " " + pos.z);
             gameManager.BallMoved(id, new Vector3(pos.x, pos.y, pos.z));
         }
         else if (changes[i].Field == "rotation")
         {
             Quat rot = (Quat)changes[i].Value;
             //Debug.Log("Ball changed " + rot.x + " " + rot.y + " " + rot.z + " " + rot.w);
             gameManager.BallRotated(id, new Quaternion(rot.x, rot.y, rot.z, rot.w));
         }
     }
 }
Esempio n. 30
0
        /**
         * creates a rotation matrix for affine transformation
         * @param axis axis to Rotate
         * @param angleRad angle to Rotate
         * @param erg Matrix4 object to store the result
         */

        public static Matrix4 CreateRotationMatrix(Vect3 axis, double angleRad)
        {
            double cosa = System.Math.Cos(angleRad);
            double sina = System.Math.Sin(angleRad);

            double icosa = 1 - cosa; // performance ... every bit matters

            double v1xICosA = axis.X * icosa;

            return(new Matrix4
            {
                A0 = cosa + axis.X * v1xICosA,
                A1 = axis.Y * v1xICosA - axis.Z * sina,
                A2 = axis.Z * v1xICosA + axis.Y * sina,
                B0 = axis.Y * v1xICosA + axis.Z * sina,
                B1 = cosa + axis.Y * axis.Y * icosa,
                B2 = axis.Y * axis.Z * icosa - axis.X * sina,
                C0 = axis.Z * v1xICosA - axis.Y * sina,
                C1 = axis.Z * axis.Y * icosa + axis.X * sina,
                C2 = cosa + axis.Z * axis.Z * icosa,
                D3 = 1
            });
        }
Esempio n. 31
0
        public static double GetHitPointRayTriangleDistance(Vect3 rayPosition, Vect3 rayDirection, Vect3 trianglePos,
                                                            Vect3 triangleVect1, Vect3 triangleVect2)
        {
            Vect3  tmp = triangleVect1.CrossProduct(triangleVect2);
            double ret = RayPlane.GetHitPointRayPlaneDistance(rayPosition, rayDirection, trianglePos, tmp);

            if (double.IsPositiveInfinity(ret) || ret < Constants.EPS)
            {
                return(double.PositiveInfinity);
            }

            tmp  = rayPosition + rayDirection * ret;
            tmp -= trianglePos;

            double uu = triangleVect1 * triangleVect1;
            double uv = triangleVect1 * triangleVect2;
            double vv = triangleVect2 * triangleVect2;
            double wu = triangleVect1 * tmp;
            double wv = triangleVect2 * tmp;
            double d  = uv * uv - uu * vv;

            double s = (uv * wv - vv * wu) / d;

            if (s < -TriEPS || s > 1 + TriEPS)
            {
                return(double.PositiveInfinity);
            }

            double t = (uv * wu - uu * wv) / d;

            if (t < -TriEPS || s + t > 1 + TriEPS)
            {
                return(double.PositiveInfinity);
            }

            return(ret);
        }
Esempio n. 32
0
    public static Structure SetSimpleCube()
    {
        Structure structure = new Structure();

        structure.addComponent(new Component());
        structure.components[0].AddVertex(new Vertex(0, 0, 0));
        structure.components[0].AddVertex(new Vertex(0, 0, 1));
        structure.components[0].AddVertex(new Vertex(0, 1, 0));
        structure.components[0].AddVertex(new Vertex(1, 0, 0));
        structure.components[0].AddVertex(new Vertex(0, 1, 1));
        structure.components[0].AddVertex(new Vertex(1, 0, 1));
        structure.components[0].AddVertex(new Vertex(1, 1, 0));
        structure.components[0].AddVertex(new Vertex(1, 1, 1));

        var frontNormal = new Vect3(0, 0, -1);
        var rightNormal = new Vect3(1, 0, 0);
        var leftNormal  = new Vect3(-1, 0, 0);
        var downNormal  = new Vect3(0, -1, 0);
        var backNormal  = new Vect3(0, 0, 1);
        var upNormal    = new Vect3(0, 1, 0);

        structure.components[0].CreateFace(frontNormal, new int[] { 0, 3, 6 });
        structure.components[0].CreateFace(frontNormal, new int[] { 0, 2, 6 });
        structure.components[0].CreateFace(rightNormal, new int[] { 3, 5, 7 });
        structure.components[0].CreateFace(rightNormal, new int[] { 3, 6, 7 });
        structure.components[0].CreateFace(leftNormal, new int[] { 1, 0, 2 });
        structure.components[0].CreateFace(leftNormal, new int[] { 1, 4, 2 });
        structure.components[0].CreateFace(downNormal, new int[] { 0, 3, 5 });
        structure.components[0].CreateFace(downNormal, new int[] { 0, 1, 5 });
        structure.components[0].CreateFace(backNormal, new int[] { 5, 1, 4 });
        structure.components[0].CreateFace(backNormal, new int[] { 5, 7, 4 });
        structure.components[0].CreateFace(upNormal, new int[] { 2, 6, 7 });
        structure.components[0].CreateFace(upNormal, new int[] { 2, 4, 7 });

        return(structure);
    }
Esempio n. 33
0
        public static IAABB CalulateAABB(this IPointCloud pointCloud)
        {
            var agg = pointCloud.Points.Aggregate(new
            {
                MinX = Double.PositiveInfinity,
                MinY = Double.PositiveInfinity,
                MinZ = Double.PositiveInfinity,
                MaxX = Double.NegativeInfinity,
                MaxY = Double.NegativeInfinity,
                MaxZ = Double.NegativeInfinity,
            }, (a, p) => new
            {
                MinX = Math.Min(a.MinX, p.Position.X),
                MinY = Math.Min(a.MinY, p.Position.Y),
                MinZ = Math.Min(a.MinZ, p.Position.Z),
                MaxX = Math.Max(a.MaxX, p.Position.X),
                MaxY = Math.Max(a.MaxY, p.Position.Y),
                MaxZ = Math.Max(a.MaxZ, p.Position.Z),
            });
            var min = new Vect3(agg.MinX, agg.MinY, agg.MinZ);
            var max = new Vect3(agg.MaxX, agg.MaxY, agg.MaxZ);

            return(new AABB((max + min) * 0.5f, (max - min) * 0.5f));
        }
Esempio n. 34
0
        private int MakeDynamic4StarAlignment(Vect3 star0, string name0, PairA stand0, double eqAngle0,
                                              Vect3 star1, string name1, PairA stand1, double eqAngle1,
                                              Vect3 star2, string name2, PairA stand2, double eqAngle2,
                                              Vect3 star3, string name3, PairA stand3, double eqAngle3,
                                              out Alignment calc)
        {
            Vect3  eqNorth        = new Vect3(0, latitude_);
            Vect3  eqAxis         = eqNorth;
            double equAngleFactor = 1;

            calc = null;
            int i = 0;

            for (; i < 50; ++i)
            {
                Vect3 star1_corrected = new Rotation3((eqAngle1 - eqAngle0) * equAngleFactor, eqAxis).Apply(star1);
                Vect3 star3_corrected = new Rotation3((eqAngle3 - eqAngle2) * equAngleFactor, eqAxis).Apply(star3);
                calc = new DSCAlignment(new Vect3(0, latitude_), precesions_);
                calc.AddStar(new AlignStar(name0, star0, stand0, eqAngle0));
                calc.AddStar(new AlignStar(name1, star1_corrected, stand1, eqAngle0));
                calc.AddStar(new AlignStar(name2, star2, stand2, eqAngle2));
                calc.AddStar(new AlignStar(name3, star3_corrected, stand3, eqAngle2));

                Vect3  equAxis    = calc.EquAxis;
                PairA  correction = new PairA(-equAxis.Azm, latitude_ - equAxis.Alt);
                Vect3  eqAxisNew  = new Vect3(eqNorth.Azm - correction.Azm, eqNorth.Alt - correction.Alt);
                double diff       = Vect3.VMul(eqAxis, eqAxisNew).Abs;
                if (diff < toRad / 240)
                {
                    break;
                }
                eqAxis         = eqAxisNew;
                equAngleFactor = calc.EquAngleFactor;
            }
            return(i);
        }
Esempio n. 35
0
        public static double InterpolateTriangleEdge(Vect3 v1, Vect3 v2, Vect3 v3, Vect3 point)
        {
            Vect3 v23N = v3 - v2;

            v23N = v23N.Normalize();

            Vect3 v21 = v1 - v2;

// ReSharper disable InconsistentNaming
            Vect3 v1o = v21.ProjectOn(v23N); //punkt gegenüber der ecke v1 (o ... opposite)

// ReSharper restore InconsistentNaming

            v1o -= v21;

            double h1 = v1o.Length(); //höhe auf v1

            v1o = v1o / h1;           //normieren

            Vect3 v1P = point - v1;
            Vect3 p1  = v1P.ProjectOn(v1o); //projektion von v1p auf v1hn

            return(1 - (p1.Length() / h1));
        }
Esempio n. 36
0
        public void When_CreateDeepCopy_Expect_SeparateEqualInstance()
        {
            Vertex    vertex1 = new Vertex(1, 2, 3);
            Vertex    vertex2 = new Vertex(2, 2, 2);
            Vertex    vertex3 = new Vertex(3, 8, 1);
            Component comp    = new Component();

            int[] vertices = new int[3];
            vertices[0] = comp.AddVertex(vertex1);
            vertices[1] = comp.AddVertex(vertex2);
            vertices[2] = comp.AddVertex(vertex3);

            Vect3 normal = Vect3.Cross(vertex1.coordinate - vertex2.coordinate,
                                       vertex1.coordinate - vertex3.coordinate);

            Face face      = new Face(normal, vertices);
            int  faceIndex = comp.AddFace(face);

            Component compCopy = comp.DeepCopy();

            for (int i = 0; i < comp.vertices.Count; i++)
            {
                Assert.AreEqual(comp.vertices[i], compCopy.vertices[i]);
            }

            for (int i = 0; i < comp.faces.Count; i++)
            {
                Assert.AreEqual(comp.faces[i], compCopy.faces[i]);
            }

            Assert.AreEqual(comp, compCopy);

            compCopy.vertices[0].coordinate.x = 99;

            Assert.AreNotEqual(comp, compCopy);
        }
Esempio n. 37
0
        public static bool IsPlaneIntersectingCone(Vect3 planeNormal, Vect3 planePoint, Vect3 conePosition,
                                                   Vect3 coneAxis, double coneAxisLength, double coneCosPhi)
        {
            double len;

            //try "bending" axis towards plane normal
            Vect3 q  = conePosition + coneAxis * coneAxisLength;
            Vect3 qx = planeNormal.ProjectOn(coneAxis);
            Vect3 p  = qx - planeNormal;

            if (System.Math.Abs(p.QuadLength() - 0) < Constants.EPS)
            {
                // axis equals plane normal
                p   = coneAxis;
                len = coneAxisLength;
            }
            else
            {
//bend axis towards plane normal as far as sinPhi allows
                p   = p.Normalize();
                q   = q + (p * coneAxisLength * System.Math.Sin(System.Math.Acos(coneCosPhi)));
                q  -= conePosition;
                len = q.Length();
                p   = q / len;
            }

            double d = RayPlane.GetHitPointRayPlaneDistance(conePosition, p, planePoint, planeNormal);

            return(d < len);
        }
Esempio n. 38
0
 protected BaseHalfEdge(string name, Vect3 end, Lazy<IHalfEdge> opposite)
 {
     Name = name;
     End = end;
     Opposite = opposite;
 }
Esempio n. 39
0
 public static void UVect3ToVect3(this Vector3 self, ref Vect3 vect)
 {
     vect.x = self.x;
     vect.y = self.y;
     vect.z = self.z;
 }
Esempio n. 40
0
 public static Vector3 Vect3ToUVect3(this Vect3 self)
 {
     return(new Vector3(self.x, self.y, self.z));
 }
Esempio n. 41
0
 public void Update(TickTime tickTime)
 {
     if (Parent != null)
     {
         //Velocity = Velocity + (Acceleration * tickTime.GameTimeDelta.TotalSeconds);
         this.Rotation = this._rotation * (this.RotationalVelocity * tickTime.GameTimeDelta.TotalSeconds);
         this._position = this._position + (this.Velocity * tickTime.GameTimeDelta.TotalSeconds);
     }
 }
Esempio n. 42
0
 public Point(Vect3 position)
 {
     Position = position;
 }
Esempio n. 43
0
 public TestCorner(Vect3 position)
 {
     Position = position;
 }
Esempio n. 44
0
 public LineHalfEdge(string name, Vect3 end, Lazy<IHalfEdge> opposite)
     : base(name, end, opposite)
 {
     Equation = t => Vect3.Lerp(Start, End, t);
 }
Esempio n. 45
0
 public void Translate(Vect3 v)
 {
     Postion += -v;
 }
Esempio n. 46
0
 public static Vector3 ToVector3(this Vect3 v)
 {
     return(new Vector3((float)v.X, (float)v.Y, (float)v.Z));
 }
Esempio n. 47
0
 public Vert(Vect3 position, Vect3 normal, Vect4 colour)
 {
     Position = position;
     Normal = normal;
     Colour = colour;
 }
Esempio n. 48
0
 private void LoadBinary(string filename)
 {
     using (var br = new BinaryReader(File.Open(filename, FileMode.Open)))
     {
         br.ReadBytes(80); //header
         var count = (int)br.ReadUInt32();
         for (var i = 0; i < count; i++)
         {
             var normal = new Vect3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
             var p1 = new Vect3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
             var p2 = new Vect3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
             var p3 = new Vect3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
             br.ReadUInt16(); //attrib
             Elements.Add(new STLElement { P1 = p1, P2 = p2, P3 = p3, Normal = normal });
         }
     }
 }
Esempio n. 49
0
 public void Vect3SubtractTest()
 {
     Vect3 vec = new Vect3(5.0, 8.0, 9.0) - new Vect3(5.0, 2.0, 2.0);
     Assert.AreEqual<double>(0.0, vec.X);
     Assert.AreEqual<double>(6.0, vec.Y);
     Assert.AreEqual<double>(7.0, vec.Z);
     vec = new Vect3(5.0, 8.0, 9.0).Subtract(new Vect3(5.0, 2.0, 2.0));
     Assert.AreEqual<double>(0.0, vec.X);
     Assert.AreEqual<double>(6.0, vec.Y);
     Assert.AreEqual<double>(7.0, vec.Z);
 }
Esempio n. 50
0
    public void DrawStructure(DrawStructure choices, Structure structure, Vect3 structureMiddlePoint)
    {
        GameObject structureObject = new GameObject("Structure");

        for (int componentIndex = 0; componentIndex < structure.components.Count; componentIndex++)
        {
            GameObject componentObject = new GameObject(string.Format("Component {0}", componentIndex));
            componentObject.transform.parent = structureObject.transform;
            Nodegraph_Generator.Component component = structure.components[componentIndex];

            // To prepare color
            List <int>       floorFaces = ComponentGraphGenerator.GetFloorFaces(component);
            LinkedList <int> linkedList = ComponentGraphGenerator.GetShellVertices(component, floorFaces);
            (LinkedList <int>, LinkedList <int>)sidePair = ComponentGraphGenerator.SplitLinkedList(component, linkedList);

            if (choices.drawVertices)
            {
                GameObject verticesObject = new GameObject(string.Format("Component {0}, Vertices", componentIndex));
                verticesObject.transform.parent = componentObject.transform;
                for (int vertexIndex = 0; vertexIndex < component.vertices.Count; vertexIndex++)
                {
                    Vertex     vertex         = component.GetVertex(vertexIndex);
                    Vect3      vertexPosition = Utilities.GetScaledTransletedVect3(vertex.coordinate, structureMiddlePoint, scalingFactor);
                    GameObject vertexObject   = Utilities.DrawObject(vertexPrefab, vertexPosition, verticesObject);
                    vertexObject.name = string.Format("Vertex {0}", vertexIndex);
                    if (choices.colorFloor)
                    {
                        if (sidePair.Item1.Contains(vertexIndex))
                        {
                            Utilities.ColorObject(vertexObject, Color.blue);
                        }
                        else if (sidePair.Item2.Contains(vertexIndex))
                        {
                            Utilities.ColorObject(vertexObject, Color.red);
                        }
                    }
                }
            }

            if (choices.drawFaces)
            {
                var        drawnVertexPairs = new List <(int, int)>();
                var        drawnFaceSides   = new List <GameObject>();
                GameObject faces            = new GameObject(string.Format("Component {0}, Faces", componentIndex));
                faces.transform.parent = componentObject.transform;
                for (int faceIndex = 0; faceIndex < component.faces.Count; faceIndex++)
                {
                    Face face            = component.GetFace(faceIndex);
                    var  faceMiddlepoint = new Vect3();
                    for (int i = 0; i < face.vertexIndices.Length; i++)
                    {
                        int    firstVertexIndex = face.vertexIndices[i];
                        Vertex firstVertex      = component.GetVertex(firstVertexIndex);
                        faceMiddlepoint += firstVertex.coordinate;
                        for (int j = i + 1; j < face.vertexIndices.Length; j++)
                        {
                            int secondVertexIndex = face.vertexIndices[j];
                            if (!(drawnVertexPairs.Contains((firstVertexIndex, secondVertexIndex)) ||
                                  drawnVertexPairs.Contains((secondVertexIndex, firstVertexIndex))))
                            {
                                Vertex secondVertex = component.GetVertex(secondVertexIndex);
                                Vect3  startPos     = Utilities.GetScaledTransletedVect3(firstVertex.coordinate,
                                                                                         structureMiddlePoint, scalingFactor);
                                Vect3 endPos = Utilities.GetScaledTransletedVect3(secondVertex.coordinate,
                                                                                  structureMiddlePoint, scalingFactor);
                                GameObject faceSideObject = Utilities.DrawLine(startPos, endPos, faces);
                                faceSideObject.name = string.Format("Faceside to Face {0}", faceIndex);
                                Utilities.ColorObject(faceSideObject,
                                                      (choices.colorFloor && floorFaces.Contains(faceIndex)) ? Color.green : Color.black);
                                drawnVertexPairs.Add((secondVertexIndex, firstVertexIndex));
                                drawnFaceSides.Add(faceSideObject);
                            }
                            else
                            {
                                GameObject faceSideObject = drawnFaceSides[drawnVertexPairs.FindIndex(a =>
                                                                                                      (a.Item1 == firstVertexIndex && a.Item2 == secondVertexIndex) || (a.Item1 == secondVertexIndex && a.Item2 == firstVertexIndex))];
                                if (choices.colorFloor && floorFaces.Contains(faceIndex))
                                {
                                    Utilities.ColorObject(faceSideObject, Color.green);
                                }
                                faceSideObject.name += ", " + faceIndex;
                            }
                        }
                    }
Esempio n. 51
0
 public void Vect3NormalTest()
 {
     Vect3 vec = new Vect3(5.0, 0.0, 0.0);
     Assert.AreEqual<double>(1.0, vec.Normalise().X);
     Assert.AreEqual<double>(0.0, vec.Normalise().Y);
     Assert.AreEqual<double>(0.0, vec.Normalise().Z);
 }
Esempio n. 52
0
 public void Vect3MultiplyTest()
 {
     Vect3 vec = new Vect3(5.0, 8.0, 9.0) * 4.0;
     Assert.AreEqual<double>(20.0, vec.X);
     Assert.AreEqual<double>(32.0, vec.Y);
     Assert.AreEqual<double>(36.0, vec.Z);
 }
Esempio n. 53
0
 public static Vector3d ToVector3d(this Vect3 v)
 {
     return(new Vector3d(v.X, v.Y, v.Z));
 }
Esempio n. 54
0
 public WhiteBlock(IMessageBus bus, Vect3 position, Quat rotation)
     : base(bus, position, rotation, Color.WhiteSmoke)
 {
 }
Esempio n. 55
0
 public Camera()
 {
     Rotation = Quat.Identity;
     Postion  = Vect3.Zero;
 }
Esempio n. 56
0
 public Point(Vect3 position)
 {
     Position = position;
 }
Esempio n. 57
0
 public Sphere(Vect3 position, Quat rotation, double radius)
 {
     Position = position;
     Rotation = rotation;
     Radius = radius;
 }
Esempio n. 58
0
 public Vertex(string name, Vect3 v)
     : base(v)
 {
     Name = name;
 }
Esempio n. 59
0
 public ColorPoint(Vect3 position, Color color)
 {
     Position = position;
     Color    = color;
 }
Esempio n. 60
0
 public AxisAngle(Vect3 axis, Angle angle)
 {
     Axis = axis;
     Angle = angle;
 }