I can't get RenderCollision
to work, no matter how I try.
The documentation says :
RenderCollision (view_id: int, vtx_layout: VertexLayout, prg: ProgramHandle, render_state: RenderState, depth: int) -> None
Here's my (limited) understanding of what I should pass as parameters to this function :
view_id
: can be set from 0 to 255, according to the doc. In my case, it is 0vtx_layout
: the vertex layout to store 3D linesProgramHandle
: the program (shader) needed to draw 3D linesRenderState
: something I'm supposed to provide usingComputeRenderState
(found it here)depth
: something relative to the zDepth, I guess?
At this point, I feel I'm not far from using it properly, but I'm having a hard time to figure out the RenderState thing. Anyone been there before?
CodePudding user response:
RenderCollision
is a debug function, so it won't "consume" any view_id. Indeed, you can pass it the view_id, it will write into the current view.
vtx_layout and prg, as you guessed it, handle the rendering of the debug lines (RenderCollision is using lines to draw the collision shapes).
It usually works this way:
Avoid clearing the view when drawing the debug info
hg.SetViewClear(view_id, hg.CF_None, 0, 1.0, 0)
Set the rect of the current view (the same as your main rendering)
hg.SetViewRect(view_id, 0, 0, screen_size_x, screen_size_y)
Set the camera transformation matrix (the same as your current camera)
hg.SetViewTransform(view_id, view_matrix, projection_matrix)
This is the one you were probably looking at: BM_Opaque
will let know Harfang where you want to specifically draw within the rendering pipeline:
render_state = hg.ComputeRenderState(hg.BM_Opaque, hg.DT_Disabled, hg.FC_Disabled)
Final instruction that will draw the collision shapes:
physics.RenderCollision(view_id, vtx_line_layout, line_shader, render_state , 0)
You will find a working example here, I hope it will help: https://github.com/harfang3d/tutorials-hg2/blob/master/physics_overrides_matrix.py#L69