Procedural cube

   6417   14   1
User Avatar
Member
282 posts
Joined: Jan. 2006
Offline
Hi! I'm trying to put a box onto all points of the current object which has this procedural shader. But smth is wrong.


VRAY_test::render()
{
GU_Detail *gdpBase;
GEO_Point *pointPtr;
UT_Vector3 pointPos;
void *handle = queryObject(“/obj/a”);
int samples = queryTransformSamples(&handle);
GU_Detail gdp = queryGeometry(&handle, samples);


// Build geometry
FOR_ALL_GPOINTS(&gdp, pointPtr)
{

pointPos = pointPtr->getPos();
gdpBase->cube(pointPos.x() - 0.5, pointPos.x() + 0.5, pointPos.y() - 0.5, pointPos.y() + 0.5,pointPos.z() - 0.5, pointPos.z() + 0.5, );

openGeometryObject();
addGeometry(gdpBase, 0);
setSurface(“showst type st”);
closeObject();
}
Houdini is great! O'right?
User Avatar
Member
282 posts
Joined: Jan. 2006
Offline
test.C:70: error: conversion from ‘const GU_Detail*’ to non-scalar type ‘GU_Detail’ requested
Compile failed
Houdini is great! O'right?
User Avatar
Member
44 posts
Joined: July 2005
Offline
HDK:


const GU_Detail *queryGeometry(void *object_handle, int sample);


Your declaration of “gdp” is not a GU_Detail *

You might also need to cast the return value depending on how strict your compiler settings are


GU_Detail *gdp = (GU_Detail *)queryGeometry(&handle, samples);


User Avatar
Member
282 posts
Joined: Jan. 2006
Offline
Hey, Mondi! Thanks. Now it's ok.
Houdini is great! O'right?
User Avatar
Member
282 posts
Joined: Jan. 2006
Offline
Hi. One more question. I want to rotate object inside FOR_ALL_GPOINTS from one vector to another:

UT_Vector3 baseDir(1, 0, 0);
UT_Vector3 zDir(0, 0, 1);
UT_Matrix3 NRot;
UT_Matrix4 xform;

FOR_ALL_GPOINTS(gdpa, pointPtr)
{
…………………………………..
xform.identity();
NRot.dihedral(baseDir, zDir);
xform = NRot;
openGeometryObject();
setTransform(xform, 0);
…………………………………
}

But all geos are disappear.
Thanks.
Edited by - Aug. 16, 2008 04:04:46
Houdini is great! O'right?
User Avatar
Member
44 posts
Joined: July 2005
Offline
Some thoughts.. Although I could be very off given that I only have a section of your code to work with, and I've never played with the VRAY stuff

You set both baseDir and zDir to the same vector (thus the dihedral result should be the identity matrix ..), are you setting these anywhere else?

Calling openGeometryObject() and setTransform() seems to me to be something that you would do outside a loop, you really shouldn't be orienting an object during the processing of each point (or at least I wouldn't )

Setting a 4x4 matrix to identity will put the the transform at the origin (0,0,0) - is that where your camera is pointing?

Also, given the syntax of setTransform(), I would assume that this actually sets (copies) the xForm matrix to the object, whereas your earlier code suggests that what you actually want to do is multiply each point with the resultant matrix after the dihedral computation, thus transforming your point to the new point and rotating the object. What probably happens now is that your objects xForm matrix is being set to a matrix designed to transform a vector, not the new matrix you want.

Sorry if that seems a little confusing, let me know if I'm way off.
User Avatar
Member
282 posts
Joined: Jan. 2006
Offline
Hi.
zDir is my mistake in this post. It's ok in code. (0, 0, 1).

You mean that xform matrix would be stored in loop and openGeometryObject can transform all of my instnsing objects after loop?

Why do you think that such way of transformation isn't right?
Anyway we transforming a vector. A point is a vector too. Right? I initialize matrix4 by identity matrix. Then I rotate point by dihedral(matrix3 to matrix4 will make matrix4 with last column(transformation) equal to zero - the same as identity but with rotation part) and then I mult this matrix with matrix which include ttransformation or scale part. After that - setTransform to the object(after loop) with the resultant matrix. Вот такие пироги.
Houdini is great! O'right?
User Avatar
Member
44 posts
Joined: July 2005
Offline
Aha - I forgot you were instancing objects, in that case of course you would use those commands in the loop, provided of course that they apply to the current instance and not the main object.

Otherwise you seem to be on the right track, I'm not sure exactly the results you want so I can't comment on the exact order of commands, but with a little experimentation I'm sure you'll find it .. Good luck!
User Avatar
Member
282 posts
Joined: Jan. 2006
Offline
Hey, guys! What is the most right way to use UT_Matrix3 dihedral?
Houdini is great! O'right?
User Avatar
Member
44 posts
Joined: July 2005
Offline
That's a somewhat vague question, what do you mean exactly? Is it that you don't know how to use the result you get, or are you unsure as to what to pass to the function?

UT_Matrix3.h
Compute the dihedral: return the matrix that computes the rotation around
the axes normal to both a and b, (their cross product), by the angle
which is between a and b. The resulting matrix maps a onto b. If a and
b have the same direction, what comes out is the identity matrix. If a
and b are opposed, the rotation is undefined and the method returns a
vector c of zeroes (check with !c); if all is OK, c != 0.
The transformation is a symmetry around vector a, then a symmetry around
(norm(a) and norm(b)). If a or b needs to be normalized, pass a non-zero
value in norm.
User Avatar
Member
282 posts
Joined: Jan. 2006
Offline
heh) Dihedral with 2 args is a good function. But what is the third arg in dihedral function with 3 args? Up vector?
Houdini is great! O'right?
User Avatar
Member
44 posts
Joined: July 2005
Offline
In the case of the UT_Matrix3 functions, the third argument is a signal from you that one or both of the first two vector arguments needs to be normalized (pass non-zero to normalize)
User Avatar
Member
282 posts
Joined: Jan. 2006
Offline
static UT_Matrix3 UT_Matrix3::dihedral ( UT_Vector3 & a,
UT_Vector3 & b,
UT_Vector3 & c,
int norm = 1
)

Look. The third arg is UT_Vector3 too.
Houdini is great! O'right?
User Avatar
Member
44 posts
Joined: July 2005
Offline
Wow, color me embarassed, I didn't see that at all for some reason ops:

UT_Matrix3.h
If a and b are opposed, the rotation is undefined and the method returns a vector c of zeroes (check with !c); if all is OK, c != 0.

Just pass a temp vector in there, it's there to give you more information about the returned matrix
User Avatar
Member
282 posts
Joined: Jan. 2006
Offline
Hey, Mondi! That's simply check… Thanks)
Houdini is great! O'right?
  • Quick Links