public override void Initialize() { _position = new Properties.Vector3(0, 0, 0); _position.PropertyChanged += PositionPropertyChanged; Engine.QueueInitializationAction(() => { _viewCamera = Engine.Renderer.Scene.CreateCamera("ViewPoint"); _viewCamera.ProjectionType = ProjectionType.PT_PERSPECTIVE; _viewCamera.Position = Mogre.Vector3.ZERO; _viewCamera.LookAt(Mogre.Vector3.ZERO); _viewCamera.NearClipDistance = 0.01f; _viewCamera.FarClipDistance = 1000.0f; _viewCamera.FOVy = new Degree(100f); _viewCamera.AutoAspectRatio = true; Engine.Renderer.Camera = _viewCamera; Engine.Renderer.RenderWindow.AddViewport(_viewCamera); _initialized = true; }); }
private void RenderFrame() { if (!MogitorsRoot.Instance.IsSceneLoaded || (Width <= 0 && Height <= 0)) { return; } if (MogitorsRoot.Instance.IsClearScreenNeeded) { Mogre.Camera clearCam = MogitorsRoot.Instance.SceneManager.CreateCamera("sbtClearCam"); clearCam.NearClipDistance = 0.0001f; clearCam.FarClipDistance = 0.0002f; clearCam.LookAt(0, -1, 0); MogitorsRoot.Instance.RenderTarget.AddViewport(clearCam, 0); } if (PreRender != null) { PreRender(this, EventArgs.Empty); } this.root.RenderOneFrame(); if (PostRender != null) { PostRender(this, EventArgs.Empty); } if (MogitorsRoot.Instance.IsClearScreenNeeded) { MogitorsRoot.Instance.RenderTarget.RemoveViewport(0); MogitorsRoot.Instance.SceneManager.DestroyCamera("sbtClearCam"); MogitorsRoot.Instance.IsClearScreenNeeded = false; } }
/// <summary> /// Converts a 3D scene position to a 2D screen position (in relative screen size, 0.0-1.0). /// </summary> /// <param name="cam"></param> /// <param name="pt"></param> /// <returns></returns> public static Mogre.Vector2 SceneToScreen(Mogre.Camera cam, Mogre.Vector3 pt) { Mogre.Vector3 result = cam.ProjectionMatrix * cam.ViewMatrix * pt; return(new Mogre.Vector2((result.x + 1) / 2, (-result.y + 1) / 2)); }
/// <summary> /// Converts a 2D screen coordinate (in pixels) to a 3D ray into the scene. /// </summary> /// <param name="cam"></param> /// <param name="pt"></param> /// <returns></returns> public static Mogre.Ray ScreenToScene(Mogre.Camera cam, Mogre.Vector2 pt) { return(cam.GetCameraToViewportRay(pt.x, pt.y)); }
/// <summary> /// Returns a 3D ray into the scene that is directly underneath the cursor. /// </summary> /// <param name="cam"></param> /// <returns></returns> public Mogre.Ray GetCursorRay(Mogre.Camera cam) { return(ScreenToScene(cam, new Mogre.Vector2(cursor._getLeft(), cursor._getTop()))); }
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; }
public override bool ObjectRendering(Mogre.MovableObject o, Mogre.Camera c) { return(base.ObjectRendering(o, c)); }