sibarrick Posted July 22, 2005 Share Posted July 22, 2005 Must be something wrong, I've using length() loads already and it always works fine. Try adding cout<<rvec<<endl; so you can see what it's evaluting to Quote Link to comment Share on other sites More sharing options...
Mario Marengo Posted July 22, 2005 Share Posted July 22, 2005 Strange indeed... you must be doing something wrong... UT_Vector4::length() just runs ::dot() on the argument and itself. But a 4-vector represents homogeneous coordinates, so a 4-component dot product ain't the same as a 3-component one (likely, it will return a value which is bigger by 1). Then there is the normalize() issue. Looking at its definition, you'll realize that it normalizes *itself* -- it does the normalization "in place" (modifies itself so as to have a length of 1) and UT_Vector3 returns (for convenience) its current length squared, whereas UT_Vector4::normalize() returns nothing. But given that you don't specify the type for either rvec or nrvec in your code snippet, it's hard to tell exactly what brand of catastrophe the statement nrvec = rvec.normalize(); is actually causing (even though I'm not an experienced programmer, I think I can safely say that types are very important in C++ -- keep track of them at all times). Anyway. I'm pretty sure I know what you're trying to do so, reading between the lines a little, here's a possible fix: //... include all the proper headers, etc...// //...// // vec4-to-vec3 truncation via UT_Vector3::operator=(UT_Vector4 const &); UT_Vector3 rvec = ppt_emitter->getPos() - ppt_receiver->getPos(); // length squared since you might need it for other tests...I think;) fpreal d2 = dot(rvec,rvec)+1e-9; //tiny offset to avoid 0-length // stuff that makes use of d2 and the full-length rvec goes here... maybe... // Now make rvec unit length, and use it in the dot product stuff... perhaps... rvec /= SYSsqrt(d2); //...// Hope that helps. Quote Link to comment Share on other sites More sharing options...
MADjestic Posted July 23, 2005 Share Posted July 23, 2005 Thanks, Mario. I think that helps. At least I am digging the code now Could be the possible reason that the things go wrong the way I cycle my points?: ... GEO_Point *ppt, *emit_ppt; ... FOR_ALL_GPOINTS(gdp, ppt) { ... FOR_ALL_GPOINTS(emit_gdp, emit_ppt) {...} ... } or it's fine? And, btw, should be points' position (eP, rP)of UT_Vector3 or UT_Vector4 type? Thanks. Quote Link to comment Share on other sites More sharing options...
hoknamahn Posted July 23, 2005 Author Share Posted July 23, 2005 And, btw, should be points' position (eP, rP)of UT_Vector3 or UT_Vector4 type? I think it doesn't matter. The fourth component is W. If you want to clamp value you can use UTclamp(val, min, max). Quote Link to comment Share on other sites More sharing options...
MADjestic Posted July 23, 2005 Share Posted July 23, 2005 I think it's WAY better now, then it was. Another question - how can I control the precision of variables? I think the result of some multiplications exeeds normal ranges and I get something like -0.179462e-18 and I am not sure how Houdini interprets this in its turn - So I think I would be happy to render such numbers as, say 4 digits after point, i.e. -0.1794. What do you say? And how can I achieve this? Thanks. Quote Link to comment Share on other sites More sharing options...
MADjestic Posted July 23, 2005 Share Posted July 23, 2005 I think this question should be a simple one. vect = Pemit - Preciev; Is it, in a general case, a vector FROM emitter or TO emitter? Thanks. Quote Link to comment Share on other sites More sharing options...
Mario Marengo Posted July 24, 2005 Share Posted July 24, 2005 I think the result of some multiplications exeeds normal ranges and I get something like -0.179462e-18 and I am not sure how Houdini interprets this in its turn - So I think I would be happy to render such numbers as, say 4 digits after point, i.e. -0.1794. What do you say? And how can I achieve this? The value -0.179462e-18 is scientific notation for a decimal point followed by 18 zeros and then the value 179462. In other words, it is a compact way of writing the value -0.000000000000000000179462, which you can safely read as simply "zero". And which as you can see, is not at all the same as "-0.1794". So no, please don't feel "happy to render such numbers as, say 4 digits after point". I think this question should be a simple one.vect = Pemit - Preciev; Is it, in a general case, a vector FROM emitter or TO emitter? There is no "general case" here; it is what the expression makes it, which in this case can be interpreted as a vector FROM the receiver TO the emitter, but whose origin is at {0,0,0} -- i.e: a "free" vector. Meaning that the expression Preceiv + vect will have a value exactly equal to Pemit. Hope that makes some sense. Quote Link to comment Share on other sites More sharing options...
MADjestic Posted July 24, 2005 Share Posted July 24, 2005 Thank you, Mario. Quote Link to comment Share on other sites More sharing options...
MADjestic Posted July 30, 2005 Share Posted July 30, 2005 Hi, I need to create an array of pointers, pointing at different ppt. Then I want to access different points' attributes via my array of pointers (as if I was dealing with normal ppt). What type of should be my array? The same as ppt(which is GEO_Point) or something different? What is the maximum size of such array, are there any limits? And the second question. How can I destroy such array when I don't need it any more? Or will it be destroyed automatically? Thanks. P.S. I am trying to develope a hand-made kd_tree_kind_of_structure - so that I could make a kind of array of ponts and sort them as I want. Quote Link to comment Share on other sites More sharing options...
edward Posted July 30, 2005 Share Posted July 30, 2005 What type of should be my array? The same as ppt(which is GEO_Point) or something different? Depends on what you want. "GEO_Point *" is certainly the most flexible. What is the maximum size of such array, are there any limits? You can make use of <UT/UT_PtrArray.h>. It's dynamically resizeable. Thus if you choose GEO_Point pointers as your base type, your variable becomes: UT_PtrArray<GEO_Point *> myPointArray; And the second question. How can I destroy such array when I don't need it any more? Or will it be destroyed automatically? It's destroyed automatically with UT_PtrArray when the object instance destructs. Quote Link to comment Share on other sites More sharing options...
MADjestic Posted July 31, 2005 Share Posted July 31, 2005 UT_PtrArray<GEO_Point *> myPointArray; It's destroyed automatically with UT_PtrArray when the object instance destructs. 20033[/snapback] That's very valuable, edward, thanks. A small question - do I still have to initialize my array and its bounds presizely? I.e. do I have to initialize my array as: UT_PtrArray<GEO_Point *> myPointArray[8][8][1000]; or can I just initialize it as : UT_PtrArray<GEO_Point *> myPointArray; - and then, later in the code, assign the members of the array, like for(i=1;i<=100;i++) { myPointArray[i]=my_var; } ? Thank you. Quote Link to comment Share on other sites More sharing options...
FrankFirsching Posted July 31, 2005 Share Posted July 31, 2005 UT_PtrArray<GEO_Point *> myPointArray[8][8][1000];UT_PtrArray<GEO_Point *> myPointArray; The first line is doing something completely different than the second line. Here you initialize a fixed size 3-dimensional array of UT_PtrArrays. So taking into account, that UT_PtrArray is a 1-dimensional data structure, You have 4 dimensional totally. In the second line you allocate 1 UT_PtrArray (instead of 64000 above). So you have one 1-dimensional data structure. But your array has a length of zero. You can specify the size of the array in the constructor of UT_PtrArray: UT_PtrArray<GeoPoint*> myPointArray(100); Here 100 is passed on to the sz parameter of the constructor. This will set the initial size of the array to 100. So square brackets always allocate a number of objects of the given type. Parentheses pass the values to the constructor. To make a long explanation short: UT_PtrArray <GeoPoint*> myArray1[100]; and UT_PtrArray <GeoPoint*> myArray1(100); are two different things. The first allocates 100 UT_PtrArrays with zero entries, while the second one allocates one array with 100 entries. Quote Link to comment Share on other sites More sharing options...
MADjestic Posted July 31, 2005 Share Posted July 31, 2005 Thanks, FrankFirsching another question - How can I choose a specific point in gdp? Or cycle'em through for(i=1;i<=100;i++){ppt= gdp->getPoint(i);} or something like that. Quote Link to comment Share on other sites More sharing options...
Mario Marengo Posted August 1, 2005 Share Posted August 1, 2005 If you intend to modify the points, then: GEO_Point *ppt; GEO_PointList &pl = gdp->points(); unsigned npt = pl.entries(); for(unsigned i=0;i<npt;i++) { ppt=pl[i]; /*...*/ } Or, alternatively... GEO_Point *ppt = gdp->points().head(); while(ppt) { /*...*/ ppt=ppt->next(); } Of course, if you just want to read the points, you should use the const versions of those: GEO_Point const *ppt; GEO_PointList const &pl = gdp->points(); //...// Quote Link to comment Share on other sites More sharing options...
MADjestic Posted August 13, 2005 Share Posted August 13, 2005 Hi, is there a standard way to get a point number? I need to do the following: FOR_ALL_PRIMITIVES(gdp, prim)//here I need to cycle all faces of my geo { ofstream f("file.txt", ios::app); //here I plan to somehow cycle all points of a face ( f << "Face's points" << _point_number_ << endl; ) } Any ideas how to do it? Thanks. Quote Link to comment Share on other sites More sharing options...
MADjestic Posted August 13, 2005 Share Posted August 13, 2005 Or another question - 1)How can I cycle through points of a certain face (primitive)? 2)Is there an easy way to get the number of primitives in a gdp, similar to points? (e.g. GEO_PointList &pl = gdp->points(); unsigned npt = pl.entries(); ) Thanks Quote Link to comment Share on other sites More sharing options...
edward Posted August 14, 2005 Share Posted August 14, 2005 untested example ... int vertex_count; int i; GEO_Primitve *prim; cerr << "Number of primitives: " << gdp->primitives().entries() << endl; FOR_ALL_PRIMITIVES(gdp, prim) { cerr << "Primitive #" << prim->getNum() << ": "; vertex_count = prim->getVertexCount(); for( i = 0; i < vertex_count; i++ ) { const GEO_Vertex &vertex = prim->getVertex(i); GEO_Point *pt = vertex.getPt(); UT_ASSERT( pt ); cerr << pt->getNum() << " "; } cerr << endl; } Quote Link to comment Share on other sites More sharing options...
MADjestic Posted August 14, 2005 Share Posted August 14, 2005 Thanks, edward - works like magic! Another question =) : What is the easiest way to rotate gdp (the whole scene) say, 90 degrees around X axis? Thanks. Quote Link to comment Share on other sites More sharing options...
edward Posted August 15, 2005 Share Posted August 15, 2005 Any of the functions in GEO_Detail, GU_Detail, etc are fair game so you really should try to familiarize yourself with those headers. Off the top of my head transform() should work. Quote Link to comment Share on other sites More sharing options...
MADjestic Posted August 15, 2005 Share Posted August 15, 2005 Any of the functions in GEO_Detail, GU_Detail, etc are fair game so you really should try to familiarize yourself with those headers. Off the top of my head transform() should work. 20521[/snapback] ok, I've played with transform() a little bit, but I don't seem to make it work: UT_Matrix4 mat(1,1,1,1, 1,1,1,1, 1,1,1,1, 0,0,0,0); gdp->transform(mat, 0, 0, 0, 1, 1, 1, 0, 0); has anybody got an example how to make it work properly? Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.