Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "cbase.h"
- #include <string>
- #include "in_buttons.h"
- #include "physics.h"
- #ifdef CLIENT_DLL
- #include "c_prop_sfr_vehicle.h"
- #include "asw_input.h"
- #define CPropSFRVehicle C_PropSFRVehicle
- #define CESTestVehicle C_ESTestVehicle
- #else
- #include "prop_sfr_vehicle.h"
- #endif
- static const Vector m_angTurnMax( 75.0f, 75.0f, 45.0f );
- static const Vector m_angAccelMax( 110.0f, 300.0f, 140.0f );
- static const Vector m_vecAccelMax( 60.0f, 30.0f, 40.0f );
- class CESTestVehicle : public CPropSFRVehicle
- {
- public:
- DECLARE_CLASS( CESTestVehicle, CPropSFRVehicle );
- DECLARE_NETWORKCLASS();
- #ifdef CLIENT_DLL
- DECLARE_PREDICTABLE();
- DECLARE_INTERPOLATION();
- #else
- DECLARE_DATADESC();
- #endif
- CESTestVehicle();
- virtual void Precache()
- {
- PrecacheModel( c_VEHICLE_MODEL.c_str() );
- BaseClass::Precache();
- }
- virtual void Spawn();
- void InitPhysics();
- virtual void DriveVehicle( float flFrameTime, CUserCmd *ucmd, int iButtonsDown, int iButtonsReleased );
- //virtual void SetupMove( C_BasePlayer *player, CUserCmd *ucmd, IMoveHelper *pHelper, CMoveData *move );
- void SetupMove( CBasePlayer *player, CUserCmd *ucmd, IMoveHelper *pHelper, CMoveData *move );
- void ProcessMovement( CBasePlayer *pPlayer, CMoveData *pMoveData );
- void FinishMove( CBasePlayer *player, CUserCmd *ucmd, CMoveData *move );
- void ItemPostFrame( CBasePlayer *pPlayer ); // AFAIK used for weapon stuff, though the inputs up there can be used too.
- void CommitInputs(float Interval);
- #ifdef GAME_DLL
- // VPhysics stuff.
- virtual void VPhysicsShadowUpdate( IPhysicsObject *pPhysics );
- virtual void VPhysicsPreCollision( int index, gamevcollisionevent_t *pEvent );
- virtual void VPhysicsShadowCollision( int index, gamevcollisionevent_t *pEvent );
- #endif
- virtual void VPhysicsUpdate( IPhysicsObject *pPhysics );
- // Custom physics stuff.
- void PhysicsSimulate( void );
- #ifdef CLIENT_DLL
- virtual void ClientThink();
- virtual bool IsPredicted() const {return true;}
- virtual bool ShouldPredict();
- virtual bool ShouldInterpolate();
- virtual void PostDataUpdate( DataUpdateType_t updateType );
- virtual void OnDataChanged(DataUpdateType_t type);
- virtual C_BasePlayer *GetPredictionOwner( void ){ return ToBasePlayer( GetPassenger( 0 ) ); }
- virtual void UpdateViewAngles( C_BasePlayer *pLocalPlayer, CUserCmd *pCmd );
- #else
- virtual void Think();
- #endif
- virtual void GetVehicleViewPosition( int nRole, Vector *pOrigin, QAngle *pAngles, float *pFOV = NULL );
- protected:
- static const std::string c_VEHICLE_MODEL;
- //CNetworkVar( QAngle, m_angCur );
- //CNetworkVar( QAngle, m_angTarget );
- CNetworkVector( m_vOffset );
- QAngle m_angLastViewAngles;
- AngularImpulse m_anginVehicleTurning;
- CNetworkVar( Vector, m_vVphysicsPos );
- CNetworkVar( QAngle, m_angVPhysAngles );
- CNetworkVar( Vector, m_vNetPos );
- CNetworkVar( QAngle, m_angNetAngles );
- //es
- CNetworkVector( m_vecEntityAngVelocity );
- Vector m_vecMetersVelocity;
- Vector input_torque;
- Vector input_force;
- float m_fForce;
- };
- const std::string CESTestVehicle::c_VEHICLE_MODEL("models/arwing/arwing.mdl");
- PRECACHE_REGISTER( CESTestVehicle );
- IMPLEMENT_NETWORKCLASS_ALIASED( ESTestVehicle, DT_ESTestVehicle );
- BEGIN_NETWORK_TABLE( CESTestVehicle, DT_ESTestVehicle )
- #ifdef CLIENT_DLL
- //RecvPropQAngles( RECVINFO( m_angCur ) ),
- //RecvPropQAngles( RECVINFO( m_angTarget ) ),
- RecvPropVector( RECVINFO( m_vOffset ) ),
- RecvPropVector( RECVINFO( m_vVphysicsPos ) ),
- RecvPropQAngles( RECVINFO( m_angVPhysAngles ) ),
- RecvPropVector( RECVINFO( m_vNetPos ) ),
- RecvPropQAngles( RECVINFO( m_angNetAngles ) ),
- RecvPropVector( RECVINFO( m_vecEntityAngVelocity ) ),
- #else
- //SendPropQAngles( SENDINFO( m_angCur ) ),
- //SendPropQAngles( SENDINFO( m_angTarget ) ),
- SendPropVector( SENDINFO( m_vOffset ) ),
- SendPropVector( SENDINFO( m_vVphysicsPos ) ),
- SendPropQAngles( SENDINFO( m_angVPhysAngles ) ),
- SendPropVector( SENDINFO( m_vNetPos ) ),
- SendPropQAngles( SENDINFO( m_angNetAngles ) ),
- SendPropVector ( SENDINFO( m_vecEntityAngVelocity ), 16, SPROP_CHANGES_OFTEN, -256.0f, 256.0f ), // Artificially high for collisions
- #endif
- END_NETWORK_TABLE();
- #ifndef CLIENT_DLL
- LINK_ENTITY_TO_CLASS( vehicle_es_test, CESTestVehicle );
- BEGIN_DATADESC(CESTestVehicle)
- END_DATADESC();
- #else
- BEGIN_PREDICTION_DATA(C_ESTestVehicle)
- //DEFINE_PRED_FIELD( m_angCur, FIELD_VECTOR, FTYPEDESC_INSENDTABLE ),
- //DEFINE_PRED_FIELD( m_angTarget, FIELD_VECTOR, FTYPEDESC_INSENDTABLE ),
- DEFINE_PRED_FIELD( m_vOffset, FIELD_VECTOR, FTYPEDESC_INSENDTABLE ),
- DEFINE_PRED_FIELD( m_vVphysicsPos, FIELD_VECTOR, FTYPEDESC_INSENDTABLE ),
- DEFINE_PRED_FIELD( m_angVPhysAngles, FIELD_VECTOR, FTYPEDESC_INSENDTABLE ),
- DEFINE_PRED_FIELD_TOL( m_vecEntityAngVelocity, FIELD_VECTOR, FTYPEDESC_INSENDTABLE, 0.5 ), // 15 bits over 1440 spread
- END_PREDICTION_DATA();
- #endif
- CESTestVehicle::CESTestVehicle()
- {
- m_vOffset.GetForModify().Init(0,0,0);
- //m_angCur.GetForModify().Init(0,0,0);
- m_angLastViewAngles.Init();
- m_angVPhysAngles.GetForModify().Init();
- m_vVphysicsPos.GetForModify().Init();
- m_anginVehicleTurning.Init();
- m_vecEntityAngVelocity.GetForModify().Init();
- SetPredictionEligible( true );
- }
- #ifdef CLIENT_DLL
- void CESTestVehicle::UpdateViewAngles( C_BasePlayer *pLocalPlayer, CUserCmd *pCmd )
- {
- // Blend the view angles.
- //int eyeAttachmentIndex = LookupAttachment( "vehicle_driver_eyes" );
- //Vector vehicleEyeOrigin;
- //QAngle vehicleEyeAngles;
- //GetAttachmentLocal( eyeAttachmentIndex, vehicleEyeOrigin, vehicleEyeAngles );
- // QAngle outAngles;
- //InterpolateAngles( pCmd->viewangles, vehicleEyeAngles, outAngles, 1.0f );
- //pCmd->viewangles = outAngles;
- BaseClass::UpdateViewAngles(pLocalPlayer,pCmd);
- }
- #endif
- void CESTestVehicle::GetVehicleViewPosition( int nRole, Vector *pOrigin, QAngle *pAngles, float *pFOV )
- {
- if( pOrigin )
- {
- *pOrigin = GetAbsOrigin();
- #ifdef CLIENT_DLL
- Vector eyePos;
- QAngle eyeAngles;
- GetAttachment( "vehicle_driver_eyes3rd", eyePos, eyeAngles );
- *pOrigin = eyePos;
- #endif
- }
- if( pAngles )
- {
- *pAngles = GetAbsAngles();/* + m_angCur;*/
- }
- if( pFOV )
- {
- *pFOV = 110.0f;
- }
- }
- #ifdef CLIENT_DLL
- void CESTestVehicle::ClientThink()
- #else
- void CESTestVehicle::Think()
- #endif
- {
- #ifdef CLIENT_DLL
- //if( !physenv )
- // return;
- //else if( !VPhysicsGetObject() )
- // InitPhysics();
- //Draw Client entity pos
- NDebugOverlay::Cross3DOriented( GetAbsOrigin(), GetAbsAngles(), 10.0f, 0, 255, 0, true, 0.0f);
- #else
- //Draw Server entity pos
- NDebugOverlay::Cross3DOriented( GetAbsOrigin(), GetAbsAngles(), 10.0f, 255, 0, 0, true, 0.0f);
- #endif
- //if( VPhysicsGetObject() )
- //{
- Vector pos = GetAbsOrigin();
- QAngle ang = GetAbsAngles();
- // //Draw Vphysics entity pos
- // NDebugOverlay::Cross3DOriented( pos, ang, 10.0f, 128, 128, 0, true, 0.0f );
- #ifdef CLIENT_DLL
- Vector Smoothed;
- Smoothed = VectorLerp( m_vVphysicsPos.Get(), pos, 1.0f/gpGlobals->frametime );
- SetAbsOrigin(Smoothed);
- SetAbsAngles(m_angVPhysAngles.Get());
- #else
- m_vVphysicsPos = pos;
- m_angVPhysAngles = ang;
- #endif
- //}
- //if( VPhysicsGetObject() )
- //{
- // m_anginVehicleTurning = m_anginVehicleTurning * 10.0f;
- // Vector vel, forward;
- // GetVectors( &forward, NULL, NULL );
- // vel = m_fForce * forward;
- // VPhysicsGetObject()->SetVelocity( &vel, &m_anginVehicleTurning );
- //}
- #ifdef CLIENT_DLL
- BaseClass::ClientThink();
- #else
- BaseClass::Think();
- #endif
- }
- void CESTestVehicle::Spawn()
- {
- //SetModel( c_VEHICLE_MODEL.c_str() );
- BaseClass::Spawn();
- m_fForce = 0;
- #ifdef CLIENT_DLL
- SetNextClientThink( CLIENT_THINK_ALWAYS );
- #else
- SetSolid( SOLID_VPHYSICS );
- SetSolidFlags( 0 );
- InitPhysics(); //init on server this early, wait for the client
- #endif
- }
- void CESTestVehicle::InitPhysics()
- {
- #ifdef GAME_DLL
- VPhysicsDestroyObject();
- solid_t solid;
- PhysModelParseSolid( solid, this, GetModelIndex() );
- IPhysicsObject *pPhysicsObject = PhysModelCreate( this, GetModelIndex(), GetAbsOrigin(), GetAbsAngles(), &solid );//VPhysicsInitNormal( SOLID_VPHYSICS, 0, false, &solid );
- //Set physics flags
- Assert( pPhysicsObject );
- PhysSetGameFlags( pPhysicsObject, FVPHYSICS_NO_SELF_COLLISIONS );
- pPhysicsObject->EnableGravity( false );
- pPhysicsObject->EnableDrag( true );
- pPhysicsObject->SetCallbackFlags( CALLBACK_GLOBAL_COLLISION | CALLBACK_SHADOW_COLLISION | CALLBACK_GLOBAL_FRICTION );
- //// Setup Defaults
- VPhysicsSetObject( pPhysicsObject );
- pPhysicsObject->SetShadow( 256.0f, 256.0f, true, true );
- pPhysicsObject->GetShadowController()->SetPhysicallyControlled( true );
- pPhysicsObject->GetShadowController()->SetTeleportDistance( 0.0f );
- pPhysicsObject->EnableCollisions( true );
- pPhysicsObject->Wake();
- PhysAddShadow( this );
- #endif
- }
- void CESTestVehicle::DriveVehicle( float flFrameTime, CUserCmd *ucmd, int iButtonsDown, int iButtonsReleased )
- {
- // //ConVarRef m_yaw("m_yaw");
- // int iButtons = ucmd->buttons;
- //
- // Vector forward, right;
- // GetVectors( &forward, &right, NULL );
- //
- // if( ucmd->forwardmove > 0 )
- // {
- // //m_vOffset += Vector( flFrameTime * 1, 0, 0 );
- // // ApplyAbsVelocityImpulse( forward * 1.0f );
- // //m_angTarget.GetForModify()[PITCH] += 5.0f * flFrameTime;
- // m_fForce = Approach( 255, m_fForce, 1.0f );
- // }
- // else if( ucmd->forwardmove < 0 )
- // {
- // //m_vOffset += Vector( -flFrameTime * 1, 0, 0 );
- // //ApplyAbsVelocityImpulse( forward * -1.0f );
- // //m_angTarget.GetForModify()[PITCH] -= 5.0f * flFrameTime;
- // m_fForce = - Approach( 255, m_fForce, 1.0f );
- // }
- // else
- // {
- // m_fForce = Approach( 0, m_fForce, 1.0f );
- // }
- //
- // if( ucmd->sidemove > 0 )
- // {
- // //m_vOffset += Vector( flFrameTime * 1, 0, 0 );
- // //ApplyAbsVelocityImpulse( right * -1.0f );
- // m_angTarget.GetForModify()[YAW] -= 5.0f * flFrameTime;
- // }
- // else if( ucmd->sidemove < 0 )
- // {
- // //m_vOffset += Vector( -flFrameTime * 1, 0, 0 );
- // //ApplyAbsVelocityImpulse( right * 1.0f );
- // m_angTarget.GetForModify()[YAW] += 5.0f * flFrameTime;
- // }
- //
- // if( iButtons & IN_JUMP )
- // {
- ////#ifndef CLIENT_DLL
- // if( VPhysicsGetObject() )
- // {
- // VPhysicsGetObject()->EnableMotion( false );
- // }
- ////#endif
- // }
- // else if( iButtonsReleased & IN_JUMP )
- // {
- ////#ifndef CLIENT_DLL
- // if( VPhysicsGetObject() )
- // {
- // VPhysicsGetObject()->EnableMotion( true );
- // }
- ////#endif
- // }
- //
- // if( iButtons & IN_RUN )
- // {
- // m_fForce = Approach( 255, m_fForce, 1.0f * gpGlobals->frametime );
- // }
- // else
- // {
- // m_fForce = Approach( 0, m_fForce, 1.0f * gpGlobals->frametime );
- // }
- //
- ////#ifdef CLIENT_DLL
- //// engine->Con_NPrintf( 14, "Pitch: %6.1f Yaw: %6.1f 3rdCamera angles Client", ucmd->camera_angles[PITCH], ucmd->camera_angles[YAW] );
- ////#else
- //// engine->Con_NPrintf( 16, "Pitch: %6.1f Yaw: %6.1f 3rdCamera angles Server", ucmd->camera_angles[PITCH], ucmd->camera_angles[YAW] );
- ////#endif
- //
- ////#ifdef CLIENT_DLL
- // //QAngle angDelta( ucmd->camera_angles[YAW] - m_angLastViewAngles[YAW], ucmd->camera_angles[PITCH] - m_angLastViewAngles[PITCH], 0 );
- // QAngle angDelta( ucmd->mouse_control_axis[YAW], ucmd->mouse_control_axis[PITCH], 0 );
- //
- // //m_angTarget.GetForModify()[YAW] = angDelta[YAW];
- // //m_angTarget.GetForModify()[PITCH] = angDelta[PITCH];
- //
- // //We need to stock a torque value instead of an angle
- // m_anginVehicleTurning.Init();
- // m_anginVehicleTurning.y = ucmd->mouse_control_axis[YAW] / 255.0f * 1000.0f;// * 0.5f;
- // m_anginVehicleTurning.z = ucmd->mouse_control_axis[PITCH] / 255.0f * 1000.0f;// * 0.5f;
- //
- // m_angLastViewAngles = ucmd->camera_angles;
- //
- // engine->Con_NPrintf( 14, "X: %6.1f Y: %6.1f Mouse Values",ucmd->mouse_control_axis.x, ucmd->mouse_control_axis.y );
- // //engine->Con_NPrintf( 16, "Pitch: %6.1f Yaw: %6.1f AngleTarget vehicle", m_angTarget.Get()[PITCH], m_angTarget.Get()[YAW] );
- ////#endif
- }
- //-----------------------------------------------------------------------------
- // Do the move (apply usercmd to vehicle/physics here)
- //-----------------------------------------------------------------------------
- void CESTestVehicle::SetupMove( CBasePlayer *player, CUserCmd *ucmd, IMoveHelper *pHelper, CMoveData *move )
- {
- if( GetPassenger(0) == player )
- {
- #define SCALEINPUT( x ) x > 0 ? (float)( x * x ) * ( 1.0f / ( 128.0f * 128.0f ) ) : (float)( x * x ) * ( -1.0f / ( 128.0f * 128.0f ) )
- input_torque.Init( 0 , SCALEINPUT(ucmd->mouse_control_axis.y), -SCALEINPUT(ucmd->mouse_control_axis.x) /*-SCALEINPUT(ucmd->mouse_control_axis.z)*/ );
- input_force.Init( -SCALEINPUT( ( ucmd->buttons & IN_FORWARD )? 128.0f : 0.0f ), 0, 0 );
- #undef SCALEINPUT
- engine->Con_NPrintf( 4, "input_torque x: %f y: %f z: %f", input_torque.x, input_torque.y, input_torque.z );
- engine->Con_NPrintf( 6, "mouse_control_axis x: %i y: %i z: %i", ucmd->mouse_control_axis.x, ucmd->mouse_control_axis.y, ucmd->mouse_control_axis.z );
- #ifdef CLIENT_DLL
- SetLocalVelocity( m_vecMetersVelocity );
- #endif
- }
- }
- //-----------------------------------------------------------------------------
- // Process movement functions
- //-----------------------------------------------------------------------------
- void CESTestVehicle::ProcessMovement( CBasePlayer *pPlayer, CMoveData *pMoveData )
- {
- // Not sure what this function does. I think it's safe to stub for now.
- // Run the move and update the velocity of the craft
- if ( GetPassenger(0) == pPlayer )
- {
- CommitInputs( gpGlobals->frametime );
- }
- }
- void CESTestVehicle::PhysicsSimulate( void )
- {
- #ifdef GAME_DLL // This could be shared, but it could be causing hitching and desync
- BaseClass::PhysicsSimulate();
- Vector origin = GetAbsOrigin();
- //if( origin.x >= MAX_COORD_INTEGER ||
- // origin.y >= MAX_COORD_INTEGER ||
- // origin.z >= MAX_COORD_INTEGER ||
- // origin.x <= MIN_COORD_INTEGER ||
- // origin.y <= MIN_COORD_INTEGER ||
- // origin.z <= MIN_COORD_INTEGER || enginetrace->GetPointContents( origin ) == CONTENTS_SOLID )
- //{
- // Warning("Out of world ship was cleaned up\n");
- // Event_Killed( CTakeDamageInfo( this, this, m_iMaxHealth, DMG_NEVERGIB ) );
- // return;
- //}
- if( !GetPassenger() ) // No players present
- {
- input_force = vec3_origin;
- input_torque = vec3_origin;
- if( GetAbsVelocity() != vec3_origin || m_vecEntityAngVelocity != vec3_origin )
- CommitInputs( gpGlobals->frametime );
- }
- #endif
- }
- void CESTestVehicle::VPhysicsUpdate( IPhysicsObject *pPhysics )
- {
- BaseClass::VPhysicsUpdate( pPhysics );
- }
- //-----------------------------------------------------------------------------
- // Finish movement functions
- //-----------------------------------------------------------------------------
- void CESTestVehicle::FinishMove( CBasePlayer *player, CUserCmd *ucmd, CMoveData *move )
- {
- if( GetPassenger(0) == player )
- {
- #ifdef CLIENT_DLL
- SetNetworkOrigin( GetLocalOrigin() );
- SetNetworkAngles( GetLocalAngles() );
- // For prediction
- m_vecMetersVelocity = GetLocalVelocity();
- #else
- PhysicsTouchTriggers();
- PhysicsRelinkChildren( gpGlobals->frametime );
- #endif
- }
- }
- //-----------------------------------------------------------------------------
- // Post-frame player processing
- //-----------------------------------------------------------------------------
- void CESTestVehicle::ItemPostFrame( CBasePlayer *player )
- {
- BaseClass::ItemPostFrame(player);
- }
- /* This is what sdk_playermove.cpp has to say about these functions:
- SetupMove:
- This is called pre player movement and copies all the data necessary from the player for movement.
- (Server-side, the client-side version of this code can be found in prediction.cpp.)
- FinishMove:
- This is called post player movement to copy back all data that movement could have modified and that
- is necessary for future movement. (Server-side, the client-side version of this code can be found
- in prediction.cpp.)
- */
- /* Guesstimates about what the functions do:
- SetupMove:
- Called before player movement code, to handle commands
- ProcessMovement:
- Called after player movement code; now has access to processed player movements.
- Not relevant for us because we don't rely on player movement.
- */
- void CESTestVehicle::CommitInputs(float Interval)
- {
- // Ok, it's time to redo this flying code, and write long comments like this one
- // The main idea behind this is to go for full arcade flight
- // with a bit of a newtonian flare on the "cut engines" key
- // so what we will do is rotate the velocity vector, rather than do all the acceleration shit
- // that will allow us to use realistic accels for translational without compromising turn speed
- // Define a bunch of vectors over here
- Vector localvelocity, accel;
- AngularImpulse angaccel(0,0,0);
- {
- // Speed depends on wether or not turbo is on
- float flSpeedMax = 100.0f;
- VectorIRotate( GetAbsVelocity(), EntityToWorldTransform(), localvelocity );
- // Just regular turning for angles
- VectorMultiply( m_angTurnMax, input_torque, angaccel );
- angaccel -= m_vecEntityAngVelocity.Get(); // "angaccel" and "angular" are angular velocities
- angaccel /= Interval; // "angaccel" now an angular acceleration
- angaccel.x = MIN( m_angAccelMax.x, angaccel.x );
- angaccel.y = MIN( m_angAccelMax.y, angaccel.y );
- angaccel.z = MIN( m_angAccelMax.z, angaccel.z );
- // Poor man's normalization. Basically projects the box to a circle
- // Its not perfect, but it works (problem is being at 0.7 x and 0.7 y is the same as 1 x and 1 y)
- float vel = input_force.LengthSqr();
- if( vel > 1.0f )
- input_force *= FastRSqrt( vel );
- accel = input_force * flSpeedMax - localvelocity; // "accel" now a velocity delta in local space
- // Note: here and in the VectorMultiply following are the only
- // cases in which a specific input parameter is referenced.
- accel /= Interval; // "accel" now an acceleration
- accel.x = MIN( m_vecAccelMax.x, accel.x ); // Clamp to max
- accel.y = MIN( m_vecAccelMax.y, accel.y ); // Clamp to max
- accel.z = MIN( m_vecAccelMax.z, accel.z ); // Clamp to max
- accel *= Interval;
- angaccel *= Interval;
- localvelocity += accel;
- m_vecEntityAngVelocity += angaccel;
- QAngle angvel;
- matrix3x4_t AngVel, output, localToWorld;
- AngularImpulseToQAngle( m_vecEntityAngVelocity, angvel );
- #ifdef CLIENT_DLL
- AngleMatrix( GetNetworkAngles(), localToWorld ); // Nothing lost here, it gets done if you call EntityToWorld too
- #else
- AngleMatrix( GetLocalAngles(), localToWorld ); // Nothing lost here, it gets done if you call EntityToWorld too
- #endif
- AngleMatrix( angvel * Interval, AngVel );
- ConcatTransforms( localToWorld, AngVel, output );
- MatrixAngles( output, angvel );
- #ifdef CLIENT_DLL
- // This should fix pred errors
- angvel[0] = anglemod(angvel[0]);
- angvel[1] = anglemod(angvel[1]);
- angvel[2] = anglemod(angvel[2]);
- #endif
- SetAbsAngles( angvel );
- // NOTE: output is the new angle, this bypasses all the slippage inducing stuff by hard clamping the rotation
- VectorRotate( localvelocity, output, accel );
- SetAbsVelocity( accel );
- }
- //m_iEngineBits = EngineBits( input_force );
- #ifdef CLIENT_DLL
- Vector origin = GetNetworkOrigin() + GetAbsVelocity() * TICK_INTERVAL;
- #else
- Vector origin = GetLocalOrigin() + GetAbsVelocity() * TICK_INTERVAL;
- #endif
- SetAbsOrigin( origin );
- #ifdef GAME_DLL
- if( VPhysicsGetObject() )
- {
- VPhysicsGetObject()->UpdateShadow( GetAbsOrigin(), GetAbsAngles(), false, TICK_INTERVAL );
- }
- #endif
- }
- //-----------------------------------------------------------------------------
- // VPhysics stuff
- //-----------------------------------------------------------------------------
- #ifdef GAME_DLL
- void CESTestVehicle::VPhysicsPreCollision( int index, gamevcollisionevent_t *pEvent )
- {
- pEvent->pObjects[index]->SetVelocity( &(GetAbsVelocity() ), &m_vecEntityAngVelocity.Get() );
- }
- void CESTestVehicle::VPhysicsShadowCollision( int index, gamevcollisionevent_t *pEvent )
- {
- Vector velocity; QAngle angles;
- pEvent->pObjects[index]->GetPosition( &velocity, &angles );
- SetAbsOrigin( velocity );
- SetAbsAngles( angles );
- AngularImpulse angvel;
- pEvent->pObjects[index]->GetVelocity( &velocity, &angvel );
- SetAbsVelocity( velocity );
- m_vecEntityAngVelocity = angvel;
- Vector damagePos;
- pEvent->pInternalData->GetContactPoint( damagePos );
- Vector damageForce = pEvent->postVelocity[index] * pEvent->pObjects[index]->GetMass();
- if ( damageForce == vec3_origin )
- {
- // This can happen if this entity is a func_breakable, and can't move.
- // Use the velocity of the entity that hit us instead.
- damageForce = pEvent->postVelocity[!index] * pEvent->pObjects[!index]->GetMass();
- }
- //int otherIndex = !index;
- //CBaseEntity *pOther = pEvent->pEntities[otherIndex];
- //// We're to take normal damage from this
- //int damageType;
- //float damage = CalculateDefaultPhysicsDamage( index, pEvent, (IsInSpace()?ES_SCALEFACTOR*4.0f:4.0f/ES_SCALEFACTOR), true, damageType );
- //if ( damage > 0 )
- //{
- // CTakeDamageInfo dmgInfo( pOther, pOther, damageForce, damagePos, damage, damageType | DMG_TACTICAL_SHIP );
- // PhysCallbackDamage( this, dmgInfo, *pEvent, index );
- // CBasePlayer *player = dynamic_cast< CBasePlayer * >( GetPassenger() );
- // if( player )
- // {
- // CSingleUserRecipientFilter filter( player );
- // EmitSound( filter, entindex(), "Cockpit.ImpactAlarm" );
- // }
- //}
- }
- void CESTestVehicle::VPhysicsShadowUpdate( IPhysicsObject *pPhysics )
- {
- Vector origin = GetAbsOrigin();
- if ( pPhysics->GetGameFlags() & FVPHYSICS_PENETRATING || pPhysics->GetContactPoint( NULL, NULL ) )
- {
- Vector velocity, angvel; QAngle angles;
- pPhysics->GetPosition( &velocity, &angles );
- SetAbsOrigin( velocity );
- SetAbsAngles( angles );
- PhysicsTouchTriggers( &origin );
- PhysicsRelinkChildren(gpGlobals->frametime);
- }
- }
- #endif
- #ifdef CLIENT_DLL
- bool CESTestVehicle::ShouldPredict()
- {
- C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
- if( !player )
- return false;
- if( GetPassenger(0) == player )
- return true;
- return false;
- }
- bool CESTestVehicle::ShouldInterpolate( void )
- {
- C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
- if ( player && player->GetVehicle() && static_cast<CESTestVehicle *>(player->GetVehicle()->GetVehicleEnt() ) == this )
- return true;
- return BaseClass::ShouldInterpolate();
- }
- void CESTestVehicle::PostDataUpdate( DataUpdateType_t updateType )
- {
- BaseClass::PostDataUpdate( updateType );
- }
- void CESTestVehicle::OnDataChanged( DataUpdateType_t type )
- {
- BaseClass::OnDataChanged( type );
- if( type == DATA_UPDATE_CREATED )
- {
- //m_nType = GetVehicleInfo()->nRole;
- //m_vecAccelMax = GetVehicleInfo()->vecAccel;
- //m_angAccelMax = GetVehicleInfo()->vecAngularAccel;
- //m_flSpeedMax = GetVehicleInfo()->flMaxSpeed; // Updated later
- //m_flBoostMax = GetVehicleInfo()->flMaxBoostSpeed;
- //m_angTurnMax = GetVehicleInfo()->angTurnMax;
- //CreateVPhysics();
- MDLCACHE_CRITICAL_SECTION();
- //m_VehicleFX.Init( this );
- SetNextClientThink( CLIENT_THINK_ALWAYS );
- }
- UpdateVisibility();
- //if( m_iOldTeamNum != GetTeamNumber() )
- //{
- // m_VehicleFX.InitTeam();
- // m_iOldTeamNum = GetTeamNumber();
- //}
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement