Jump to content

Hdk Basics


Recommended Posts

As far as I know, a null pointer is simply the value 0 (zero). So I'm thinking he means something like this:

prefarr(gdp,0);

19463[/snapback]

I'll try it when I get home, if it is that why the blue blazes doesn't it initialise to 0 if you don't specify it. :huh: Would've saved me hours of reading. Oh well I learnt some stuff anyway. :)

Yup, 0 does it. grrrrrr.... all so simply once you know how. Well definitely one to watch out for in the future. :rolleyes:

Edited by sibarrick
Link to comment
Share on other sites

  • Replies 84
  • Created
  • Last Reply

Top Posters In This Topic

Yeah, GB_PointRefArray's constructor doesn't have a default parameter for the GB_Group (but GEO_PointRefArray has one for the mask -- so you could do:

GEO_PointRefArray   ptrefarr(gdp);

and that should work also). Default parameters are useful when used properly, but they are a hit and miss with programmers, some people like them, others hate them.

didn't try giving it a null pointer cos I thought that was *bad*

Dereferencing a NULL pointer is bad, but you can still query it to see if it is NULL before you dereference it. That way they can be useful as optional parameters. So you can write a method that takes a particular parameter if the user wants to supply it, but can work more generally if the user doesn't care and just passes NULL. Your methods have to be careful and check for NULL. If you don't want an optional parameter and want pass-by-reference semantics in C++, it's probably best to use references (or const references).

Take care,

George.

Link to comment
Share on other sites

No your right, the first thing I tried was GB_Group not GEO_PointRefArray, i never thought of trying GEO_PointRefArray that way cos GB_Group had already failed, doh!

So near yet so far.

19491[/snapback]

Great! So you got it to work the way you like?

George.

Link to comment
Share on other sites

I hope it won't sound too abstract.

Imagine we have created several duplicates of our geometry before editing it in a cook method. Will it be posiible to, for example, create a vector between the points of these two different copies of the geometry?

No, I don't actually need this - I am just curious.

Link to comment
Share on other sites

Ok, folks :)

I need to put a face's normal into a "central point" that I've created and placed it in the center of a face (who could've guessed! ;) )

I mean my "central point" doesn't have a normal (I suppose) - at least I don't see it in Houdini. Or it is 0, 0, 0. I a not sure. So I need to create its normal and make it the same as face's normal.

How can I do it?

Thanks.

Link to comment
Share on other sites

Ok, I did that. It was relatively easy - just find out a couple of methods and it's ok: (if somebody, like me, might be interested - here's the code)

gdp->normal();

int nml_index = gdp->findPointAttrib("N", sizeof(UT_Vector3), GB_ATTRIB_VECTOR);

...

face_normal = prim->computeNormal();

chNml = (UT_Vector3 *)ppt->getAttribData(nml_index);

*chNml = face_normal;

=============================================

Another question:

Is there some way to find out the distance between a point and the nearest edge? (With a condition that the point doesn't lie on an edge)

Thanks.

Link to comment
Share on other sites

Is there some way to find out the distance between a point and the nearest edge? (With a condition that the point doesn't lie on an edge)

I'd first look at the vector classes for vector-like operations like that.

A quick scan of UT_Vector3 reveals:

A free-floating (i.e: non-member) function which returns the square distance between a point (pos) and a line segment (pt1,pt2):

inline	fpreal  segmentPointDist2( const UT_Vector3 &pos, 
        const UT_Vector3 &pt1, 
        const UT_Vector3 &pt2 );

And one member function which returns the signed distance between itself and a segment:

fpreal UT_Vector3::distance(const UT_Vector3 &p1, const UT_Vector3 &v1) const;

So I'm guessing you could use whichever's more convenient.

The closest segment would be a matter of running the above for all edges and keeping the one whose distance has the smallest magnitude (watch out for "signed" distances in the case of the member function).

(oh, btw, a "point", in the geometry-detail sense, contains a UT_Vector4, which can be reinterpreted as UT_Vector3, then the above applies... though it would be nicer if they made those functions available in hte UT_Vector4 class too...)

Hope that helps,

Cheers!

Link to comment
Share on other sites

Hello again,

the code is simple and it must work, I suppose, but it doesn''t for some reason:(it is supposed to add "central points" to emit_gdp and rewrite gdp)

GU_Detail *emit_gdp = new GU_Detail();

if (lockInputs(context) >= UT_ERROR_ABORT)

return error();

now = context.myTime;

duplicateSource(0, context);

FOR_ALL_PRIMITIVES(gdp, prim)

{

pos = prim->baryCenter();

ppt = emit_gdp->appendPoint();

ppt->getPos() = pos;

}

gdp->clearAndDestroy();

gdp = emit_gdp; // or gdp->merge(*emit_gdp); - it doesn't work either

unlockInputs();

return error();

}

what could be wron woth that? The current result is 0 geoetry - 0 points, 0 primitives, etc.

Link to comment
Share on other sites

And yes I am sure that the points are created in emit_gdp - coz if I don't clearAndDestroy my gdp and just merge'em - I see the 2 geos merged all right.

gdp->merge(*emit_gdp);

But actually what I need is to get rid of the initial gdp and substitute it with the new emit_gdp.

Thanks.

Link to comment
Share on other sites

Is there an easy way to Clamp a value in HDK, the same as Clamp VOP or Clamp VEX function works? (to clamp my_var, say, between 0 and 1)

Or should I use just maths?, soething like:

if (tmp<0)tmp=0;

if (tmp>1)tmp=1;

================

and the same question about max( a , b ); function. Is there such in HDK?

Thanks

Link to comment
Share on other sites

It's strange - but the vector.length(); seems to return a noralized vector no matter it was NOT normalized.

rP = ppt->getPos();

eP = emit_ppt->getPos();

rvec = eP - rP;

rvec.length(); //returns a result of 1;

nrvec = rvec.normalize();

nrvec.length(); //returns a result > 1;

that's weird, isn't it? Is it a normal behaiviour or I did something wrong?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...