Пример #1
0
        public BallApi CreateBall(Player player, IBallCreationPosition ballCreator, float radius, float mass)
        {
            // calculate mass and scale
            var m = player.TableToWorld;

            var localPos = ballCreator.GetBallCreationPosition(_table).ToUnityFloat3();
            var localVel = ballCreator.GetBallCreationVelocity(_table).ToUnityFloat3();

            localPos.z += radius;
            //float4x4 model = player.TableToWorld * Matrix4x4.TRS(localPos, Quaternion.identity, new float3(radius));

            var worldPos = m.MultiplyPoint(localPos);
            var scale3   = new Vector3(
                m.GetColumn(0).magnitude,
                m.GetColumn(1).magnitude,
                m.GetColumn(2).magnitude
                );
            var scale    = (scale3.x + scale3.y + scale3.z) / 3.0f;          // scale is only scale (without radiusfloat now, not vector.
            var material = BallMaterial.CreateMaterial();
            var mesh     = GetSphereMesh();

            // create ball entity
            EngineProvider <IPhysicsEngine> .Get()
            .BallCreate(mesh, material, worldPos, localPos, localVel, scale, mass, radius);

            return(null);
        }
 protected override void OnCreate()
 {
     _player = Object.FindObjectOfType <Player>();
     _simulateCycleSystemGroup = World.GetOrCreateSystem <SimulateCycleSystemGroup>();
     _eventQueue = new NativeQueue <EventData>(Allocator.Persistent);
 }