示例#1
0
 private void Func1()
 {
     DebugUtils.Info("TestInst", "Func1");
     // 第一次 还是会 执行 Func2
     // 后一次 才不会 被执行
     EnumEventDispatcher.RemoveEventListener(EnumEventType.JoystickRelease, Func2);
 }
示例#2
0
        public static void Test()
        {
            List <List <AdjacentTest> > all = new List <List <AdjacentTest> >();
            int count = 20;

            for (int i = 0; i < count - 1; ++i)
            {
                List <AdjacentTest> row = new List <AdjacentTest>();
                if (i != 1 && i != 10 && i != 15)
                {
                    for (int j = i + 1; j < count; ++j)
                    {
                        AdjacentTest test = new AdjacentTest(i, j, i * count + j);
                        row.Add(test);
                    }
                }
                all.Add(row);
            }
            List <AdjacentTest>         group  = new List <AdjacentTest>();
            List <List <AdjacentTest> > groups = new List <List <AdjacentTest> >();

            GeoAlgorithmUtils.AdjacentGraphTravel(all, groups, group);

            foreach (List <AdjacentTest> adj in groups)
            {
                string str = "";
                for (int i = 0; i < adj.Count; ++i)
                {
                    str = string.Format("{0} {1} {2}", str, adj[i].Previous(), adj[i].Next());
                }
                DebugUtils.Info("", "{0}", str);
            }
        }
示例#3
0
        public static Properties Create(string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                DebugUtils.Info("Create", "Attempting to create a Properties object from an empty URL!");
                return(null);
            }
            // Calculate the file and full namespace path from the specified url.
            string        urlString     = url;
            string        fileString    = null;
            List <string> namespacePath = new List <string>();

            CalculateNamespacePath(ref urlString, ref fileString, namespacePath);
            using (NullMemoryStream stream = NullMemoryStream.ReadTextFromFile(fileString))
            {
                Properties properties = new Properties(stream);
                properties.ResolveInheritance();
                // Get the specified properties object.
                Properties p = GetPropertiesFromNamespacePath(properties, namespacePath);
                if (p == null)
                {
                    DebugUtils.Warning("Create", "Failed to load properties from url '%s'.", url);
                    return(null);
                }
                if (p != properties)
                {
                    p = p.Clone();
                }
                p.SetDirectoryPath(Path.GetDirectoryName(fileString));
                p.Rewind();
                return(p);
            }
        }
示例#4
0
        public OOMesh(MeshFilter filter)
        {
            MeshFilter = filter;
            MeshFilter.sharedMesh.RecalculateBounds();

#if TEST_DRAW_ONE
            Vector3 world1 = new Vector3(1.14f, -0.7f, -5.94f);
            Vector3 world2 = new Vector3(1.14f, 1.96f, -7.81f);
            Vector3 world3 = new Vector3(7.28f, -0.7f, -5.94f);
            Vertices = new Vector3[]
            {
                filter.transform.worldToLocalMatrix.MultiplyPoint3x4(world1),
                filter.transform.worldToLocalMatrix.MultiplyPoint3x4(world2),
                filter.transform.worldToLocalMatrix.MultiplyPoint3x4(world3)
            };
            world1 = Camera.main.WorldToScreenPoint(world1) * 32;
            world2 = Camera.main.WorldToScreenPoint(world2) * 32;
            world3 = Camera.main.WorldToScreenPoint(world3) * 32;
            DebugUtils.Info("OOModel", string.Format("world1({0}, {1})", world1.x, world1.y));
            DebugUtils.Info("OOModel", string.Format("world2({0}, {1})", world2.x, world2.y));
            DebugUtils.Info("OOModel", string.Format("world3({0}, {1})", world3.x, world3.y));
            Faces = new Vector3i[] { new Vector3i(0, 1, 2) };
#else
            Vertices = MeshFilter.sharedMesh.vertices;
            Faces    = ArrayToList(MeshFilter.sharedMesh.triangles);
#endif
            NumVert             = Vertices.Length;
            NumFace             = Faces.Length;
            CameraSpaceVertices = new Vector3[NumVert];
            ClipSpaceVertices   = new Vector4[NumVert];
            Bounds b = MeshFilter.sharedMesh.bounds;
            Box = new OOBox(b.min, b.max);
        }
示例#5
0
 public void LateUpdate()
 {
     if (Culler != null)
     {
         // 如果相机存在变化,需要打开
         // Culler.UpdateCameraMatrix();
         // Culler.DrawFrustumPlanes();
         foreach (OOModel obj in DrawObjects.Values)
         {
             obj.UpdateTransform();
         }
         Culler.FindVisible(OOCE.OOCE_OCCLUSION_CULLING);
         int visible = Culler.GetFirstObject();
         int count   = 0;
         while (visible == 1)
         {
             int id = Culler.GetObjectID();
             if (DrawObjects.ContainsKey(id))
             {
                 DrawObjects[id].Draw();
             }
             visible = Culler.GetNextObject();
             count++;
         }
         DebugUtils.Info("MannulDrawManager", "LateUpdate ", count);
     }
 }
示例#6
0
        public static void Test()
        {
            Dijkstra <string> test = new Dijkstra <string>();

            test.AddConnection("A", "B", 20, false);
            test.AddConnection("A", "G", 90, 20);
            test.AddConnection("A", "D", 80, false);

            test.AddConnection("B", "F", 10, false);

            test.AddConnection("C", "D", 10, true);
            test.AddConnection("C", "H", 20, false);
            test.AddConnection("C", "F", 50, 10);

            test.AddConnection("D", "G", 20, false);

            test.AddConnection("E", "B", 50, false);
            test.AddConnection("E", "G", 30, false);

            test.AddConnection("F", "D", 40, false);

            List <string> path = new List <string>();

            test.GetShortestPath(path, "A", "H", float.MaxValue);
            test.PrintCostMatrix();
            DebugUtils.Info("DijkstraTest", string.Concat(path.ToArray()));
        }
示例#7
0
        // Use this for initialization
        void Start()
        {
            EffectConfig config = new EffectConfig();

            config.Id        = EnumUtils.EnumToInt(EffectConfigName.THIRD_PERSON);
            config.Directory = "CameraFollowDemo/ThirdPersonCharacter/Prefabs";
            config.Names     = new List <string>()
            {
                "ThirdPersonController.prefab"
            };
            config.Delay         = false;
            config.StrategyType  = StrategyType.FixedForce;
            config.MaxSize       = 4;
            config.MinSize       = 1;
            config.LifeTime      = 2000;
            config.GoName        = "Test";
            config.Reset         = true;
            config.BehaviourName = typeof(EffectBehaviour).FullName;
            config.Mask          = EnumUtils.EnumToInt(ResourceCacheMask.Testing);
            config.Level         = DeviceLevel.High;
            config.IsTimerOn     = true;

            bool   test = LuaTable.PackLuaTable(config, out Lua);
            string v1   = Lua.ToString();

            DebugUtils.Info("LuaTableTest", v1);

            //Lua.Clear();
            //LuaTable.ParseLuaTable(v1, out Lua);
            //string v2 = Lua.ToString();
            //DebugUtils.Info("LuaTableTest", v2);
        }
示例#8
0
        public static void TestMain()
        {
            MSTKruskal g = new MSTKruskal(9);

            g.AddEdge(0, 1, 4);
            g.AddEdge(0, 7, 8);
            g.AddEdge(1, 2, 8);
            g.AddEdge(1, 7, 11);
            g.AddEdge(2, 3, 7);
            g.AddEdge(2, 5, 4);
            g.AddEdge(8, 2, 2);
            g.AddEdge(3, 4, 9);
            g.AddEdge(3, 5, 14);
            g.AddEdge(5, 4, 10);
            g.AddEdge(6, 5, 2);
            g.AddEdge(8, 6, 6);
            g.AddEdge(7, 6, 1);
            g.AddEdge(7, 8, 7);

            DebugUtils.Info("", "Graph Vertex Count : {0}", g.VertexCount);
            DebugUtils.Info("", "Graph Edge Count : {0}", g.EdgeCount);
            DebugUtils.Info("", "Is there cycle in graph: {0}", g.HasCycle());

            MSTEdge[] mst = g.Kruskal();
            Console.WriteLine("MST Edges:");
            foreach (var edge in mst)
            {
                DebugUtils.Info("", "\t{0}", edge);
            }
        }
示例#9
0
 /// <summary>
 /// 默认结束处理
 /// </summary>
 /// <param name="target"></param>
 /// <param name="total"></param>
 /// <param name="current"></param>
 public override void FinishedProcess(ProcessTimer <CommandTimerType, int> target, int total, int current)
 {
     DebugUtils.Info("AutoCountTimer", "AutoCountTimer FinishedProcess");
     target.SetCount(1, 0);
     target.AddTarget(CommandTimerType.Default);
     target.Produce(ProcessState.COOLDOWN, true, 3);
     target.Produce(ProcessState.PROCESS);
     target.Control(ProcessState.START);
 }
示例#10
0
 public void OnPathTrigger(AbstractCallback callback)
 {
     if (callback != null)
     {
         callback.Run();
         ObjectPools.Instance.Release(callback);
     }
     DebugUtils.Info("FixedPathMoableTest", "OnPathTrigger AbstractCallback");
 }
示例#11
0
 public void PrintConnection()
 {
     foreach (var item1 in mAdjacencyLists)
     {
         NodeType node = item1.Key;
         foreach (var item2 in item1.Value)
         {
             DebugUtils.Info("PrintConnection", "{0} -> {1} : {2}", node.ToString(), item2.Key.ToString(), item2.Value);
         }
     }
 }
示例#12
0
 public virtual void RemoveByDestroy(int instanceId, GameObject obj)
 {
     if (mAcquiredItems.ContainsKey(instanceId))
     {
         mAcquiredItems.Remove(instanceId);
     }
     else
     {
         DebugUtils.Info("ObjectMaster:RemoveByDestroy", string.Format("{0} is not right set", obj.name));
     }
 }
示例#13
0
 public void DrawPlanes()
 {
     // 对比计算值与unity的API是否一致
     // 不过, 这里需要取反方向
     Plane[] planes = GeometryUtility.CalculateFrustumPlanes(Camera.main);
     DebugUtils.Info("planes[0]", string.Format("u:({0},{1},{2},{3}), m:({4},{5},{6},{7})", planes[0].normal[0], planes[0].normal[1], planes[0].normal[2], planes[0].distance, mPlanes[0][0], mPlanes[0][1], mPlanes[0][2], mPlanes[0][3]));
     DebugUtils.Info("planes[1]", string.Format("u:({0},{1},{2},{3}), m:({4},{5},{6},{7})", planes[1].normal[0], planes[1].normal[1], planes[1].normal[2], planes[1].distance, mPlanes[1][0], mPlanes[1][1], mPlanes[1][2], mPlanes[1][3]));
     DebugUtils.Info("planes[2]", string.Format("u:({0},{1},{2},{3}), m:({4},{5},{6},{7})", planes[2].normal[0], planes[2].normal[1], planes[2].normal[2], planes[2].distance, mPlanes[2][0], mPlanes[2][1], mPlanes[2][2], mPlanes[2][3]));
     DebugUtils.Info("planes[3]", string.Format("u:({0},{1},{2},{3}), m:({4},{5},{6},{7})", planes[3].normal[0], planes[3].normal[1], planes[3].normal[2], planes[3].distance, mPlanes[3][0], mPlanes[3][1], mPlanes[3][2], mPlanes[3][3]));
     DebugUtils.Info("planes[4]", string.Format("u:({0},{1},{2},{3}), m:({4},{5},{6},{7})", planes[4].normal[0], planes[4].normal[1], planes[4].normal[2], planes[4].distance, mPlanes[4][0], mPlanes[4][1], mPlanes[4][2], mPlanes[4][3]));
     DebugUtils.Info("planes[5]", string.Format("u:({0},{1},{2},{3}), m:({4},{5},{6},{7})", planes[5].normal[0], planes[5].normal[1], planes[5].normal[2], planes[5].distance, mPlanes[5][0], mPlanes[5][1], mPlanes[5][2], mPlanes[5][3]));
 }
示例#14
0
        private void OnGUI()
        {
            if (GUILayout.Button("Save XML"))
            {
                SaveXMl();
            }

            if (GUILayout.Button("Load XML"))
            {
                XmlDataLoader.Instance.InitAndLoad(XmlFileNameDefine.Namespace, XmlFileNameDefine.SuffixFlag);
                DebugUtils.Info("XmlDataTest", TestXmlData.DataMap.Count);
            }
        }
示例#15
0
        public object FormatXMLData(string fileName, Type dicType, Type type, string fileContent = null)
        {
            object result = null;

            if (string.IsNullOrEmpty(fileName))
            {
                DebugUtils.Warning("FormatXMLData", "fileName IsNullOrEmpty");
                return(result);
            }
            try
            {
                result = dicType.GetConstructor(Type.EmptyTypes).Invoke(null);
                Dictionary <Int32, Dictionary <String, String> > map;//Int32 为 mId, string 为 属性名, string 为 属性值
                if (fileContent != null && XmlFileUtils.LoadIntMap(fileContent, out map))
                {
                    var props = type.GetProperties();//获取实体属性
                    foreach (var item in map)
                    {
                        var t = type.GetConstructor(Type.EmptyTypes).Invoke(null);//构造实体实例
                        foreach (var prop in props)
                        {
                            if (prop.Name == XmlData.mKeyFieldName)
                            {
                                prop.SetValue(t, item.Key, null);
                            }
                            else
                            {
                                if (item.Value.ContainsKey(prop.Name))
                                {
                                    var value = XmlFileUtils.GetValue(item.Value[prop.Name], prop.PropertyType);
                                    prop.SetValue(t, value, null);
                                }
                            }
                        }
                        dicType.GetMethod("Add").Invoke(result, new object[] { item.Key, t });
                    }
                    DebugUtils.Info(fileName + " Loaded ", map.Count);
                }
                else
                {
                    result = null;
                    DebugUtils.Warning(fileName + " Not Founded ", "Please Check Timestamps right");
                }
            }
            catch (Exception ex)
            {
                DebugUtils.Error("XmlData", ex.Message);
            }
            return(result);
        }
示例#16
0
        public void PrintCostMatrix()
        {
            List <NodeType> keys = mAdjacencyLists.Keys.ToList();
            string          temp = "";

            foreach (NodeType key in keys)
            {
                temp = temp + " " + key.ToString();
            }
            DebugUtils.Info("PrintCostMatrix1", temp);

            for (int i = 0; i < mAdjacencyLists.Count; ++i)
            {
                temp = keys[i].ToString();
                for (int j = 0; j < mAdjacencyLists.Count; ++j)
                {
                    temp = string.Format("{0} {1}", temp, mCostMatrix[i * mAdjacencyLists.Count + j]);
                }
                DebugUtils.Info("PrintCostMatrix2", temp);
            }
        }
示例#17
0
 private void CheckLifeExpired()
 {
     DebugUtils.Info("ObjectPools", "CheckLifeExpired");
     ClearEmptyPools.Clear();
     foreach (ObjectPool pool in Pools.Values)
     {
         pool.RemoveExpired();
         if (pool.IsEmpty())
         {
             ClearEmptyPools.Add(pool.Type);
         }
     }
     if (ClearEmptyPools.Count > 0)
     {
         foreach (Type type in ClearEmptyPools)
         {
             Pools.Remove(type);
         }
         // 这个可以屏蔽
         // GC.Collect();
     }
 }
示例#18
0
        private void PrintInfo()
        {
            string printStr = "";
            int    cnt      = 0;

            foreach (ResourceCacheEntity entity in mAcquiredItems.Values)
            {
                cnt      = cnt + 1;
                printStr = printStr + " " + entity.ManagerId;
            }
            DebugUtils.Info("ResourceCachePools:PrintInfo", string.Format("Entity Used Total: {0} {1}", cnt, printStr));
            cnt      = 0;
            printStr = "";
            int totalCnt = 0;

            foreach (ResourceCachePool pool in mPools.Values)
            {
                cnt      = cnt + 1;
                printStr = printStr + " id: " + pool.GetManagerId() + ", count: " + pool.Count;
                totalCnt = totalCnt + pool.Count;
            }
            DebugUtils.Info("ResourceCachePools:PrintInfo", string.Format("Manager Cached Total:  {0}, {1}", totalCnt, printStr));
        }
示例#19
0
 private void OnGUI()
 {
     if (GUILayout.Button("Save"))
     {
         Save();
     }
     if (!IsInitialized && GUILayout.Button("Initialize"))
     {
         XmlDataLoader.Instance.InitAndLoad(XmlFileNameDefine.Namespace, XmlFileNameDefine.SuffixFlag);
         DebugUtils.Info("EffectConfig", "DataPath " + Application.dataPath + " Count: " + EffectConfig.DataMap.Count);
         EffectPools.Initialize(ResourceCacheMask.Testing, EffectConfig.DataMap);
         IsInitialized = true;
     }
     if (IsInitialized)
     {
         if (GUILayout.Button("Play"))
         {
             int poolId = EnumUtils.EnumToInt(EffectConfigName.THIRD_PERSON);
             ResourceCacheBehaviourParam param = new ResourceCacheBehaviourParam();
             EffectPools.Play(poolId, 5000, ResourceCacheBindParent.WorldEffectBind, param);
         }
     }
 }
示例#20
0
 public void OnPathEnd()
 {
     DebugUtils.Info("FixedPathMoableTest", "OnPathEnd");
 }
示例#21
0
 private void InsertCallback(int id)
 {
     DebugUtils.Info("SequenceBehaviourTest", "InsertCallback ", id);
 }
示例#22
0
 private void OnComplete(int id)
 {
     DebugUtils.Info("SequenceBehaviourTest", "OnComplete ", id);
 }
示例#23
0
文件: OOCE.cs 项目: ByteKay/Nullspace
        /// <summary>
        /// 遮挡剔除 算法入口
        /// </summary>
        private void OcclusionCull()
        {
            Stat[0] = Stat[1] = 0;
            Map.Clear();
            mMinQueue.Clear();
            mMaxQueue.Clear();
            PushBox2(Tree.Root, ref Tree.Root.Box);
            // 按 负无穷范数(最小值) 作为优先权中 遍历
            while (mMinQueue.Size > 0)
            {
                OONode nd = (OONode)mMinQueue.Dequeue();
                nd.Distribute(mMaxLevel, mMaxItems);
                MinMax(ref nd.Box, ref nd.Box.Zmin, ref nd.Box.Zmax);
                if (nd.SplitAxis != OONode.LEAF) // 非叶节点
                {
                    // 该节点存在两个子节点
                    // 如果 该节点 Visible 为可见 ,则不需要进一步计算
                    // 如果 该结点 Visible 为不可见,则进一步计算判断可见性
                    // KDTree的Node不是每次重新分配,带有一定的缓存功能。所以, Visible 可以加速计算
                    // 存在一个问题:如果所有的物体都分到了一个Node中,可能会不停的划分到最大深度。后期需要优化
                    if ((nd.Visible != 0) || IsVisible(1, ref nd.Box, nd.Box.Zmin) != 0)
                    {
                        // 标记为可见
                        nd.Visible = 1;
                        // 父节点可见,接下来判断左右孩子结点的可见性
                        PushBox2(nd.Left, ref nd.Left.Box);
                        PushBox2(nd.Right, ref nd.Right.Box);
                    }
                    else
                    {
                        // 标记为不可见
                        nd.Visible = 0;
                        if (nd.Parent != null)
                        {
                            nd.Parent.Visible = 0;
                        }
                    }
                }
                else // 叶节点
                {
                    // 叶节点的Box测试
                    if (IsVisible(1, ref nd.Box, nd.Box.Zmin) != 0)
                    {
                        OOItem itm = nd.Head.Next;
                        // 保存需要绘制的物体,以 Zmax 为优先级排序
                        while (itm != nd.Tail)
                        {
                            if (itm.Obj.TouchId != Tree.TouchCounter)
                            {
                                itm.Obj.TouchId = Tree.TouchCounter;
                                OOModel obj = itm.Obj;
                                MinMax(ref obj.Box, ref obj.Box.Zmin, ref obj.Box.Zmax);
                                // 查询物体的Box是否可见
                                if (IsVisible(0, ref obj.Box, 0) != 0)
                                {
                                    // 如果一个物体的Box可见,则为待绘制的物体
                                    mMaxQueue.Enqueue(obj.Box.Zmax, obj, obj.Box.Zmax);
                                    obj.Next = null;
                                    if (mVisible == null)
                                    {
                                        mVisible = mTail = obj;
                                    }
                                    else
                                    {
                                        mTail.Next = obj;
                                        mTail      = obj;
                                    }
                                }
                            }
                            itm = itm.Next;
                        }
                    }
                    if (nd.Parent != null)
                    {
                        nd.Parent.Visible = 0;
                    }
                }
            }

#if TEST_DRAW
            VisualKDTree(Tree.Root);
            if (mMaxQueue.Size > 0)
            {
                DebugUtils.Info("OcclusionCull", "Before Max Left: ", mMaxQueue.Size);
                FlushOccluders(float.MaxValue);
                DebugUtils.Info("OcclusionCull", "After Max Left: ", mMaxQueue.Size);
            }
            Map.DrawScreenShot();
#endif
        }
示例#24
0
 private static void DefaultProgress(int index, int count, string name)
 {
     DebugUtils.Info("XmlData", string.Format("{0} {1} of {2} completed", name, index, count));
 }
示例#25
0
 private static void DefaultCompleted()
 {
     DebugUtils.Info("XmlData", "DefaultCompleted");
 }
示例#26
0
        private bool LoadData(string timeStamps, List <Type> gameDataType)
        {
            UnloadAB();
            var count = gameDataType.Count;
            var i     = 1;

#if LoadXmlAsync
            mLoadResult = true;
            List <Thread> threads = new List <Thread>();
#endif
            foreach (var item in gameDataType)
            {
                var p = item.GetProperty(XmlData.mKeyValueFieldName, ~BindingFlags.DeclaredOnly);
                XmlDataAttribute attr = XmlDataAttribute.GetCustomAttribute(item, typeof(XmlDataAttribute), false) as XmlDataAttribute;
                if (p != null && attr != null)
                {
                    string content = GetXmlContent(attr.mFileName + timeStamps);
                    if (String.IsNullOrEmpty(content))
                    {
                        // 没有内容,文件不存在或者时间戳有问题,加载失败
                        DebugUtils.Info("XmlData", attr.mFileName + timeStamps, " IsNullOrEmpty");
                        return(false);
                    }
#if LoadXmlAsync
                    XmlThreadData xmlData;
                    xmlData.FileName    = attr.mFileName + timeStamps;
                    xmlData.DicType     = p.PropertyType;
                    xmlData.Type        = item;
                    xmlData.p           = p;
                    xmlData.Loader      = this;
                    xmlData.index       = i;
                    xmlData.count       = count;
                    xmlData.FileContent = content;
                    Thread t = new Thread(new ParameterizedThreadStart(FormatXMLDataThread));
                    t.Start(xmlData);
                    threads.Add(t);
#else
                    UnityEngine.Profiling.Profiler.BeginSample("LoadData");
                    var result = FormatXMLData(attr.mFileName, p.PropertyType, item, content);
                    if (result == null)
                    {
                        return(false);
                    }
                    p.GetSetMethod().Invoke(null, new object[] { result });
                    string name = attr != null ? attr.mFileName : null;
                    if (mProgress != null)
                    {
                        mProgress(i, count, name);
                    }
                    UnityEngine.Profiling.Profiler.EndSample();
#endif
                }
                i++;
            }

#if LoadXmlAsync
            DebugUtils.Info("XmlData", "thread.Join began");
            foreach (var thread in threads)
            {
                thread.Join();
            }

            UnloadAB();

            DebugUtils.Info("XmlData", "thread.Join end");
            // 多线程加载过程中可能有问题
            return(mLoadResult);
#else
            return(true);
#endif
        }
示例#27
0
文件: OOCE.cs 项目: ByteKay/Nullspace
        /// <summary>
        /// 绘制一个物体到缓冲区
        /// </summary>
        /// <param name="obj">待绘制物体</param>
        private void DrawOccluder(OOModel obj)
        {
            // 获取物体的模型
            OOMesh mdl = obj.Model;
            // 计算 ModelView 矩阵.注意:这里需要相机的变换矩阵的逆矩阵
            // 另一问题:左手系和右手系问题。
            Matrix4x4 modelViewMatrix = mView * obj.ModelWorldMatrix;

            // 变换mesh的顶点到 相机空间 和 裁剪空间
            for (int i = 0; i < mdl.NumVert; i++)
            {
                // Vector3 p = obj.ModelWorldMatrix.MultiplyPoint3x4(mdl.Vertices[i]);
                Vector4 tmp = modelViewMatrix.MultiplyPoint3x4(mdl.Vertices[i]);
                mdl.CameraSpaceVertices[i] = tmp;
                tmp.w = 1;
                mdl.ClipSpaceVertices[i] = mProject * tmp;
            }
            int xmin = 100000;
            int xmax = 0;
            int ymin = 100000;
            int ymax = 0;

            // 遍历所有面
            for (int i = 0; i < mdl.NumFace; i++)
            {
                // 面索引
                int p1 = mdl.Faces[i][0];
                int p2 = mdl.Faces[i][1];
                int p3 = mdl.Faces[i][2];
                // 计算法向量。此处可以优化成:初始化时计算,而后变换一下法向量即可。
                // 构建右手坐标系 逆时针为正方向
                Vector3 a = mdl.CameraSpaceVertices[p2] - mdl.CameraSpaceVertices[p1];
                Vector3 b = mdl.CameraSpaceVertices[p3] - mdl.CameraSpaceVertices[p1];
                Vector3 n = Vector3.Cross(a, b);
                // 背面剔除。可计算相机的朝向,然后与三角面的法线计算即可。
                // 此处实际上计算 Camera 空间 原点到平面的距离是否小于0
                if (Vector3.Dot(n, mdl.CameraSpaceVertices[p1]) < 0)
                {
                    mClip.mClipSpaceVertices[0] = mdl.ClipSpaceVertices[p1];
                    mClip.mClipSpaceVertices[1] = mdl.ClipSpaceVertices[p2];
                    mClip.mClipSpaceVertices[2] = mdl.ClipSpaceVertices[p3];
                    // 裁剪计算
                    int nv = mClip.ClipAndProject(3);
#if TEST_DRAW_ONE
                    DebugUtils.Info("ClipAndProject", string.Format("world1({0}, {1})", mClip.mScreenSpaceVertices[0][0], mClip.mScreenSpaceVertices[0][1]));
                    DebugUtils.Info("ClipAndProject", string.Format("world2({0}, {1})", mClip.mScreenSpaceVertices[1][0], mClip.mScreenSpaceVertices[1][1]));
                    DebugUtils.Info("ClipAndProject", string.Format("world3({0}, {1})", mClip.mScreenSpaceVertices[2][0], mClip.mScreenSpaceVertices[2][1]));
#endif
                    // 裁剪判断
                    if (nv > 2)
                    {
                        // 裁剪后,计算屏幕区域的AABB
                        for (int j = 0; j < nv; j++)
                        {
                            if (mClip.mScreenSpaceVertices[j][0] < xmin)
                            {
                                xmin = mClip.mScreenSpaceVertices[j][0];
                            }
                            else
                            {
                                if (mClip.mScreenSpaceVertices[j][0] > xmax)
                                {
                                    xmax = mClip.mScreenSpaceVertices[j][0];
                                }
                            }
                            if (mClip.mScreenSpaceVertices[j][1] < ymin)
                            {
                                ymin = mClip.mScreenSpaceVertices[j][1];
                            }
                            else if (mClip.mScreenSpaceVertices[j][1] > ymax)
                            {
                                ymax = mClip.mScreenSpaceVertices[j][1];
                            }
                        }
                        // 绘制多边形到缓冲
                        Map.DrawPolygon(mClip.mScreenSpaceVertices, nv);
                    }
                }
            }
            // 设置该区域内有被覆盖
            Map.SetDirtyRectangle(xmin, ymin, xmax, ymax);
        }
示例#28
0
 public void OnPathStart()
 {
     DebugUtils.Info("FixedPathMoableTest", "OnPathStart");
 }
示例#29
0
 public void OnPathTrigger(int triggerId)
 {
     DebugUtils.Info("FixedPathMoableTest", "OnPathTrigger ", triggerId);
 }
示例#30
0
 public void TriggerCallback(int test)
 {
     DebugUtils.Info("FixedPathMoableTest", "TriggerCallback ", test);
 }