Draw minib3d objects as max2d "images"
BlitzMax Forums/MiniB3D Module/Draw minib3d objects as max2d "images"
| ||
Tonight i tried to solve this question, and here im done. Maybe someone can use this, its a little bit dirty but it works fine :) Add this to Tglobal in tglobal.bmx Global HudCamera:TCamera Global HudLight:TLight Function Create2dCamera:TCamera() Local newcam:TCamera = TCamera.createCamera() TCamera.cam_list.Remove(newcam) 'remove so its ignored by all other normal minib3d stuff 'TEntity.entity_list.Remove(newcam) 'remove so its ignored by all other normal minib3d stuff newcam.CameraClsMode(0, 0) newcam.proj_mode = 0 positionEntity(newcam, 1, -1, 0) HudLight = CreateLight(2) TLight.light_list.Remove(HudLight) 'remove so its ignored by all other normal minib3d stuff HudCamera = newcam End Function Function RenderMeshTo2D(mesh:TMesh, x:Float, y:Float) 'render mesh ortho 'ignores hidden state of mesh EndMax2d positionEntityto2d(mesh, x:Float, y:Float) HudCamera.Update() HudLight.Update() ' For Local light:TLight = EachIn TLight.light_list ' ' light.Update() ' EntityHidden code inside Update ' ' Next mesh.GetBounds() Local inview:Int If ((mesh.brush.fx And 16) = 16) Then inview=True Else inview = HudCamera.EntityInFrustum(mesh) End If If inview If mesh.auto_fade = True Then AutoFade(HudCamera, mesh) If mesh.Alpha() mesh.alpha_order:Float = HudCamera.EntityDistanceSquared:Float(mesh) Else mesh.alpha_order#=0.0 EndIf mesh.Update() EndIf beginmax2d End Function Function positionEntityto2d(entity:TEntity, x:Float, y:Float) PositionEntity(entity, 2 * (x:Float / Self.width), -2 * (y:Float / Self.Height), 1) End Function then you just need to do this once at start: tglobal.Create2dCamera() and after this you will be able to use this between the beginmax2d and endmax2d area, and so its ordered into the 2d Drawings like an image drawn with DrawImage() tglobal.RenderMeshTo2D(mesh:TMesh, x:Float, y:Float) mesh is the mesh you want to render, and X and Y are the position (on your screen) Dont forget to maybe scale the mesh before render it with this, because the screen is exacly 1 Minib3d Distance unit big, so you need to scale you mesh in screen relation, otherwise it will be very big and look differend on differend resolutions. i used this for example: ScaleEntity(mesh, Float(10.0 / screenwidth) * 2, Float(10.0 / screenheight) * 2, 1) Also the mesh will have its midpoint at the X and Y position. example: (all the red fruits are minib3d meshes drawn with this trick well ordered into the max2d stuff) Last edited 2011 |
| ||
Why not just use CameraProjMode? something like: BeginMax2D() <draw max2d images> EndMax2D() CameraClsMode cam,false,false CameraProjMode cam,2 <render mesh here> CameraProjMode cam,1 CameraClsMode cam,true,true That's what I did to render 3D on top of 2D... Last edited 2011 |
| ||
Because in that case, the 3d stuff is over all max2d stuff, not ordered between the drawimage() thingies, also i wanted to use it for GUI stuff (specialy for my inventory here shown on the screen), just with X and Y coordinates that fits with max2d and in ortho projection mode. Just with 1 function to draw the stuff like using drawimage() or something. so i just thought that its bether to have a special camera for rendering the stuff in the GUI, instead of modifing the main camera all the time. And a special render function that is not looping through all the meshes again, instead of just show the given mesh. |