Drawing miniB3D 3D Objects Over Max2D

BlitzMax Forums/MiniB3D Module/Drawing miniB3D 3D Objects Over Max2D

AdamRedwoods(Posted 2011) [#1]
Took me a while to figure this out, so I thought I'd post it (I know-- I use miniB3D in obscure ways).

If you want to draw 3D Entities over your 2D, which is already drawing over 3D, specifically a certain render order:

- Draw your RenderWorld()
- Do a BeginMax2D(), draw stuff, then an EndMax2D()
- Then draw a specific 3D entity over that other stuff

Here's how I did it, fairly simple:
RenderWorld()
''
BeginMax2D()
''do some stuff, like DrawImage
EndMax2D()

cam.CameraClsMode(0,1)
cam.Update()
ent1.PositionEntity (v.x, v.y, v.z)
ent1.Update()

''and dont forget to set this back:
cam.CameraClsMode(1,1)

If you want to convert 2d into 3d coordinates:
Function project2Dto3D:TVector(cam:TCamera, vx:float, vy:float)
	Local px:Double
	Local py:Double
	Local pz:Double
	local vw:float = 0.1 ''I had to play with this value depending on camera depth range
	vy = TGlobal.height - vy ''opengl is bottom left (0,0)
     gluUnProject(vx,vy,vw,cam.mod_mat,cam.proj_mat,cam.viewport,Varptr px,Varptr py,Varptr pz)

	Local v:TVector = TVector.Create(Float(px), Float(py), -Float(pz) )
	Return v
EndFunction


And yes, this is all vanilla miniB3D. Shows it's versatility.

******
Now theoretically, you could use this to enable certain Shader Functions for specific entities, without redrawing the whole scene.
But this idea is untested (for now).

******
I couldn't get the overlays to work with multiple cameras, but that's too minor at this point for me to figure it out.

Last edited 2011

Last edited 2011

Last edited 2011

Last edited 2011


ima747(Posted 2011) [#2]
nice, thanks for this. I love NOT having to modify the module to get something new to work :0)


Kryzon(Posted 2011) [#3]
Very nice, that projection function is very valuable. Do you think there is a way to compute the best 'vw' value depending on the current camera range, in order to avoid the tweaking?

For instance, what was your camera range for that '0.1' value to be acceptable?


AdamRedwoods(Posted 2011) [#4]
My arbitrary value is for a camera range of 1 to 100, with orthographic perspective. The value vw ranges from 0.0 to 1.0. At 0.0 the position returns a clipped object, and 1.0 is too far, so I chose 0.1. I was trying to get as close to the camera without clipping.

There are different ways to compute vw. I found some detailed descriptions online, one being that they're reading the depth buffer to grab the nearest vw:

http://www.idevgames.com/forums/thread-8544.html
http://www.idevgames.com/forums/thread-2246.html

The way it is normally used is to call it twice: once for vw=0.0 and again for vw=1.0
This way you can get your location vector values, which would be your near and far values of the depth buffer at that point. You could then create a ray and do a ray/triangle intersection to find a specific object location.

BTW-- this is code right out of the CameraPick function.

Last edited 2011

Last edited 2011