2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
26 ===========================================================================
29 #include "../../idlib/precompiled.h"
32 #include "../Game_local.h"
34 CLASS_DECLARATION( idForce, idForce_Drag )
39 idForce_Drag::idForce_Drag
42 idForce_Drag::idForce_Drag( void ) {
44 dragPosition = vec3_zero;
48 dragPosition = vec3_zero;
53 idForce_Drag::~idForce_Drag
56 idForce_Drag::~idForce_Drag( void ) {
64 void idForce_Drag::Init( float damping ) {
65 if ( damping >= 0.0f && damping < 1.0f ) {
66 this->damping = damping;
72 idForce_Drag::SetPhysics
75 void idForce_Drag::SetPhysics( idPhysics *phys, int id, const idVec3 &p ) {
83 idForce_Drag::SetDragPosition
86 void idForce_Drag::SetDragPosition( const idVec3 &pos ) {
87 this->dragPosition = pos;
92 idForce_Drag::GetDragPosition
95 const idVec3 &idForce_Drag::GetDragPosition( void ) const {
96 return this->dragPosition;
101 idForce_Drag::GetDraggedPosition
104 const idVec3 idForce_Drag::GetDraggedPosition( void ) const {
105 return ( physics->GetOrigin( id ) + p * physics->GetAxis( id ) );
110 idForce_Drag::Evaluate
113 void idForce_Drag::Evaluate( int time ) {
115 idVec3 dragOrigin, dir1, dir2, velocity, centerOfMass;
116 idMat3 inertiaTensor;
118 idClipModel *clipModel;
124 clipModel = physics->GetClipModel( id );
125 if ( clipModel != NULL && clipModel->IsTraceModel() ) {
126 clipModel->GetMassProperties( 1.0f, mass, centerOfMass, inertiaTensor );
131 centerOfMass = physics->GetOrigin( id ) + centerOfMass * physics->GetAxis( id );
132 dragOrigin = physics->GetOrigin( id ) + p * physics->GetAxis( id );
134 dir1 = dragPosition - centerOfMass;
135 dir2 = dragOrigin - centerOfMass;
136 l1 = dir1.Normalize();
137 l2 = dir2.Normalize();
139 rotation.Set( centerOfMass, dir2.Cross( dir1 ), RAD2DEG( idMath::ACos( dir1 * dir2 ) ) );
140 physics->SetAngularVelocity( rotation.ToAngularVelocity() / MS2SEC( USERCMD_MSEC ), id );
142 velocity = physics->GetLinearVelocity( id ) * damping + dir1 * ( ( l1 - l2 ) * ( 1.0f - damping ) / MS2SEC( USERCMD_MSEC ) );
143 physics->SetLinearVelocity( velocity, id );
148 idForce_Drag::RemovePhysics
151 void idForce_Drag::RemovePhysics( const idPhysics *phys ) {
152 if ( physics == phys ) {