コード例 #1
0
        public void Clear()
        {
            _materials.Clear();
            _collisionListeners.Clear();

            Newton.NewtonMaterialDestroyAllGroupID(_world.Handle);
        }
コード例 #2
0
        public bool GetNearestPoint_HullToHull(out Point3D?contactPointThis, out Point3D?contactPointOther, out Vector3D?normal, CollisionHull otherHull, int threadIndex, Transform3D thisTransform, Transform3D otherTransform)
        {
            float[] finalOffsetThis  = thisTransform == null ? new NewtonMatrix(Matrix3D.Identity).Matrix : new NewtonMatrix(thisTransform.Value).Matrix;               // not including the member's offset, because newton is already accounting for it.
            float[] finalOffsetOther = thisTransform == null ? new NewtonMatrix(Matrix3D.Identity).Matrix : new NewtonMatrix(otherTransform.Value).Matrix;

            NewtonVector3 contactANewt = new NewtonVector3();
            NewtonVector3 contactBNewt = new NewtonVector3();
            NewtonVector3 normalNewt   = new NewtonVector3();

            int retVal = Newton.NewtonCollisionClosestPoint(_world.Handle, _handle, finalOffsetThis, otherHull.Handle, finalOffsetOther, contactANewt.Vector, contactBNewt.Vector, normalNewt.Vector, threadIndex);

            // Exit Function
            if (retVal == 1)
            {
                contactPointThis  = contactANewt.ToPointWPF();
                contactPointOther = contactBNewt.ToPointWPF();
                normal            = normalNewt.ToVectorWPF();
                return(true);
            }
            else
            {
                contactPointThis  = null;
                contactPointOther = null;
                normal            = null;
                return(false);
            }
        }
コード例 #3
0
            public void NewtonAddNullTest()
            {
                double temp1  = 20;
                var    newton = new Newton(temp1);

                Assert.AreEqual(newton.Value, (newton + null).Value);
            }
コード例 #4
0
        /// <summary>
        /// This is different than the other joints.  It locks a body to a single axis of rotation (doesn't affect translation)
        /// </summary>
        /// <param name="pinDirection">Line of action of the hinge (world coords)</param>
        public static JointUpVector CreateUpVector(World world, Vector3D pinDirection, Body body)
        {
            // Up vector joint functions
            IntPtr handle = Newton.NewtonConstraintCreateUpVector(world.Handle, new NewtonVector3(pinDirection).Vector, body.Handle);

            return(new JointUpVector(world, handle));
        }
コード例 #5
0
ファイル: NewtonTest.cs プロジェクト: V-vltru/MathLibrary
        public void SetNextIndexesTest()
        {
            Newton newton = new Newton(this.Points);
            int    actualLeft, actualRight;

            // left case
            int expectedLeftIndex  = -1;
            int expectedRightIndex = 0;

            newton.SetNextIndexes(out actualLeft, out actualRight, this.LeftX);
            Assert.AreEqual(expectedLeftIndex, actualLeft);
            Assert.AreEqual(expectedRightIndex, actualRight);

            // right case
            expectedLeftIndex  = this.Points.Length - 1;
            expectedRightIndex = -1;
            newton.SetNextIndexes(out actualLeft, out actualRight, this.RightX);
            Assert.AreEqual(expectedLeftIndex, actualLeft);
            Assert.AreEqual(expectedRightIndex, actualRight);

            // middle case
            expectedLeftIndex  = 20;
            expectedRightIndex = 21;
            newton.SetNextIndexes(out actualLeft, out actualRight, this.MiddleX);
            Assert.AreEqual(expectedLeftIndex, actualLeft);
            Assert.AreEqual(expectedRightIndex, actualRight);
        }
コード例 #6
0
ファイル: FletcherReeves.cs プロジェクト: barbaracs/T2-PO2
        public static double[] Calcular(int n, string fx, double e, string x_ini)
        {
            double[] xk   = x_ini.SplitToDoubles();
            double[] grad = Gradiente.CalculaGradiente(n, fx, x_ini.SplitToDoubles()).ToArray();
            double[] gk   = (double[])grad.Clone();
            double[] gk_1;
            double[] dk = gk.Negativo();
            double   beta;

            while (Interpretadores.NormaVetor(grad) > e)
            {
                for (int i = 0; i < n; i++)
                {
                    string xk_s = Interpretadores.GeraVetorY(xk, Interpretadores.LambdaVDirec(dk));
                    double lamb = Newton.Calcular(0, ((Interpretadores.GeraFy(fx, xk_s)).Replace(',', '.')).Replace("lamb", "x[1]"), 0.1);

                    xk   = Interpretadores.SubsLambda(lamb, xk_s.Replace(',', '.'));
                    gk_1 = Gradiente.CalculaGradiente(n, fx, xk).ToArray();
                    if (i >= n - 1)
                    {
                        break;
                    }
                    beta = GradConjugado.MultEscalar(gk_1, gk_1) / GradConjugado.MultEscalar(gk, gk);
                    dk   = Interpretadores.SomaVetor(gk_1.Negativo(), dk.MultConstante(beta));
                    gk   = (double[])gk_1.Clone();
                }
                grad = Gradiente.CalculaGradiente(n, fx, xk).ToArray();
            }
            return(xk);
        }
コード例 #7
0
        public void Respawn(IntPtr body)
        {
            Notifier.AddMessage("Respawned");
            Matrix mat = Matrix.CreateTranslation(0, 0, -10);

            Newton.NewtonBodySetMatrixRecursive(body, MatrixHelper.ToFloats(mat));
        }
コード例 #8
0
            public void TorqueAndEnergy()
            {
                Assert.AreEqual(Joule.Sense, NewtonMeter.Sense, "Joule and NewtonMeter dimension are different");
                Assert.AreNotEqual(Joule.Family, NewtonMeter.Family, "Joule and NewtonMeter families are the same");

                Meter  distance = (Meter)10.0;
                Newton force    = (Newton)100.0;

                Joule energy = force * distance;

                Assert.AreEqual((Joule)1000.0, energy, "Energy calculation failed");

                NewtonMeter torque = force ^ distance;

                Assert.AreEqual((NewtonMeter)1000.0, torque, "Torque calculation failed");

                Meter distanceFromEnergy = energy / force;
                Meter distanceFromTorque = torque / force;

                Assert.AreEqual(distanceFromEnergy, distanceFromTorque, "Distances from Energy and Torque are different");

                Newton forceFromEnergy = energy / distance;
                Newton forceFromTorque = torque / distance;

                Assert.AreEqual(forceFromEnergy, forceFromTorque, "Forces from Energy and Torque are different");

                Assert.AreEqual(1, Catalog.Units <double>(Joule.Family).Count(), "Selection by Family failed");
                Assert.AreEqual(2, Catalog.Units <double>(Joule.Sense).Count(), "Selection by Dimension failed");
            }
コード例 #9
0
        public void AddBuoyancyForce(float pFluidDensity, float pFluidLinearViscosity, float pFluidAngularViscosity, Vector3D pGravityVector, EventHandler <CBuoyancyPlaneEventArgs> pBuoyancyPlane, int pContext)
        {
            m_GetBuoyancyPlane       = pBuoyancyPlane;
            m_NewtonGetBuoyancyPlane = new Newton.NewtonGetBuoyancyPlane(InvokeAddBuoyancyForce);

            Newton.NewtonBodyAddBuoyancyForce(m_Handle, pFluidDensity, pFluidLinearViscosity, pFluidAngularViscosity, new NewtonVector3(pGravityVector).NWVector3, m_NewtonGetBuoyancyPlane, pContext);
        }
コード例 #10
0
 public void CreateCollisionTree(IList <Point3D> points, int pointsPerFace, bool optimise)
 {
     m_Handle = Newton.NewtonCreateTreeCollision(m_World.Handle, null);
     TreeBeginBuild();
     TreeAddFaces(points, pointsPerFace);
     TreeEndBuild(optimise);
 }
コード例 #11
0
        public static void ShareHullsAcrossWorlds()
        {
            // Worlds
            Newton.NewtonSetMemorySystem(null, null);

            IntPtr world1 = Newton.NewtonCreate();

            Newton.NewtonSetSolverModel(world1, 1);             //adaptive
            Newton.NewtonCollisionDestructor callback1 = new Newton.NewtonCollisionDestructor(HullDestroyed);
            Newton.NewtonSetCollisionDestructor(world1, callback1);

            IntPtr world2 = Newton.NewtonCreate();

            Newton.NewtonSetSolverModel(world2, 1);
            Newton.NewtonCollisionDestructor callback2 = new Newton.NewtonCollisionDestructor(HullDestroyed);
            Newton.NewtonSetCollisionDestructor(world2, callback2);

            // Hulls
            IntPtr hull1a = Newton.NewtonCreateBox(world1, 1f, 1f, 1f, 0, null);
            IntPtr hull1b = Newton.NewtonCreateBox(world1, 1f, 1f, 1f, 0, null);                // handle is same as 1a

            IntPtr hull2a = Newton.NewtonCreateBox(world2, 1f, 1f, 1f, 0, null);
            IntPtr hull2b = Newton.NewtonCreateBox(world2, 1f, 2f, 1f, 0, null);

            // Dispose
            Newton.NewtonReleaseCollision(world1, hull1a);
            Newton.NewtonReleaseCollision(world1, hull1b);
            Newton.NewtonReleaseCollision(world1, hull1b);              // this just silently does nothing

            Newton.NewtonReleaseCollision(world2, hull2a);
            Newton.NewtonReleaseCollision(world2, hull2b);
        }
コード例 #12
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                //BUG: this will dispose ALL world's bodies.
                CJoint[] joints = new CJoint[CHashTables.Joint.Count];
                CHashTables.Joint.Values.CopyTo(joints, 0);

                foreach (CJoint joint in joints)
                {
                    joint.Dispose();
                }

                CBody[] bodies = new CBody[CHashTables.Body.Count];
                CHashTables.Body.Values.CopyTo(bodies, 0);

                foreach (CBody body in bodies)
                {
                    body.Dispose();
                }

                if (m_Handle != IntPtr.Zero)
                {
                    Newton.NewtonDestroy(m_Handle);
                    m_Handle = IntPtr.Zero;
                }

                // Stuff was left behind, so I'm clearing everything (there's likely only one world anyway)
                CHashTables.Clear();
            }
        }
コード例 #13
0
 public void Update(float pTimeStep)
 {
     if (m_Handle != IntPtr.Zero)
     {
         Newton.NewtonUpdate(m_Handle, pTimeStep);
     }
 }
コード例 #14
0
 public void CalculateAABB(Matrix3D pMatrix, Vector3D p0, Vector3D p1)
 {
     Newton.NewtonCollisionCalculateAABB(m_Handle,
                                         new NewtonMatrix(pMatrix).NWMatrix,
                                         new NewtonVector3(p0).NWVector3,
                                         new NewtonVector3(p1).NWVector3);
 }
コード例 #15
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)// && _handle != IntPtr.Zero)
            {
                if (_isDisposed)
                {
                    System.Diagnostics.Debug.WriteLine($"Dispose already disposed: {_handle}");
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine($"Disposing: {_handle}");

                    _isDisposed = true;

                    if (Disposing != null)
                    {
                        Disposing(this, new EventArgs());
                    }

                    _world.BodyDisposed(this);      //NOTE: This just gives the .net world object a chance to unhook event listeners
                    Newton.NewtonDestroyBody(_worldHandle, _handle);
                    ObjectStorage.Instance.RemoveBody(_handle);
                    //_handle = IntPtr.Zero;
                }
            }
        }
コード例 #16
0
ファイル: NewtonTest.cs プロジェクト: V-vltru/MathLibrary
        public void GetPointsAround()
        {
            int          MaxDotsInArea         = 20;
            List <Point> expectedPointsForLeft = new List <Point>();

            for (int i = 0; i < MaxDotsInArea; i++)
            {
                expectedPointsForLeft.Add(this.Points[i]);
            }

            Newton       newton           = new Newton(this.Points);
            List <Point> actualCollection = newton.GetPointsAround(this.LeftX, MaxDotsInArea);

            this.AssertPoints(expectedPointsForLeft, actualCollection);

            // right checking
            List <Point> expectedPointsForRight = new List <Point>();

            for (int i = 21; i < this.Points.Length; i++)
            {
                expectedPointsForRight.Add(this.Points[i]);
            }

            newton           = new Newton(this.Points);
            actualCollection = newton.GetPointsAround(this.RightX, MaxDotsInArea);
            this.AssertPoints(expectedPointsForRight, actualCollection);

            // middle checking
            List <Point> expectedpointsForMiddle = new List <Point>();

            for (int i = 11; i <= 30; i++)
            {
                expectedpointsForMiddle.Add(this.Points[i]);
            }

            newton           = new Newton(this.Points);
            actualCollection = newton.GetPointsAround(this.MiddleX, MaxDotsInArea);
            this.AssertPoints(expectedpointsForMiddle, actualCollection);

            // middle left checking
            List <Point> expectedPointsForLeftMiddle = new List <Point>();

            for (int i = 0; i < MaxDotsInArea; i++)
            {
                expectedPointsForLeftMiddle.Add(this.Points[i]);
            }

            actualCollection = newton.GetPointsAround(this.MiddleXLeft, MaxDotsInArea);
            this.AssertPoints(expectedPointsForLeftMiddle, actualCollection);

            List <Point> expectedpointsForRightMiddle = new List <Point>();

            for (int i = 21; i < this.Points.Length; i++)
            {
                expectedpointsForRightMiddle.Add(this.Points[i]);
            }

            actualCollection = newton.GetPointsAround(this.MiddleXRight, MaxDotsInArea);
            this.AssertPoints(expectedpointsForRightMiddle, actualCollection);
        }
コード例 #17
0
        public void WorldRayCast(Vector3D origin, Vector3D endPoint, EventHandler <CWorldRayFilterEventArgs> pWorldRayFilter, object userData, EventHandler <CWorldRayPreFilterEventArgs> pWorldRayPrefilter)
        {
            if (pWorldRayFilter != null)
            {
                m_WorldRayFilter       = new EventHandler <CWorldRayFilterEventArgs>(pWorldRayFilter);
                m_NewtonWorldRayFilter = new Newton.NewtonWorldRayFilterCallback(InvokeWorldRayFilter);
            }
            else
            {
                m_NewtonWorldRayFilter = null;
            }

            if (pWorldRayPrefilter != null)
            {
                m_WorldRayPrefilter       = new EventHandler <CWorldRayPreFilterEventArgs>(pWorldRayPrefilter);
                m_NewtonWorldRayPrefilter = new Newton.NewtonWorldRayPrefilterCallback(InvokeWorldRayPrefilter);
            }
            else
            {
                m_NewtonWorldRayPrefilter = null;
            }

            Newton.NewtonWorldRayCast(m_Handle,
                                      new NewtonVector3(origin).NWVector3,
                                      new NewtonVector3(endPoint).NWVector3,
                                      m_NewtonWorldRayFilter,
                                      (IntPtr)(userData ?? IntPtr.Zero),
                                      m_NewtonWorldRayPrefilter);
        }
コード例 #18
0
        public Vector3D GetContactForce()
        {
            NewtonVector3 aForce = new NewtonVector3(new Vector3D());

            Newton.NewtonMaterialGetContactForce(m_Handle, aForce.NWVector3);
            return(aForce.ToDirectX());
        }
コード例 #19
0
ファイル: NewtonTests.cs プロジェクト: Infarh/MathCore
    public void GetPolynomCoefficients2()
    {
        double[] xx = { 1, 2, 3, 4 };
        double[] yy = { 6, 9, 2, 5, };

        double[] d = { 6, 3, -5, 10 / 3d };

        var p = new Polynom(d[0]);

        var p1  = new Polynom(-xx[0], 1);
        var pp1 = d[1] * p1;

        p += pp1;

        var p2 = new Polynom(-xx[1], 1);

        p += d[2] * p1 * p2;

        var p3 = new Polynom(-xx[2], 1);

        p += d[3] * p1 * p2 * p3;

        var expected_coefficients = p.Coefficients;

        var actual_coefficients = Newton.GetPolynomCoefficients(xx, yy);

        var actual_coefficients2 = Lagrange.GetPolynomCoefficients(xx, yy);

        const double accuracy = 7.106e-15;

        Assert.That.Collection(actual_coefficients).IsEqualTo(expected_coefficients, accuracy);
    }
コード例 #20
0
        /// <summary>
        /// Vector is in world coords
        /// </summary>
        public Vector3D GetContactForceWorld(Body body)
        {
            NewtonVector3 retVal = new NewtonVector3();

            Newton.NewtonMaterialGetContactForce(_handle, body.Handle, retVal.Vector);

            return(retVal.ToVectorWPF());
        }
コード例 #21
0
        public void CreateSphere(Vector3D pRadius, Matrix3D pOffsetMatrix)
        {
            NewtonMatrix aMatrix = new NewtonMatrix(pOffsetMatrix);

            m_Handle = Newton.NewtonCreateSphere(m_World.Handle, (float)pRadius.X, (float)pRadius.Y, (float)pRadius.Z, aMatrix.NWMatrix);

            CHashTables.Collision.Add(m_Handle, this);
        }
コード例 #22
0
 public void Release()
 {
     if (m_Handle != IntPtr.Zero)
     {
         Newton.NewtonReleaseCollision(m_World.Handle, m_Handle);
         CHashTables.Collision.Remove(m_Handle);
     }
 }
コード例 #23
0
 public float RayCast(Vector3D p0, Vector3D p1, Vector3D pNormals, int pAttribute)
 {
     return(Newton.NewtonCollisionRayCast(m_Handle,
                                          new NewtonVector3(p0).NWVector3,
                                          new NewtonVector3(p1).NWVector3,
                                          new NewtonVector3(pNormals).NWVector3,
                                          pAttribute));
 }
コード例 #24
0
            public void InRangeEmptyConstructorTest()
            {
                var newton = new Newton {
                    Value = 500
                };

                Assert.AreEqual(500, newton.Value, double.Epsilon);
            }
コード例 #25
0
        /// <summary>
        /// Tells you how much force to apply to get the desired velocity (doesn't consider rotation)
        /// </summary>
        /// <remarks>
        /// From newton.cpp:
        ///
        /// Calculate the next force that needs to be applied to the body to archive the desired velocity in the current time step.
        ///
        /// Parameters:
        /// *const NewtonBody* *bodyPtr - pointer to the body.
        /// *dFloat* timestep - time step that the force will be applyed.
        /// *const dFloat* *desiredVeloc - pointer to an array of 3 floats containing the desired velocity.
        /// *dFloat* *forceOut - pointer to an array of 3 floats to hold the calculated net force.
        ///
        /// Remark: this function can be useful when creating object for game play.
        ///
        /// remark: this treat the body as a point mass and is uses the solver to calculates the net force that need to be applied to the body
        /// such that is reach the desired velocity in the next time step.
        /// In general the force should be calculated by the expression f = M * (dsiredVeloc - bodyVeloc) / timestep
        /// however due to algorithmic optimization and limitations if such equation is used then the solver will generate a different desired velocity.
        /// </remarks>
        public Vector3D GetForceForDesiredVelocity(Vector3D desiredVelocity, double timestep)
        {
            NewtonVector3 retVal = new NewtonVector3();

            Newton.NewtonBodyCalculateInverseDynamicsForce(_handle, Convert.ToSingle(timestep), new NewtonVector3(desiredVelocity).Vector, retVal.Vector);

            return(retVal.ToVectorWPF());
        }
コード例 #26
0
        public void TestElectromagnetism()
        {
            var    particleOne  = new Sphere().SetCharge(new Coulomb(1));
            var    particleTwo  = new Sphere().SetCharge(new Coulomb(1)).SetCoordinates(PhysicalCoordinate <Meter> .Create(0, 0, 1));
            Newton forceBetween = Electromagnetism.ForceBetween(particleOne, particleTwo);

            Assert.AreEqual(8987551787.3681755, forceBetween.Value);
        }
コード例 #27
0
 static void Main(string[] args)
 {
     Console.WriteLine("Calculate by Newton");
     Console.WriteLine(Newton.Calculate(2, 10, 0.000000001));
     Console.WriteLine("Calculate by Math.Pow");
     Console.WriteLine(Math.Pow(2, 1 / 10.0));
     Console.ReadKey();
 }
コード例 #28
0
        public static Vector3D MatrixToEulerAngle(Matrix3D pMatrix)
        {
            NewtonVector3 aNewtonVector3 = new NewtonVector3(new Vector3D());

            Newton.NewtonGetEulerAngle(new NewtonMatrix(pMatrix).NWMatrix,
                                       aNewtonVector3.NWVector3);
            return(aNewtonVector3.ToDirectX());
        }
コード例 #29
0
        public MatrixValue Function(ScalarValue x0, ScalarValue xn, ScalarValue y0, ScalarValue yn)
        {
            var m      = new Newton();
            var xsteps = (int)Math.Abs(Math.Ceiling((xn.Re - x0.Re) / 0.1));
            var ysteps = (int)Math.Abs(Math.Ceiling((yn.Re - y0.Re) / 0.1));

            return(m.CalculateMatrix(x0.Re, xn.Re, y0.Re, yn.Re, xsteps, ysteps));
        }
コード例 #30
0
        public static Matrix3D EulerAngleToMatrix(Vector3D pEulersAngles)
        {
            NewtonMatrix aNewtonMatrix = new NewtonMatrix(Matrix3D.Identity);

            Newton.NewtonSetEulerAngle(new NewtonVector3(pEulersAngles).NWVector3,
                                       aNewtonMatrix.NWMatrix);
            return(aNewtonMatrix.ToDirectX());
        }
コード例 #31
0
		public object m_UserData;			// user data passed to the collision geometry at creation time

		internal UserMeshCollisionRayHitDesc(Newton.NewtonUserMeshCollisionRayHitDesc pRayHitDesc)
		{
			m_NormalOut = new NewtonVector4(pRayHitDesc.m_NormalOut).ToDirectX();
			m_P0 = new NewtonVector4(pRayHitDesc.m_P0).ToDirectX();
			m_P1 = new NewtonVector4(pRayHitDesc.m_P1).ToDirectX();
			m_UserData = CHashTables.BodyUserData[pRayHitDesc.m_UserData];
			m_UserIdOut = pRayHitDesc.m_UserIdOut;
		}
コード例 #32
0
		public CBody m_PolySoupBody;          	// pointer to the rigid body owner of this collision tree 

		internal UserMeshCollisionCollideDesc(Newton.NewtonUserMeshCollisionCollideDesc pDesc)
		{
			m_BoxP0 = new NewtonVector4(pDesc.m_BoxP0).ToDirectX();
			m_BoxP1 = new NewtonVector4(pDesc.m_BoxP1).ToDirectX();
			m_UserData = pDesc.m_UserData;
			m_FaceCount = pDesc.m_FaceCount;
			m_Vertex = pDesc.m_Vertex;
			m_VertexStrideInBytes = pDesc.m_VertexStrideInBytes;
			m_UserAttribute = pDesc.m_UserAttribute;
			m_FaceIndexCount = pDesc.m_FaceIndexCount;
			m_FaceVertexIndex = pDesc.m_FaceVertexIndex;
			m_ObjBody =  (CBody)CHashTables.Body[pDesc.m_ObjBody];
			m_PolySoupBody = (CBody)CHashTables.Body[pDesc.m_PolySoupBody];
		}
コード例 #33
0
		private void InvokeUserMeshCollisionCollide(Newton.NewtonUserMeshCollisionCollideDesc pCollideDescData)
		{
			UserMeshCollisionCollideDesc aCollideDescData = new UserMeshCollisionCollideDesc(pCollideDescData);

			//aCollideDescData.m_BoxP0 = new NewtonVector4(pCollideDescData.m_BoxP0).ToDirectX();
			//aCollideDescData.m_BoxP1 = new NewtonVector4(pCollideDescData.m_BoxP1).ToDirectX();
			//aCollideDescData.m_FaceCount = pCollideDescData.m_FaceCount;
			//aCollideDescData.m_FaceIndexCount = pCollideDescData.m_FaceIndexCount;
			//aCollideDescData.m_FaceVertexIndex = pCollideDescData.m_FaceVertexIndex;
			//aCollideDescData.m_ObjBody = (CBody)CHashTables.Body[pCollideDescData.m_ObjBody];
			//aCollideDescData.m_PolySoupBody = (CBody)CHashTables.Body[pCollideDescData.m_PolySoupBody];
			//aCollideDescData.m_UserAttribute = pCollideDescData.m_UserAttribute;
			//aCollideDescData.m_UserData = pCollideDescData.m_UserData;
			//aCollideDescData.m_Vertex = pCollideDescData.m_Vertex;
			//aCollideDescData.m_VertexStrideInBytes = pCollideDescData.m_VertexStrideInBytes;

			OnUserMeshCollisionCollide(
				new CUserMeshCollisionCollideEventArgs(aCollideDescData));
		}
コード例 #34
0
        private uint InvokeHinge(IntPtr pNewtonJoint, Newton.NewtonHingeSliderUpdateDesc pDesc)
		{
            CHingeEventArgs e = new CHingeEventArgs(new HingeSliderUpdateDesc(pDesc));
            OnHinge(e);

            if (e.ApplyConstraint)
            {
                e.Desc.ToNewton(pDesc);
                return 1;
            }
            else
                return 0;
		}
コード例 #35
0
ファイル: MainWindow.xaml.cs プロジェクト: lohasbai/Arctanx
        private void Button_Click_Calc(object sender, RoutedEventArgs e)
        {
            string inputNum_string = Input_TextBox.Text;
            Number inputNum = new Number(inputNum_string, false, 0, 0);
            string inputAccuracy_string = Accuracy_TextBox.Text;
            int accuracy = Convert.ToInt32(inputAccuracy_string);
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();

            //进行计算
            RangeAssist rangeAssist = new RangeAssist(inputNum, accuracy);
            //泰勒展开法进行计算
            stopwatch.Start();
            Taylor TaylorCal = new Taylor(rangeAssist.numConverted, accuracy);
            Number resultTaylor = rangeAssist.NumRecover(TaylorCal.TaylorCalculate());
            stopwatch.Stop();
            float taylorTime = (float)stopwatch.ElapsedMilliseconds / 1000;
            //外推加速法进行计算
            stopwatch.Start();
            Romberg RombergCal = new Romberg(rangeAssist.numConverted, accuracy);
            Number resultRomberg = rangeAssist.NumRecover(RombergCal.RombergCalculate());
            stopwatch.Stop();
            float rombergTime = (float)stopwatch.ElapsedMilliseconds / 1000;
            //牛顿法进行计算
            stopwatch.Start();
            Newton NewtonCal = new Newton(rangeAssist.numConverted, accuracy);
            Number resultNewton = rangeAssist.NumRecover(NewtonCal.NewtonCalculate());
            stopwatch.Stop();
            float newtonTime = (float)stopwatch.ElapsedMilliseconds / 1000;

            //显示字符串
            //泰勒法
            string resultTaylor_string = "";
            if (resultTaylor.sign == -1)
            {
                resultTaylor_string += "-";
            }
            for (int i = 0; i < resultTaylor.intLength; i++)
            {
                resultTaylor_string += resultTaylor.intPart[i].ToString();
            }
            resultTaylor_string += ".";
            for (int i = 0; i < resultTaylor.decLength; i++)
            {
                resultTaylor_string += resultTaylor.decPart[i].ToString();
            }
            Taylor_TextBox.Text = resultTaylor_string;
            TaylorTime_TextBox.Text = taylorTime.ToString() + "秒";
            //外推加速法
            string resultRomberg_string = "";
            if (resultRomberg.sign == -1)
            {
                resultRomberg_string += "-";
            }
            for (int i = 0; i < resultRomberg.intLength; i++)
            {
                resultRomberg_string += resultRomberg.intPart[i].ToString();
            }
            resultRomberg_string += ".";
            for (int i = 0; i < resultRomberg.decLength; i++)
            {
                resultRomberg_string += resultRomberg.decPart[i].ToString();
            }
            Romberg_TextBox.Text = resultRomberg_string;
            RombergTime_TextBox.Text = rombergTime.ToString() + "秒";
            //牛顿法
            string resultNewton_string = "";
            if (resultNewton.sign == -1)
            {
                resultNewton_string += "-";
            }
            for (int i = 0; i < resultNewton.intLength; i++)
            {
                resultNewton_string += resultNewton.intPart[i].ToString();
            }
            resultNewton_string += ".";
            for (int i = 0; i < resultNewton.decLength; i++)
            {
                resultNewton_string += resultNewton.decPart[i].ToString();
            }
            Newton_TextBox.Text = resultNewton_string;
            NewtonTime_TextBox.Text = newtonTime.ToString() + "秒";
        }
コード例 #36
0
		private uint InvokeUniversal(IntPtr pNewtonJoint,
			Newton.NewtonHingeSliderUpdateDesc pDesc)
		{
			HingeSliderUpdateDesc aUpdateDesc = new HingeSliderUpdateDesc();

			aUpdateDesc.m_Accel = pDesc.m_Accel;
			aUpdateDesc.m_MaxFriction = pDesc.m_MaxFriction;
			aUpdateDesc.m_MinFriction = pDesc.m_MinFriction;
			aUpdateDesc.m_Timestep = pDesc.m_Timestep;

			OnUniversal(new CUniversalEventArgs(aUpdateDesc));

			return 1;
		}
コード例 #37
0
ファイル: NewtonPhysics.cs プロジェクト: NinjaSteph/SureShot
        /// <summary>
        /// Set a user defined NewtonSetTransform callback function to be used for this physics object.
        /// If not specified, a default callback function will be used.
        /// </summary>
        /// <remarks>
        /// This is an advanced functionality. We do not recommend using this method unless you know
        /// what exactly to do with the returned transform from Newton physics.
        /// </remarks>
        /// <param name="physObj"></param>
        /// <param name="callback"></param>
        /// <see cref="GetPhysicsObject"/>
        public void SetTransformCallback(IPhysicsObject physObj, Newton.NewtonSetTransform callback)
        {
            if (setTransformMap.ContainsKey(physObj))
                setTransformMap.Remove(physObj);

            setTransformMap.Add(physObj, callback);
        }
コード例 #38
0
ファイル: Newton.cs プロジェクト: boracaliskanbas/ReachKral
    void Start()
    {
        self = this;

        NewtonSetup();
    }
コード例 #39
0
		internal void ToNewton(Newton.NewtonHingeSliderUpdateDesc newton)
		{
            newton.m_Accel = this.m_Accel;
            newton.m_MinFriction = this.m_MinFriction;
            newton.m_MaxFriction = this.m_MaxFriction;
            newton.m_Timestep = this.m_Timestep;
		}
コード例 #40
0
        internal HingeSliderUpdateDesc(Newton.NewtonHingeSliderUpdateDesc pUpdateDesc)
		{
            m_Accel = pUpdateDesc.m_Accel;
            m_MaxFriction = pUpdateDesc.m_MaxFriction;
            m_MinFriction = pUpdateDesc.m_MinFriction;
            m_Timestep = pUpdateDesc.m_Timestep;
		}
コード例 #41
0
		private float InvokeUserMeshCollisionRayHit(Newton.NewtonUserMeshCollisionRayHitDesc pLineDescData)
		{
			UserMeshCollisionRayHitDesc aUserMeshCollisionRayHitDesc = new UserMeshCollisionRayHitDesc();

			aUserMeshCollisionRayHitDesc.m_NormalOut = new NewtonVector4(pLineDescData.m_NormalOut).ToDirectX();
			aUserMeshCollisionRayHitDesc.m_P0 = new NewtonVector4(pLineDescData.m_P0).ToDirectX();
			aUserMeshCollisionRayHitDesc.m_P1 = new NewtonVector4(pLineDescData.m_P1).ToDirectX();
			aUserMeshCollisionRayHitDesc.m_UserData = pLineDescData.m_UserData;
			aUserMeshCollisionRayHitDesc.m_UserIdOut = pLineDescData.m_UserIdOut;

			OnUserMeshCollisionRayHit(
				new CUserMeshCollisionRayHitEventArgs(aUserMeshCollisionRayHitDesc));

			return 1.2f;
		}
コード例 #42
0
 public void Setup()
 {
     _rootFinder = new Newton();
 }
コード例 #43
0
ファイル: NewtonPhysics.cs プロジェクト: NinjaSteph/SureShot
        /// <summary>
        /// Set a user defined NewtonApplyForceAndTorque callback function to be used for this 
        /// physics object. If not specified, a default callback function will be used.
        /// </summary>
        /// <remarks>
        /// This is an advanced functionality. We do not recommend using this method unless you know
        /// how exactly you want to manipulate the force and torque calculation.
        /// </remarks>
        /// <param name="physObj"></param>
        /// <param name="callback"></param>
        /// <see cref="GetPhysicsObject"/>
        public void SetApplyForceAndTorqueCallback(IPhysicsObject physObj,
            Newton.NewtonApplyForceAndTorque callback)
        {
            if (applyForceMap.ContainsKey(physObj))
                applyForceMap.Remove(physObj);

            applyForceMap.Add(physObj, callback);
        }
コード例 #44
0
ファイル: newtons.cs プロジェクト: CyborgPatrick/CS-Misc
 public static void Main()
 {
     Func<double, double> f = delegate(double x) { return x*x-5; };
     Newton newton = new Newton(f,10e-7,100,10.2);
     newton.Aproximate();
 }
コード例 #45
0
		private uint InvokeCorkscrew(IntPtr pNewtonJoint,
			Newton.NewtonHingeSliderUpdateDesc pDesc)
		{
			HingeSliderUpdateDesc aHingeSliderUpdateDesc = new HingeSliderUpdateDesc();

			aHingeSliderUpdateDesc.m_Accel = pDesc.m_Accel;
			aHingeSliderUpdateDesc.m_MaxFriction = pDesc.m_MaxFriction;
			aHingeSliderUpdateDesc.m_MinFriction = pDesc.m_MinFriction;
			aHingeSliderUpdateDesc.m_Timestep = pDesc.m_Timestep;

			OnCorkscrew(new CCorkscrewEventArgs(aHingeSliderUpdateDesc));

			return 1;
		}
コード例 #46
0
ファイル: NewtonPhysics.cs プロジェクト: NinjaSteph/SureShot
        /// <summary>
        /// Set a user defined NewtonTreeCollision callback function to be used for this 
        /// physics object. If not specified, null will be passed.
        /// </summary>
        /// <param name="?"></param>
        /// <param name="callback"></param>
        public void SetTreeCollisionCallback(IPhysicsObject physObj, Newton.NewtonTreeCollision callback)
        {
            if (treeCollisionMap.ContainsKey(physObj))
                treeCollisionMap.Remove(physObj);

            treeCollisionMap.Add(physObj, callback);
        }