Game Development Community

Compass Direction

by Edward Gardner · in Torque Game Engine · 08/25/2001 (6:43 pm) · 7 replies

the direction the models face is tracked somewhere in the engine code, right, not in script?

Any pointers as to where?

#1
08/25/2001 (8:40 pm)
If you are talking about the player himself, take a look at getEyeTransform in the player class (game/player.cc). There is also a render eye transform method. If you are in a guiControl (for instance, for a compass control), you could do the following:

GameConnection * con = GameConnection::getServerConnection();

if (con != NULL)
{
ShapeBase * obj = con->getControlObject();
if (obj != NULL)
{
//find the eye vector
MatrixF mat;
obj->getEyeTransform(&mat);
VectorF v1(0,1,0),v2;
mat.mulV(v1,&v2);
v2.normalize();

...and so on...

v2.x and v2.y will now be your x,y facing in the world, where the magnitude of the vector is of unit length (if that makes sense to you).
#2
08/25/2001 (8:48 pm)
Oddly enough, I was hacking through the GUI editor scripts and realized that I could get a psuedo-compass by inserting this in about line 168 of playgui.gui

new GuiTerrPreviewCtrl(HeightfieldPreview) {
profile = "GuiDefaultProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "400 4";
extent = "100 100";
minExtent = "8 8";
visible = "1";
helpTag = "0";
};


That puts a little black window with the read camera indicator in the center of the screen at the top.

Now, if I knew any more about what the params of GuiTerrPreviewCtrl were, I could also insert the .Ter or maybe the bitmap as the background for that (much like the Map editor's terrain heightfield screen).

Anyone?
#3
08/26/2001 (5:38 am)
I think Frank Bignone (sp?) has solved the Ter preview problems Ed, lets see if he posts a control.. not worth wasting effort sussing out what someone else already has.

Phil.
#4
08/26/2001 (5:45 am)
I guess I thought that just applied to a rendered preview.

But now that I look more closely at what he's doing, I bet you're right.

I can get the rendered preview window to display something like what he's got going (at least, in an early version of the GUI I had a window like his "terrain display post" I'll have to open that back up and see if it really does work), I'm just having trouble with the "top down" part.
#5
08/26/2001 (6:06 am)
I don't know if my control will help you as in order to display the terrain, I add it to the clientscenegraph and then render this scenegraph.

From what I have looked in the code, during the game the function gameRender (or something like that) is called each render time and then it renders the scenegraph.

So, if you add my control in a gameCtrlGui you will end up with two terrain file, and I may screw up your rendering or something may go wrong (didn't try it yet).

I still need some work on my control, but for the moment I suggest that you use it only at the starting GUI (when no scene is loaded). I will modify it in order to be able to add it in an ingame GUI. In fact, I SHOULD as I need it in my dog fight application.
#6
08/26/2001 (9:02 am)
I just read Franks tut (very cool by the way).

I think that is more than i need for above (though I will probably implement that cool map selectory :)).

I guess my question is more simple/direct. How do I pass the currently loaded .ter filename to the above control?

Still struggling through this :)
#7
08/26/2001 (9:20 am)
If the control you speak about is the terrainPreviewCtrl, you can't pass it a filename.

In fact, in the code of the terrain editor, there is the following function cAttachTerrain that attach to the editor the terrain from the current mission. You can also pass an argument that is the name of your object.

here is an extract of this function :

SimSet * missionGroup = dynamic_cast<SimSet*>(Sim::findObject("MissionGroup"));
   if(argc == 2)
   {
      for(SimSetIterator itr(missionGroup); *itr; ++itr)
      {
         terrBlock = dynamic_cast<TerrainBlock*>(*itr);
         if(terrBlock)
            break;
      }

      if(!terrBlock)
         Con::errorf(ConsoleLogEntry::Script, "TerrainEditor::attach: no TerrainBlock objects found!");
   }
   else  // attach to named object
   {
      terrBlock = dynamic_cast<TerrainBlock*>(Sim::findObject(argv[2]));

      if(!terrBlock)
         Con::errorf(ConsoleLogEntry::Script, "TerrainEditor::attach: failed to attach to object '%s'", argv[2]);
   }

You can call it from the console / script too.