Beispiel #1
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            MyObjectBuilder_GhostCharacter characterOb = (MyObjectBuilder_GhostCharacter)objectBuilder;

            base.Init(objectBuilder);

            SetupPhysics(true);

            m_worldMatrixOriginal = this.WorldMatrix;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.BEFORE_NEXT_FRAME;

            MyOpenVR.LMUAdd(null, WorldMatrix, ControllerRole.head, 1);
        }
Beispiel #2
0
        private void SwitchWeapon(ref IMyHandheldGunObject <MyDeviceBase> weapon, ref MyVRWeaponInfo weaponInfo, List <MyVRWeaponInfo> weapons, ControllerRole role, Vector2?touchpadPos)
        {
            int currentIndex = -1;

            if (weapon != null)
            {
                for (int i = 0; i < weapons.Count; ++i)
                {
                    var info = weapons[i];
                    if (info.DefinitionId == weapon.DefinitionId)
                    {
                        currentIndex = i;
                        break;
                    }
                }
            }

            int nextIndex = 0;

            if (touchpadPos != null)
            {
                Vector2 pos = touchpadPos.Value;
                if (touchpadPos != Vector2.Zero)
                {
                    pos.Normalize();
                    float anglePerWeaponSector = 360f / weapons.Count;
                    float dot   = Vector2.Dot(Vector2.UnitX, pos);
                    float angle = (float)Math.Acos(Math.Abs(dot));
                    if (pos.Y >= 0)
                    {
                        if (dot < 0)
                        {
                            angle = 180 - angle;
                        }
                    }
                    else
                    {
                        if (dot < 0)
                        {
                            angle = 180 + angle;
                        }
                        else
                        {
                            angle = 360 - angle;
                        }
                    }

                    nextIndex = (int)Math.Floor(angle / anglePerWeaponSector);
                    Debug.Assert(nextIndex < weapons.Count);
                }
            }

            if (nextIndex == currentIndex)
            {
                return;
            }

            if (weapon != null)
            {
                weapon.OnControlReleased();
                MyEntity weaponEntity = (MyEntity)weapon;
                weaponEntity.Close();
                weapon = null;
            }

            {
                weaponInfo = weapons[nextIndex];
                weapon     = CreateWeapon(weaponInfo.DefinitionId, weaponInfo.Reference);
                weapon.OnControlAcquired(null);
                MyEntity weaponEntity = (MyEntity)weapon;
            }

            var    gunBase       = weapon.GunBase as MyGunBase;
            Matrix holdingMatrix = gunBase != null ? gunBase.m_holdingDummyMatrix : Matrix.Identity;

            MyOpenVR.LMUAdd(holdingMatrix, m_worldMatrixOriginal, role, weaponInfo.Reference);
        }