Sign in to follow this  

Design of a object clipping code

This topic is 4712 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

hi. Part of a project I am doing at the moment involves using poly meshes as clipping objects for other poly meshes. The poly mesh is used to produce a BSP rep of the volume it contains and the planes of this are used as clipping planes. MY question is of design... I have coded all the functions required and everything works fine (I actually did this a while ago) but I am not totally satisfied that my design is the best. I have CObject classes that contain lists of polygons as well as a BSPTree member for the mesh of the object. To clip a poly to a BSP I call a clipTriangle method on an objects BSP with a triangle and it is capable of just informing the caller of a clip result or it can actually clip the triangle and return a new list of sub triangles instead. Is this the best way to do this? All my geometry calculation methods (primitive intersection routines etc) are in a separate class as static members and so rather than say calling CPlane::intersects() etc you would call GeomLib::intersects(CPlane&, CLine&) for example. This is a more C-style way of doing things I guess but is there anything wrong with this (ignoring the C++/C issue). The last issue is to do with positional relativity. The polygons of an object have vertices whose positions are relative to the world space position of the object to which they belong. Therefore, the BSP trees of an object are also in the objects local space. When I need to clip a poly from one object against the BSP tree of another, I calculate a value (objApos - objBpos) which i then set to a static variable. Then inside the geometry functions, this value is used to adjust the positions of the primitives involved so they are both in the same coordinate space. Is this a good idea or could it be done better? Thanks. [Edited by - BigBadBob on January 19, 2005 12:46:11 AM]

Share this post


Link to post
Share on other sites
Personnaly, I think it's good the way you do it.

CObject* pxClippedObject = = pxTheClipper->Clip(pxMyObject);

You just use the clipper as a tool, a tool you apply on an object and it returns a result. Then if you have different types of objects, all the cliping code will be inside the Clipper class, so tidier. You can also have inherited classes of clippers as well. Other ways would make the code rather messy.

#include "Polygon.h"
#include "Mesh.h"
#include "Nurbs.h"

CPolygon* CClipper::Clip(CPolygon* pxPolygon);
CMesh* CClipper::Clip(CMesh* pxMesh);
CSegment* CClipper::Clip(CSegment* pxSegment);
CNurbs* CClipper::Clip(CNurbs* pxNurbs);


as for the local space transform, it's also a good idea. It should be a lot more memory efficient (no need for copies, and possible mem allocs). Besides, do you *REALLY* want to convert a BSP tree entirely into world space coords every frame? And your complex meshed models? Even if only a couple of triangles get clipped? Compute the relative transform, it's a bit more complex and you have to be a bit careful in the order of things and what needs to be converted to what, but with 3D geometry, it's almost a requirement.

Share this post


Link to post
Share on other sites

This topic is 4712 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this