Game Development Community

Shadows from mounted objects? (if not: fix here)

by Joel Baxter · in Torque Game Engine · 04/09/2002 (3:32 pm) · 8 replies

I can't really test this easily right now, but... in preparation for doing some object-mounting stuff with our codebase I had a look at the mounting code, and I noticed something that sure seems like a bug. Maybe someone can check this out more easily with the code they have at hand than I can. If it is indeed a bug, I'm also pretty sure what the fix is.

OK, so, ShapeBase::renderImage does not call renderShadow if this object is mounted to some other object.

It seems reasonable then that the mount would assume responsibility for rendering the shadows of its mounted objects. And as a matter of fact there's some code in renderShadow that looks like it's supposed to do that (or at least, do the shadow of one mounted object):
// We only render the first mounted object for now...
      if (mMount.link && mMount.link->mShapeInstance)
      {
         Point3F linkScale = mMount.link->getScale();
         maxScale = getMax(linkScale.x,getMax(linkScale.y,linkScale.z));
         mShadow->selectShapeDetail(mMount.link->mShapeInstance,dist,maxScale);
         mShadow->renderToBitmap(mMount.link->mShapeInstance,
                                 mMount.link->getRenderTransform(),
                                 pos,
                                 linkScale);
      }
However I'm pretty sure that this is wrong. AFAICT mMount.link is a pointer to some other object mounted to the same object that this one is mounted to, not a pointer to an object mounted on this one. mMount.list should probably be used in that code snippet instead of mMount.link.

(It also seems like it would be straightforward to render shadows for all the mounted objects, not just one of them. Cf. the loop structure for iterating through mounted objects in functions like ShapeBase::getMountedObjectCount.)

BTW if the use of mMount.link is incorrect there, then it's also incorrect in the ShapeBase destructor.

#1
10/27/2005 (9:33 am)
Resurrecting an old link here, but I was doing a search and found this post. Would anyone be able to post a few words here clarifying the relationship between mMount.list, and mMount.link? I'm working with mounting objects, and am a bit fuzzy on this relationship.
#2
12/17/2005 (10:56 am)
Maybe you already discover Steve!!! I understand that mMount.link is just a memory pointer that search the next object mounted by mMount.object. mMount.list shows the last (first of line) mounted in this dynamic list.

Ex.
1499.mountObject(1500,0);
1499.mountObject(1501,0);
1499.mountObject(1502,0);

Owr list will be:

[1499.mMount.link = 1501 ]
[1499.mMount.list = 1502 ]
[1499.mMount.link = 1500 ]
[1499.mMount.list = 1501 ]
[1499.mMount.link = NULL ]
[1499.mMount.list = 1500 ]



I believe that Joel was right. There was a mistake by use mMount.link to render the shadow of first mounted object. If we have only one mounted object, mMount.link equals null.. Than any mounted shadow will be rendered.
#3
12/17/2005 (12:06 pm)
Hmm, this is a good one. Issue #985.
#4
12/19/2005 (9:32 am)
@ Calibre,
Thanks for the reply.

So mMount.list is pretty self-explanatory, it's just a list of the objects mounted onto the current object, which makes Joels observation correct. I'm still a little fuzzy on mMount.link, even after your example. Is it a pointer to the object that is mounted on the first object on mMount.list? If so, I'm not sure if I understand what it's used for, but that's another question.

I got my code working awhile ago, but I don't believe that I'm using mMount.link at all, which is probably just as well, as like I said, I'm still a little fuzzy on it.
#5
12/19/2005 (11:18 am)
Hi steve,

We'll need both link and list, to make any search on owr line of mounted objects. For example... on the ShapeBase.cc has a comment: "We only render the first mounted object for now...", but.. we'ld render all shadows of mounted objects... swapping a condition by a loop.

So replace that old code...



if (mMount.link && mMount.link->mShapeInstance)
{
Point3F linkScale = mMount.link->getScale();
maxScale = getMax(linkScale.x,getMax(linkScale.y,linkScale.z));
mShadow->selectShapeDetail(mMount.link->mShapeInstance,dist,maxScale);
mShadow->renderToBitmap(mMount.link->mShapeInstance,
mMount.link->getRenderTransform(),
pos,
linkScale);
}

to this....

// We'll render shadow of all mounted objects ( excluding mounted objects by mounted objects... :) )
for(ShapeBase *ptr = mMount.list; (ptr)&&(ptr)->mShapeInstance; ptr = ((ptr)->mMount.link) )
{
Point3F linkScale = ptr->getScale();
maxScale = getMax(linkScale.x,getMax(linkScale.y,linkScale.z));
mShadow->selectShapeDetail(ptr->mShapeInstance,dist,maxScale);
mShadow->renderToBitmap(ptr->mShapeInstance,
ptr->getRenderTransform(),
pos,
linkScale);

}


So you needed of mMount.list pointer to get address of first object.. and the mMount.link pointer
for to navigate step-by-step on the loop sentence.

I wait that this help you.
#6
12/19/2005 (1:49 pm)
Alright, I think I have it now. List is a pointer to the first object mounted, and link is a pointer to the next one, so list and link together are the list. You start at list, and move on by going to the link object, then on further by going to the link object on that object. When you reach an object whose link object is NULL, you're done.

If this is correct, thanks for the clarification.
#7
12/20/2005 (2:54 am)
Yes.. correct!!
#8
12/20/2005 (10:09 am)
@ Calibre,

Thanks again.