29 #include "../../idlib/precompiled.h"
34 #include "../Game_local.h"
45 void idForce_Grab::Save(
idSaveGame *savefile )
const {
47 savefile->WriteFloat( damping );
48 savefile->WriteVec3( goalPosition );
49 savefile->WriteFloat( distanceToGoal );
50 savefile->WriteInt(
id );
72 idForce_Grab::idForce_Grab(
void ) {
83 idForce_Grab::~idForce_Grab(
void ) {
91 void idForce_Grab::Init(
float damping ) {
92 if ( damping >= 0.0
f && damping < 1.0
f ) {
93 this->damping = damping;
102 void idForce_Grab::SetPhysics(
idPhysics *phys,
int id,
const idVec3 &goal ) {
103 this->physics = phys;
105 this->goalPosition = goal;
113 void idForce_Grab::SetGoalPosition(
const idVec3 &goal ) {
114 this->goalPosition = goal;
122 float idForce_Grab::GetDistanceToGoal(
void ) {
123 return distanceToGoal;
131 void idForce_Grab::Evaluate(
int time ) {
135 idVec3 forceDir,
v, objectCenter;
137 float mass = physics->GetMass(
id);
139 objectCenter = physics->GetAbsBounds(
id).GetCenter();
146 objectCenter.
x += ( SinOffset * 3.5f * randScale1 ) + ( randScale2 * 1.2
f );
147 objectCenter.
y += ( SinOffset * -3.5f * randScale1 ) + ( randScale2 * 1.4f );
148 objectCenter.
z += ( SinOffset * 2.4f * randScale1 ) + ( randScale2 * 1.6f );
151 forceDir = goalPosition - objectCenter;
154 float temp = distanceToGoal;
155 if ( temp > 12.f && temp < 32.f ) {
158 forceAmt = (1000.f * mass) + (500.f * temp * mass);
160 if ( forceAmt/mass > 120000.f ) {
161 forceAmt = 120000.f * mass;
163 physics->AddForce(
id, objectCenter, forceDir * forceAmt );
165 if ( distanceToGoal < 196.f ) {
166 v = physics->GetLinearVelocity(
id );
167 physics->SetLinearVelocity( v * damping,
id );
169 if ( distanceToGoal < 16.f ) {
170 v = physics->GetAngularVelocity(
id);
172 physics->SetAngularVelocity( v * 0.99999f,
id );
182 void idForce_Grab::RemovePhysics(
const idPhysics *phys ) {
183 if ( physics == phys ) {
void ReadFloat(float &value)
static float Sin(float a)
float LengthSqr(void) const
#define CLASS_DECLARATION(nameofsuperclass, nameofclass)
void ReadVec3(idVec3 &vec)