Drawing a grid for an editor...
Blitz3D Forums/Blitz3D Programming/Drawing a grid for an editor...
| ||
Well this ones got me a bit stumped. At the moment, Im drawing my grid by using a mesh with WAY too many poly's to be efficient. I was thinking of drawing it in 2d, but that would overwrite anything that is in the scene.... Any ideas? |
| ||
http://members.home.nl/wdw/bbtips.html Try GRIB 1.0 very useful... |
| ||
Awe, you're a life saver! |
| ||
Thank Mr. Wiebo ;c) |
| ||
shame its only for blitzplus Matt |
| ||
You could set the ClsMode of the camera to false,true. That is, only clear the zbuffer. 1) Clear the screen with CLS or RECT 2) Draw the 2D grid 3) Render Entities |
| ||
^ ...wot Sweenie said =] That is the correct way to do it. You could also render the grid to a texture, put it on a quad, and make sure the lines match up to the blitz3d unit system... |
| ||
Wireframe.... Looks like I'll be manually drawing the grid. I had hoped there was a better alternative, but I knew there really wasn't one ;). |
| ||
Have a look at this example...(Warning, Messy code!)Graphics3D 640,480,0,2 SetBuffer BackBuffer() AmbientLight 255,255,255 WireFrame True CamScale#=0.1 Global Camera = CreateCamera() PositionEntity Camera,0,0,-50 CameraProjMode Camera,2 CameraZoom Camera,CamScale# CameraClsMode Camera,False,True ClsColor 150,150,150 Global GRIDSTEP#=1.0 ; Size of each GridBlock Global GRIDCOLR=90 Global GRIDCOLG=90 Global GRIDCOLB=90 SeedRnd MilliSecs() mesh1 = CreateCylinder() PositionEntity mesh1,Int(Rnd(-5,5)),Int(Rnd(-5,5)),0 EntityColor mesh1,255,0,0 mesh2 = CreateSphere() PositionEntity mesh2,Int(Rnd(-5,5)),Int(Rnd(-5,5)),0 EntityColor mesh2,0,0,255 While Not KeyDown(1) Select MouseZSpeed () Case -1 CamScale#=CamScale#*0.9 If CamScale#<0.001 Then camScale#=0.001 CameraZoom Camera,CamScale# Case 1 CamScale#=CamScale#*1.1 If CamScale#<0.001 Then camScale#=0.001 CameraZoom Camera,CamScale# End Select ; MousePanning XDiff=-MouseXSpeed() YDiff=MouseYSpeed() If MouseDown(1) Then MoveEntity Camera,XDiff/(400.0*CamScale#),YDiff/(300.0*CamScale#),0 EndIf DrawGrid() Color 0,0,0 RenderWorld Flip False Wend End Function DrawGrid() Cls CenterX#=EntityX#(Camera) CenterY#=EntityY#(Camera) StartDrawX#=Int(CenterX#/GRIDSTEP#)*GRIDSTEP# StartDrawY#=Int(CenterY#/GRIDSTEP#)*GRIDSTEP# ; Vertical lines ;Draw lines center to left CurrPosX#=StartDrawX# Repeat CameraProject(Camera,CurrPosX#,CenterY#,0) Xpos=ProjectedX() If CurrPosX#=0 Then Color 0,0,0 Else Color GRIDCOLR,GRIDCOLG,GRIDCOLB EndIf Line Xpos,0,Xpos,480 CurrPosX#=CurrPosX#-GRIDSTEP# Until Xpos<0 ;Draw lines center to right CurrPosX#=StartDrawX#+GRIDSTEP# Repeat CameraProject(Camera,CurrPosX#,CenterY#,0) Xpos=ProjectedX() If CurrPosX#=0 Then Color 0,0,0 Else Color GRIDCOLR,GRIDCOLG,GRIDCOLB EndIf Line Xpos,0,Xpos,480 CurrPosX#=CurrPosX#+GRIDSTEP# Until Xpos>640 ; Horizontal lines ;Draw lines center to up CurrPosY#=StartDrawY# Repeat CameraProject(Camera,CenterX#,CurrPosY#,0) Ypos=ProjectedY() If CurrPosY#=0 Then Color 0,0,0 Else Color GRIDCOLR,GRIDCOLG,GRIDCOLB EndIf Line 0,Ypos,640,Ypos CurrPosY#=CurrPosY#+GRIDSTEP# Until Ypos<0 ;Draw lines center to down CurrPosY#=StartDrawY#-GRIDSTEP# Repeat CameraProject(Camera,CenterX#,CurrPosY#,0) Ypos=ProjectedY() If CurrPosY#=0 Then Color 0,0,0 Else Color GRIDCOLR,GRIDCOLG,GRIDCOLB EndIf Line 0,Ypos,640,Ypos CurrPosY#=CurrPosY#-GRIDSTEP# Until Ypos>480 End Function |
| ||
great stuff! |
| ||
yea , really great ! |
| ||
Kinda hi-jacking the thread, but it's a similar question. how might you do an editor grid like maplet/droplet? |
| ||
I've also been experimenting with an editing grid for a program I'm working on. The code below is what I'm currently using to do the grid. It requires a 256 x 256 texture with 10 pixel wide opaque lines across the top and down the left side, and with the remainder of the image transparent. ; -- Setup code. ; -- Grid positioning variables. Global grid_height# Global grid_height_spacer# = 0.003 Global grid_scale# = 1.0 ;^^^^^^ Global grid = CreatePlane () Global grid_tex = LoadTexture ( "C:\Documents and Settings\Owner\Desktop\B3D VIEWER\media\images\Copy3 of Copy of grid.png", 11 ) EntityTexture grid, grid_tex EntityFX grid, 13 MoveEntity grid, -0.0195312, grid_height_spacer#, -0.0195312 the_grid2 = CopyEntity ( grid, grid ) MoveEntity the_grid2, 0.0, -grid_height_spacer#, 0.0 ScaleEntity the_grid2, 1.0, -1.0, 1.0, True ; -- Update function. Function move_and_size_grid() If KeyHit ( 18 ) ; The 'E' key. grid_height# = grid_height# + grid_scale# PositionEntity grid, -0.0195312, grid_height# + grid_height_spacer#, -0.0195312, True do_update = True EndIf If KeyHit ( 16 ) ; The 'Q' key. grid_height# = grid_height# - grid_scale# PositionEntity grid, -0.0195312, grid_height# + grid_height_spacer#, -0.0195312, True do_update = True EndIf If KeyHit ( 13 ) ; The '+/=' key. grid_scale# = grid_scale# * 2.0 ScaleTexture grid_tex, grid_scale#, grid_scale# do_update = True EndIf If KeyHit ( 12 ) ; The '-/_' key. grid_scale# = grid_scale# / 2.0 ScaleTexture grid_tex, grid_scale#, grid_scale# do_update = True EndIf End Function |
| ||
Sweenie, that's great! I'ev been working on an editor for something and doing it all 2D but this works much better. I'd never seen that CameraClsMode command before. Do you mind if I poach a bit of that code and rework it for mine? |
| ||
Do you mind if I poach a bit of that code and rework it for mine? Trying to steal our preciousssssssshhh..., filthy little hobbitssssss. Hehehe, just kidding. Go ahead, hope you find it useful. :) |
| ||
TA! |