[Closed] C++ SDK; pointer to incomplete class – TriObject
Greetings All
[EDIT3]
Interestingly I get an error when I run it, that has something to do with an [] error (I can’t figure out how to attach to process with C++ as opposed to dotNet, so can’t be sure)
Something to do with passing in a Tab<Ray*> item is making it grumpy.
[/EDIT3]
[EDIT2]
OK… So I was confused by the SDK documentation…
IntersectRay (Ray &ray, float &at, Point3 &norm, DWORD &fi, Point3 &bary)
I thought I needed to define variables as Point3* norm, before passing them in, but I guess the & in the definition is just saying implicitly that it uses a reference to that argument, and doesn’t make a copy by passing in the value. And it seems accessing an array member would normally return a value, so the extra little ‘*’ before rays[i] makes sure the address is passed in instead. I think
So in my example, the following no longer throws an error – yay, life and learn.
Tab<Ray*> rays;
…
TriObject* tri;
float at;
Point3 norm;
Point3 bary;
DWORD face;
…
result = tri->GetMesh().IntersectRay(*rays[i], at, norm, face, bary);
[/EDIT2]
[EDIT]
OK… So looks like i needed to add ‘#include <triobj.h>’ to my .h file. I’m not quite sure why it needed to be included specifically. But I guess tri objects aren’t in maxtypes.h or whatever the pre_include stuff does…
However I’m left with the line
result = tri->GetMesh().IntersectRay(rays[i], at, norm, face, bary);
Not matching the argument list. The whole passing pointers vs passing values thing still confuses me, so will try to get some matching arguments, and update if I find them. (So others might learn from my dumbness)
[/EDIT]
Starting to dip my toes into the SDK, using function publishing as the ‘easy’ stepping stone – and have run into a snag I havn’t been able to google my way out of.
I have the following function, which throws an error when I try to access the members of tri.
‘pointer to incomplete class type is not allowed’
The code to access the triObject from the Node, seems fairly standard and used in many examples, so I’m not sure if there is an include I’m missing, or some nuance of the syntax I’ve overlooked, as I’m quite new to the language.
int CalcPos(bool moveStuff) {
int result = 0;
TriObject* tri;
//run intersect ray on resultant mesh, temp variables for testing
float at; // distance to hit from source
Point3 norm;
Point3 bary;
int face;
// get tgt object
Object *obj = target->EvalWorldState(ip->GetTime()).obj;
// make sure it's a tri object, and apply convsion to make sure
if (obj->CanConvertToType(Class_ID(TRIOBJ_CLASS_ID, 0)))
{
tri = (TriObject *)obj->ConvertToType(ip->GetTime(), Class_ID(TRIOBJ_CLASS_ID, 0));
// for each winch
for (int i = 0; i < Winches.Count(); ++i)
{
// get object
INode* winch = Winches[i];
// this throws the error on trying to access GetMesh()
result = tri->GetMesh()->IntersectRay(rays[i], &at, &norm, &face, &bary);
// TODO: Calculate hitPos from Ray.P, Dir and at
// if (moveStuff) {Move Stuff}
if (moveStuff)
{
Matrix3 m = winch->GetNodeTM(0); // doesn't animate except up/down
m.SetTranslate(hitPos[i]);
winch->SetNodeTM(0, m); // hack but just want to see if it works
}
}
}
else
{
result = -1;
}
return result;
}
Thanks for the help
Mikie
//run intersect ray on resultant mesh, temp variables for testing
float at; // distance to hit from source
Point3 norm;
Point3 bary;
DWORD face;
TimeValue t = GetCOREInterface()->GetTime();
// get tgt object
Object *obj = target->EvalWorldState(t).obj;
// make sure it's a tri object, and apply convsion to make sure
if (obj->CanConvertToType(Class_ID(TRIOBJ_CLASS_ID, 0)))
{
TriObject* tri = (TriObject *)obj->ConvertToType(t, Class_ID(TRIOBJ_CLASS_ID, 0));
Mesh mesh = tri->GetMesh();
// for each winch
for (int i = 0; i < Winches.Count(); ++i)
{
// get object
INode* winch = Winches[i];
// this throws the error on trying to access GetMesh()
result = mesh.IntersectRay(rays[i], at, norm, face, bary);
it should be something like this…
of course you have to define or pass target, Winches and rays , as well as check that mesh is valid