Author Topic: Help fixing thirdperson crosshair  (Read 98 times)

0 Members and 1 Guest are viewing this topic.

Revility

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
  • Doom Newbie
    • View Profile
Help fixing thirdperson crosshair
« on: August 23, 2018, 09:12:15 PM »
Looking to see if there is anyone who can give me a hand fixing up the thirdperson cross hair for Ruiner.  There are 2 bugs in it.   I'm hoping to get a fix included for the upcoming, and long overdue, patch for the mod.

The first bug is from the trace line made to determine the cross hair's position.  When playing the mod, type g_debugweapon 1 in the console to show the line used to determine the position and also for the melee combat related additions.  When something gets in the way of the line, the cross hair won't update.  This is easily duplicated by standing next to a wall or door way and just shooting. I have a hunch the issue is mainly caused by the shoulder camera offsetting the camera.  Maybe being able to offset the origin of the line to the right would help?

The other bug deals with launching projectiles from the barrel.  When set to 1, the cross hair is always off.  to counter act it an offset can be set in the cursor.gui  It works alright, but will still be off when looking too high or low because of the weapons barrel position.  The only thing I can think of is maybe a flag in the projectiles fired to aim towards it... which could look wierd unless the crosshair position is offset right in the cursor.gui.

Any help would be really appreciated!

We uploaded the source code for the mods years ago on the mod db. 
https://www.moddb.com/mods/ruiner/downloads/ruiner-hardqore-2-source-codes

below is the playercursor.cpp which handles the position of the crosshairs.

Code: [Select]
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "Game_local.h"
#include "PlayerCursor.h"

/*
===============
idPlayerCursor::idPlayerCursor
===============
*/
idPlayerCursor::idPlayerCursor() {
   cursorHandle   = -1;
   created = false;
}

/*
===============
idPlayerCursor::~idPlayerCursor
===============
*/
idPlayerCursor::~idPlayerCursor() {
   FreeCursor();
}

/*
===============
idPlayerCursor::FreeCursor
===============
Post: tells the game render world to free the cross hair entity, sets the cursor
handle to -1 and sets created to false
*/
void idPlayerCursor::FreeCursor( void ) {
   if ( cursorHandle != - 1 ) {
      gameRenderWorld->FreeEntityDef( cursorHandle );
      cursorHandle = -1;
      created = false;
   }
}

/*
===============
idPlayerCursor::Draw
===============
*/
void idPlayerCursor::Draw( const idVec3 &origin, const idMat3 &axis,const char *material) {

idPlayer *localPlayer = gameLocal.GetLocalPlayer();
trace_t         tr;
float          distance = 60;
float          length;
float          zoomMult; //ivan
//detemine the point at which the weapon is aiming
idAngles angle = axis.ToAngles();
idVec3 endPos = (origin + (angle.ToForward() * 120000.0f));
gameLocal.clip.TracePoint(tr,origin,endPos,MASK_SHOT_RENDERMODEL,localPlayer);
endPos = tr.endpos;

//find the distance from the camera to the point at which the weapon is aiming
idMat3 cameraAxis = localPlayer->GetRenderView()->viewaxis;
idVec3 cameraOrigin = localPlayer->GetRenderView()->vieworg;
idVec3 vectorLength = endPos - cameraOrigin;
length = vectorLength.Length();

zoomMult = 90.0f/localPlayer->CalcFov( true ); //ivan
//gameLocal.Printf( "zoom: %f\n",zoomMult ); //ivan

length = zoomMult*distance/length; //ivan - zoomMult forces constant cursor size

//linearly interpolate 5 feet between the camera position and the point at which the weapon is aiming
endPos.Lerp(cameraOrigin,endPos,length);

if ( !CreateCursor(localPlayer, endPos, cameraAxis,material )) {
  UpdateCursor(localPlayer,  endPos, cameraAxis);
}
}

/*
===============
idPlayerCursor::CreateCursor
===============
*/
bool idPlayerCursor::CreateCursor( idPlayer *player, const idVec3 &origin, const idMat3 &axis, const char *material ) {
   const char *mtr =  material;
   int out = cursorHandle;
   if ( out >= 0 ) {
      return false;
   }
   FreeCursor();
   memset( &renderEnt, 0, sizeof( renderEnt ) );
   renderEnt.origin   = origin;
   renderEnt.axis      = axis;
   renderEnt.shaderParms[ SHADERPARM_RED ]            = 1.0f;
   renderEnt.shaderParms[ SHADERPARM_GREEN ]         = 1.0f;
   renderEnt.shaderParms[ SHADERPARM_BLUE ]         = 1.0f;
   renderEnt.shaderParms[ SHADERPARM_ALPHA ]         = 1.0f;
   renderEnt.shaderParms[ SHADERPARM_SPRITE_WIDTH ]   = 7.0f;
   renderEnt.shaderParms[ SHADERPARM_SPRITE_HEIGHT ]   = 7.0f;
   renderEnt.hModel = renderModelManager->FindModel( "_sprite" );
   renderEnt.callback = NULL;
   renderEnt.numJoints = 0;
   renderEnt.joints = NULL;
   renderEnt.customSkin = 0;
   renderEnt.noShadow = true;
   renderEnt.noSelfShadow = true;
   renderEnt.customShader = declManager->FindMaterial( mtr );
   renderEnt.referenceShader = 0;
   renderEnt.bounds = renderEnt.hModel->Bounds( &renderEnt );
   cursorHandle = gameRenderWorld->AddEntityDef( &renderEnt );

   //AddRenderGui( temp, &renderEnt->gui[ 0 ], args ); //ivan
   //renderEnt.gui[ 0 ] = uiManager->FindGui( "guis/cursor.gui", false, false ); //ivan test
   //if(renderEnt.gui[ 0 ] == NULL) gameLocal.Printf( "renderEnt.gui[ 0 ] == NULL\n"); //ivan test
   return false;
}

/*
===============
idPlayerCursor::UpdateCursor
===============
*/
void idPlayerCursor::UpdateCursor(idPlayer* player,  const idVec3 &origin, const idMat3 &axis) {
   assert( cursorHandle >= 0 );
   renderEnt.origin = origin;
   renderEnt.axis   = axis;
   gameRenderWorld->UpdateEntityDef( cursorHandle, &renderEnt );