Finding Vehicle Mount Positions
by David Reed · in Torque Game Engine · 11/21/2004 (10:34 am) · 18 replies
Hey everyone,
I've been trying to find out how to access the mount0-9 nodes locations. I've been trying to do this in the script but so far I can't get anything other than the vehicles x,y,z positions. I'm trying to find out the map locations ( using getWords at this point ) of each mount node. I'd like to know if this is possible in the script, and if not where would I look in the engine's code. I've browsed shapebase.cc without much luck. Any pointers would be greatly appreciated, thanks.
I've been trying to find out how to access the mount0-9 nodes locations. I've been trying to do this in the script but so far I can't get anything other than the vehicles x,y,z positions. I'm trying to find out the map locations ( using getWords at this point ) of each mount node. I'd like to know if this is possible in the script, and if not where would I look in the engine's code. I've browsed shapebase.cc without much luck. Any pointers would be greatly appreciated, thanks.
#2
Add to vehicle.cc:
and add this to vehicle.h inside the class Vehicle { ... } block:
Then from script, call %obj.getNodePosition("mount0"); where %obj is the vehicle instance in question, and mount0 is the mount point you want (could be mount1, mount2, etc).
Note: This will return the position in "x y z" format of the specified node in World coordinates.
Please note also: I have not tested this with the Vehicle class. It was written and works for my own Ship class, which should still be close enough to Vehicle to work without incident, but I make no guarantees.
Also, you are not limited to mount points. This function will return the coordinates of any node in the vehicle shape.
11/21/2004 (3:10 pm)
I needed something similar for one of my projects. After a bit of searching I could find no console function to do this, so I added one. I will post the code here. This was written for my own class "Ship", which is essentially a modified copy of Vehicle, but it should work fine for the Vehicle class as well.Add to vehicle.cc:
ConsoleMethod(Vehicle, getNodePosition, const char*, 3, 3,
"point getNodePosition(string nodeName)")
{
Point3F nodePoint;
MatrixF vehicleTransform;
nodePoint = object->getNodePoint(argv[2]);
vehicleTransform = object->getTransform();
vehicleTransform.mulP(nodePoint);
char* buff = Con::getReturnBuffer(100);
dSprintf(buff, 100, "%g %g %g", nodePoint.x, nodePoint.y, nodePoint.z);
return buff;
}
// Supporting Vehicle::Function
Point3F Vehicle::getNodePoint(const char* nodeName) {
Point3F nodePoint;
MatrixF nodeMat;
// Note that there is no error checking here. I'm not sure what will happen
// if the requested node does not exist. This should be addressed.
nodeMat = mShapeInstance->mNodeTransforms[mDataBlock->shape->findNode(nodeName)];
nodeMat.getColumn(3, &nodePoint);
return nodePoint;
}and add this to vehicle.h inside the class Vehicle { ... } block:
// A supporting function for the getNodePosition ConsoleMethod Point3F getNodePoint(const char* nodeName);
Then from script, call %obj.getNodePosition("mount0"); where %obj is the vehicle instance in question, and mount0 is the mount point you want (could be mount1, mount2, etc).
Note: This will return the position in "x y z" format of the specified node in World coordinates.
Please note also: I have not tested this with the Vehicle class. It was written and works for my own Ship class, which should still be close enough to Vehicle to work without incident, but I make no guarantees.
Also, you are not limited to mount points. This function will return the coordinates of any node in the vehicle shape.
#3
11/21/2004 (4:06 pm)
Thank you so much. After getting the first response I knuckled down and wrote a function that could output 1 mount point (hardcoded). But this appears to be exactly what Im trying to accomplish. Above and beyond what I hoped for thanks again.
#4
11/21/2004 (6:07 pm)
Well after adding that it does output a co-ordinate. I have no way of being sure which co-ordinate it is tho. As no matter what mount point I ask for it gives the same numbers. The numbers do change when the vehicle moves but It seems to be the same problem I was having with my code. I think its only reading 1 mount point. I've double checked my model and it does have mount8 and mount9 as well as mount 0. All 3 show the same location in the console when I run your function for them. I'll have to keep trying again tomorrow. If anyone could shed some light on this I'd be very grateful.
#5
%nodePosition = %vehicle.getNodePosition("mount8");
11/21/2004 (6:24 pm)
Are you using it like so?%nodePosition = %vehicle.getNodePosition("mount8");
#6
Is what I have been using, I've also tried things like the mass node. Everything is just returning the same coordinates. I'll have to try a few new things tomorrow. If anyone else tries this and it works let me know. I might try on a fresh copy of HEAD. Could my datablock be the problem here? I kinda figured the code in the vehicle.cc would be reading my model directly. It should be able to pick the data up just from the dts? Thanks for the replies I'll continue trying things.
11/21/2004 (7:17 pm)
%buffer = %vehicle.getNodePosition("mount8"); Is what I have been using, I've also tried things like the mass node. Everything is just returning the same coordinates. I'll have to try a few new things tomorrow. If anyone else tries this and it works let me know. I might try on a fresh copy of HEAD. Could my datablock be the problem here? I kinda figured the code in the vehicle.cc would be reading my model directly. It should be able to pick the data up just from the dts? Thanks for the replies I'll continue trying things.
#7
The fact that the coordinates change with the position of your ship suggests that %vehicle is a valid Vehicle instance.. Are you sure it's the correct Vehicle?
Here, try this:
Replace the previous Vehicle::getNodePoint with this one. This will print an error to the console if findNode can't find the specified node. It should also print the name of the node it's attempting to find, which may or may not be helpful.
11/21/2004 (8:30 pm)
How strange. In truth, I've never tried this with a "mount#" node, only my own nodes "gunPoint#". However, a node is a node. It shouldn't matter what they're called. The functions I used to find the nodes are the same functions used throughout the engine to find nodes. The camera nodes, mass nodes, and mount nodes are all retrieved in the same way.The fact that the coordinates change with the position of your ship suggests that %vehicle is a valid Vehicle instance.. Are you sure it's the correct Vehicle?
Here, try this:
// Supporting Vehicle::Function
Point3F Vehicle::getNodePoint(const char* nodeName) {
Point3F nodePoint;
MatrixF nodeMat;
S32 nodeIndex;
nodeIndex = mDataBlock->shape->findNode(nodeName);
if (nodeIndex != -1) {
nodeMat = mShapeInstance->mNodeTransforms[nodeIndex];
nodeMat.getColumn(3, &nodePoint);
} else {
Con::warnf("Error from getNodePosition(%s). The node does not exist.",
nodeName);
}
return nodePoint;
}Replace the previous Vehicle::getNodePoint with this one. This will print an error to the console if findNode can't find the specified node. It should also print the name of the node it's attempting to find, which may or may not be helpful.
#8
Have you checked your console.log for any errors regarding the loading of your vehicle dts shape?
11/21/2004 (8:36 pm)
Regarding your data block question: No, I highly doubt anything in your datablock could interfere with this function. Nodes are read directly from the DTS shape. Provided your DTS shape is valid and properly loaded, the nodes should be there.Have you checked your console.log for any errors regarding the loading of your vehicle dts shape?
#9
11/21/2004 (8:45 pm)
One more thought: You said you have a mount0, mount8, and mount9? My function does not care what you call the nodes, but is it possible that your DTS exporter doesn't like the non-sequential mount node numbers? Maybe it's not exporting mount8 and 9 because it can't find a mount1-7? Have you tried using mount0, mount1, and mount2 instead?
#10
I use this code in my vehicle.cs from a tutorial in the example code section. Its in the onPlayerMount function. Which is called from player.cs like so:
And is accepted by vehicle cs function:
So it seems like I dont have a problem with passing the wrong vehicle in. Now to figure out why its only giving me the coord's of the vehicle itself and not the coords of its nodes.
Console shows the same thing for all points:
The last values are the vehicles transform. I've tried on all 3 hover vehicles that I've created and the buggy thats provided with the racing starter kit. It still could be a model problem but all my mounts are linked to "shape" which is the parent for everything except bounds. The mesh and collision meshes are linked to start which has a parent of shape as well. And I changed my mounts now theyre: mount0,mount1,mount2. Does capitalization matter in models?
11/22/2004 (7:46 am)
%buffer = %vehicle.getNodePosition("mass");
echo(%buffer);
%buffer1 = %vehicle.getNodePosition("mount0");
echo(%buffer1);
%buffer2 = %vehicle.getNodePosition("mount1");
echo(%buffer2);
%buffer3 = %vehicle.getNodePosition("mount2");
echo(%buffer3);
echo(%vehicle.getTransform());I use this code in my vehicle.cs from a tutorial in the example code section. Its in the onPlayerMount function. Which is called from player.cs like so:
function Armor::onMount(%this,%obj,%vehicle,%node)
{
onPlayerMount(%this,%obj,%vehicle,%node);
}And is accepted by vehicle cs function:
function onPlayerMount(%player,%obj,%vehicle,%node)
So it seems like I dont have a problem with passing the wrong vehicle in. Now to figure out why its only giving me the coord's of the vehicle itself and not the coords of its nodes.
Console shows the same thing for all points:
Quote:
-16.3322 -5.3414 259.009
-16.3322 -5.3414 259.009
-16.3322 -5.3414 259.009
-16.3322 -5.3414 259.009
-16.3322 -5.3414 259.009 1 0 0 0
The last values are the vehicles transform. I've tried on all 3 hover vehicles that I've created and the buggy thats provided with the racing starter kit. It still could be a model problem but all my mounts are linked to "shape" which is the parent for everything except bounds. The mesh and collision meshes are linked to start which has a parent of shape as well. And I changed my mounts now theyre: mount0,mount1,mount2. Does capitalization matter in models?
#11
...
Apon examination of the onMount function, I think I may have found something. It looks like the parameters "%this, %obj, %vehicle, %node" might be incorrect. See, onMount is called from C++ like so:
Con::executef(mDataBlock,4,"onMount",scriptThis(),obj->scriptThis(),buff1);
Now, I think that translates into "%this, %vehicle, %node". Three arguments, not four. So I think that script should read:
I'm not sure of that, but it's probably worth a try.
Also... To be sure that %vehicle is what it's supposed to be, might I suggest that you echo(%vehicle) right after whatever code spawns it, and then again echo(%vehicle) in your onPlayerMount function. If they're not the same, something's wrong.
11/22/2004 (12:00 pm)
I think capitalization does matter, but I'm pretty sure "mount" in all lower case is correct. Did you try the new version of getNodePoint that I posted?...
Apon examination of the onMount function, I think I may have found something. It looks like the parameters "%this, %obj, %vehicle, %node" might be incorrect. See, onMount is called from C++ like so:
Con::executef(mDataBlock,4,"onMount",scriptThis(),obj->scriptThis(),buff1);
Now, I think that translates into "%this, %vehicle, %node". Three arguments, not four. So I think that script should read:
function Armor::onMount(%this,%vehicle,%node)
{
onPlayerMount(%this,%vehicle,%node);
}I'm not sure of that, but it's probably worth a try.
Also... To be sure that %vehicle is what it's supposed to be, might I suggest that you echo(%vehicle) right after whatever code spawns it, and then again echo(%vehicle) in your onPlayerMount function. If they're not the same, something's wrong.
#12
Just had another thought:
Is gunPoint# a dummy object? and what did you use for its parent?
11/22/2004 (5:41 pm)
When I printed %vehicle the number matched up with what the editor showed as my vehicle. So I guess theyre ruled out. As it stands the new function is saying mass, mount0, mount1, mount2 are all non-existant. I'm starting to think its my model. I used tork.beffy.de/_tutorials/Modelling/vehicles/wheeled.htm to create my models this tutorial dates back to pre 1.2 I believe. I'll take a look at the chapter 8 of the docs. I'll probably throw in one of their example "shapes" just to see if I find the mass node. Should tell me if my model is to blame. Thanks again Scott.Just had another thought:
Is gunPoint# a dummy object? and what did you use for its parent?
#13
I'm afraid I can offer no insight into DTS creation in Max.
I am however pretty sure the problem lies in your DTS shape. Just to be sure that my functions work with models not created with my exporter, I added the code I posted to my Vehicle class, and then ran an unmodified starter.racing. From there I looked for nodes on the starter buggy. Below is an excerpt from my console.log:
Those numbers look correct, so I believe it found the nodes. So the getNodePosition function does work with the Vehicle class and the default buggy shape.
11/22/2004 (9:07 pm)
Um, see, my models weren't created in Max. They were made in Wings3D, exported to OBJ format, and converted to DTS with an OBJ to DTS converter that I wrote specifically for my project. Wings has no "dummy objects", and my nodes have no parents. I'm afraid I can offer no insight into DTS creation in Max.
I am however pretty sure the problem lies in your DTS shape. Just to be sure that my functions work with models not created with my exporter, I added the code I posted to my Vehicle class, and then ran an unmodified starter.racing. From there I looked for nodes on the starter buggy. Below is an excerpt from my console.log:
==>echo(1468.getNodePosition("hub0"));
-162.123 907.748 196.098
==>echo(1468.getNodePosition("hub1"));
-158.917 907.882 195.709
==>echo(1468.getNodePosition("hub2"));
-158.632 903.264 195.701
==>echo(1468.getNodePosition("hub3"));
-162.066 903.13 196.118Those numbers look correct, so I believe it found the nodes. So the getNodePosition function does work with the Vehicle class and the default buggy shape.
#14
11/23/2004 (7:39 am)
I just repeated your experiment and found that it's finding the hubs just fine. So I'd like to thank you for sticking with it and helping me. The rest is up to me I guess. The function still says mount0 and mass are not found (and still returns values for the vehicle). But I think if I add my own dummy objects it will be able to find them. Thats what I'll try next. Thanks again.
#15
11/23/2004 (7:46 am)
Scott, is this obj2dts converter available?
#16
11/23/2004 (8:24 am)
I just tried an old car I had made with max4. Its working perfectly. I guess the new max exporter isnt working. I'll have to search for the fix in the forums. Or *gasp* fix the exporter myself (haha yea right). Thanks again, Hopefully I'll post with fixes and the final product.
#17
The one big feature it lacks is animation. Neither Wings3D nor the OBJ format supports animation, so it's doubtful I will ever add animation capabilities to this particular converter.
It does currently support:
One collision mesh
Multiple visible meshes with multiple levels of detail (no automatic lod generation however)
Nodes
Multiple materials
Self-illuminating materials
Triangle Stripping (A rather crude stipping function which I wrote myself. Not the best by any means, but it works).
It should also support Billboarding and the following material flags: Additive, Subtractive, Translucent, NoMipMap, MipMapZeroBorder, NeverEvnMap. These are untested, however.
I also haven't written any documentation for it. As I said, I'm not really "ready" to distribute it, but I'll send you a copy if you want it.
Edit: Oh yeah, it's a command line tool. No GUI. Just FYI.
11/23/2004 (10:46 am)
Dirk, yes and no. I had every intention of releasing it, but I haven't quite gotten around to "finishing" it. There are some things I think I could have written better, some funtions still untested, etc. Still, it does work, and AFAIK it has no major bugs. The one big feature it lacks is animation. Neither Wings3D nor the OBJ format supports animation, so it's doubtful I will ever add animation capabilities to this particular converter.
It does currently support:
One collision mesh
Multiple visible meshes with multiple levels of detail (no automatic lod generation however)
Nodes
Multiple materials
Self-illuminating materials
Triangle Stripping (A rather crude stipping function which I wrote myself. Not the best by any means, but it works).
It should also support Billboarding and the following material flags: Additive, Subtractive, Translucent, NoMipMap, MipMapZeroBorder, NeverEvnMap. These are untested, however.
I also haven't written any documentation for it. As I said, I'm not really "ready" to distribute it, but I'll send you a copy if you want it.
Edit: Oh yeah, it's a command line tool. No GUI. Just FYI.
#18
11/23/2004 (11:31 am)
Maybe we can cooperate on this one? I wrote an .obj importer for CShop some while ago. So, please, yes, send me copy.
Torque Owner CdnGater
Duggan Software Studio