Exemplo n.º 1
0
        private static void PrepareM2Info(MapDoodadDefinition def, M2Model model)
        {
            TerrainConstants.TilePositionToWorldPosition(ref def.Position);

            Matrix scaleMatrix;

            Matrix.CreateScale(def.Scale, out scaleMatrix);

            var rotateZ = Matrix.CreateRotationZ(MathHelper.ToRadians(def.OrientationB + 180));
            var rotateY = Matrix.CreateRotationY(MathHelper.ToRadians(def.OrientationA));
            var rotateX = Matrix.CreateRotationX(MathHelper.ToRadians(def.OrientationC));

            var modelToWorld = Matrix.Multiply(scaleMatrix, rotateZ);

            modelToWorld     = Matrix.Multiply(modelToWorld, rotateX);
            modelToWorld     = Matrix.Multiply(modelToWorld, rotateY);
            def.ModelToWorld = modelToWorld;

            Matrix worldToModel;

            Matrix.Invert(ref modelToWorld, out worldToModel);
            def.WorldToModel = worldToModel;

            CalculateModelBounds(def, model);
        }
Exemplo n.º 2
0
        private static void PrepareWMOInfo(MapObjectDefinition def)
        {
            TerrainConstants.TilePositionToWorldPosition(ref def.Position);
            TerrainConstants.TileExtentsToWorldExtents(ref def.Extents);

            Matrix modelToWorld;

            Matrix.CreateRotationZ(MathHelper.ToRadians(def.OrientationB + 180), out modelToWorld);
            Matrix worldToModel;

            Matrix.Invert(ref modelToWorld, out worldToModel);
            def.WMOToWorld = modelToWorld;
            def.WorldToWMO = worldToModel;

            // Reposition the m2s contained within the wmos
            //WMORoot root;
            //if (!LoadedWmoRoots.TryGetValue(def.FilePath, out root))
            //{
            //    log.Error(String.Format("WMORoot file: {0} missing from the Dictionary!", def.FilePath));
            //    continue;
            //}

            //var setIndices = new List<int> { 0 };
            //if (def.DoodadSet > 0) setIndices.Add(def.DoodadSet);

            //foreach (var index in setIndices)
            //{
            //    var doodadSet = root.DoodadSets[index];
            //    for (var i = 0; i < doodadSet.InstanceCount; i++)
            //    {
            //        var dDef = root.DoodadDefinitions[doodadSet.FirstInstanceIndex + i];
            //        if (string.IsNullOrEmpty(dDef.FilePath)) continue;

            //        M2Model model;
            //        if (!LoadedM2Models.TryGetValue(dDef.FilePath, out model))
            //        {
            //            log.Error(String.Format("M2Model file: {0} missing from the Dictionary!", dDef.FilePath));
            //            continue;
            //        }

            //        // Calculate and store the models' transform matrices
            //        Matrix scaleMatrix;
            //        Matrix.CreateScale(dDef.Scale, out scaleMatrix);

            //        Matrix rotMatrix;
            //        Matrix.CreateFromQuaternion(ref dDef.Rotation, out rotMatrix);

            //        Matrix modelToWMO;
            //        Matrix.Multiply(ref scaleMatrix, ref rotMatrix, out modelToWMO);

            //        Matrix wmoToModel;
            //        Matrix.Invert(ref modelToWMO, out wmoToModel);
            //        dDef.ModelToWMO = modelToWMO;
            //        dDef.WMOToModel = wmoToModel;

            //        // Calculate the wmoSpace bounding box for this model
            //        var wmoSpaceVecs = new List<Vector3>(model.BoundingVertices.Length);
            //        for (var j = 0; j < model.BoundingVertices.Length; j++)
            //        {
            //            Vector3 rotated;
            //            Vector3.Transform(ref model.BoundingVertices[i], ref modelToWMO, out rotated);

            //            Vector3 final;
            //            Vector3.Add(ref rotated, ref dDef.Position, out final);
            //            wmoSpaceVecs.Add(final);
            //        }

            //        dDef.Extents = new BoundingBox(wmoSpaceVecs.ToArray());
            //        def.M2Refs.Add(dDef);
            //    }
            //}
        }