Ejemplo n.º 1
0
        // --------------------------------------------------------------------

        public void WriteXml(XmlWriter writer)
        {
            writer.WriteStartElement("Transform");
            writer.WriteAttributeString("position", XmlUtils.Vector3ToString(LocalPosition));
            writer.WriteAttributeString("rotation", XmlUtils.Vector4ToString(LocalRotation.ToAxisAngle()));
            writer.WriteAttributeString("scale", XmlUtils.Vector3ToString(LocalScale));
            writer.WriteEndElement();
        }
Ejemplo n.º 2
0
 protected override void WriteObject(AssetsWriter writer)
 {
     LocalRotation.Write(writer);
     LocalPosition.Write(writer);
     LocalScale.Write(writer);
     writer.WriteArrayOf(Children, (x, y) => x.Write(y));
     Father.Write(writer);
 }
Ejemplo n.º 3
0
 public override void Write(AssetsWriter writer)
 {
     base.WriteBase(writer);
     LocalRotation.Write(writer);
     LocalPosition.Write(writer);
     LocalScale.Write(writer);
     writer.WriteArrayOf(Children, x => x.WritePtr(writer));
     Father.WritePtr(writer);
 }
Ejemplo n.º 4
0
        public override void Read(AssetStream stream)
        {
            base.Read(stream);

            LocalRotation.Read(stream);
            LocalPosition.Read(stream);
            LocalScale.Read(stream);
            m_children = stream.ReadArray <PPtr <Transform> >();
            Father.Read(stream);
        }
Ejemplo n.º 5
0
        private Vector3f GetLocalEulerAnglesHint(Version version, TransferInstructionFlags flags)
        {
#if UNIVERSAL
            if (HasLocalEulerAnglesHint(version, flags))
            {
                return(LocalEulerAnglesHint);
            }
#endif
            return(LocalRotation.ToEuler());
        }
Ejemplo n.º 6
0
        public override void Read(AssetReader reader)
        {
            base.Read(reader);

            LocalRotation.Read(reader);
            LocalPosition.Read(reader);
            LocalScale.Read(reader);
            m_children = reader.ReadArray <PPtr <Transform> >();
            Father.Read(reader);
        }
Ejemplo n.º 7
0
        public override void Read(EndianStream stream)
        {
            base.Read(stream);

            LocalRotation.Read(stream);
            LocalPosition.Read(stream);
            LocalScale.Read(stream);
            m_children = stream.ReadArray(() => new PPtr <Transform>(AssetsFile));
            Father.Read(stream);
        }
Ejemplo n.º 8
0
        public Wall[] GetValue(Wall[] walls)
        {
            foreach (var wall in walls)
            {
                wall.Rotation      = Rotation.Random(Random);
                wall.LocalRotation = LocalRotation.Random(Random);
            }

            return(walls);
        }
Ejemplo n.º 9
0
            public void Execute(int i)
            {
                var speed = rotationSpeeds[i].Value;

                if (speed > 0.0f)
                {
                    rotations[i] = new LocalRotation
                    {
                        Value = math.mul(math.normalize(rotations[i].Value), math.axisAngle(math.up(), speed * dt))
                    };
                }
            }
Ejemplo n.º 10
0
        protected override YAMLMappingNode ExportYAMLRoot(IExportContainer container)
        {
            YAMLMappingNode node = base.ExportYAMLRoot(container);

            node.Add("m_LocalRotation", LocalRotation.ExportYAML(container));
            node.Add("m_LocalPosition", LocalPosition.ExportYAML(container));
            node.Add("m_LocalScale", LocalScale.ExportYAML(container));
            node.Add("m_Children", Children.ExportYAML(container));
            node.Add("m_Father", Father.ExportYAML(container));
            node.Add("m_RootOrder", GetSiblingIndex());
            node.Add("m_LocalEulerAnglesHint", LocalRotation.ToEuler().ExportYAML(container));
            return(node);
        }
Ejemplo n.º 11
0
        protected override YAMLMappingNode ExportYAMLRoot(IExportContainer container)
        {
            YAMLMappingNode node = base.ExportYAMLRoot(container);

            node.Add(LocalRotationName, LocalRotation.ExportYAML(container));
            node.Add(LocalPositionName, LocalPosition.ExportYAML(container));
            node.Add(LocalScaleName, LocalScale.ExportYAML(container));
            node.Add(ChildrenName, Children.ExportYAML(container));
            node.Add(FatherName, Father.ExportYAML(container));
            node.Add(RootOrderName, GetRootOrder(container.Version, container.Flags));
            node.Add(LocalEulerAnglesHintName, GetLocalEulerAnglesHint(container.Version, container.Flags).ExportYAML(container));
            return(node);
        }
Ejemplo n.º 12
0
        protected override YAMLMappingNode ExportYAMLRoot(IExportContainer container)
        {
            YAMLMappingNode node   = base.ExportYAMLRoot(container);
            TransformLayout layout = container.Layout.Transform;

            node.Add(layout.LocalRotationName, LocalRotation.ExportYAML(container));
            node.Add(layout.LocalPositionName, LocalPosition.ExportYAML(container));
            node.Add(layout.LocalScaleName, LocalScale.ExportYAML(container));
            node.Add(layout.ChildrenName, Children.ExportYAML(container));
            node.Add(layout.FatherName, Father.ExportYAML(container));
            node.Add(layout.RootOrderName, RootOrder);
            node.Add(layout.LocalEulerAnglesHintName, LocalEulerAnglesHint.ExportYAML(container));
            return(node);
        }
Ejemplo n.º 13
0
        public override void Read(AssetReader reader)
        {
            base.Read(reader);

            LocalRotation.Read(reader);
            LocalPosition.Read(reader);
            LocalScale.Read(reader);
            Children = reader.ReadAssetArray <PPtr <Transform> >();
            Father.Read(reader);
#if UNIVERSAL
            if (HasRootOrder(reader.Version, reader.Flags))
            {
                RootOrder = reader.ReadInt32();
            }
            if (HasLocalEulerAnglesHint(reader.Version, reader.Flags))
            {
                LocalEulerAnglesHint.Read(reader);
            }
#endif
        }
Ejemplo n.º 14
0
        public override void Write(AssetWriter writer)
        {
            base.Write(writer);

            LocalRotation.Write(writer);
            LocalPosition.Write(writer);
            LocalScale.Write(writer);
            Children.Write(writer);
            Father.Write(writer);
#if UNIVERSAL
            TransformLayout layout = writer.Layout.Transform;
            if (layout.HasRootOrder)
            {
                writer.Write(RootOrder);
            }
            if (layout.HasLocalEulerAnglesHint)
            {
                LocalEulerAnglesHint.Write(writer);
            }
#endif
        }
Ejemplo n.º 15
0
        public override void Read(AssetReader reader)
        {
            base.Read(reader);

            LocalRotation.Read(reader);
            LocalPosition.Read(reader);
            LocalScale.Read(reader);
            Children = reader.ReadAssetArray <PPtr <Transform> >();
            Father.Read(reader);
#if UNIVERSAL
            TransformLayout layout = reader.Layout.Transform;
            if (layout.HasRootOrder)
            {
                RootOrder = reader.ReadInt32();
            }
            if (layout.HasLocalEulerAnglesHint)
            {
                LocalEulerAnglesHint.Read(reader);
            }
#endif
        }
Ejemplo n.º 16
0
    protected override void OnUpdate()
    {
        EntityManager manager = World.Active.GetOrCreateManager <EntityManager>();

        for (int idx = 0; idx < m_data.Length; ++idx)
        {
            float   nearestDistance = float.MaxValue;
            Vector3 nearestToEnemy  = new Vector3(0.0f, 0.0f, 1.0f);
            Vector3 nearestPosition = new Vector3(0.0f, 0.0f, 0.0f);

            bool nearestFound = false;

            Entity   turretBody = m_data.Parent[idx].Value;
            Position position   = manager.GetComponentData <Position>(turretBody);

            for (int enemyIdx = 0; enemyIdx < m_enemies.Length; ++enemyIdx)
            {
                Vector3 toEnemy = m_enemies.EnemyPositions[enemyIdx].Value - position.Value;

                if (toEnemy.magnitude < nearestDistance && toEnemy.magnitude < 5.0f)
                {
                    nearestDistance = toEnemy.magnitude;
                    nearestPosition = m_enemies.EnemyPositions[enemyIdx].Value;
                    nearestToEnemy  = toEnemy;
                    nearestFound    = true;
                }
            }

            ComponentTypes.TurretHeadState tempState = m_data.State[idx];
            tempState.TimeSinceLastFire += Time.deltaTime;
            tempState.CanFire            = 0;

            float delta = tempState.TargetAngle - tempState.Angle;

            float rotSpeed = 45.0f;
            if (nearestFound)
            {
                tempState.CanFire = 1;

                nearestToEnemy.Normalize();
                float   dot   = Vector3.Dot(new Vector3(0.0f, 0.0f, 1.0f), nearestToEnemy);
                Vector3 cross = Vector3.Cross(new Vector3(0.0f, 0.0f, 1.0f), nearestToEnemy);

                tempState.TargetAngle = Mathf.Rad2Deg * Mathf.Acos(dot);

                if (cross.y < 0.0f)
                {
                    tempState.TargetAngle = 360.0f - tempState.TargetAngle;
                }

                rotSpeed = 180.0f;

                Vector3 basis        = new Vector3(0.0f, 0.0f, 1.0f);
                Vector3 angleVector  = Quaternion.Euler(0.0f, tempState.Angle, 0.0f) * basis;
                Vector3 targetVector = Quaternion.Euler(0.0f, tempState.TargetAngle, 0.0f) * basis;

                Vector3 angleTargetCross = Vector3.Cross(angleVector, targetVector);
                angleTargetCross.Normalize();

                float adjustment = Time.deltaTime * rotSpeed;

                if (adjustment > Mathf.Abs(tempState.TargetAngle - tempState.Angle))
                {
                    adjustment = Mathf.Abs(tempState.TargetAngle - tempState.Angle);
                }

                if (angleTargetCross.y < 0.0f)
                {
                    tempState.Angle -= adjustment;
                }
                else
                {
                    tempState.Angle += adjustment;
                }
            }

            if (tempState.Angle < 0.0f)
            {
                tempState.Angle += 360.0f;
            }
            if (tempState.Angle > 0.0f)
            {
                tempState.Angle -= 360.0f;
            }

            LocalRotation tempRotation = m_data.LocalRotation[idx];
            tempRotation.Value        = Quaternion.Euler(0.0f, tempState.Angle, 0.0f);
            m_data.LocalRotation[idx] = tempRotation;
            m_data.State[idx]         = tempState;
        }
    }