/
CAbstractMovers.c
98 lines (80 loc) · 2.25 KB
/
CAbstractMovers.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
Copyright ©1995-1996, Juri Munkki
All rights reserved.
File: CAbstractMovers.c
Created: Tuesday, December 5, 1995, 6:03
Modified: Tuesday, February 20, 1996, 10:37
*/
#include "CAbstractMovers.h"
void CAbstractMovers::IAbstractActor()
{
inherited::IAbstractActor();
mass = FIX(50); // Some default mass
speed[0] = 0;
speed[1] = 0;
speed[2] = 0;
internalImpulse[0] = 0;
internalImpulse[1] = 0;
internalImpulse[2] = 0;
impulse[0] = 0;
impulse[1] = 0;
impulse[2] = 0;
impulseSlowDown = FIX3(800);
}
void CAbstractMovers::GetSpeedEstimate(
Fixed *theSpeed)
{
*theSpeed++ = speed[0]+internalImpulse[0];
*theSpeed++ = speed[1]+internalImpulse[1];
*theSpeed++ = speed[2]+internalImpulse[2];
}
void CAbstractMovers::Push(
Fixed *direction)
{
Vector curSpeed;
isActive |= kHasImpulse;
GetSpeedEstimate(curSpeed);
internalImpulse[0] += direction[0] - curSpeed[0];
internalImpulse[1] += direction[1] - curSpeed[1];
internalImpulse[2] += direction[2] - curSpeed[2];
}
void CAbstractMovers::Accelerate(
Fixed *direction)
{
Fixed theMass;
isActive |= kHasImpulse;
theMass = GetTotalMass();
if(theMass)
{ internalImpulse[0] += FMulDivNZ(direction[0], FIX(300), theMass);
internalImpulse[1] += FMulDivNZ(direction[1], FIX(300), theMass);
internalImpulse[2] += FMulDivNZ(direction[2], FIX(300), theMass);
}
}
void CAbstractMovers::WasHit(RayHitRecord *theHit, Fixed hitEnergy)
{
Vector impulseMotion;
Fixed impulsePower;
inherited::WasHit(theHit, hitEnergy);
if(shields)
{ impulsePower = hitEnergy>>1;
impulseMotion[0] = FMul(impulsePower, theHit->direction[0]);
impulseMotion[1] = FMul(impulsePower, theHit->direction[1]);
impulseMotion[2] = FMul(impulsePower, theHit->direction[2]);
Accelerate(impulseMotion);
}
}
void CAbstractMovers::FrameAction()
{
inherited::FrameAction();
if(isActive & kHasImpulse)
{ impulse[0] = internalImpulse[0];
impulse[1] = internalImpulse[1];
impulse[2] = internalImpulse[2];
internalImpulse[0] = FMul(internalImpulse[0], impulseSlowDown);
internalImpulse[1] = FMul(internalImpulse[1], impulseSlowDown);
internalImpulse[2] = FMul(internalImpulse[2], impulseSlowDown);
if(!(internalImpulse[0] || internalImpulse[1] || internalImpulse[2]))
{ isActive &= ~kHasImpulse;
}
}
}