コード例 #1
0
        public override void InitJoint()
        {
            Vector3 childPin  = m_Pin.normalized;
            Vector3 parentPin = m_ParentPin.normalized;

            NewtonBody child     = GetComponent <NewtonBody>();
            IntPtr     otherBody = (m_OtherBody != null) ? m_OtherBody.GetBody().GetBody() : IntPtr.Zero;

            dVector childPin_  = new dVector(childPin.x, childPin.y, childPin.z, 0.0f);
            dVector parentPin_ = new dVector(parentPin.x, parentPin.y, parentPin.z, 0.0f);

            m_Joint = new dNewtonJointGear(m_GearRatio, childPin_, parentPin_, child.GetBody().GetBody(), otherBody);

            EnableCollision = m_EnableCollision;
        }
コード例 #2
0
        public override void InitJoint()
        {
            NewtonBody child     = GetComponent <NewtonBody>();
            IntPtr     otherBody = (m_OtherBody != null) ? m_OtherBody.GetBody().GetBody() : IntPtr.Zero;

            var gearPinNorm  = m_GearPin.normalized;
            var slidePinNorm = m_SlidePin.normalized;

            dVector childPin  = new dVector(gearPinNorm.x, gearPinNorm.y, gearPinNorm.z, 0.0f);
            dVector parentPin = new dVector(slidePinNorm.x, slidePinNorm.y, slidePinNorm.z, 0.0f);

            m_Joint = new dNewtonJointRackAndPinion(m_GearRatio, childPin, parentPin, child.GetBody().GetBody(), otherBody);

            EnableCollision = m_EnableCollision;
        }
コード例 #3
0
    public override void Create()
    {
        NewtonBody child       = GetComponent <NewtonBody>();
        Matrix4x4  localMatrix = Matrix4x4.identity;

        localMatrix.SetTRS(m_posit, Quaternion.Euler(m_rotation), Vector3.one);
        IntPtr otherBody = (m_otherBody != null) ? m_otherBody.GetBody().GetBody() : new IntPtr(0);

        Vector3 pin    = localMatrix.GetColumn(0);
        dVector normal = new dVector(pin.x, pin.y, pin.z, 0.0f);
        dVector posit  = new dVector(m_posit.x, m_posit.y, m_posit.z, 1.0f);

        m_joint   = new dNewtonJointPlane3DOF(posit, normal, child.GetBody().GetBody(), otherBody);
        Stiffness = m_stiffness;
    }
コード例 #4
0
        public override void InitJoint()
        {
            var childPinNorm  = m_Pin.normalized;
            var parentPinNorm = m_ParentPin.normalized;
            var refPinNorm    = m_ReferencePin.normalized;

            NewtonBody child         = GetComponent <NewtonBody>();
            IntPtr     otherBody     = (m_OtherBody != null) ? m_OtherBody.GetBody().GetBody() : IntPtr.Zero;
            IntPtr     referenceBody = (m_ReferenceBody != null) ? m_ReferenceBody.GetBody().GetBody() : IntPtr.Zero;

            dVector dChildPin     = new dVector(childPinNorm.x, childPinNorm.y, childPinNorm.z, 0.0f);
            dVector dParentPin    = new dVector(parentPinNorm.x, parentPinNorm.y, parentPinNorm.z, 0.0f);
            dVector dReferencePin = new dVector(refPinNorm.x, refPinNorm.y, refPinNorm.z, 0.0f);

            m_Joint = new dNewtonJointDifferentialGear(m_GearRatio, dChildPin, dParentPin, dReferencePin, child.GetBody().GetBody(), otherBody, referenceBody);

            EnableCollision = m_EnableCollision;
        }
コード例 #5
0
    public override void Create()
    {
        Matrix4x4 localMatrix0 = Matrix4x4.identity;
        Matrix4x4 localMatrix1 = Matrix4x4.identity;

        localMatrix0.SetTRS(Vector3.zero, Quaternion.Euler(m_rotation), Vector3.one);
        localMatrix1.SetTRS(Vector3.zero, Quaternion.Euler(m_parentRotation), Vector3.one);

        Vector4 childPin  = localMatrix0.GetColumn(0);
        Vector4 parentPin = localMatrix1.GetColumn(0);

        NewtonBody child     = GetComponent <NewtonBody>();
        IntPtr     otherBody = (m_otherBody != null) ? m_otherBody.GetBody().GetBody() : new IntPtr(0);

        dVector childPin_  = new dVector(childPin.x, childPin.y, childPin.z, 0.0f);
        dVector parentPin_ = new dVector(parentPin.x, parentPin.y, parentPin.z, 0.0f);

        m_joint = new dNewtonJointGear(m_gearRatio, childPin_, parentPin_, child.GetBody().GetBody(), otherBody);
    }
コード例 #6
0
        public override dNewtonCollision Create(NewtonWorld world)
        {
            TerrainData data = m_terrain.terrainData;
            //Debug.Log("xxxx  " + data.alphamapWidth + "   xxx  " + data.detailHeight);
            //Debug.Log("xxxx  " + data.heightmapScale);
            //Debug.Log("xxxx  " + data.size);

            int     resolution = data.heightmapResolution;
            dVector scale      = new dVector(data.size.x, data.size.y, data.size.z, 0.0f);

            m_oldSize       = data.size;
            m_oldResolution = resolution;

            data.GetHeights(0, 0, resolution, resolution);

            int   hash           = 0;
            float elevationScale = data.size.y;

            float[] elevation = new float[resolution * resolution];
            for (int z = 0; z < resolution; z++)
            {
                for (int x = 0; x < resolution; x++)
                {
                    float value = data.GetHeight(x, z);
                    elevation[z * resolution + x] = value;
                    hash = Utils.dRand((int)(elevationScale * value), hash);
                }
            }
            m_elevationHash = hash;

            IntPtr elevationPtr = Marshal.AllocHGlobal(resolution * resolution * Marshal.SizeOf(typeof(float)));

            Marshal.Copy(elevation, 0, elevationPtr, elevation.Length);
            dNewtonCollision collider = new dNewtonCollisionHeightField(world.GetWorld(), elevationPtr, resolution, scale);

            Marshal.FreeHGlobal(elevationPtr);

            SetDefualtParams();
            SetMaterial(collider);
            SetLayer(collider);
            return(collider);
        }
コード例 #7
0
    public override void InitJoint()
    {
        Matrix4x4 localMatrix0 = Matrix4x4.identity;
        Matrix4x4 localMatrix1 = Matrix4x4.identity;
        Matrix4x4 localMatrix2 = Matrix4x4.identity;

        localMatrix0.SetTRS(Vector3.zero, Quaternion.Euler(m_rotation), Vector3.one);
        localMatrix1.SetTRS(Vector3.zero, Quaternion.Euler(m_parentRotation), Vector3.one);
        localMatrix2.SetTRS(Vector3.zero, Quaternion.Euler(m_referenceRotation), Vector3.one);

        Vector4 childPin     = localMatrix0.GetColumn(0);
        Vector4 parentPin    = localMatrix1.GetColumn(0);
        Vector4 referencePin = localMatrix2.GetColumn(0);

        NewtonBody child         = GetComponent <NewtonBody>();
        IntPtr     otherBody     = (m_otherBody != null) ? m_otherBody.GetBody().GetBody() : new IntPtr(0);
        IntPtr     referenceBody = (m_referenceBody != null) ? m_referenceBody.GetBody().GetBody() : new IntPtr(0);

        dVector dChildPin     = new dVector(childPin.x, childPin.y, childPin.z, 0.0f);
        dVector dParentPin    = new dVector(parentPin.x, parentPin.y, parentPin.z, 0.0f);
        dVector dReferencePin = new dVector(referencePin.x, referencePin.y, referencePin.z, 0.0f);

        m_joint = new dNewtonJointDifferentialGear(m_gearRatio, dChildPin, dParentPin, dReferencePin, child.GetBody().GetBody(), otherBody, referenceBody);
    }
コード例 #8
0
    public bool ContinuousCollide(NewtonBody body1, NewtonBody body2, out NewtonCollideInfo hitInfo)
    {
        dMatrix matrix1   = Utils.ToMatrix(body1.Position, body1.Rotation);
        dMatrix matrix2   = Utils.ToMatrix(body2.Position, body2.Rotation);
        dVector velocity1 = new dVector(body1.Velocity.x, body1.Velocity.y, body1.Velocity.z);
        dVector velocity2 = new dVector(body2.Velocity.x, body2.Velocity.y, body2.Velocity.z);
        dVector omega1    = new dVector(body1.Omega.x, body1.Omega.y, body1.Omega.z);
        dVector omega2    = new dVector(body2.Omega.x, body2.Omega.y, body2.Omega.z);

        var hitInfoPtr = m_world.ContinuousCollide(matrix1, matrix2, velocity1, velocity2, omega1, omega2, body1.m_collision.GetShape(), body2.m_collision.GetShape(), 1);// m_world.Raycast(startPos.x, startPos.y, startPos.z, endPos.x, endPos.y, endPos.z, layerMask);

        //mat_handle.Free();
        if (hitInfoPtr != IntPtr.Zero)
        {
            _InternalConvexCastInfo info = (_InternalConvexCastInfo)Marshal.PtrToStructure(hitInfoPtr, typeof(_InternalConvexCastInfo));

            hitInfo.body = body2;

            hitInfo.position     = info.point;
            hitInfo.normal       = info.normal;
            hitInfo.collisionID1 = (uint)info.contactID1;
            hitInfo.collisionID2 = (uint)info.contactID2;
            hitInfo.penetration  = info.penetration;
            hitInfo.timeOfImpact = info.timeOfImpact;
            return(true);
        }

        hitInfo.body         = null;
        hitInfo.position     = Vector3.zero;
        hitInfo.normal       = Vector3.zero;
        hitInfo.collisionID1 = 0;
        hitInfo.collisionID2 = 0;
        hitInfo.penetration  = 0;
        hitInfo.timeOfImpact = 0;
        return(false);
    }