示例#1
0
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            MogreApp.setLocations(prj.getMogreLocations());
            SetupMogre();
            Mogre.SceneManager sm = app.SceneManager;

            foreach (MogreGis.FilterGraph graph in prj.getFilterGraphs())
            {
                foreach (osgGISProjects.Source source in prj.getSources())
                {
                    if (Path.GetExtension(source.getURI()) != ".shp")
                    {
                        throw new NotImplementedException();
                    }

                    if (source.getName() == graph.getName())
                    {
                        MogreGis.FilterEnv   env         = null;
                        MogreGis.FeatureList featureList = null;

                        FeatureDataSet ds = new FeatureDataSet();
                        source.DataSource.Open();
                        source.DataSource.ExecuteIntersectionQuery(source.DataSource.GetExtents(), ds);
                        source.DataSource.Close();
                        FeatureDataTable features = (FeatureDataTable)ds.Tables[0];
                        featureList = MogreGis.Feature.DataTableToList(features);

                        foreach (Script script in prj.getScripts())
                        {
                            Registry.instance().GetEngine("Python").run(script);
                        }

                        foreach (Feature feature in featureList)
                        {
                            SharpMapSpatialReferenceFactory smsrf = new SharpMapSpatialReferenceFactory();
                            ShapeFile shp = new ShapeFile(source.getURI());
                            shp.Open();
                            SharpMapSpatialReference sr;
                            sr = (SharpMapSpatialReference)smsrf.createSRSfromWKT(shp.CoordinateSystem.WKT);
                            feature.getGeometry().SpatialReference = sr;
                        }

                        env = new MogreGis.FilterEnv(sm, "env" + graph.getName());
                        env.setScriptEngine(Registry.instance().GetEngine("Python"));
                        foreach (MogreGis.Filter filter in graph.getFilters())
                        {
                            if (filter is MogreGis.FragmentFilter)
                            {
                                (filter as MogreGis.FragmentFilter).process(featureList, env);
                            }
                            if (filter is MogreGis.FeatureFilter)
                            {
                                featureList = (filter as MogreGis.FeatureFilter).process(featureList, env);
                            }
                        }
                    }
                }
            }
            app.getRoot().StartRendering();
        }
示例#2
0
        //
        //ORIGINAL LINE: Ogre::MeshPtr transformToMesh(const string& name, const Ogre::String& group = "General") const
        //
        public MeshPtr transformToMesh(string name, string group)
        {
            //Mogre.SceneManager sceneMgr = Root.Singleton.GetSceneManagerIterator().Current;
            Mogre.SceneManagerEnumerator.SceneManagerIterator item = Root.Singleton.GetSceneManagerIterator();
            item.MoveNext();
            Mogre.SceneManager sceneMgr = item.Current;
            item.Dispose();
            Mogre.ManualObject manual = sceneMgr.CreateManualObject(name);
            manual.Begin("BaseWhiteNoLighting", RenderOperation.OperationTypes.OT_TRIANGLE_LIST);

            foreach (var it in mVertices)
            {
                manual.Position(it.mPosition);
                manual.TextureCoord(it.mUV);
                manual.Normal(it.mNormal);
            }
            foreach (var it in mIndices)
            {
                manual.Index((ushort)it);
            }
            manual.End();

            Mogre.MeshPtr mesh = manual.ConvertToMesh(name, group);

            sceneMgr.DestroyManualObject(manual);

            return(mesh);
        }
示例#3
0
        //
        //ORIGINAL LINE: Ogre::MeshPtr realizeMesh(const string& name = "") const
        //
        public MeshPtr realizeMesh(string name)
        {
            SceneManagerEnumerator.SceneManagerIterator item = Root.Singleton.GetSceneManagerIterator();
            item.MoveNext();//
            Mogre.SceneManager smgr = item.Current;
            item.Dispose();
            Mogre.ManualObject manual = smgr.CreateManualObject(name);
            manual.Begin("BaseWhiteNoLighting", RenderOperation.OperationTypes.OT_LINE_STRIP);

            foreach (var itPos in mPoints)
            {
                manual.Position(itPos);
            }
            if (mClosed)
            {
                manual.Position(mPoints[0]);
            }
            manual.End();

            Mogre.MeshPtr mesh = MeshManager.Singleton.CreateManual(name, "General");
            if (name == "")
            {
                mesh = manual.ConvertToMesh(Utils.getName("mesh_procedural_"));
            }
            else
            {
                mesh = manual.ConvertToMesh(name);
            }

            return(mesh);
        }
示例#4
0
        //
        //ORIGINAL LINE: MeshPtr realizeMesh(const string& name ="")
        public MeshPtr realizeMesh(string name)
        {
            //Mogre.SceneManager smgr = Root.Singleton.GetSceneManagerIterator().Current;
            Mogre.SceneManagerEnumerator.SceneManagerIterator item = Root.Singleton.GetSceneManagerIterator();
            item.MoveNext();
            Mogre.SceneManager smgr = item.Current;
            item.Dispose();
            ManualObject manual = smgr.CreateManualObject(name);

            //for (List<Shape>.Enumerator it = mShapes.GetEnumerator(); it.MoveNext(); ++it)
            foreach (var it in mShapes)
            {
                manual.Begin("BaseWhiteNoLighting", RenderOperation.OperationTypes.OT_LINE_STRIP);
                it._appendToManualObject(manual);
                manual.End();
            }

            MeshPtr mesh = null;// MeshManager.Singleton.CreateManual(Guid.NewGuid().ToString("N"), "General"); //new MeshPtr();

            if (name == "")
            {
                mesh = manual.ConvertToMesh(Utils.getName("mutishape_procedural_"));
            }
            else
            {
                mesh = manual.ConvertToMesh(name);
            }
            smgr.DestroyManualObject(manual);
            return(mesh);
        }
        /// Builds the normals representation as a manual object
        /// \exception Ogre::InvalidStateException The input triangle buffer must not be null
        /// \exception Ogre::InvalidStateException Scene Manager is not set in OGRE root object
        //
        //ORIGINAL LINE: ManualObject* buildManualObject() const
        public ManualObject buildManualObject()
        {
            if (mTriangleBuffer == null)
            {
                OGRE_EXCEPT("Ogre::Exception::ERR_INVALID_STATE", "The input triangle buffer must not be null", "Procedural::ShowNormalsGenerator::buildManualObject()");
            }
            ;
            //SceneManager sceneMgr = Root.Singleton.GetSceneManagerIterator().Current;
            Mogre.SceneManagerEnumerator.SceneManagerIterator item = Root.Singleton.GetSceneManagerIterator();
            item.MoveNext();
            Mogre.SceneManager sceneMgr = item.Current;
            item.Dispose();
            if (sceneMgr == null)
            {
                OGRE_EXCEPT("Ogre::Exception::ERR_INVALID_STATE", "Scene Manager must be set in Root", "Procedural::ShowNormalsGenerator::buildManualObject()");
            }
            ;
            ManualObject manual = sceneMgr.CreateManualObject("debug_procedural_" + Guid.NewGuid().ToString("N"));

            manual.Begin("BaseWhiteNoLighting", RenderOperation.OperationTypes.OT_LINE_LIST);
            std_vector <TriangleBuffer.Vertex> vertices = mTriangleBuffer.getVertices();

            //for (List<TriangleBuffer.Vertex>.Enumerator it = vertices.GetEnumerator(); it.MoveNext(); ++it)
            foreach (var it in vertices)
            {
                manual.Position(it.mPosition);
                manual.Position(it.mPosition + it.mNormal * mSize);

                if (mVisualStyle == VisualStyle.VS_ARROW)
                {
                    Vector3 axis2 = it.mNormal.Perpendicular;
                    Vector3 axis3 = it.mNormal.CrossProduct(axis2);

                    manual.Position(it.mPosition + it.mNormal * mSize);
                    manual.Position(it.mPosition + (.8f * it.mNormal + .1f * axis2) * mSize);

                    manual.Position(it.mPosition + it.mNormal * mSize);
                    manual.Position(it.mPosition + .8f * (it.mNormal - .1f * axis2) * mSize);

                    manual.Position(it.mPosition + it.mNormal * mSize);
                    manual.Position(it.mPosition + .8f * (it.mNormal + .1f * axis3) * mSize);

                    manual.Position(it.mPosition + it.mNormal * mSize);
                    manual.Position(it.mPosition + .8f * (it.mNormal - .1f * axis3) * mSize);
                }
            }
            manual.End();

            return(manual);
        }
        public MeshPtr buildMesh(string name, string group)
        {
            System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(name));
            if (string.IsNullOrEmpty(name))
            {
                name = Utils.getName("debugrender_procedural");
            }
            //SceneManager sceneMgr = Root.Singleton.GetSceneManagerIterator().Current;
            Mogre.SceneManagerEnumerator.SceneManagerIterator item = Root.Singleton.GetSceneManagerIterator();
            item.MoveNext();
            Mogre.SceneManager sceneMgr = item.Current;
            item.Dispose();
            ManualObject mo   = buildManualObject();
            MeshPtr      mesh = mo.ConvertToMesh(name, group);

            sceneMgr.DestroyManualObject(mo);

            return(mesh);
        }
示例#7
0
        public bool Initialise()
        {
            m_Shutdown = false;

            m_Rand = new Random();

            new Mogre.LogManager();
            m_Log = Mogre.LogManager.Singleton.CreateLog("OgreLogfile.log", true, true, false);

            m_Root = new Root();
            ConfigFile cf = new ConfigFile();
            cf.Load("Resources.cfg", "\t:=", true);

            ConfigFile.SectionIterator seci = cf.GetSectionIterator();

            while (seci.MoveNext())
            {
                ConfigFile.SettingsMultiMap settings = seci.Current;
                foreach (KeyValuePair<string, string> pair in settings)
                    ResourceGroupManager.Singleton.AddResourceLocation(pair.Value, pair.Key, seci.CurrentKey);
            }

            if (!m_Root.RestoreConfig())    // comment this line to view configuration dialog box
                if (!m_Root.ShowConfigDialog())
                    return false;

            m_RenderWindow = m_Root.Initialise(true);
            ResourceGroupManager.Singleton.InitialiseAllResourceGroups();

            m_SceneManager = m_Root.CreateSceneManager(SceneType.ST_GENERIC);
            m_Camera = m_SceneManager.CreateCamera("MainCamera");
            m_Viewport = m_RenderWindow.AddViewport(m_Camera);
            m_Camera.NearClipDistance = 0.1f;
            m_Camera.FarClipDistance = 1000.0f;

            MOIS.ParamList pl = new MOIS.ParamList();
            IntPtr windowHnd;
            m_RenderWindow.GetCustomAttribute("WINDOW", out windowHnd);
            pl.Insert("WINDOW", windowHnd.ToString());

            m_InputManager = MOIS.InputManager.CreateInputSystem(pl);

            m_Keyboard = (MOIS.Keyboard)m_InputManager.CreateInputObject(MOIS.Type.OISKeyboard, true);
            m_Mouse = (MOIS.Mouse)m_InputManager.CreateInputObject(MOIS.Type.OISMouse, true);

            m_NewtonWorld = new World();
            m_NewtonWorld.SetWorldSize(new AxisAlignedBox(-500, -500, -500, 500, 500, 500));
            m_NewtonDebugger = new Debugger(m_NewtonWorld);
            m_NewtonDebugger.Init(m_SceneManager);

            m_GameCamera = new GameCamera();
            m_ObjectManager = new ObjectManager();
            m_StateManager = new StateManager();
            m_PhysicsManager = new PhysicsManager();
            m_SoundDict = new SoundDict();

            /*
             * To co tu mamy nalezy przeniesc jak najszybciej do ogitora
             * Materialy dla kazdej mapy moga byc inne inne parametry inne powiazania itp wiec tworzone
             * sa oddzielnie dla kazdej nowej mapy, a potem przy obiektach konkretny material jest przypsiywany
             * przy starcie ladowania physicsmanager powinien byc wyczyszczony
             */

            //inicjalizacja konkretnych obiektow, w sumie tylko nadanie nazw w dictionary
            m_PhysicsManager.addMaterial("Metal");
            //podstawowe
            m_PhysicsManager.addMaterial("Ground");
            m_PhysicsManager.addMaterial("Trigger");
            m_PhysicsManager.addMaterial("Player");
            m_PhysicsManager.addMaterial("NPC");

            //laczenie materialow w pary
            //dla kazdej mapy rozne powiazania (zapewne beda sie powtarzac ale im wieksza ilosc
            //materialow tym wieksze obciazenie dla silnika wiec nalezy to ograniczac
            //dla kazdej pary materialow mozna ustawic rozne parametry kolizji
            //jak tarcie, elastycznosc, miekkosc kolizji oraz callback ktory jest wywolywany przy kolizji
            m_PhysicsManager.addMaterialPair("Metal", "Metal");
            m_PhysicsManager.getMaterialPair("MetalMetal").SetDefaultFriction(1.5f, 1.4f);
            m_PhysicsManager.setPairCallback("MetalMetal", "MetalCallback");

            //obowiazkowe
            m_PhysicsManager.addMaterialPair("Trigger", "Player");//wyzwalacze pozycja obowiazkowa
            m_PhysicsManager.setPairCallback("TriggerPlayer", "TriggerCallback");

            //obowiazkowe
            m_PhysicsManager.addMaterialPair("Ground", "Player");//ground material podstawowy
            m_PhysicsManager.getMaterialPair("GroundPlayer").SetDefaultElasticity(0);
            m_PhysicsManager.setPairCallback("GroundPlayer", "GroundPlayerCallback");

            // NPC:
            //m_PhysicsManager.addMaterialPair("NPC", "NPC");//ground material podstawowy
            //m_PhysicsManager.getMaterialPair("NPCNPC").SetDefaultElasticity(0);
            //m_PhysicsManager.setPairCallback("NPCNPC", "NPCNPCCallback");

            //m_PhysicsManager.addMaterialPair("Ground", "NPC");//ground material podstawowy
            //m_PhysicsManager.getMaterialPair("GroundNPC").SetDefaultElasticity(0);
            // m_PhysicsManager.setPairCallback("GroundNPC", "GroundPlayerCallback");
            /*
                                    * Koniec inicjalizacji materialow ktora musi sie znalezc w opisie mapy, dla niekumatych w ogitorze.
                                    */

            CreateOgitorScene();
            //CreateScene();

            /*
             *  Rejestracja listenerów
             **/
            m_Root.FrameRenderingQueued += new FrameListener.FrameRenderingQueuedHandler(Update);

            m_Keyboard.KeyPressed += new MOIS.KeyListener.KeyPressedHandler(KeyPressed);
            m_Keyboard.KeyReleased += new MOIS.KeyListener.KeyReleasedHandler(KeyReleased);

            m_Keyboard.KeyPressed += new MOIS.KeyListener.KeyPressedHandler(m_StateManager.KeyPressed);
            m_Keyboard.KeyReleased += new MOIS.KeyListener.KeyReleasedHandler(m_StateManager.KeyReleased);
            m_Mouse.MouseMoved += new MOIS.MouseListener.MouseMovedHandler(m_StateManager.MouseMoved);
            m_Mouse.MousePressed += new MOIS.MouseListener.MousePressedHandler(m_StateManager.MousePressed);
            m_Mouse.MouseReleased += new MOIS.MouseListener.MouseReleasedHandler(m_StateManager.MouseReleased);

            Tools.ConsoleParser.Init();
            m_RenderWindow.SetDeactivateOnFocusChange(false);

            return true;
        }
示例#8
0
        public void render2d(Project project, PictureBox picBox)
        {
            SharpMap.Map myMap = new SharpMap.Map();

            foreach (BuildLayer layer in project.getLayers())
            {
                Source source = layer.getSource();

                BoundingBox    envelope = new BoundingBox(-1000.0, -1000.0, 1000.0, 1000.0);//TODO
                FeatureDataSet ds       = new FeatureDataSet();
                source.DataSource.Open();
                source.DataSource.ExecuteIntersectionQuery(envelope, ds);
                source.DataSource.Close();

                FeatureDataTable features = (FeatureDataTable)ds.Tables[0];

                string label = "Trace test:\n";

                foreach (FeatureDataRow row in features)
                {
                    foreach (Object item in row.ItemArray)
                    {
                        label += " - " + item;
                    }
                    label += "\n";
                }

                setLabel(label);

                //Show map

                //Filters
                FilterGraph graph = project.getFilterGraph(source.getName());
                if (graph != null)
                {
                    foreach (FeatureFilter filter in graph.getFilters())
                    {
                        //aplicar filtro segun el tipo
                        Mogre.DefaultSceneManagerFactory dsmf = new DefaultSceneManagerFactory();
                        Mogre.SceneManager sm  = dsmf.CreateInstance("scenemanager");
                        FilterEnv          env = new FilterEnv(sm, "env");
                        foreach (MogreGis.Resource resource in project.getResources())
                        {
                            env.getSession().Resources.addResource(resource);
                        }
                        FeatureList list = Feature.DataTableToList(features);
                        filter.process(list, env);
                        //falta devolver la lista y procesarla ***************************************
                    }
                }

                SharpMap.Layers.VectorLayer myLayer = new SharpMap.Layers.VectorLayer(layer.getName());
                myLayer.DataSource = source.DataSource;
                myMap.Layers.Add(myLayer);
            }

            myMap.Size = new Size(picBox.Width, picBox.Height);
            myMap.ZoomToExtents();
            picBox.Image = myMap.GetMap();
            this.map     = myMap;
        }