Game Development Community

MountObject VS MountImage

by Steve Lamperti · in Torque Game Engine · 09/02/2004 (9:27 am) · 55 replies

I am working with mounting objects onto other objects. Objects, not Images, therefore the topic title.
It's all been working great, until I tried to use a 'mountPoint' node on the object that is to be mounted that was somewhere other then the default bottom of the object.
Looking at the code, it looks like the 'mountPoint' on the object/image to be mounted is only supported for Images and Players, not other shapebase objects. Does this sound right to those of you more familiar with the code then me, or am I missing something here?

I would appreciate any feedback.
Page«First 1 2 3 Next»
#41
11/13/2006 (1:19 pm)
@MB - Does it have to be mount5? Does the number really matter?
#42
11/13/2006 (1:22 pm)
It can be from mount0 to mount31


And from reading Steve Lamperti's message it looks like he named mountPoint 'MountPoint' and I think caps matter in the nodes.
#43
11/13/2006 (1:48 pm)
Ok, I'm giving it a shot MB, will let you know how it works.
I'm also trying your resource Peter, in a separate build, but I've hit a snag which I've posted on the resource page.
#44
11/13/2006 (3:24 pm)
I read in another forum post that theres no limit to mounting shapes to shapes, but for images to shapes.
#45
11/13/2006 (3:45 pm)
I tested it with starter.fps and it worked for me. I created a new script called 'myObject.cs' and placed this code in it:

// test shape
datablock StaticShapeData( myObject )
{
shapeFile = "~/data/shapes/player/player.dts";
};

it's the ork model.

then in game.cs at the top do the exec("./myObject.cs"); in its proper place with all the other execs.

then down after the player spawns in CreatePlayer .. at the end of that function add;

%myObject = new StaticShape() {
dataBlock = myObject;
position = %player.position;
};

%player.mountObject(%myObject,2);


This just creates a new Ork model & places at the players position then mounts it onto the players shoulder. :D
#46
11/14/2006 (5:25 am)
I definitely have objects mounting, that's for sure =). They just aren't mounting in the right spots. They always appear to be mounting at the origin. I'm waiting to talk to my artist and have a look at the raw Maya file to see how he has things named and situated.
#47
11/14/2006 (6:48 am)
Just for testing purposes, I tried calling mountImage from a staticShape instance.

$device.mountImage($battery.getDatablock().image, 0);

It mounted perfectly in place, but when trying to manipulate the object, I got a crash in SceneGraph::rezoneObject():

Quote:Error, no zones found? Should always find root at least.

It's like I can't win =) Any ideas on why the crash occurs?
#48
11/14/2006 (9:54 am)
I searched a little on 'Error, no zones found?' and found this:

Quote:
This problem is as people have found out, due to the updating of objects outside a valid "zone". Basically when you do an updatePosition, it filters down to rezoneObject which removes the object from its old zone and inserts it in its new zone.

Only, if it cant find a zone, it does this assert.

Usually its because the position has gone "off to neptune", typically via some numeric instability in physics code, but there could be any number of reasons.

You might need to set the position of the image before mounting it.
#49
07/03/2007 (12:13 pm)
Bumping this again...
Has anyone fond a way to mount (mountObject(%obj,0)) to an object, or shape.

Let me explain what I'm trying to do... i'm trying to test a new way of doing lasers. And want to mount my "laser" to the gun when I fire, and schedule the unmount after the laser (StaticShapeData) has fired.

So I'm trying to mount an object to my ShapeBaseImage (Weapon Image) and umount it.

Can anyone point me in the right direction?

PS! I know there's an laser resource, but it's not flexible enough in many ways.
#50
07/03/2007 (12:17 pm)
As far as I know, you can't mount an object onto a ShapeBaseImage.
#51
07/03/2007 (12:17 pm)
You can't actually do what you are looking at in stock.

The reason is that the weapon scripting system is an unusual beast--when you "mount" a ShapeBaseImage, you aren't actually creating another game object that acts like other game objects--you are setting up a series of associations between the ShapeBaseImageData definition, the ShapeBaseImage scriptable state machine, and the Player object.

In effect, after you've mounted the image to your player, there is no real "object" in his hands--it's a combined entity that can render, and interface with the statemachine, but not a fully independent object like you would use in the normal "mount" sense.
#52
07/03/2007 (1:31 pm)
Thanx for the replies.

Just thought of something different I'll give a bash:
Mount the laser (StaticShapeData with a DTS) to the same mountpoint the weapon is mounted to, and just change the offset. Any objection to that?

< So close, yet so far ;-) >
#53
07/03/2007 (3:00 pm)
@ James -- By itself, it's probably not a big enough reason to buy AFX, but AFX does include a general object constraint system that often serves as an alternative to the stock mounting system. Specifically, AFX has a mechanism for mounting DTS based models (and other effects) to named nodes of a mounted ShapeBaseImage. In your case, you would mount the gun in the usual way, and then use an AFX effect to mount your laser to a node of the gun.
#54
07/09/2007 (1:37 am)
I'm trying to do a similar thing here - namely, make Items use a mountPoint. I've had partial success. I basically copied and pasted stuff from ShapeBaseImage - you have to find the mountPoint node in the shape as Steve Lamperti does above, but then you have to find its transform relative to the origin of the Item. Then you use this transform when calculating the Item's position. I'm going to nick off and get my code (it's on another computer) so I can post specifics. Be back soon.
#55
07/09/2007 (8:50 am)
Sorry that wasn't exactly 'soon', but better late than never, right?

Be warned, my solution isn't guaranteed to work. Still has some little problems. Namely, the mounted object lags behind the animation of its holder a small amount, and sometimes the transform to the mount point gets messed up - but I think that's a problem with the art rather than the coding.

Firs thing to add is in item.h, in the declaration of ItemData. Anywhere in there, add:
MatrixF mountTransform;

Then in item.cc, we need to initialise it in ItemData::ItemData():
mountTransform.identity();

So now you just have to get the transform of the mountPoint node. I pasted this snippet straight from ShapeBaseImage::preload:
S32 node = shape->findNode("mountPoint"); //Find mountPoint node
   if (node != -1) {
      MatrixF total(1);
      do {
         MatrixF nmat;
         QuatF q;
         TSTransform::setMatrix(shape->defaultRotations[node].getQuatF(&q),shape->defaultTranslations[node],&nmat);
         total.mul(nmat);
         node = shape->nodes[node].parentIndex;
      }
      while(node != -1);
      total.inverse();
      mountTransform.mul(total);
   }
That's the part I'm not sure about - I'm not really up to scratch with matrices as they relate to object transforms, world transforms etc.

There's a change in registerLights, but I don't know if it does anything useful - it was in shapeImage.cc so I put it in. I'll post it if anyone really wants to see.

Item::processTick is where the real magic happens. This function by default doesn't take mounting into account, so that has to change. Basically, everything from if (delta.warpTicks > 0) downwards has to go under an else clause. The if clause before it should look like:
if(isMounted())
   {
	  MatrixF mat;
      mMount.object->getMountTransform(mMount.node,&mat);
	  mat.mul(mat,mDataBlock->mountTransform);
      setTransform(mat);
      setRenderTransform(mat);
   }
ShapeBaseImage uses Parent::setTransform all the time, but Item has its own setTransform, so we use that.

The same thing in interpolateTick:
if (isMounted()) {
      MatrixF mat;
      mMount.object->getRenderMountTransform(mMount.node,&mat);
  	  mat.mul(mat,mDataBlock->mountTransform);
      Parent::setRenderTransform(mat);
   }
Everything goes in the else clause.

That was all I changed. This seems to work fine mounting the crossbow, except for a little lag. However, when I try to mount a homemade object (exported to dts from Blender), my mountPoint gets warped and seems to eb registering as twice as far from the origin as it should be. Anyway, it's probably a problem with the art - I'll work it out.
Page«First 1 2 3 Next»