Example #1
0
        void RpcUpdateTransforms(float[] transforms)
        {
            if (isServer || rigidBodies == null)
            {
                return;
            }

            BulletSharp.Math.Matrix[] bmTransforms = new BulletSharp.Math.Matrix[rigidBodies.Length];

            // TODO: Combine these loops.

            for (int i = 0; i < bmTransforms.Length; i++)
            {
                float[] rawTransform = new float[7];

                for (int j = 0; j < rawTransform.Length; j++)
                {
                    rawTransform[j] = transforms[i * 13 + j];
                }

                bmTransforms[i] = BulletExtensions.DeserializeTransform(rawTransform);

                rigidBodies[i].GetCollisionObject().Activate();
                BulletSharp.Math.Matrix rbTransform = rigidBodies[i].GetCollisionObject().WorldTransform;
            }

            for (int i = 0; i < bmTransforms.Length; i++)
            {
                float[] rawLinearVelocity = new float[3];

                for (int j = 0; j < rawLinearVelocity.Length; j++)
                {
                    rawLinearVelocity[j] = transforms[i * 13 + 7 + j];
                }

                float[] rawAngularVelocity = new float[3];

                for (int j = 0; j < rawAngularVelocity.Length; j++)
                {
                    rawAngularVelocity[j] = transforms[i * 13 + 7 + rawLinearVelocity.Length + j];
                }

                BulletSharp.Math.Vector3 linearVelocity  = new BulletSharp.Math.Vector3(rawLinearVelocity);
                BulletSharp.Math.Vector3 angularVelocity = new BulletSharp.Math.Vector3(rawAngularVelocity);

                networkMeshes[i].TargetLinearVelocity = linearVelocity.ToUnity();

                RigidBody rbCo = (RigidBody)rigidBodies[i].GetCollisionObject();

                rbCo.WorldTransform  = bmTransforms[i];
                rbCo.LinearVelocity  = linearVelocity;
                rbCo.AngularVelocity = angularVelocity;
            }
        }
Example #2
0
        void RpcUpdateTransform(float[] transform)
        {
            if (isServer || rigidBody == null)
            {
                return;
            }

            BulletSharp.Math.Matrix bmTransform = BulletExtensions.DeserializeTransform(transform.Take(7).ToArray());
            BulletSharp.Math.Matrix rbTransform = rigidBody.WorldTransform;

            BulletSharp.Math.Vector3 linearVelocity  = new BulletSharp.Math.Vector3(transform.Skip(7).Take(3).ToArray());
            BulletSharp.Math.Vector3 angularVelocity = new BulletSharp.Math.Vector3(transform.Skip(10).Take(3).ToArray());

            if (networkMesh != null)
            {
                networkMesh.TargetLinearVelocity = linearVelocity.ToUnity();
            }

            rigidBody.WorldTransform  = bmTransform;
            rigidBody.LinearVelocity  = linearVelocity;
            rigidBody.AngularVelocity = angularVelocity;
        }