//internal override void SetTileSet( TileSet TileSet ) { this.TileSet = TileSet; } internal override void Render( Display render, ref Box ParentPosition ) { Vector3 TopLeft, BottomRight, BarBottomRight; // Frame Position Computing if( Flag_Show_Master ) { EffectivePosition.Position = ParentPosition.Position + Dimensions.Position; EffectivePosition.Size = Dimensions.Size; // Render this frame if( Flag_Show_Frame ) { TopLeft = EffectivePosition.Position; BottomRight = EffectivePosition.Position + EffectivePosition.Size; BarBottomRight = BottomRight; BarBottomRight.X = TopLeft.X + ( ( BottomRight.X - TopLeft.X ) * this.Factor / 100.0f ); { Vector3[] coords = new Vector3[4]; coords[0] = TopLeft; coords[1] = TopLeft; coords[1].Y = BottomRight.Y; coords[2] = TopLeft; coords[2].X = BarBottomRight.X; coords[3] = BarBottomRight; coords[3].X = BarBottomRight.X; Vector4 c = new Vector4( 1 ); render.simple_gui.Activate(); render.simple_gui.DrawQuad( coords, ref c ); } if( TileSet != null ) { //TopLeft.z -= 1.0f; TileSet.RenderTile( render, ref TopLeft, ref BarBottomRight, 10, ref DrawColor ); //TileSet.RenderTile(&TopLeft, &BottomRight, 8, &DrawColor); } } // Render child frames if( Flag_Show_Childs ) { foreach( Frame frame in SubFrameList ) { frame.Render( render, ref EffectivePosition ); } } } }
static void DrawBoundingBox( Display render, BoundingBox bb ) { ///Box box = e as Box; // = e.CollisionInformation.BoundingBox; //Vector3 corner = Matrix.TransformNormal( Vector3.One, e.WorldTransform ); Vector3[] corners = new Vector3[8]; //Vector3 half_size = new Vector3( box.HalfWidth, box.HalfHeight, box.HalfLength ); corners[0] = bb.Min; corners[6] = bb.Max; corners[1] = corners[0]; corners[1].X = corners[6].X; corners[2] = corners[0]; corners[2].X = corners[6].X; corners[2].Y = corners[6].Y; corners[3] = corners[0]; corners[3].Y = corners[6].Y; corners[4] = corners[0]; corners[4].Z = corners[6].Z; corners[5] = corners[0]; corners[5].X = corners[6].X; corners[5].Z = corners[6].Z; corners[7] = corners[0]; corners[7].Y = corners[6].Y; corners[7].Z = corners[6].Z; Vector3 white = Vector3.One; white.Y = 0; white.Z = 0; drawLine( render, ref corners[0], ref corners[1], ref white, ref white ); drawLine( render, ref corners[1], ref corners[2], ref white, ref white ); drawLine( render, ref corners[2], ref corners[3], ref white, ref white ); drawLine( render, ref corners[3], ref corners[0], ref white, ref white ); drawLine( render, ref corners[0], ref corners[4], ref white, ref white ); drawLine( render, ref corners[1], ref corners[5], ref white, ref white ); drawLine( render, ref corners[2], ref corners[6], ref white, ref white ); drawLine( render, ref corners[3], ref corners[7], ref white, ref white ); drawLine( render, ref corners[4], ref corners[5], ref white, ref white ); drawLine( render, ref corners[5], ref corners[6], ref white, ref white ); drawLine( render, ref corners[6], ref corners[7], ref white, ref white ); drawLine( render, ref corners[7], ref corners[4], ref white, ref white ); }
public static void drawLine( Display render, ref Vector3 from, ref Vector3 to, ref Vector3 fromColor, ref Vector3 toColor ) { OpenTK.Vector3[] v = new OpenTK.Vector3[2]; OpenTK.Vector4 c; OpenTK.Vector4 c2; c.X = fromColor.X; c.Y = fromColor.Y; c.Z = fromColor.Z; c.W = 1; c2.X = toColor.X; c2.Y = toColor.Y; c2.Z = toColor.Z; c2.W = 1; v[0].X = from.X; v[0].Y = from.Y; v[0].Z = from.Z; v[1].X = to.X; v[1].Y = to.Y; v[1].Z = to.Z; geometry.AddLine( v, ref c ); }
internal GameDisplay( VoxelGameEnvironment game ):base( Settings.Read( "GL.Width", System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width ) , Settings.Read( "GL.Height", System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height ) , new OpenTK.Graphics.GraphicsMode( 32, 24, 24, 4, ColorFormat.Empty, 2, true ) , "Voxelarium", GameWindowFlags.Default ) { display = new Display( game ); X = Settings.Read( "GL.Display.X", System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.X ); Y = Settings.Read( "GL.Display.Y", System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Y ); this.WindowBorder = OpenTK.WindowBorder.Hidden; display.Mouse = Mouse; display.Keyboard = Keyboard; UpdateFrame += display.Display_UpdateFrame; RenderFrame += display.Display_RenderFrame; RenderFrame += GameDisplay_RenderFrame; display.Width = Width; display.Height = Height; display.X = X; display.Y = Y; KeyDown += display.Display_KeyDown; KeyUp += display.Display_KeyUp; MouseWheel += display.Display_MouseWheel; MouseMove += display.Display_MouseMove; MouseDown += display.Display_MouseDown; MouseUp += display.Display_MouseUp; Load += display.Display_Load; Resize += GameDisplay_Resize; Move += GameDisplay_Move; Display.Exit = Exit; //display.SwapBuffers = SwapBuffers; }
internal override void Render( Display render, ref Box ParentPosition ) { Vector3 TopLeft, BottomRight; // Frame Position Computing if( Flag_Show_Master ) { EffectivePosition.Position.X = ParentPosition.Position.X + Dimensions.Position.Y; EffectivePosition.Position.Y = ParentPosition.Position.Y + Dimensions.Position.Y; EffectivePosition.Position.Z = ParentPosition.Position.Z + Dimensions.Position.Z; EffectivePosition.Size.X = Dimensions.Size.X; EffectivePosition.Size.Y = Dimensions.Size.Y; EffectivePosition.Size.Z = Dimensions.Size.Z; if( this.Flag_Draging ) { EffectivePosition.Position.X = DragAbsolutePosition.X; EffectivePosition.Position.Y = DragAbsolutePosition.Y; EffectivePosition.Position.Z = ParentPosition.Position.Z + Dimensions.Position.Z + 2.0f; } // Render this frame if( Flag_Show_Frame ) { TopLeft = EffectivePosition.Position; BottomRight = EffectivePosition.Position + EffectivePosition.Size; // if (TileSet) TileSet.RenderTile(&TopLeft, &BottomRight, Tile, &DrawColor); Vector2 P1, P2, P3, P4; P1.X = TopLeft.X; P1.Y = TopLeft.Y; P2.X = BottomRight.X; P2.Y = TopLeft.Y; P3.X = BottomRight.X; P3.Y = BottomRight.Y; P4.X = TopLeft.X; P4.Y = BottomRight.Y; int texture; Vector4 color; // Render float[] uvs = new float[2 * 4]; if( activeEntry != null ) { texture = render.game.World.TextureAtlas.OpenGl_TextureRef; uvs = VoxelTypeManager.VoxelTable[activeEntry.VoxelType].TextureUVs; } else texture = 0; if( activeEntry != null ) color = Vector4.One; else color = new Vector4( 0.4f, 0.4f, 0.4f, 0.6f ); // glColor4f(0.7f, 0.7f, 0.7f, 0.9f); float[] verts = new float[3 * 4]; verts[0 * 3 + 0] = P1.X; verts[0 * 3 + 1] = P1.Y; verts[0 * 3 + 2] = TopLeft.Z; verts[0 * 3 + 0] = P2.X; verts[0 * 3 + 1] = P2.Y; verts[0 * 3 + 2] = TopLeft.Z; verts[0 * 3 + 0] = P3.X; verts[0 * 3 + 1] = P3.Y; verts[0 * 3 + 2] = BottomRight.Z; verts[0 * 3 + 0] = P4.X; verts[0 * 3 + 1] = P4.Y; verts[0 * 3 + 2] = BottomRight.Z; render.simple_gui_texture.DrawQuad( verts, uvs ); // Rendering Quantity if( activeEntry.Quantity > 1 ) { String QuantityText; QuantityText = activeEntry.Quantity.ToString(); Box FontBox; Vector2 Dim; TileStyle.TileSet.GetFontRenderSize( TileStyle, QuantityText, out Dim ); FontBox.Position.X = BottomRight.X - Dim.X - 1.0f; FontBox.Position.Y = BottomRight.Y - Dim.Y - 1.0f; FontBox.Position.Z = TopLeft.Z + 2.0f; FontBox.Size.X = Dim.X; FontBox.Size.Y = Dim.Y; FontBox.Size.Z = 0.0f; Vector4 Color; Vector4 BkColor; Color = Vector4.One; BkColor = Vector4.Zero; TileStyle.TileSet.RenderFont( render, TileStyle, ref FontBox, QuantityText, ref Color ); FontBox.Position.Z -= 1.0f; FontBox.Position.X -= Display.SclX(1.0f ); FontBox.Position.Y -= Display.SclY(1.0f ); TileStyle.TileSet.RenderFont( render, TileStyle, ref FontBox, QuantityText, ref BkColor ); } } // Render child frames if( Flag_Show_Childs ) { //SubFrameList.Dump(); foreach( Frame frame in SubFrameList ) { frame.Render( render, ref EffectivePosition ); } } } }
internal void DropItem( Display render, Frame Item, ushort nButton ) { if( Item.FrameType == VoxelUtils.MulticharConst( 'I', 'B', 'O', 'X' ) ) { InventoryBox IbItem; ushort In_VoxelType, Temp_VoxelType; int In_Quantity, Temp_Quantity; IbItem = (InventoryBox)Item; Inventory.Entry entry = IbItem.GetEntry(); In_VoxelType = entry.VoxelType; In_Quantity = entry.Quantity; if( In_VoxelType != activeEntry.VoxelType && entry.Quantity > 0 ) { if( nButton == 1 ) { Temp_VoxelType = In_VoxelType; Temp_Quantity = In_Quantity; entry.VoxelType = activeEntry.VoxelType; entry.Quantity = activeEntry.Quantity; activeEntry.VoxelType = Temp_VoxelType; activeEntry.Quantity = Temp_Quantity; } } else if( In_VoxelType == activeEntry.VoxelType || activeEntry.Quantity == 0 ) { if( nButton == 1 ) { activeEntry.Quantity += In_Quantity; activeEntry.VoxelType = In_VoxelType; entry.Quantity = 0; entry.VoxelType = 0; } if( nButton == 3 ) { int TransfertQuantity = 1; if( render.keyboard[ Key.ShiftLeft] || render.keyboard[Key.ShiftRight] ) TransfertQuantity = 10; if( render.keyboard[Key.ControlLeft] || render.keyboard[Key.ControlRight] ) TransfertQuantity = 100; if( render.keyboard[Key.AltLeft] || render.keyboard[Key.AltRight] ) TransfertQuantity = 1000; if( TransfertQuantity > In_Quantity ) TransfertQuantity = In_Quantity; if( In_Quantity > 0 ) { ( activeEntry.Quantity ) += TransfertQuantity; entry.Quantity = In_Quantity - TransfertQuantity; activeEntry.VoxelType = In_VoxelType; } } } } // printf("Dropped : %lx in %lx\n",(ULong)Item, (ULong)this); }
internal override void Render( Display render, ref Box ParentPosition ) { if( Flag_Show_Master ) { EffectivePosition.Position = ParentPosition.Position + Dimensions.Position; EffectivePosition.Position.Z -= 0.1f; EffectivePosition.Size = Dimensions.Size; if( Flag_Show_Frame ) { if( font != null ) font.RenderFont( render, ref EffectivePosition, line_height , this.TextToDisplay, ref DrawColor ); } // Render child frames if( Flag_Show_Childs ) { //SubFrameList.Dump(); foreach( Frame frame in SubFrameList ) { frame.Render( render, ref EffectivePosition ); } } } }
internal virtual void Render( Display render, ref Box ParentPosition ) { quad P; // Frame Position Computing if( Flag_Show_Master ) { EffectivePosition.Position = ParentPosition.Position + Dimensions.Position; EffectivePosition.Position.Z -= 0.1f; EffectivePosition.Size = Dimensions.Size; if( this.Flag_Draging ) { EffectivePosition.Position.X = DragAbsolutePosition.X; EffectivePosition.Position.Y = DragAbsolutePosition.Y; } // Render this frame if( Flag_Show_Frame ) { P.P1.X = EffectivePosition.Position.X; P.P1.Y = EffectivePosition.Position.Y; P.P1.Z = EffectivePosition.Position.Z + EffectivePosition.Size.Z; P.P2.X = EffectivePosition.Position.X + EffectivePosition.Size.X; P.P2.Y = EffectivePosition.Position.Y; P.P2.Z = EffectivePosition.Position.Z + EffectivePosition.Size.Z; P.P3.X = EffectivePosition.Position.X + EffectivePosition.Size.X; P.P3.Y = EffectivePosition.Position.Y + EffectivePosition.Size.Y; P.P3.Z = EffectivePosition.Position.Z + EffectivePosition.Size.Z; P.P4.X = EffectivePosition.Position.X; P.P4.Y = EffectivePosition.Position.Y + EffectivePosition.Size.Y; P.P4.Z = EffectivePosition.Position.Z + EffectivePosition.Size.Z; int TextureRef = GuiManager.TextureManager.GetTextureEntry( this.TextureNum ).OpenGl_TextureRef; tex_coords[0] = 0.0f; tex_coords[1] = 1.0f; coords[0] = P.P1.X; coords[1] = P.P1.Y; coords[2] = P.P1.Z; tex_coords[2] = 1.0f; tex_coords[3] = 1.0f; coords[3] = P.P2.X; coords[4] = P.P2.Y; coords[5] = P.P2.Z; tex_coords[4] = 1.0f; tex_coords[5] = 0.0f; coords[6] = P.P3.X; coords[7] = P.P3.Y; coords[8] = P.P3.Z; tex_coords[6] = 1.0f; tex_coords[7] = 0.0f; coords[9] = P.P3.X; coords[10] = P.P3.Y; coords[11] = P.P3.Z; tex_coords[8] = 0.0f; tex_coords[9] = 0.0f; coords[12] = P.P4.X; coords[13] = P.P4.Y; coords[14] = P.P4.Z; tex_coords[10] = 0.0f; tex_coords[11] = 1.0f; coords[15] = P.P1.X; coords[16] = P.P1.Y; coords[17] = P.P1.Z; //lprintf( "%3d %g,%g,%g %g,%g,%g", TextureRef, P.P1.X, P.P1.Y, P.P1.Z, P.P3.X, P.P3.Y, P.P3.Z ); render.simple_gui_texture.Activate(); render.simple_gui_texture.SetUniforms( TextureRef, ref DrawColor ); render.simple_gui_texture.DrawQuadTris( coords, tex_coords ); render.simple_texture.Activate(); render.simple_texture.SetUniforms( TextureRef, ref DrawColor ); render.simple_texture.DrawQuadTris( coords, tex_coords ); } // Render child frames if( Flag_Show_Childs ) { lock ( SubFrameList ) { foreach( Frame frame in SubFrameList ) frame.Render( render, ref EffectivePosition ); } } } }
internal override void Render( Display display, VoxelGameEnvironment game, VoxelWorld world ) { HighPerfTimer Timer = new HighPerfTimer(); HighPerfTimer Timer_SectorRefresh = new HighPerfTimer(); long Time; uint RenderedSectors; int i; int in_centerX, in_centerY, in_centerZ; Timer.Start(); Stat_RenderDrawFaces = 0; Stat_FaceTop = 0; Stat_FaceBottom = 0; Stat_FaceLeft = 0; Stat_FaceRight = 0; Stat_FaceFront = 0; Stat_FaceBack = 0; // Stats reset GameStats Stat = GameEnv.GameStat; if( Stat == null ) return; // Precomputing values for faster math // Update per cycle. int UpdatePerCycle = 2; int n; if( Stat_RefreshWaitingSectorCount < 50 ) UpdatePerCycle = 1; if( Stat_RefreshWaitingSectorCount < 500 ) UpdatePerCycle = 2; else if( Stat.SectorRefresh_TotalTime < 32 ) UpdatePerCycle = 5; Stat_RefreshWaitingSectorCount = 0; // Stat Reset Stat.SectorRefresh_Count = 0; Stat.SectorRefresh_TotalTime = 0; Stat.SectorRefresh_MinTime = 0; Stat.SectorRefresh_MaxTime = 0; Stat.SectorRender_Count = 0; Stat.SectorRender_TotalTime = 0; Stat.SectorRefresh_Waiting = 0; // Renderwaiting system for( i = 0; i < 64; i++ ) RefreshToDo[i] = 0; for( i = 63; i > 0; i-- ) { n = RefreshWaiters[i]; if( n > UpdatePerCycle ) n = UpdatePerCycle; UpdatePerCycle -= n; RefreshToDo[i] = n; } RefreshToDo[0] = UpdatePerCycle; for( i = 0; i < 64; i++ ) RefreshWaiters[i] = 0; // Computing Frustum and Setting up Projection int Sector_x, Sector_y, Sector_z; int x, y, z; VoxelSector Sector; int Priority, PriorityBoost; uint Sector_Refresh_Count; // Transforming Camera coords to sector coords. One Voxel is 256 observer units. One sector is 16x16x32. btVector3 origin; Camera.location.getOrigin( out origin ); Sector_x = ( (int)origin.x >> ( world.VoxelBlockSizeBits + VoxelSector.ZVOXELBLOCSHIFT_X ) ); Sector_y = ( (int)origin.y >> ( world.VoxelBlockSizeBits + VoxelSector.ZVOXELBLOCSHIFT_Y ) ); Sector_z = ( (int)origin.z >> ( world.VoxelBlockSizeBits + VoxelSector.ZVOXELBLOCSHIFT_Z ) ); in_centerX = (int)origin.x & VoxelSector.ZVOXELBLOCMASK_X; in_centerY = (int)origin.y & VoxelSector.ZVOXELBLOCMASK_Y; in_centerZ = (int)origin.z & VoxelSector.ZVOXELBLOCMASK_Z; // Rendering loop // Preparation and first rendering pass RenderedSectors = 0; Sector_Refresh_Count = 0; int voxelSizeBits = world.VoxelBlockSizeBits; float voxelSize = world.VoxelBlockSize; SectorSphere.SphereEntry SectorSphereEntry; uint SectorsToProcess = SectorSphere.GetEntryCount(); btVector3 Cv; btVector3 Cv2; Cv2.w = 0; Cv.w = 0; for( int Entry = 0; Entry < SectorsToProcess; Entry++ ) { SectorSphere.GetEntry( Entry, out SectorSphereEntry ); x = SectorSphereEntry.x + Sector_x; y = SectorSphereEntry.y + Sector_y; z = SectorSphereEntry.z + Sector_z; // for (x = Start_x ; x <= End_x ; x++) // for (y = Start_y; y <= End_y ; y++) // for (z = Start_z; z <= End_z ; z++) // try to see if sector is visible bool SectorVisible; Cv.x = (float)( ( x ) << ( voxelSizeBits + VoxelSector.ZVOXELBLOCSHIFT_X ) ); Cv.y = (float)( ( y ) << ( voxelSizeBits + VoxelSector.ZVOXELBLOCSHIFT_Y ) ); Cv.z = (float)( ( z ) << ( voxelSizeBits + VoxelSector.ZVOXELBLOCSHIFT_Z ) ); SectorVisible = false; Cv2.x = ( 0 * VoxelSector.ZVOXELBLOCSIZE_X * voxelSize ); Cv2.y = ( 0 * VoxelSector.ZVOXELBLOCSIZE_Y * voxelSize ); Cv2.z = ( 0 * VoxelSector.ZVOXELBLOCSIZE_Z * voxelSize ); Cv2.Add( ref Cv, out Cv2 ); SectorVisible |= Is_PointVisible( ref Camera.location, ref Cv2 ); Cv2.x = ( 1 * VoxelSector.ZVOXELBLOCSIZE_X * voxelSize ); Cv2.y = ( 0 * VoxelSector.ZVOXELBLOCSIZE_Y * voxelSize ); Cv2.z = ( 0 * VoxelSector.ZVOXELBLOCSIZE_Z * voxelSize ); Cv2.Add( ref Cv, out Cv2 ); SectorVisible |= Is_PointVisible( ref Camera.location, ref Cv2 ); Cv2.x = ( 1 * VoxelSector.ZVOXELBLOCSIZE_X * voxelSize ); Cv2.y = ( 0 * VoxelSector.ZVOXELBLOCSIZE_Y * voxelSize ); Cv2.z = ( 1 * VoxelSector.ZVOXELBLOCSIZE_Z * voxelSize ); Cv2.Add( ref Cv, out Cv2 ); SectorVisible |= Is_PointVisible( ref Camera.location, ref Cv2 ); Cv2.x = ( 0 * VoxelSector.ZVOXELBLOCSIZE_X * voxelSize ); Cv2.y = ( 0 * VoxelSector.ZVOXELBLOCSIZE_Y * voxelSize ); Cv2.z = ( 1 * VoxelSector.ZVOXELBLOCSIZE_Z * voxelSize ); Cv2.Add( ref Cv, out Cv2 ); SectorVisible |= Is_PointVisible( ref Camera.location, ref Cv2 ); Cv2.x = ( 0 * VoxelSector.ZVOXELBLOCSIZE_X * voxelSize ); Cv2.y = ( 1 * VoxelSector.ZVOXELBLOCSIZE_Y * voxelSize ); Cv2.z = ( 0 * VoxelSector.ZVOXELBLOCSIZE_Z * voxelSize ); Cv2.Add( ref Cv, out Cv2 ); SectorVisible |= Is_PointVisible( ref Camera.location, ref Cv2 ); Cv2.x = ( 1 * VoxelSector.ZVOXELBLOCSIZE_X * voxelSize ); Cv2.y = ( 1 * VoxelSector.ZVOXELBLOCSIZE_Y * voxelSize ); Cv2.z = ( 0 * VoxelSector.ZVOXELBLOCSIZE_Z * voxelSize ); Cv2.Add( ref Cv, out Cv2 ); SectorVisible |= Is_PointVisible( ref Camera.location, ref Cv2 ); Cv2.x = ( 1 * VoxelSector.ZVOXELBLOCSIZE_X * voxelSize ); Cv2.y = ( 1 * VoxelSector.ZVOXELBLOCSIZE_Y * voxelSize ); Cv2.z = ( 1 * VoxelSector.ZVOXELBLOCSIZE_Z * voxelSize ); Cv2.Add( ref Cv, out Cv2 ); SectorVisible |= Is_PointVisible( ref Camera.location, ref Cv2 ); Cv2.x = ( 0 * VoxelSector.ZVOXELBLOCSIZE_X * voxelSize ); Cv2.y = ( 1 * VoxelSector.ZVOXELBLOCSIZE_Y * voxelSize ); Cv2.z = ( 1 * VoxelSector.ZVOXELBLOCSIZE_Z * voxelSize ); Cv2.Add( ref Cv, out Cv2 ); SectorVisible |= Is_PointVisible( ref Camera.location, ref Cv2 ); Sector = world.FindSector( x, y, z ); Priority = RadiusZones.GetZone( x - Sector_x, y - Sector_y, z - Sector_z ); PriorityBoost = ( SectorVisible && Priority <= 2 ) ? 1 : 0; // Go = true; if( Sector != null ) { if( Sector.transparent_geometry.transparent_render_sorting != SectorSphereEntry.relative_pos ) { Sector.transparent_geometry.transparent_render_sorting = SectorSphereEntry.relative_pos; Sector.Flag_Render_Dirty_Transparent = true; Sector.transparent_geometry.sortedX = -1; } if( SectorSphereEntry.relative_pos == VoxelSector.RelativeVoxelOrds.INCENTER ) { if( center_sorted_x != in_centerX || center_sorted_y != in_centerY || center_sorted_z != in_centerZ ) { Sector.Flag_Render_Dirty_Transparent = true; BuildSortListInSector( in_centerX, in_centerY, in_centerZ ); } } Sector.Flag_IsVisibleAtLastRendering = SectorVisible || Priority >= 3; // Display lists preparation if( ( Sector.Flag_Render_Dirty || Sector.Flag_Render_Dirty_Transparent ) && GameEnv.Enable_NewSectorRendering ) { // if (Sector_Refresh_Count < 5 || Priority==4) if( ( RefreshToDo[Sector.RefreshWaitCount] != 0 ) || Sector.Flag_HighPriorityRefresh ) { if ( VoxelGlobalSettings.COMPILEOPTION_FINETIMINGTRACKING ) Timer_SectorRefresh.Start(); RefreshToDo[Sector.RefreshWaitCount]--; Sector.Flag_HighPriorityRefresh = false; //Log.log( "Draw sector geometry {0} {1} {2}", Sector.Pos_x, Sector.Pos_y, Sector.Pos_z ); MakeSectorRenderingData( Sector ); MakeSectorRenderingData_Sorted( Sector, SectorSphereEntry.relative_pos , in_centerX, in_centerY, in_centerZ ); //Log.log( "Drew sector geometry {0} {1} {2}", Sector.Pos_x, Sector.Pos_y, Sector.Pos_z ); Sector_Refresh_Count++; Sector.RefreshWaitCount = 0; Stat.SectorRefresh_Count++; if( VoxelGlobalSettings.COMPILEOPTION_FINETIMINGTRACKING ) { Timer_SectorRefresh.End(); Time = Timer_SectorRefresh.GetResult(); Stat.SectorRefresh_TotalTime += (uint)Time; if( Time < Stat.SectorRefresh_MinTime ) Stat.SectorRefresh_MinTime = (uint)Time; if( Time > Stat.SectorRefresh_MaxTime ) Stat.SectorRefresh_MaxTime = (uint)Time; } } else { Sector.RefreshWaitCount++; if( Sector.RefreshWaitCount > 31 ) Sector.RefreshWaitCount = 31; if( Priority == 4 ) Sector.RefreshWaitCount++; RefreshWaiters[Sector.RefreshWaitCount]++; Stat_RefreshWaitingSectorCount++; Stat.SectorRefresh_Waiting++; } } // Rendering first pass if( Sector.Flag_IsVisibleAtLastRendering && ( !Sector.Flag_Void_Regular ) ) { if( VoxelGlobalSettings.COMPILEOPTION_FINETIMINGTRACKING ) Timer_SectorRefresh.Start(); Sector.solid_geometry.SetupUniforms( world.TextureAtlas.OpenGl_TextureRef ); Sector.solid_geometry.DrawBuffer(); //glCallList( ( (ZRender_Interface_displaydata*)Sector.DisplayData ).DisplayList_Regular[current_gl_camera] ); Stat.SectorRender_Count++; RenderedSectors++; if( VoxelGlobalSettings.COMPILEOPTION_FINETIMINGTRACKING ) { Timer_SectorRefresh.End(); Time = Timer_SectorRefresh.GetResult(); Stat.SectorRender_TotalTime += (uint)Time; } } } else { if( GameEnv.Enable_LoadNewSector ) world.RequestSector( x, y, z, Priority + PriorityBoost ); if( VoxelGlobalSettings.COMPILEOPTION_DRAW_MISSING_SECTORS ) { GL.Disable( EnableCap.DepthTest ); if( SectorVisible ) // culling Render_EmptySector( display, world, x, y, z, 1.0f, 0.3f, 0.1f ); GL.Enable( EnableCap.DepthTest ); } //return; } } // Second pass rendering //GL.Disable( EnableCap.DepthTest ); //GL.DepthMask( false ); //glDepthMask( GL_FALSE ); #if !USE_GLES2 GL.AlphaFunc( AlphaFunction.Greater, 0.2f ); GL.Enable( EnableCap.AlphaTest ); #endif Display.EnableBlending( true ); for( int Entry = 0; Entry < SectorsToProcess; Entry++ ) { SectorSphere.GetEntry( Entry, out SectorSphereEntry ); x = SectorSphereEntry.x + Sector_x; y = SectorSphereEntry.y + Sector_y; z = SectorSphereEntry.z + Sector_z; Sector = world.FindSector( x, y, z ); // printf("Sector : %ld %ld %ld %lu\n", x, y, z, (uint)(Sector != 0));9 if( Sector != null ) { if( Sector.Flag_IsVisibleAtLastRendering && ( !Sector.Flag_Void_Transparent ) ) { if( VoxelGlobalSettings.COMPILEOPTION_FINETIMINGTRACKING ) Timer_SectorRefresh.Start(); Sector.transparent_geometry.SetupUniforms( world.TextureAtlas.OpenGl_TextureRef ); Sector.transparent_geometry.DrawBuffer(); //glCallList( ( (ZRender_Interface_displaydata*)Sector.DisplayData ).DisplayList_Transparent[current_gl_camera] ); Stat.SectorRender_Count++; if( VoxelGlobalSettings.COMPILEOPTION_FINETIMINGTRACKING ) { Timer_SectorRefresh.End(); Time = Timer_SectorRefresh.GetResult(); Stat.SectorRender_TotalTime += (uint)Time; } } } } GL.Enable( EnableCap.DepthTest ); Display.EnableBlending( false ); Timer.End(); /*printf("Frame Time : %lu Rend Sects: %lu Draw Faces :%lu Top:%lu Bot:%lu Le:%lu Ri:%lu Front:%lu Back:%lu\n",Timer.GetResult(), RenderedSectors, Stat_RenderDrawFaces, Stat_FaceTop, Stat_FaceBottom, Stat_FaceLeft,Stat_FaceRight,Stat_FaceFront,Stat_FaceBack);*/ //printf("RenderedSectors : %lu\n",RenderedSectors); //SDL_GL_SwapBuffers( ); }
public void drawContactPoint( Display render, ref Vector3 PointOnB, ref Vector3 normalOnB, double distance, int lifeTime, ref Vector3 color ) { Vector3 tmpD; PointOnB.Add( ref normalOnB, out tmpD ); drawLine( render, ref PointOnB, ref tmpD, ref color, ref color ); }
public static void DrawSpace( Display render, PhysicsEngine engine ) { if( engine != null ) { geometry.Clear(); foreach( Entity e in engine.test_entitites ) { Box box = e as Box; DrawBox( render, box ); } lock( engine.active_sectors ) { //if( false ) foreach( PhysicsEngine.Sector s in engine.active_sectors ) { int n = 0; if( s.Empty ) continue; if( false ) foreach( VoxelShape shp in s.content ) { if( shp != VoxelShape.Empty ) { int x = (int)(( n / s.sector.Size_y ) % s.sector.Size_x); int y = (int)( n % s.sector.Size_y); int z = (int)( ( n / ( s.sector.Size_x * s.sector.Size_y ) ) % s.sector.Size_z ); BoundingBox bb; //Log.log( "found non empty at sector {0} {1} {2} offset {3}" // , s.sector.Pos_x, s.sector.Pos_y, s.sector.Pos_z // , n ); bb.Min.X = s.sector.Pos_x * 32 + x; bb.Min.Y = s.sector.Pos_y * 32 + y; bb.Min.Z = s.sector.Pos_z * 32 + z; bb.Max.X = bb.Min.X + 1; bb.Max.Y = bb.Min.Y + 1; bb.Max.Z = bb.Min.Z + 1; DrawBoundingBox( render, bb ); //if( n > 2000 ) // break; } n++; } DrawBoundingBox( render, s.grid.BoundingBox ); } } geometry.DrawBuffer( PrimitiveType.Lines ); } }
static void DrawBox( Display render, Box box ) { { Vector3 o = box.WorldTransform.Translation; Vector3 xdir; Matrix3x3.Transform( ref Vector3.UnitX, ref box.orientationMatrix, out xdir ); Vector3 ydir; Matrix3x3.Transform( ref Vector3.UnitY, ref box.orientationMatrix, out ydir ); Vector3 zdir; Matrix3x3.Transform( ref Vector3.UnitZ, ref box.orientationMatrix, out zdir ); Vector3 corner; Matrix3x3.Transform( ref Vector3.One, ref box.orientationMatrix, out corner ); Vector3[] corners = new Vector3[8]; Vector3 size = new Vector3( box.Width, box.Height, box.Length ); corners[0] = o + corner * ( size * 0.5f); corners[1] = corners[0] - ( xdir * size.X ); corners[2] = corners[0] - ( xdir * size.X ) - ( ydir * size.Y ); corners[3] = corners[0] - ( ydir * size.Y ); corners[4] = corners[0] - ( zdir * size.Z ); corners[5] = corners[0] - ( zdir * size.Z ) - ( xdir * size.X ); corners[6] = corners[0] - ( zdir * size.Z ) - ( xdir * size.X ) - ( ydir * size.Y ); corners[7] = corners[0] - ( zdir * size.Z ) - ( ydir * size.Y ); Vector3 white = Vector3.One; drawLine( render, ref corners[0], ref corners[1], ref white, ref white ); drawLine( render, ref corners[1], ref corners[2], ref white, ref white ); drawLine( render, ref corners[2], ref corners[3], ref white, ref white ); drawLine( render, ref corners[3], ref corners[0], ref white, ref white ); drawLine( render, ref corners[0], ref corners[4], ref white, ref white ); drawLine( render, ref corners[1], ref corners[5], ref white, ref white ); drawLine( render, ref corners[2], ref corners[6], ref white, ref white ); drawLine( render, ref corners[3], ref corners[7], ref white, ref white ); drawLine( render, ref corners[4], ref corners[5], ref white, ref white ); drawLine( render, ref corners[5], ref corners[6], ref white, ref white ); drawLine( render, ref corners[6], ref corners[7], ref white, ref white ); drawLine( render, ref corners[7], ref corners[4], ref white, ref white ); } }
internal void Render( Display render ) { Box Dimensions; Dimensions.Position.X = -1; Dimensions.Position.Y = -1; Dimensions.Position.Z = 1; Dimensions.Size.X = 2; Dimensions.Size.Y = 2; Dimensions.Size.Z = 10; FirstFrame.Render( render, ref Dimensions ); }
internal void Render_EmptySector( Display display, VoxelWorld world, int x, int y, int z, float r, float g, float b ) { Vector4 c; int sx = (int)(VoxelSector.ZVOXELBLOCSIZE_X * world.VoxelBlockSize ); int sy = (int)(VoxelSector.ZVOXELBLOCSIZE_Y * world.VoxelBlockSize ); int sz = (int)(VoxelSector.ZVOXELBLOCSIZE_Z * world.VoxelBlockSize ); c.X = r; c.Y = g; c.Z = b; c.W = 0.5f; unsafe { fixed ( float* _v = sector_verts ) { float* v = _v; *(v++) = x * sx; *(v++) = y * sy; *(v++) = z * sz; *(v++) = x * sx; *(v++) = y * sy; *(v++) = z * sz + sz; *(v++) = x * sx; *(v++) = y * sy; *(v++) = z * sz + sz; *(v++) = x * sx + sx; *(v++) = y * sy; *(v++) = z * sz + sz; *(v++) = x * sx + sx; *(v++) = y * sy; *(v++) = z * sz + sz; *(v++) = x * sx + sx; *(v++) = y * sy; *(v++) = z * sz; *(v++) = x * sx + sx; *(v++) = y * sy; *(v++) = z * sz; *(v++) = x * sx; *(v++) = y * sy; *(v++) = z * sz; *(v++) = x * sx; *(v++) = y * sy + sy; *(v++) = z * sz; *(v++) = x * sx; *(v++) = y * sy + sy; *(v++) = z * sz + sz; *(v++) = x * sx; *(v++) = y * sy + sy; *(v++) = z * sz + sz; *(v++) = x * sx + sx; *(v++) = y * sy + sy; *(v++) = z * sz + sz; *(v++) = x * sx + sx; *(v++) = y * sy + sy; *(v++) = z * sz + sz; *(v++) = x * sx + sx; *(v++) = y * sy + sy; *(v++) = z * sz; *(v++) = x * sx + sx; *(v++) = y * sy + sy; *(v++) = z * sz; *(v++) = x * sx; *(v++) = y * sy + sy; *(v++) = z * sz; *(v++) = x * sx; *(v++) = y * sy; *(v++) = z * sz; *(v++) = x * sx; *(v++) = y * sy + sy; *(v++) = z * sz; *(v++) = x * sx; *(v++) = y * sy; *(v++) = z * sz + sz; *(v++) = x * sx; *(v++) = y * sy + sy; *(v++) = z * sz + sz; *(v++) = x * sx + sx; *(v++) = y * sy; *(v++) = z * sz + sz; *(v++) = x * sx + sx; *(v++) = y * sy + sy; *(v++) = z * sz + sz; *(v++) = x * sx + sx; *(v++) = y * sy; *(v++) = z * sz; *(v++) = x * sx + sx; *(v++) = y * sy + sy; *(v++) = z * sz; if( display.simple.Activate() ) display.simple.DrawBox( sector_verts, ref c ); } } }
internal abstract void Render( Display display, VoxelGameEnvironment game, VoxelWorld world );
/// <summary> /// Draw a string. /// </summary> /// <param name="render">display to draw string in/on</param> /// <param name="EffectivePosition">Where to draw the text (size unused)</param> /// <param name="scale">how big to render the font...</param> /// <param name="text"></param> /// <param name="color"></param> internal void RenderFont( Display render, ref Box EffectivePosition , float scale, string text , ref Vector4 color ) { int c; uint rune; Display.EnableBlending( true ); GL.Enable( EnableCap.DepthTest ); render.simple_gui_texture.Activate(); render.simple_gui_texture.SetUniforms( OpenGl_TextureRef, ref color ); float[] quad = new float[12]; float x_left, y_bottom; float x = EffectivePosition.Position.X; float y = EffectivePosition.Position.Y; float z = EffectivePosition.Position.Z + EffectivePosition.Size.Z; float xp, yp; FontCharacter ch; for( c = 0; c < text.Length; c++ ) { rune = GetUnicode( ref c, text ); if( rune == '\n' ) { y -= scale; x = EffectivePosition.Position.X; } else { ch = GetCharacter( rune ); if( ch.width > 0 ) { x_left = x + ( ch.leftSideBearing * scale / line_height ); yp = y + ( ( ch.topSideBearing - descent) * scale / line_height );//( ( ( line_height + ch.yOffset ) * scale ) / line_height ); xp = x_left + ( ch.width * scale / line_height ); y_bottom = yp + ( ch.height * scale / line_height ); quad[0 * 3 + 0] = x_left; quad[0 * 3 + 1] = yp; quad[0 * 3 + 2] = z; quad[1 * 3 + 0] = x_left; quad[1 * 3 + 1] = y_bottom; quad[1 * 3 + 2] = z; quad[2 * 3 + 0] = xp; quad[2 * 3 + 1] = yp; quad[2 * 3 + 2] = z; quad[3 * 3 + 0] = xp; quad[3 * 3 + 1] = y_bottom; quad[3 * 3 + 2] = z; render.simple_gui_texture.DrawQuad( quad, ch.uvs ); } x = x + ( ch.advanceWidth * scale / line_height ); } } }
internal void RenderFont( Display render, ref Box EffectivePosition , ref Vector3 u, ref Vector3 v , float scale, string text , ref Vector4 color ) { int c; uint rune; Display.EnableBlending( true ); GL.Enable( EnableCap.DepthTest ); render.simple_texture.Activate(); render.simple_texture.SetUniforms( OpenGl_TextureRef, ref color ); float[] quad = new float[12]; float x_left, y_bottom; Vector3 o = EffectivePosition.Position; Vector3 topleft; Vector3 topright; Vector3 bottomleft; Vector3 bottomright; Vector3 tmp_x_left; Vector3 tmp_x_right; Vector3 tmp_y_top; Vector3 tmp_y_bottom; float x_del = 0; float y_del = 0; float x_right, yp; FontCharacter ch; for( c = 0; c < text.Length; c++ ) { rune = GetUnicode( ref c, text ); if( rune == '\n' ) { y_del -= scale; x_del = 0; } else { ch = GetCharacter( rune ); if( ch.width > 0 ) { x_left = x_del + ( ch.leftSideBearing * scale / line_height ); yp = y_del + ( ( ch.topSideBearing - descent ) * scale / line_height );//( ( ( line_height + ch.yOffset ) * scale ) / line_height ); x_right = x_left + ( ch.width * scale / line_height ); y_bottom = yp + ( ch.height * scale / line_height ); Vector3.Multiply( ref u, x_left, out tmp_x_left ); Vector3.Add( ref o, ref tmp_x_left, out topleft ); Vector3.Multiply( ref v, yp, out tmp_y_top ); Vector3.Add( ref topleft, ref tmp_y_top, out topleft ); Vector3.Multiply( ref u, x_right, out tmp_x_right ); Vector3.Add( ref o, ref tmp_x_right, out topright ); Vector3.Add( ref topright, ref tmp_y_top, out topright ); Vector3.Add( ref o, ref tmp_x_left, out bottomleft ); Vector3.Multiply( ref v, y_bottom, out tmp_y_bottom ); Vector3.Add( ref bottomleft, ref tmp_y_bottom, out bottomleft ); Vector3.Add( ref o, ref tmp_x_right, out bottomright ); Vector3.Add( ref bottomright, ref tmp_y_bottom, out bottomright ); quad[0 * 3 + 0] = topleft.X; quad[0 * 3 + 1] = topleft.Y; quad[0 * 3 + 2] = topleft.Z; quad[1 * 3 + 0] = bottomleft.X; quad[1 * 3 + 1] = bottomleft.Y; quad[1 * 3 + 2] = bottomleft.Z; quad[2 * 3 + 0] = topright.X; quad[2 * 3 + 1] = topright.Y; quad[2 * 3 + 2] = topright.Z; quad[3 * 3 + 0] = bottomright.X; quad[3 * 3 + 1] = bottomright.Y; quad[3 * 3 + 2] = bottomright.Z; render.simple_texture.DrawQuad( quad, ch.uvs ); } x_del += ( ch.advanceWidth * scale / line_height ); } } }
public bool Draw( Display display, float game_time ) { Timer_Draw.Start(); if( frames == 0 ) frame_start = HighPerfTimer.GetActualTime(); frames++; if( Game_Run ) { // Rendering if( Basic_Renderer != null ) { // Process Input events (Mouse, Keyboard) // this is handeld from callbacks //EventManager.ProcessEvents(); // Process incoming events. // Process incoming sectors from the make/load working thread World.ProcessNewLoadedSectors( ); // Sector Ejection processing. World.ProcessOldEjectedSectors(); // if (MoveShipCounter>125 ) {GameEnv.MoveShip(); MoveShipCounter = 0; } // Player physics // PhysicEngine.DoPhysic( GameEnv.Time_FrameTime ); // Voxel Processor Get Player Position. //ZActor* Actor; //Actor = GameEnv.PhysicEngine.GetSelectedActor(); //GameEnv.VoxelProcessor.SetPlayerPosition( Actor.Location.x, Actor.Location.y, Actor.Location.z ); // Advertising messages GameWindow_Advertising.Advertising_Actions( game_time ); //ToolManager.ProcessAndDisplay(); Basic_Renderer.Render( display, this, World ); //if( Ge && Ge->Gui ) } } if( GuiManager != null ) GuiManager.Render( display ); //Timer.End(); Timer_Draw.End(); return true; }