Game Development Community

TGEA - Select objects with FPS HUD with Arcane FX

by Vicente Buendia · 08/24/2009 (12:34 pm) · 1 comments

Hi,

With AFX, if you want to select objects without having to change gui mode, having them preselected when HUD reticle is over them, you can do these modifications:

-> In movelist.cpp, you have to add:

#include "afx/arcaneFX.h"
#include "T3D/gameFunctions.h"
#include "gui/3d/guiTSControl.h"

And, in function bool MoveList::getNextMove(Move &curMove),

After this:

if (mConnection->getControlObject())
      mConnection->getControlObject()->preprocessMove(&curMove);

You have to add (this is taken from the simmilar function with cursor, and a bit modified):

//Seleccion FPS 
   
    MatrixF cam_xfm;
  Point3F dummy_pt;
  if (GameGetCameraTransform(&cam_xfm, &dummy_pt))    
  {      
    
    Point3F cameraPoint; cam_xfm.getColumn(3,&cameraPoint); 
    
    GuiTSCtrl *tsCtrl;
    tsCtrl = dynamic_cast<GuiTSCtrl*>( Sim::findObject("PlayGui") );
    Point2I resol = tsCtrl->getExtent();

    // construct 3D screen point from coords 
    #if defined(TGEA_NEXT_GEN_API)
       Point3F screen_pt(resol.x/2.0f, resol.y/2.0f, 1.0f);  
     #else
       Point3F screen_pt(resol.x/2.0f, resol.y/2.0f, -1.0f);         
    #endif

    // convert screen point to world point
    Point3F world_pt;    
    if (tsCtrl->unproject(screen_pt, &world_pt))       
    {         
      Point3F Vec = world_pt - cameraPoint;         
      Vec.normalizeSafe();    

      F32 selectRange = arcaneFX::sTargetSelectionRange;
      Point3F Scaled = Vec*selectRange;
      Point3F rangeEnd = cameraPoint + Scaled;

      arcaneFX::rolloverRayCast(cameraPoint, rangeEnd, arcaneFX::sTargetSelectionMask);
    }   
  }
   //Fin seleccion FPS


With these changes, an object will be preselected when you run over it with central HUD reticle. It will appear highlighted when you point at it with reticle.


Then, if you want it to be selected with right mouse, with torquescript:

-> At default.bind.cs

Add:

function selec_1 (%val)
{
   
if (%val) {
   $accum_yaw = 0;
    $accum_pitch = 0;
    ServerConnection.setPreSelectedObjFromRollover();        
    
} else {
   if ($accum_yaw > 0.02 || $accum_yaw < -0.02 || $accum_pitch > 0.02 || $accum_pitch < -0.02)
      ServerConnection.clearPreSelectedObj();
    else
     ServerConnection.setSelectedObjFromPreSelected();    
}

And change line
moveMap.bind( mouse, button1, ...
for
moveMap.bind( mouse, button1, selec_1 );
Change it also in config.cs




Hope you find it useful!

About the author

Recent Blogs


#1
08/25/2009 (10:40 am)
This looks cool Vicente, Good work!

Just a tip, to make your code easier to read, try adding the code /code tags around it.

Very cool Resource though, i can see a fps rpg hybrid coming :)