• Advertisement
Sign in to follow this  

How to know what will be rendered?

This topic is 4274 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm using managed C#, dx9 and I want to process only the visible triangles of an object. Basically, drawing selectable lines for the polys. I've tried using the face normal but this approach runs into problems on concave objects such as a 3-D Letter "H." What is a better approach for this? Thanks. Jas

Share this post


Link to post
Share on other sites
Advertisement
I've done a similar thing, but it depends on what you mean by 'selectable lines'. If you mean you'd like to outline each triangle with a line, why don't you just redraw the entire object using non-textured wireframe mode - it's probably quicker than messing about working out which lines to draw. If your vertices are the wrong colour, you can simply use a very small texture of plain colour to get the required shade.

Hope this helps...

Share this post


Link to post
Share on other sites
Quote:
Original post by Jas001
I'm using managed C#, dx9 and I want to process only the visible triangles of an object. Basically, drawing selectable lines for the polys.


What do you mean by 'process'? what are you doing with these triangles? Is this for rendering, or picking or what?
What do you mean by 'selectable lines'?
Are you trying to do some kind of raycast mouse picking calculation?

It really isnt clear what you're trying to do, and that affects the solution of course...

Share this post


Link to post
Share on other sites
Thanks for the reply...
Yes, I'm doing picking on the lines.

Drawing a wireframe with a properly colored texture would visually be correct, but would not help with the picking routine. I don't want the user to select things on hidden faces and I don't want to do the routine on non visible lines.

So, DirectX can figure out which lines will be visible in wireframe mode. How can I do the same in my code? Can't use the zbuffer because of the example I listed above. Or, can I query the device (dx9 DeviceQuery9) to tell me which vertices are visible? There has got to be a better way of handling this.

Share this post


Link to post
Share on other sites
I see what you're trying to do.

You need to write a routine to pick a polygon and discard it if it is facing away (see the DX SDK). With the selected [facing] polygon, take each edge and check whether your mouse position is along that line (with perhaps a threshhold of a pixel or 2) using linear interpolation. Use D3DXVec3Transform to transform the polygon's vertices into screen space and feed those edges into your 'CheckPointOnLine' routine.

If you need to not be able to select polygons which are partly on and partly off-screen, you can just check the polygon's transformed-into-screen-space vertices against your screen size, if any of them are outside, fall through the selection routine.

I have done this before and it works well - albeit in projection mode. Using a perspective mode shouldn't be any different.

Hope that helps

Share this post


Link to post
Share on other sites
am I to understand that you are trying to use the mouse cursor, to let the user select Lines(not faces/triangles) from a wireframe mesh?
I guess you must be building a mesh editing tool or something? and need an edge selection ability?


If that is correct, then what I would do is:

take the picking ray (the projection of the mouse cursor as a line into the 3d space)
then intersect this picking ray with the Triangles of the mesh, keeping track of the intersection point that happens Nearest to the camera (the triangle in front).(make sure you discard triangles that have backwards facing Normals, theyre not visible)
Once we find the frontmost triangle, we then compare the distance of each of it's 3 edges to the picking ray, and select the edge that was closest.

This way, the user does not need to be pixel-perfect when clicking on a line to select it; the Nearest one gets chosen. Additionally, the hidden line problem is handled by the fact that we based this on the Triangles and used their depth (thus the depth of the edges that make them up).

Share this post


Link to post
Share on other sites
Guys, thanks for the pointers but I'm not looking for the picking routine. My problem is with determining which triangles are being drawn in the scene.

I need to do more than discard triangles facing away. Take the 3-D "H" example. If you are standing in a room looking at an "H" laying on the floor it would look like so:

     |    |
me |---| removing non facing polys still leaves:
     |    |


     |    |
me |    | Because the geometry on the right is still facing the camera.
     |    |


So, when I test for picking if I were to select one of the near polys, I might also select one of the far polys. Even if I didn't I'm drawing the lines on top of my object so it can look messy. So, what I want to do is only draw lines for polys that will actually be rendered to the scene.

Share this post


Link to post
Share on other sites
Ok,
So are you asking about how to do picking, (if you hit more than one face, take the one in front)
Or are you making your own software renderer and are asking about hidden line removal?

lookup articles on 'hidden line removal' I think this might be the term you're looking for.

Why is it wireframe? wireframe is a pain since well, you can see through your mesh. And you can't just use a zbuffer to hide the stuff in back... and Painter's Algorithm fails too...
Lot's of old wireframe games have the problem you describe about seeing other parts of the mesh behind front pieces...

Can you 'fake' wireframe, by using actual polygons with a textured edge isntead?

my guess is that if wireframe with lines is Absolutely required, then the only way to get rid of this problem of seeing through 'faces'(even though polygons dont have faces in wireframe) is to do a lot of painful work...

--
sort the polygons front to back

maintain a 'silhouette' of the area on screen that is covered by polygons in front; (starts out as blank, is represented as a closed loop of line segments)

for each new polygon drawn, its lines are clipped against the silhouette to make sure they dont show through an existing face (use line interesection test of new line to lines in silhouette loop)

additionally, new lines that are only partially hidden by the silhouette must be added to it's border to make it grow and count their areas as also covered (complex special cases here, such as multiple silhouettes in same mesh, etc, I don't know the details)

you can use a BSP structure to speed up the expensive polygon sorting

anyhow... thats the basic idea as far as i know
It's kinda painful, so if possible filled polygons would be easier than wireframe; then you can just do Painters Algo (draw them back to front order so front ones cover up back ones)

[Edited by - haphazardlynamed on May 10, 2006 1:54:45 PM]

Share this post


Link to post
Share on other sites

If you're trying to do a hidden line rendering, you might try doing a Z-only rendering of the faces, followed by a wire-frame rendering with Z test <=. This should give you an outline rendering with the hidden lines occluded.


JB

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement