コード例 #1
0
ファイル: Window.cs プロジェクト: ExpLife0011/JuusanKoubou
        private void MoveCameraAroundCenter(double leftRight, double topDown)
        {
            // Use WPF maths for camera rotation.
            // It is slower than using Matrix4F and Vector4F,
            // but camera calculations are only done once per camera move
            Transform3DGroup tg = new Transform3DGroup();
            //left/right drags rotate around the camera's up vector
            Vector3D leftRightRotationAxis = new Vector3D(Up.X, Up.Y, Up.Z);
            //top/down drags rotate around the vector that is perpendicular
            //to both Up and Eye (camera location) - their cross product
            Vector3D topDownRotationAxis = Vector3D.CrossProduct(
                leftRightRotationAxis,
                new Vector3D(Eye.X, Eye.Y, Eye.Z));

            tg.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(leftRightRotationAxis, leftRight)));
            tg.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(topDownRotationAxis, topDown)));
            Vector3D newEye = tg.Transform(new Vector3D(Eye.X, Eye.Y, Eye.Z));
            Vector3D newUp  = tg.Transform(new Vector3D(Up.X, Up.Y, Up.Z));

            Eye.X = (float)newEye.X;
            Eye.Y = (float)newEye.Y;
            Eye.Z = (float)newEye.Z;
            Up.X  = (float)newUp.X;
            Up.Y  = (float)newUp.Y;
            Up.Z  = (float)newUp.Z;

            effects.ViewMatrix = DXUtil.Camera.MatrixLookAtLH(Eye, At, Up);
        }
コード例 #2
0
        public ConverterRadiationToEnergy(EditorOptions options, ItemOptions itemOptions, ConverterRadiationToEnergyDNA dna, IContainer energyTanks, RadiationField radiationField)
            : base(options, dna, itemOptions.SolarPanel_Damage.HitpointMin, itemOptions.SolarPanel_Damage.HitpointSlope, itemOptions.SolarPanel_Damage.Damage)
        {
            _itemOptions    = itemOptions;
            _energyTanks    = energyTanks;
            _radiationField = radiationField;

            this.Design = new ConverterRadiationToEnergyDesign(options, true, dna.Shape);
            this.Design.SetDNA(dna);

            this.ClarityPercent_Front = 1d;
            this.ClarityPercent_Back  = 1d;

            Point3D  center;
            Vector3D normal;

            GetStats(out _mass, out center, out normal, out _scaleActual);

            // Store the center and normals
            Transform3DGroup transform = new Transform3DGroup();

            transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(dna.Orientation)));
            transform.Children.Add(new TranslateTransform3D(dna.Position.ToVector()));

            _centerPoint = transform.Transform(center);
            _normalFront = transform.Transform(normal);
            _normalBack  = transform.Transform(normal * -1d);
        }
コード例 #3
0
        /// <summary>
        /// This defines the back side of a cylinder
        /// </summary>
        private static Geometry3D GetGeometry(int numSegments, double thetaOffset, double height, double radius, double translate)
        {
            double thetaStart = 270 - thetaOffset;
            double thetaStop  = 270 + thetaOffset;

            MeshGeometry3D retVal = new MeshGeometry3D();

            #region Initial calculations

            // The rest of this method has height along Z, but the final needs to go along Y
            Transform3DGroup transform = new Transform3DGroup();
            transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 90d)));
            //transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), 180d)));
            transform.Children.Add(new TranslateTransform3D(0, 0, translate));

            double halfHeight = height / 2d;

            Point[] points = new Point[numSegments];

            double deltaTheta = Math1D.DegreesToRadians((thetaStop - thetaStart) / (numSegments - 1));        //NOTE: This will fail if theta start/stop goes past 0/360
            double theta      = Math1D.DegreesToRadians(thetaStart);

            for (int cntr = 0; cntr < numSegments; cntr++)
            {
                points[cntr] = new Point(Math.Cos(theta) * radius, Math.Sin(theta) * radius);
                theta       += deltaTheta;
            }

            #endregion

            for (int cntr = 0; cntr < numSegments; cntr++)
            {
                retVal.Positions.Add(transform.Transform(new Point3D(points[cntr].X, points[cntr].Y, -halfHeight)));
                retVal.Positions.Add(transform.Transform(new Point3D(points[cntr].X, points[cntr].Y, halfHeight)));

                retVal.Normals.Add(transform.Transform(new Vector3D(-points[cntr].X, -points[cntr].Y, 0d)));            // the normals point straight in from the side
                retVal.Normals.Add(transform.Transform(new Vector3D(-points[cntr].X, -points[cntr].Y, 0d)));

                double coord = Convert.ToDouble(cntr) / Convert.ToDouble(numSegments - 1);
                retVal.TextureCoordinates.Add(new Point(coord, 0));
                retVal.TextureCoordinates.Add(new Point(coord, 1));
            }

            for (int cntr = 0; cntr < numSegments - 1; cntr++)
            {
                // 0,2,3
                retVal.TriangleIndices.Add((cntr * 2) + 0);
                retVal.TriangleIndices.Add((cntr * 2) + 3);
                retVal.TriangleIndices.Add((cntr * 2) + 2);

                // 0,3,1
                retVal.TriangleIndices.Add((cntr * 2) + 0);
                retVal.TriangleIndices.Add((cntr * 2) + 1);
                retVal.TriangleIndices.Add((cntr * 2) + 3);
            }

            return(retVal);
        }
コード例 #4
0
        private void MakeObjects(out MeshGeometry3D cameraMesh,
                                 out MeshGeometry3D boxMesh, out MeshGeometry3D edgeMesh,
                                 out Point3D cameraCenter)
        {
            // Make a "camera."
            cameraMesh = new MeshGeometry3D();
            cameraMesh.AddBox(new Point3D(-0.6, -0.5, -0.2),
                              D3.XVector(1.2), D3.YVector(1), D3.ZVector(0.4));
            Point3D[] points = G3.MakePolygonPoints(20, new Point3D(0, 0, -0.7),
                                                    D3.XVector(0.3), D3.YVector(0.3));
            cameraMesh.AddCylinder(points, D3.ZVector(0.7), true);
            points = G3.MakePolygonPoints(20, new Point3D(0, 0, -0.8),
                                          D3.XVector(0.4), D3.YVector(0.4));
            cameraMesh.AddCylinder(points, D3.ZVector(0.2), true);
            cameraMesh.AddBox(new Point3D(0.3, 0.5, -0.1),
                              D3.XVector(0.2), D3.YVector(0.2), D3.ZVector(0.2));
            MainGroup.Children.Add(cameraMesh.MakeModel(Brushes.LightBlue));

            // Transform the camera and vector.
            Transform3DGroup  trans = new Transform3DGroup();
            RotateTransform3D r1    = D3.Rotate(D3.XVector(), D3.Origin, -45);

            trans.Children.Add(r1);
            RotateTransform3D r2 = D3.Rotate(D3.YVector(), D3.Origin, -45);

            trans.Children.Add(r2);

            // See where we need to translate to make the camera point at the origin.
            Point3D lookAtPoint = new Point3D(0, 0, -3.5);

            lookAtPoint = trans.Transform(lookAtPoint);

            TranslateTransform3D t1 = new TranslateTransform3D(
                -lookAtPoint.X, -lookAtPoint.Y, -lookAtPoint.Z);

            trans.Children.Add(t1);
            cameraMesh.ApplyTransformation(trans);

            cameraCenter = trans.Transform(D3.Origin);

            // Make a target box.
            boxMesh = new MeshGeometry3D();
            boxMesh.AddBox(new Point3D(-0.75, -0.75, -0.75),
                           D3.XVector(1.5), D3.YVector(1.5), D3.ZVector(1.5));
            MainGroup.Children.Add(boxMesh.MakeModel(Brushes.LightGreen));

            // Make the box's edges.
            edgeMesh = new MeshGeometry3D();
            HashSet <Edge> edges = new HashSet <Edge>();

            edgeMesh.AddBox(new Point3D(-0.75, -0.75, -0.75),
                            D3.XVector(1.5), D3.YVector(1.5), D3.ZVector(1.5), edges: edges);
            MainGroup.Children.Add(edgeMesh.MakeModel(Brushes.Black));
        }
コード例 #5
0
        /// <summary>
        /// Call this to apply the thruster force to the physics body
        /// </summary>
        public void ApplyForce(double percentMax, Transform3D worldTransform, BodyForceEventArgs e)
        {
            if (!_isFiring)        // the property set will make sure the visual is no longer known to the viewport
            {
                return;
            }

            double actualForce = _forceStrength * percentMax;

            if (_fuelTank != null)
            {
                #region Use Fuel

                if (_fuelTank.QuantityCurrent > 0d)
                {
                    double fuelToUse = actualForce * e.ElapsedTime * _fuelToThrustRatio;

                    double fuelUnused = _fuelTank.RemoveQuantity(fuelToUse, false);
                    if (fuelUnused > 0d)
                    {
                        // Not enough fuel, reduce the amount of force
                        actualForce -= fuelUnused / (e.ElapsedTime * _fuelToThrustRatio);
                    }
                }
                else
                {
                    actualForce = 0d;
                }

                #endregion
            }

            if (actualForce == 0d)
            {
                // No force to apply
                //TODO:  Play a clicking sound, or some kind of error tone
                //TODO:  Don't show the flames
                return;
            }

            // Figure out how to place it in world coords
            Transform3DGroup transform = new Transform3DGroup();       // I don't use _initialRotate, because that's for the visual (it's always created along the X axis, but _force is already stored correctly)
            transform.Children.Add(this.BodyOffset);
            transform.Children.Add(worldTransform);

            Vector3D positionOnBodyWorld = transform.Transform(new Point3D(0, 0, 0)).ToVector();    // note that I have to use a point (transform acts different on points than vectors)
            Vector3D deltaForceWorld     = transform.Transform(_forceDirection);
            deltaForceWorld.Normalize();
            deltaForceWorld *= actualForce;

            // Apply the force
            e.AddForceAtPoint(deltaForceWorld, positionOnBodyWorld);
        }
コード例 #6
0
ファイル: RotatableViewport3D.cs プロジェクト: lulzzz/Nucleus
        private void PanView(double dX, double dY)
        {
            Vector3D xVector = new Vector3D(1, 0, 0);

            xVector = _CameraTransform.Transform(xVector);
            Vector3D yVector = new Vector3D(0, 1, 0);

            yVector = _CameraTransform.Transform(yVector);

            _CameraPosition.OffsetX += (xVector.X * dX) + (yVector.X * dY);
            _CameraPosition.OffsetY += (xVector.Y * dX) + (yVector.Y * dY);
            _CameraPosition.OffsetZ += (xVector.Z * dX) + (yVector.Z * dY);
        }
コード例 #7
0
ファイル: DragHitShape.cs プロジェクト: wwwK/AsteroidMiner
        private static Point3D?CastRay_Cylinder(Point3D point, Vector3D direction, double radius, RayHitTestParameters mouseDownClickRay, RayHitTestParameters mouseDownCenterRay, RayHitTestParameters currentClickRay)
        {
            // Get points on the cylinder
            Point3D?mouseDownClickPoint  = null;
            Point3D?mouseDownCenterPoint = null;
            Point3D?currentClickPoint    = null;

            Point3D[] nearestCylinderPoints, nearestLinePoints;
            if (Math3D.GetClosestPoints_Cylinder_Line(out nearestCylinderPoints, out nearestLinePoints, point, direction, radius, currentClickRay.Origin, currentClickRay.Direction, Math3D.RayCastReturn.ClosestToRay))
            {
                currentClickPoint = nearestCylinderPoints[0];

                if (Math3D.GetClosestPoints_Cylinder_Line(out nearestCylinderPoints, out nearestLinePoints, point, direction, radius, mouseDownClickRay.Origin, mouseDownClickRay.Direction, Math3D.RayCastReturn.ClosestToRay))
                {
                    mouseDownClickPoint = nearestCylinderPoints[0];

                    if (Math3D.GetClosestPoints_Cylinder_Line(out nearestCylinderPoints, out nearestLinePoints, point, direction, radius, mouseDownCenterRay.Origin, mouseDownCenterRay.Direction, Math3D.RayCastReturn.ClosestToRay))
                    {
                        mouseDownCenterPoint = nearestCylinderPoints[0];
                    }
                }
            }

            if (mouseDownCenterPoint == null || mouseDownClickPoint == null || currentClickPoint == null)
            {
                return(currentClickPoint);               // it doesn't matter if this one is null or not, the offset can't be determined, so just return the raw click value
            }

            // Circle only cared about an offset angle, but cylinder needs two things:
            //		Offset line (the part of the offset that is parallel to the cylinder's axis)
            //		Offset angle (the part of the offset that is perpendicular to the cylinder's axis)
            Vector3D   offsetLinear = (mouseDownCenterPoint.Value - mouseDownClickPoint.Value).GetProjectedVector(direction);
            Quaternion offsetRadial = GetRotation_Circle(point, direction, mouseDownClickPoint.Value, mouseDownCenterPoint.Value);



            //TODO: Get the radial offset working as well (sphere is also messed up, the same fix should work for both)



            //TODO: See if this is the most effiecient way or not
            Transform3DGroup transform = new Transform3DGroup();

            //transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(offsetRadial)));
            transform.Children.Add(new TranslateTransform3D(offsetLinear));

            //TODO: Bring currentClickPoint into local coords, do the transform, then put it back into global coords

            // Find the point along the cylinder's axis that is nearest to the current click.  This will become the center of the model coords
            Point3D modelCenter = Math3D.GetClosestPoint_Line_Point(point, direction, currentClickPoint.Value);

            // Shift the click point into model coords
            Vector3D modelClick = currentClickPoint.Value - modelCenter;

            // Adjust by the offset transform (needed to put into model coords, because there is a rotation)
            modelClick = transform.Transform(modelClick);

            // Now put back into world coords
            return(modelCenter + modelClick);
        }
コード例 #8
0
        public static Tuple <Transform3D, Transform3D> GetTransformTo2D_custom_CLEAN(HelperClassesWPF.Controls3D.Debug3DWindow window, ITriangle triangle)
        {
            Vector3D zUp = new Vector3D(0, 0, 1);

            if (Math.Abs(Vector3D.DotProduct(triangle.NormalUnit, zUp)).IsNearValue(1))
            {
                // It's already 2D
                window.AddMessage("already 2D");
                return(new Tuple <Transform3D, Transform3D>(new TranslateTransform3D(0, 0, -triangle.Point0.Z), new TranslateTransform3D(0, 0, triangle.Point0.Z)));
            }

            // Don't bother with a double vector, just rotate the normal
            Quaternion rotation = Math3D.GetRotation(triangle.NormalUnit, zUp);

            Transform3DGroup transformTo2D = new Transform3DGroup();

            transformTo2D.Children.Add(new RotateTransform3D(new QuaternionRotation3D(rotation)));

            // Need to rotate the point so that it's parallel to the XY plane, then subtract off it's Z
            Point3D rotatedXYPlane = transformTo2D.Transform(triangle[0]);

            transformTo2D.Children.Add(new TranslateTransform3D(0, 0, -rotatedXYPlane.Z));

            Transform3DGroup transformTo3D = new Transform3DGroup();

            transformTo3D.Children.Add(new TranslateTransform3D(0, 0, rotatedXYPlane.Z));
            transformTo3D.Children.Add(new RotateTransform3D(new QuaternionRotation3D(rotation.ToReverse())));

            return(new Tuple <Transform3D, Transform3D>(transformTo2D, transformTo3D));
        }
コード例 #9
0
        public static Tuple <Transform3D, Transform3D> GetTransformTo2D_custom_USES_DBLVECT(HelperClassesWPF.Controls3D.Debug3DWindow window, ITriangle triangle)
        {
            if (Math.Abs(Vector3D.DotProduct(triangle.NormalUnit, new Vector3D(0, 0, 1))).IsNearValue(1))
            {
                // It's already 2D
                window.AddMessage("already 2D");
                return(new Tuple <Transform3D, Transform3D>(new TranslateTransform3D(0, 0, -triangle.Point0.Z), new TranslateTransform3D(0, 0, triangle.Point0.Z)));
            }

            Vector3D line1      = triangle.Point1 - triangle.Point0;
            Vector3D randomOrth = Math3D.GetOrthogonal(line1, triangle.Point2 - triangle.Point0);

            DoubleVector from = new DoubleVector(line1, randomOrth);
            DoubleVector to   = new DoubleVector(new Vector3D(1, 0, 0), new Vector3D(0, 1, 0));

            Quaternion rotation = from.GetRotation(to);

            Transform3DGroup transformTo2D = new Transform3DGroup();

            transformTo2D.Children.Add(new RotateTransform3D(new QuaternionRotation3D(rotation)));

            // Need to rotate the point so that it's parallel to the XY plane, then subtract off it's Z
            Point3D rotatedXYPlane = transformTo2D.Transform(triangle[0]);

            transformTo2D.Children.Add(new TranslateTransform3D(0, 0, -rotatedXYPlane.Z));

            Transform3DGroup transformTo3D = new Transform3DGroup();

            transformTo3D.Children.Add(new TranslateTransform3D(0, 0, rotatedXYPlane.Z));
            transformTo3D.Children.Add(new RotateTransform3D(new QuaternionRotation3D(rotation.ToReverse())));

            return(new Tuple <Transform3D, Transform3D>(transformTo2D, transformTo3D));
        }
コード例 #10
0
ファイル: Arm.cs プロジェクト: DIKU-HCI/SkinTouch
        private void InitializeOfflinePosition()
        {
            // NOTE: arm is centered in origin, along z-axis (forward)
            double armRadius = Radius;

            // create forearm position & orientation
            ForearmOrientation = new Quaternion(new Vector3D(0.0, 0.0, 1.0), m_forearmAngle);

            Transform3DGroup forearmTransform = new Transform3DGroup();

            forearmTransform.Children.Add(new TranslateTransform3D(
                                              new Vector3D(0.0, armRadius, 0.0)));
            forearmTransform.Children.Add(new RotateTransform3D(
                                              new QuaternionRotation3D(ForearmOrientation)));
            forearmTransform.Children.Add(new TranslateTransform3D(
                                              new Vector3D(0.0, 1250.0, 0.0)));

            ForearmPosition = forearmTransform.Transform(new Point3D(0.0, 0.0, 0.0));

            // create wrist position & orientation
            WristOrientation = new Quaternion(new Vector3D(0.0, 0.0, 1.0), m_wristAngle);

            Transform3DGroup wristTransform = new Transform3DGroup();

            wristTransform.Children.Add(new TranslateTransform3D(
                                            new Vector3D(WristWidth / 2.0, -WristHeight / 2.0, Constants.Entities.DefaultArmLength)));
            wristTransform.Children.Add(new RotateTransform3D(
                                            new QuaternionRotation3D(WristOrientation)));
            wristTransform.Children.Add(new TranslateTransform3D(
                                            new Vector3D(0.0, 1250.0, 0.0)));

            WristPosition = wristTransform.Transform(new Point3D(0.0, 0.0, 0.0));
        }
コード例 #11
0
        private void DoOrbitMovement()
        {
            var sphereCenter = new Point3D(0, 0, 0);

            var mousePositionWhenButtonPressed = _pressedButtons[ApplicationConfiguration.OrbitMouseButton];
            var vector = mousePositionWhenButtonPressed - _currentMousePosition;

            if (vector.Length != 0)
            {
                vector.Normalize();
            }

            var rotationY = -vector.Y;
            var rotationZ = vector.X;

            var transformGroup = new Transform3DGroup
            {
                Children = new Transform3DCollection
                {
                    new RotateTransform3D(new AxisAngleRotation3D(CameraViewModel.UnaryLeft, rotationY), sphereCenter),
                    new RotateTransform3D(new AxisAngleRotation3D(CameraViewModel.UnaryUp, rotationZ), sphereCenter)
                }
            };

            //This does the orbiting
            var newPosition = transformGroup.Transform(CameraViewModel.Position);

            CameraViewModel.Move(newPosition);

            //This makes the camera face the center of the sphere
            CameraViewModel.LookAt(sphereCenter);
        }
コード例 #12
0
ファイル: Renderer.cs プロジェクト: DIKU-HCI/SkinTouch
        private void TransformCamera()
        {
            Vector3D cameraLookVect = new Vector3D(0.0, 0.0, 1.0);
            Vector3D cameraUpVect   = new Vector3D(0.0, 1.0, 0.0);

            Transform3DGroup cameraTransform = new Transform3DGroup();

            cameraTransform.Children.Add(new TranslateTransform3D(new Vector3D(0.0, 0.0, -(m_cameraDistance))));
            cameraTransform.Children.Add(new RotateTransform3D(
                                             new QuaternionRotation3D(new Quaternion(new Vector3D(1.0, 0.0, 0.0), m_pitch))));
            cameraTransform.Children.Add(new RotateTransform3D(
                                             new QuaternionRotation3D(new Quaternion(new Vector3D(0.0, 1.0, 0.0), m_yaw))));
            cameraTransform.Children.Add(new RotateTransform3D(
                                             new QuaternionRotation3D(new Quaternion(new Vector3D(0.0, 0.0, 1.0), m_roll))));

            // TODO: fix this
            cameraTransform.Children.Add(new TranslateTransform3D(m_cameraTargetPosition));

            m_cameraTransform = cameraTransform;

            Point3D  cameraPosition = cameraTransform.Transform(new Point3D(0.0, 0.0, 0.0));
            Vector3D lookDirection  = cameraTransform.Transform(cameraLookVect);
            Vector3D upDirection    = cameraTransform.Transform(cameraUpVect);

            if (m_camera == null)
            {
                Debug.WriteLine("Camera:");
                Debug.WriteLine("\tPosition:     " + cameraPosition);
                Debug.WriteLine("\tLook Vector:  " + lookDirection);
                Debug.WriteLine("\tUp: Vector:   " + upDirection);

                m_camera = new PerspectiveCamera(
                    cameraPosition, lookDirection, upDirection, 45.0);
                m_camera.NearPlaneDistance = 0.01;
                m_camera.FarPlaneDistance  = 10000.0;

                m_viewport.Camera = m_camera;
            }
            else
            {
                m_camera.Position      = cameraPosition;
                m_camera.LookDirection = lookDirection;
                m_camera.UpDirection   = upDirection;
            }
        }
コード例 #13
0
ファイル: MainWindow.xaml.cs プロジェクト: mind0n/hive
        private void ResetBtnLocation(Point3D point)
        {
            Model3D m = (Model3D)(((Model3DGroup)grpMain.Children[0]).Children[0]);

            Transform3DGroup tgp = new Transform3DGroup();

            tgp.Children.Add(grpMain.Transform);
            tgp.Children.Add(m.Transform);

            GeneralTransform3DTo2D gt = lvMain.TransformToAncestor(vpMain);            //vpmain.TransformToDescendant(...);
            Point p = gt.Transform(tgp.Transform(point));

            Canvas.SetLeft(btnTest, p.X);
            Canvas.SetTop(btnTest, p.Y);
            btnTest.Content = p.X + "," + p.Y;
        }
コード例 #14
0
        /// <summary>
        /// This is exposed so it can be called externally on a separate thread, then call this asteroid's constructor
        /// in the main thread once this returns
        /// </summary>
        public static ITriangleIndexed[] GetHullTriangles(double radius)
        {
            const int NUMPOINTS = 60;           // too many, and it looks too perfect

            Exception lastException = null;
            Random    rand          = StaticRandom.GetRandomForThread();

            for (int infiniteLoopCntr = 0; infiniteLoopCntr < 50; infiniteLoopCntr++)           // there is a slight chance that the convex hull generator will choke on the inputs.  If so just retry
            {
                try
                {
                    double minRadius = radius * .9d;

                    Point3D[] points = new Point3D[NUMPOINTS];

                    // Make a point cloud
                    for (int cntr = 0; cntr < NUMPOINTS; cntr++)
                    {
                        points[cntr] = Math3D.GetRandomVector_Spherical(minRadius, radius).ToPoint();
                    }

                    // Squash it
                    Transform3DGroup transform = new Transform3DGroup();
                    transform.Children.Add(new ScaleTransform3D(.33d + (rand.NextDouble() * .66d), .33d + (rand.NextDouble() * .66d), 1d)); // squash it
                    transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(Math3D.GetRandomRotation())));                    // giving it a random rotation, since it's always squashed along the same axiis
                    transform.Transform(points);

                    // Get a hull that wraps those points
                    ITriangleIndexed[] retVal = Math3D.GetConvexHull(points.ToArray());

                    // Get rid of unused points
                    retVal = TriangleIndexed.Clone_CondensePoints(retVal);

                    // Exit Function
                    return(retVal);
                }
                catch (Exception ex)
                {
                    lastException = ex;
                }
            }

            throw new ApplicationException(lastException.ToString());
        }
コード例 #15
0
        /// <summary>
        /// Each hit line should create a cone of probability to place control points onto
        /// Once a point on the surface of a cone is chosen, choose a couple more on that circle
        /// </summary>
        private static Point3D[] GetVoronoiCtrlPoints_AroundLine_Cone(Point3D lineStart, Point3D lineStop, int count, double entryRadius, double exitRadius, double maxAxisLength)
        {
            // Figure out where on the axis the control point ring should go (the bell has a spike around 30% in)
            double axisPercent = StaticRandomWPF.NextBell(_coneAxisBell.Value);

            Vector3D axis       = lineStop - lineStart;
            double   axisLength = axis.Length;

            Point3D ringCenter = lineStart + (axis * axisPercent);

            // Figure out the radius of the cone at this point
            double exitRadiusAdjusted = (axisLength / maxAxisLength) * exitRadius;

            double ringRadius = UtilityCore.GetScaledValue(entryRadius, exitRadiusAdjusted, 0, 1, axisPercent);

            // Get some points
            var points = Enumerable.Range(0, count).
                         Select(o => Math3D.GetRandomVector_Circular_Shell(ringRadius).ToPoint());



            //TODO: Figure out the minimum to shift by
            //double shiftRadius = Math.Max(.01, ringRadius / 20);
            double shiftRadius = ringRadius / 20;

            points = points.Select(o => o + Math3D.GetRandomVector_Spherical(shiftRadius));     // the voronoi can't handle coplanar input



            // Rotate/Translate
            Quaternion roation = Math3D.GetRotation(new Vector3D(0, 0, 1), axis);

            Transform3DGroup transform = new Transform3DGroup();

            transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(roation)));
            transform.Children.Add(new TranslateTransform3D(ringCenter.X, ringCenter.Y, ringCenter.Z));

            points = points.Select(o => transform.Transform(o));

            return(points.ToArray());
        }
コード例 #16
0
        public void LoadModel(string path, bool transformYup, double scale)
        {
            var importer = new ModelImporter();
            var mod      = importer.Load(path);

            if (mod == null || mod.Children.Count == 0)
            {
                return;
            }

            var model = (mod.Children[0] as GeometryModel3D);

            if (model == null)
            {
                return;
            }

            var mesh = model.Geometry as MeshGeometry3D;

            if (mesh == null)
            {
                return;
            }

            var transform = new Transform3DGroup();

            if (transformYup)
            {
                transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 90)));
            }
            transform.Children.Add(new ScaleTransform3D(scale, scale, scale));

            for (int i = 0; i < mesh.Positions.Count; i++)
            {
                mesh.Positions[i] = transform.Transform(mesh.Positions[i]);
            }

            ScaleHeightOnly = false;
            Geometry        = mesh;
        }
コード例 #17
0
ファイル: Simulation3D.cs プロジェクト: zwmyint/6AxisRobot
        public void MoveSimulation(double angle_simulation0, double angle_simulation1, double angle_simulation2, double angle_simulation3, double angle_simulation4, double angle_simulation5)
        {
            HighestModel.Children.Clear();


            Transform3DGroup    TrafoGroup2        = new Transform3DGroup();
            AxisAngleRotation3D axisAngle2         = new AxisAngleRotation3D(new Vector3D(0, 1, 0), angle_simulation0);
            RotateTransform3D   myRotateTransform2 = new RotateTransform3D(axisAngle2, RotationCenter2);

            TrafoGroup2.Children.Add(myRotateTransform2);

            Transform3DGroup    TrafoGroup3   = new Transform3DGroup();
            Vector3D            axis3_rotated = TrafoGroup2.Transform(new Vector3D(1, 0, 0));
            AxisAngleRotation3D axisAngle3    = new AxisAngleRotation3D(axis3_rotated, angle_simulation1);
            Point3D             RotationCenter3_Transformed = new Point3D();

            RotationCenter3_Transformed = TrafoGroup2.Transform(RotationCenter3);
            RotateTransform3D myRotateTransform3 = new RotateTransform3D(axisAngle3, RotationCenter3_Transformed);

            TrafoGroup3.Children.Add(myRotateTransform2);
            TrafoGroup3.Children.Add(myRotateTransform3);


            Transform3DGroup    TrafoGroup4   = new Transform3DGroup();
            Vector3D            axis4_rotated = TrafoGroup3.Transform(new Vector3D(1, 0, 0));
            AxisAngleRotation3D axisAngle4    = new AxisAngleRotation3D(axis4_rotated, -90 + angle_simulation2);
            Point3D             RotationCenter4_Transformed = new Point3D();

            RotationCenter4_Transformed = TrafoGroup3.Transform(RotationCenter4);
            RotateTransform3D myRotateTransform4 = new RotateTransform3D(axisAngle4, RotationCenter4_Transformed);

            TrafoGroup4.Children.Add(myRotateTransform2);
            TrafoGroup4.Children.Add(myRotateTransform3);
            TrafoGroup4.Children.Add(myRotateTransform4);


            Transform3DGroup    TrafoGroup5   = new Transform3DGroup();
            Vector3D            axis5_rotated = TrafoGroup4.Transform(new Vector3D(0, 0, 1));
            AxisAngleRotation3D axisAngle5    = new AxisAngleRotation3D(axis5_rotated, angle_simulation3);
            Point3D             RotationCenter5_Transformed = new Point3D();

            RotationCenter5_Transformed = TrafoGroup4.Transform(RotationCenter5);
            RotateTransform3D myRotateTransform5 = new RotateTransform3D(axisAngle5, RotationCenter5_Transformed);

            TrafoGroup5.Children.Add(myRotateTransform2);
            TrafoGroup5.Children.Add(myRotateTransform3);
            TrafoGroup5.Children.Add(myRotateTransform4);
            TrafoGroup5.Children.Add(myRotateTransform5);


            Transform3DGroup    TrafoGroup6   = new Transform3DGroup();
            Vector3D            axis6_rotated = TrafoGroup5.Transform(new Vector3D(1, 0, 0));
            AxisAngleRotation3D axisAngle6    = new AxisAngleRotation3D(axis6_rotated, angle_simulation4);
            Point3D             RotationCenter6_Transformed = new Point3D();

            RotationCenter6_Transformed = TrafoGroup5.Transform(RotationCenter6);
            RotateTransform3D myRotateTransform6 = new RotateTransform3D(axisAngle6, RotationCenter6_Transformed);

            TrafoGroup6.Children.Add(myRotateTransform2);
            TrafoGroup6.Children.Add(myRotateTransform3);
            TrafoGroup6.Children.Add(myRotateTransform4);
            TrafoGroup6.Children.Add(myRotateTransform5);
            TrafoGroup6.Children.Add(myRotateTransform6);


            //importieren der Modele von Teil 1 bis 6 und Transformieren

            model2.Transform = TrafoGroup2;

            model3.Transform = TrafoGroup3;

            model4.Transform = TrafoGroup4;

            model5.Transform = TrafoGroup5;

            model6.Transform = TrafoGroup6;

            //alle Modelle und die Lichtquelle in den Haupt-Modell-Container Packen
            HighestModel.Children.Add(model1);
            HighestModel.Children.Add(model2);
            HighestModel.Children.Add(model3);
            HighestModel.Children.Add(model4);
            HighestModel.Children.Add(model5);
            HighestModel.Children.Add(model6);
            HighestModel.Children.Add(LightConteiner);
        }
コード例 #18
0
        /// <summary>
        /// Apply 3D translation and 3D rotation to the ball.
        /// </summary>
        /// <param name="trans">3D translation to apply</param>
        /// <param name="omega">3D rotation to apply</param>
        public void AppliquerTransformation(Vector3D trans, Vector3D omega)
        {
            Transform3DGroup trs = new Transform3DGroup();

            trs.Children.Add(new TranslateTransform3D(trans));
            //if needed
            trs.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 155), trs.Transform(P_PointDeReference)));
            //base transform to see the text
            double value = omega.Length;                                                                                       //rotation value

            trs.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(omega, value), trs.Transform(P_PointDeReference))); //rotation axis and value
            Transform = trs;
        }
コード例 #19
0
ファイル: Node.cs プロジェクト: jumpingyu/Abaqus_cs
 public Node(string line, Transform3DGroup system) : this(line)
 {
     point = system.Transform(point);
 }
コード例 #20
0
ファイル: Node.cs プロジェクト: jumpingyu/Abaqus_cs
 /// <summary>
 ///  各要素と変換を明示して作成する.
 /// </summary>
 /// <param name="id"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="z"></param>
 /// <param name="system">変換</param>
 public Node(uint id, double x, double y, double z, Transform3DGroup system)
 {
     this.id = id;
     point   = system.Transform(new Point3D(x, y, z));
 }
コード例 #21
0
        private void animate(Quaternion quat, int x)
        {
            Model3D joint = components[x];

            double[] centroid           = centroids[x];
            var      componentTransform = new Transform3DGroup();
            Point3D  origin             = new Point3D();

            if (x != 0)
            {
                Point3D original_origin = new Point3D(centroid[0], centroid[1], centroid[2]);
                var     motionOffset    = new Transform3DGroup();

                motionOffset.Children.Add(components[x - 1].Transform);

                // We need to find out where our old point is now
                origin = motionOffset.Transform(original_origin);

                TranslateTransform3D origin_translation = new TranslateTransform3D(new Vector3D(origin.X - original_origin.X, origin.Y - original_origin.Y, origin.Z - original_origin.Z));
                componentTransform.Children.Add(origin_translation);
            }

            switch (x)
            {
            case 0:
                //quat = chest(quat);
                break;

            case 1:
                // quat = UA(quat);
                break;

            case 2:
                //  quat = FA(quat);
                break;

            case 3:
                // quat = WR(quat);
                break;

            default:
                Console.WriteLine("Wut?");
                break;
            }

            RotateTransform3D transform = new RotateTransform3D(new QuaternionRotation3D(quat));

            // The point of rotation
            if (x == 0)
            {
                transform.CenterX = centroid[0];
                transform.CenterY = centroid[1];
                transform.CenterZ = centroid[2];
            }
            else
            {
                transform.CenterX = origin.X;
                transform.CenterY = origin.Y;
                transform.CenterZ = origin.Z;
            }
            componentTransform.Children.Add(transform);

            // Apply transformation
            joint.Transform = componentTransform;
        }
コード例 #22
0
ファイル: Simulation3D.cs プロジェクト: zwmyint/6AxisRobot
        private static object LockObj = new Object();  //this object can only be used from one Thread at the same time (UI-Thread OR Backgroundthread, but not both at a time, can use the same Instance of this Class)
        //Note that instead of locking on typeof(Singleton) as some versions of this implementation do,
        //I lock on the value of a static variable which is private to the class. Locking on objects
        //which other classes can access and lock on (such as the type of this Class) risks performance issues
        //and even deadlocks. Wherever possible, only lock on objects specifically created for the purpose of locking, or which document that they are
        //to be locked on for specific purposes (e.g. for waiting/pulsing a queue).
        //Usually such objects should be private to the class they are used in.
        //This helps to make writing thread-safe applications significantly easier.
        private Simulation3D(string FileName1, string FileName2, string FileName3, string FileName4, string FileName5, string FileName6)
        {
            LightSource1 = new DirectionalLight(Colors.WhiteSmoke, new Vector3D(-1, -0.5, -1));
            HighestModel = new ModelVisual3D();

            RotationCenter2 = new Point3D(0, 0.365, 0);
            RotationCenter3 = new Point3D(0.07, 0.365, 0);
            RotationCenter4 = new Point3D(-0.03, 0.365, 0.250);
            RotationCenter5 = new Point3D(0, 0.365, 0.405);
            RotationCenter6 = new Point3D(-0.0475, 0.365, 0.475);
            RotationCenter7 = new Point3D(0, 0.365, 0.620);


            Transform3DGroup    TrafoGroup2        = new Transform3DGroup();
            AxisAngleRotation3D axisAngle2         = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 40);
            RotateTransform3D   myRotateTransform2 = new RotateTransform3D(axisAngle2, RotationCenter2);

            TrafoGroup2.Children.Add(myRotateTransform2);

            Transform3DGroup    TrafoGroup3   = new Transform3DGroup();
            Vector3D            axis3_rotated = TrafoGroup2.Transform(new Vector3D(1, 0, 0));
            AxisAngleRotation3D axisAngle3    = new AxisAngleRotation3D(axis3_rotated, 0);
            Point3D             RotationCenter3_Transformed = new Point3D();

            RotationCenter3_Transformed = TrafoGroup2.Transform(RotationCenter3);
            RotateTransform3D myRotateTransform3 = new RotateTransform3D(axisAngle3, RotationCenter3_Transformed);

            TrafoGroup3.Children.Add(myRotateTransform2);
            TrafoGroup3.Children.Add(myRotateTransform3);


            Transform3DGroup    TrafoGroup4   = new Transform3DGroup();
            Vector3D            axis4_rotated = TrafoGroup3.Transform(new Vector3D(1, 0, 0));
            AxisAngleRotation3D axisAngle4    = new AxisAngleRotation3D(axis4_rotated, -90);
            Point3D             RotationCenter4_Transformed = new Point3D();

            RotationCenter4_Transformed = TrafoGroup3.Transform(RotationCenter4);
            RotateTransform3D myRotateTransform4 = new RotateTransform3D(axisAngle4, RotationCenter4_Transformed);

            TrafoGroup4.Children.Add(myRotateTransform2);
            TrafoGroup4.Children.Add(myRotateTransform3);
            TrafoGroup4.Children.Add(myRotateTransform4);


            Transform3DGroup    TrafoGroup5   = new Transform3DGroup();
            Vector3D            axis5_rotated = TrafoGroup4.Transform(new Vector3D(0, 0, 1));
            AxisAngleRotation3D axisAngle5    = new AxisAngleRotation3D(axis5_rotated, 0);
            Point3D             RotationCenter5_Transformed = new Point3D();

            RotationCenter5_Transformed = TrafoGroup4.Transform(RotationCenter5);
            RotateTransform3D myRotateTransform5 = new RotateTransform3D(axisAngle5, RotationCenter5_Transformed);

            TrafoGroup5.Children.Add(myRotateTransform2);
            TrafoGroup5.Children.Add(myRotateTransform3);
            TrafoGroup5.Children.Add(myRotateTransform4);
            TrafoGroup5.Children.Add(myRotateTransform5);


            Transform3DGroup    TrafoGroup6   = new Transform3DGroup();
            Vector3D            axis6_rotated = TrafoGroup5.Transform(new Vector3D(1, 0, 0));
            AxisAngleRotation3D axisAngle6    = new AxisAngleRotation3D(axis6_rotated, 0);
            Point3D             RotationCenter6_Transformed = new Point3D();

            RotationCenter6_Transformed = TrafoGroup5.Transform(RotationCenter6);
            RotateTransform3D myRotateTransform6 = new RotateTransform3D(axisAngle6, RotationCenter6_Transformed);

            TrafoGroup6.Children.Add(myRotateTransform2);
            TrafoGroup6.Children.Add(myRotateTransform3);
            TrafoGroup6.Children.Add(myRotateTransform4);
            TrafoGroup6.Children.Add(myRotateTransform5);
            TrafoGroup6.Children.Add(myRotateTransform6);

            Cam               = new PerspectiveCamera();
            Cam.Position      = CamPosition;
            Cam.LookDirection = CamLookDirection;
            //lichquelle manuell erzeugen in den übergeordnetsten ModelViusal3D, wo alle Teile (1 bis 6) dirn sind
            LightConteiner = new ModelVisual3D();
            Lightsource    = new Model3DGroup();
            Lightsource.Children.Add(LightSource1);
            LightConteiner.Content = Lightsource;

            //importieren der Modele von Teil 1 bis 6 und Transformieren
            model1           = Load_XAML_ModelVisual3D(FileName1);
            model2           = Load_XAML_ModelVisual3D(FileName2);
            model2.Transform = TrafoGroup2;
            model3           = Load_XAML_ModelVisual3D(FileName3);
            model3.Transform = TrafoGroup3;
            model4           = Load_XAML_ModelVisual3D(FileName4);
            model4.Transform = TrafoGroup4;
            model5           = Load_XAML_ModelVisual3D(FileName5);
            model5.Transform = TrafoGroup5;
            model6           = Load_XAML_ModelVisual3D(FileName6);
            model6.Transform = TrafoGroup6;

            //alle Modelle und die Lichtquelle in den Haupt-Modell-Container Packen
            HighestModel.Children.Add(model1);
            HighestModel.Children.Add(model2);
            HighestModel.Children.Add(model3);
            HighestModel.Children.Add(model4);
            HighestModel.Children.Add(model5);
            HighestModel.Children.Add(model6);
            HighestModel.Children.Add(LightConteiner);

            //initialize Slyder_CamRotationen
            SliderAxisRotation       = new AxisAngleRotation3D(y_achse, 0);
            SliderAxisTransform      = new RotateTransform3D(SliderAxisRotation);
            SliderAxisRotation_Over  = new AxisAngleRotation3D(y_achse, 0);
            SliderAxisTransform_Over = new RotateTransform3D(SliderAxisRotation_Over);
        }
コード例 #23
0
ファイル: Node.cs プロジェクト: jumpingyu/Abaqus_cs
 internal void Transform(Transform3DGroup system)
 {
     pos = system.Transform(pos);
 }
コード例 #24
0
        // Make an Xmas tree.
        public static MeshGeometry3D MakeXmasTree(Transform3D transform)
        {
            MeshGeometry3D mesh = new MeshGeometry3D();

            // Make the bottom.
            Point3D[] points =
            {
                new Point3D(1,     0, 0),
                new Point3D(1.2,   0, 0),
                new Point3D(1,   0.5, 0)
            };
            int num_points = points.Length;

            mesh.AddPolygon(points);

            // Make a temporary array of points.
            Point3D[] new_points = new Point3D[num_points];

            // Make a transformation that rotates around the
            // origin, scales smaller, and translates vertically.
            const int num_laps       = 6;
            const int frames_per_lap = 20;

            Transform3DGroup group = new Transform3DGroup();

            const double theta    = 360.0 / frames_per_lap;
            Vector3D     axis     = new Vector3D(0, 1, 0);
            Rotation3D   rotation = new AxisAngleRotation3D(axis, theta);
            Point3D      center   = new Point3D(0, 0, 0);

            group.Children.Add(new RotateTransform3D(rotation, center));

            const double scale = 0.98;

            group.Children.Add(new ScaleTransform3D(scale, 1, scale));

            const double vert = 2.0 / frames_per_lap / num_laps;

            group.Children.Add(new TranslateTransform3D(0, vert, 0));

            // Make a transformation that rotates around the
            // origin, scales smaller, and translates vertically.
            for (int lap = 0; lap < num_laps; lap++)
            {
                for (int frame = 0; frame < frames_per_lap; frame++)
                {
                    // Transform the points.
                    Array.Copy(points, new_points, num_points);
                    group.Transform(new_points);

                    // Make the new triangles.
                    Dictionary <Point3D, int> point_dict = new Dictionary <Point3D, int>();
                    for (int i = 0; i < num_points; i++)
                    {
                        int i1 = (i + 1) % num_points;
                        mesh.AddSmoothTriangle(point_dict, points[i], new_points[i], new_points[i1]);
                        mesh.AddSmoothTriangle(point_dict, points[i], new_points[i1], points[i1]);
                    }

                    // Update the points.
                    Point3D[] temp = points;
                    points     = new_points;
                    new_points = temp;
                }
            }

            // Transform the mesh's points if desired.
            if (transform != null)
            {
                transform.Transform(mesh);
            }

            return(mesh);
        }
        //moves generic distal
        void move_distal(int angle, string dedo, Point3D punto, Vector3D vec)
        {
            //new group of transformations, the group will "add" movements
            var Group_3D = new Transform3DGroup();

            switch (dedo)
            {
            case "pulgar":
                Group_3D.Children.Add(pulgar_proximal.Transform);
                break;

            case "indice":
                Group_3D.Children.Add(indice_proximal.Transform);
                break;

            case "mayor":
                Group_3D.Children.Add(mayor_proximal.Transform);
                break;

            case "anular":
                Group_3D.Children.Add(anular_proximal.Transform);
                break;

            case "meñique":
                Group_3D.Children.Add(meñique_proximal.Transform);
                break;
            }

            //we need to find out where our old point is now
            Point3D origin = Group_3D.Transform(punto);

            //create new transformation
            RotateTransform3D distal_transform = new RotateTransform3D(new AxisAngleRotation3D(vec, angle));

            distal_transform.CenterX = origin.X;
            distal_transform.CenterY = origin.Y;
            distal_transform.CenterZ = origin.Z;

            //add it to the transformation group (and therefore to the femores movement
            Group_3D.Children.Add(distal_transform);

            //Apply the transform
            switch (dedo)
            {
            case "pulgar":
                pulgar_distal.Transform = Group_3D;
                break;

            case "indice":
                indice_distal.Transform = Group_3D;
                break;

            case "mayor":
                mayor_distal.Transform = Group_3D;
                break;

            case "anular":
                anular_distal.Transform = Group_3D;
                break;

            case "meñique":
                meñique_distal.Transform = Group_3D;
                break;
            }
        }