Exemplo n.º 1
0
        private void CreateDetail(BinaryReader reader)
        {
            int id       = reader.ReadInt32();
            int parentID = reader.ReadInt32();

            string model = reader.ReadString();
            var    pos   = reader.ReadVector3();
            var    rot   = reader.ReadQuaternion();

            Shape shape    = null;
            bool  hasShape = reader.ReadBoolean();

            if (hasShape == true)
            {
                var shapeSize = reader.ReadVector3();
                shape = DetailHelper.CreateShape(shapeSize);
            }

            var parent = this.world.GetDetail(parentID);

            DetailObject obj = new DetailObject(parent, id, shape);

            obj.Position = pos;
            obj.Rotation = rot;
            obj.Model    = model.Length > 0 ? model : null;

            this.world.RegisterDetail(obj);
        }
Exemplo n.º 2
0
 public Vector3 GetPosition()
 {
     if (this.Position == null)
     {
         throw new InvalidOperationException("Template has no position");
     }
     return(DetailHelper.ParseVector3(this.Position));
 }
Exemplo n.º 3
0
 public Vector3 GetSize()
 {
     if (this.Size == null)
     {
         throw new InvalidOperationException("Template has no size");
     }
     return(DetailHelper.ParseVector3(this.Size));
 }
Exemplo n.º 4
0
        private DetailObject CreateDetailInstance(
            Dictionary <DetailTemplate, DetailObject> mapping,
            Dictionary <BehaviourTemplate, Behaviour> behaviours,
            DetailTemplate template,
            DetailObject parent)
        {
            Vector3 pos = Vector3.Zero;

            if (template.Position != null)
            {
                pos = template.GetPosition();
            }
            Shape shape = null;

            if (template.Shape != null)
            {
                shape = DetailHelper.CreateShape(template.Shape.GetSize());
            }

            DetailObject root = this.CreateDetail(template.Model, pos, parent, shape);

            if (template.Rotation != null)
            {
                root.Rotation = template.GetRotation();
            }

            if (template.Children != null)
            {
                foreach (var child in template.Children)
                {
                    CreateDetailInstance(mapping, behaviours, child, root);
                }
            }
            mapping.Add(template, root);

            if (template.Behaviours != null)
            {
                foreach (var behav in template.Behaviours)
                {
                    var type = Type.GetType(behav.Class);
                    if (type.IsSubclassOf(typeof(Behaviour)) == false)
                    {
                        throw new InvalidOperationException("Invalid behaviour type: " + behav.Class);
                    }
                    Behaviour behaviour = root.CreateBehaviour(type, true);
                    behaviours.Add(behav, behaviour);
                }
            }

            return(root);
        }
Exemplo n.º 5
0
        public Quaternion GetRotation()
        {
            if (this.Rotation == null)
            {
                throw new InvalidOperationException("Template has no rotation");
            }
            var ang = DetailHelper.ParseVector3(this.Rotation);

            ang *= MathHelper.DegreesToRadians(1);
            return
                (Quaternion.FromAxisAngle(Vector3.UnitY, ang.Y));              // *
            // Quaternion.FromAxisAngle(Vector3.UnitY, ang.Y) *
            // Quaternion.FromAxisAngle(Vector3.UnitY, ang.Y);
        }