Esempio n. 1
0
 protected override void OnUpdate()
 {
     Entities.WithAll <Body, Translation, Rotation>().ForEach((Entity e, ref Body body, ref Translation position, ref Rotation rotation) =>
     {
         DebugLines.DrawCubeLines(position.Value, rotation.Value, body.size, Color.black);
     });
 }
Esempio n. 2
0
        protected override void OnUpdate()
        {
            // make bones keep int3 position
            // make them reposition off their parent bones
            Entities.WithAll <Skeleton, Translation, Rotation, LocalToWorld>().ForEach((Entity e, ref Skeleton skeleton, ref Translation translation, ref Rotation rotation, ref LocalToWorld localToWorld) =>
            {
                quaternion rot       = rotation.Value;
                Quaternion rot2      = Quaternion.Euler(0, 180, 0);
                quaternion rot3      = rot2;
                rot                  = math.mul(rot, rot3);
                skeleton.mulRotation = rot;
                float3 totalSize     = skeleton.size.ToFloat3() / 32f;
                DebugLines.DrawCubeLines(translation.Value, rotation.Value, totalSize * 0.5f, Color.black);
                for (int i = 0; i < skeleton.positions.Length; i++)
                {
                    float3 newSize     = skeleton.sizes[i].ToFloat3() / 32f;
                    float3 newPosition = skeleton.positions[i].ToFloat3() / 32f;
                    newPosition       -= totalSize / 2f;
                    newPosition       += newSize / 2f;
                    newPosition        = math.rotate(rot, newPosition);
                    //DebugLines.DrawCubeLines(translation.Value + newPosition, rotation.Value, newSize * 0.5f, Color.grey);
                }
            });

            Entities.WithAll <Bone>().ForEach((Entity e, ref Bone bone) =>
            {
                if (World.EntityManager.Exists(bone.skeleton) && World.EntityManager.HasComponent <Skeleton>(bone.skeleton))
                {
                    //Matrix4x4 localToWorldPos = localToWorld.Value;
                    //Vector3 position = localToWorldPos.GetColumn(3);
                    float3 worldPosition = bone.GetWorldPosition(World.EntityManager, e);
                    var skeleton         = World.EntityManager.GetComponentData <Skeleton>(bone.skeleton);
                    var skeletonRotation = World.EntityManager.GetComponentData <Rotation>(bone.skeleton);
                    //var newPosition = math.rotate(skeleton.mulRotation, position);
                    DebugLines.DrawCubeLines(worldPosition, skeletonRotation.Value, 1.2f * (new float3(boneDebugSize, boneDebugSize, boneDebugSize)), Color.green);

                    /*float3 influenceSize = 1f * ((bone.influenceMax - bone.influenceMin).ToFloat3() / 32f);
                     * float3 midPoint = (influenceSize / 2f);
                     * float3 influenceOffset = (bone.influenceMax.ToFloat3() / 32f - midPoint);*/
                    float3 influenceSize   = bone.GetInfluenceSize();
                    float3 influenceOffset = bone.GetInfluenceOffset();
                    DebugLines.DrawCubeLines(worldPosition + influenceOffset, skeletonRotation.Value, 0.5f * influenceSize, Color.red);
                }
            });
        }