public TerrainView(TerrainModel terrainmodel) { LogFile.WriteLine("TerrainView( " + terrainmodel + ")"); this.terrainmodel = terrainmodel; terrainmodel.TerrainModified += new TerrainModel.TerrainModifiedHandler(terrainmodel_TerrainModified); GraphicsHelperGl g = new GraphicsHelperGl(); g.CheckError(); foreach (MapTextureStageModel maptexturestagemodel in terrainmodel.texturestages) { LogFile.WriteLine("create maptexturestageview for " + maptexturestagemodel); mapviewbymapmodel.Add(maptexturestagemodel, new MapTextureStageView(maptexturestagemodel)); } g.CheckError(); renderableheightmap = new RenderableHeightMap(this, terrainmodel, 1, 1); //renderableallfeatures = new RenderableAllFeatures(this); // water must be last, otherwise you cant see through it ;-) renderablewater = new RenderableWater(new Vector3(), new Vector2(terrainmodel.HeightMapWidth, terrainmodel.HeightMapHeight)); // minimap last, covers everything else //renderableminimap = new RenderableMinimap(this, renderableheightmap); }
public TerrainView( TerrainModel terrainmodel ) { LogFile.WriteLine( "TerrainView( " + terrainmodel + ")" ); this.terrainmodel = terrainmodel; terrainmodel.TerrainModified += new TerrainModel.TerrainModifiedHandler( terrainmodel_TerrainModified ); GraphicsHelperGl g = new GraphicsHelperGl(); g.CheckError(); foreach (MapTextureStageModel maptexturestagemodel in terrainmodel.texturestages) { LogFile.WriteLine( "create maptexturestageview for " + maptexturestagemodel ); mapviewbymapmodel.Add( maptexturestagemodel, new MapTextureStageView( maptexturestagemodel ) ); } g.CheckError(); renderableheightmap = new RenderableHeightMap( this, terrainmodel, 1, 1 ); //renderableallfeatures = new RenderableAllFeatures(this); // water must be last, otherwise you cant see through it ;-) renderablewater = new RenderableWater(new Vector3(), new Vector2(terrainmodel.HeightMapWidth , terrainmodel.HeightMapHeight )); // minimap last, covers everything else //renderableminimap = new RenderableMinimap(this, renderableheightmap); }
void RenderableMinimap_WriteNextFrameEvent(Vector3 camerapos) { //Console.WriteLine( "RenderableMinimap_WriteNextFrameEvent" ); GetDimensions(); GraphicsHelperGl g = new GraphicsHelperGl(); g.CheckError(); //LogFile.WriteLine( windowwidth + " " + windowheight + " " + RendererSdl.GetInstance().OuterWindowWidth + " " + RendererSdl.GetInstance().OuterWindowHeight ); g.ApplyOrtho(windowwidth, windowheight, RendererSdl.GetInstance().OuterWindowWidth, RendererSdl.GetInstance().OuterWindowHeight); g.CheckError(); DrawMinimap(); g.CheckError(); DrawFrustrum(camerapos); g.CheckError(); if (Render != null) { Render(minimapx, minimapy, minimapwidth, minimapheight); } g.CheckError(); g.RemoveOrtho(); g.CheckError(); }
// dependencies: // - RendererFactory.GetInstance() // - Tao.OpenGl public HitTarget GetClickedHitTarget(IRenderable renderable, int MouseX, int MouseY) { GraphicsHelperGl g = new GraphicsHelperGl(); g.CheckError(); IRenderer renderer = RendererFactory.GetInstance(); ArrayList results = new ArrayList(); int[] viewport = new int[4]; Gl.glGetIntegerv(Gl.GL_VIEWPORT, viewport); g.CheckError(); CreateSelectBuffer(); g.CheckError(); // This Creates A Matrix That Will Zoom Up To A Small Portion Of The Screen, Where The Mouse Is. Gl.glMatrixMode(Gl.GL_PROJECTION); g.CheckError(); Gl.glPushMatrix(); // save old matrix, we restore it at end g.CheckError(); Gl.glLoadIdentity(); g.CheckError(); Glu.gluPickMatrix((float)MouseX, (float)(renderer.WindowHeight - MouseY), 1.0f, 1.0f, viewport); g.CheckError(); Glu.gluPerspective(renderer.FieldOfView, (float)renderer.WindowWidth / (float)renderer.WindowHeight, renderer.NearClip, renderer.FarClip); g.CheckError(); Gl.glMatrixMode(Gl.GL_MODELVIEW); g.CheckError(); Gl.glRenderMode(Gl.GL_SELECT); g.CheckError(); Gl.glInitNames(); g.CheckError(); Gl.glPushName(0); // Push one entry onto the stack; we will use LoadName to change this value throughout the rendering g.CheckError(); bAddingNames = true; hittargets = new ArrayList(); renderable.Render(); bAddingNames = false; // return projection matrix to normal Gl.glMatrixMode(Gl.GL_PROJECTION); Gl.glPopMatrix(); Gl.glMatrixMode(Gl.GL_MODELVIEW); int iNumHits = Gl.glRenderMode(Gl.GL_RENDER); int hitname = GetNearestBufferName(iNumHits); LogFile.WriteLine("hitname: " + hitname.ToString()); if (hitname == -1 || hitname == 0) { LogFile.WriteLine("not in buffer"); return(null); } FreeSelectBuffer(); new GraphicsHelperGl().CheckError(); if (hittargets.Count == 0) { return(null); } if (iNumHits == 0) { //LogFile.WriteLine("no hits"); return(null); } //LogFile.WriteLine(hittargets[hitname - 1]); return((HitTarget)hittargets[hitname - 1]); }
// dependencies: // - RendererFactory.GetInstance() // - Tao.OpenGl public HitTarget GetClickedHitTarget( IRenderable renderable, int MouseX, int MouseY ) { GraphicsHelperGl g = new GraphicsHelperGl(); g.CheckError(); IRenderer renderer = RendererFactory.GetInstance(); ArrayList results = new ArrayList(); int[] viewport = new int[ 4 ]; Gl.glGetIntegerv( Gl.GL_VIEWPORT, viewport ); g.CheckError(); CreateSelectBuffer(); g.CheckError(); // This Creates A Matrix That Will Zoom Up To A Small Portion Of The Screen, Where The Mouse Is. Gl.glMatrixMode( Gl.GL_PROJECTION ); g.CheckError(); Gl.glPushMatrix(); // save old matrix, we restore it at end g.CheckError(); Gl.glLoadIdentity(); g.CheckError(); Glu.gluPickMatrix( (float)MouseX, (float)(renderer.WindowHeight - MouseY), 1.0f, 1.0f, viewport ); g.CheckError(); Glu.gluPerspective( renderer.FieldOfView, (float)renderer.WindowWidth / (float)renderer.WindowHeight, renderer.NearClip, renderer.FarClip ); g.CheckError(); Gl.glMatrixMode(Gl.GL_MODELVIEW); g.CheckError(); Gl.glRenderMode( Gl.GL_SELECT ); g.CheckError(); Gl.glInitNames(); g.CheckError(); Gl.glPushName( 0 ); // Push one entry onto the stack; we will use LoadName to change this value throughout the rendering g.CheckError(); bAddingNames = true; hittargets = new ArrayList(); renderable.Render(); bAddingNames = false; // return projection matrix to normal Gl.glMatrixMode( Gl.GL_PROJECTION ); Gl.glPopMatrix(); Gl.glMatrixMode( Gl.GL_MODELVIEW ); int iNumHits = Gl.glRenderMode( Gl.GL_RENDER ); int hitname = GetNearestBufferName( iNumHits ); LogFile.WriteLine( "hitname: " + hitname.ToString() ); if( hitname == -1 || hitname == 0 ) { LogFile.WriteLine("not in buffer"); return null; } FreeSelectBuffer(); new GraphicsHelperGl().CheckError(); if (hittargets.Count == 0) { return null; } if (iNumHits == 0) { //LogFile.WriteLine("no hits"); return null; } //LogFile.WriteLine(hittargets[hitname - 1]); return (HitTarget)hittargets[ hitname - 1 ]; }
void RenderableMinimap_WriteNextFrameEvent(Vector3 camerapos) { //Console.WriteLine( "RenderableMinimap_WriteNextFrameEvent" ); GetDimensions(); GraphicsHelperGl g = new GraphicsHelperGl(); g.CheckError(); //LogFile.WriteLine( windowwidth + " " + windowheight + " " + RendererSdl.GetInstance().OuterWindowWidth + " " + RendererSdl.GetInstance().OuterWindowHeight ); g.ApplyOrtho( windowwidth, windowheight, RendererSdl.GetInstance().OuterWindowWidth, RendererSdl.GetInstance().OuterWindowHeight ); g.CheckError(); DrawMinimap(); g.CheckError(); DrawFrustrum(camerapos); g.CheckError(); if (Render != null) { Render(minimapx, minimapy, minimapwidth, minimapheight); } g.CheckError(); g.RemoveOrtho(); g.CheckError(); }