-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.cc
137 lines (108 loc) · 3.82 KB
/
player.cc
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
#include "game/player.h"
PlayerData::PlayerData()
{
//normal datablock definitions here
skeletonBoneList = NULL;
}
bool PlayerData::preload(bool server, char errorBuffer[256])
{
//normal stuff
//IK-ready the skeleton before any animations
mSkeleton = new skeleton();
mSkeleton->bodyData = this; //get our datablock firstly
}
void PlayerData::initPersistFields()
{
//normal stuff here
addField( "skeletonBoneList", TypeFilename, Offset( skeletonBoneList, PlayerData ) );
}
void PlayerData::packData(BitStream* stream)
{
//normal stuff here
stream->writeString(skeletonBoneList);
}
void PlayerData::unpackData(BitStream* stream)
{
//normal stuff here
skeletonBoneList = stream->readSTString();
}
bool Player::onNewDataBlock(GameBaseData* dptr)
{
//normal stuff here
mDataBlock->mSkeleton->body = mShapeInstance; //set up our shapefile data to the skeleton
}
void Player::updateLookAnimation()
{
//we're doing the arm IK stuff!!
if(mDataBlock->mSkeleton->activeRegions.size() != 0)
{
//exit if we're not really doing IK
//our two end points
Point3F leftHand, rightHand, null;
leftHand = rightHand = null = Point3F(0,0,0);
if(weaponSlot == -1) //for now, bail if we have no weapon
return;
MountedImage& image = mMountedImageList[weaponSlot];
MatrixF worldMat, rHand, lHand, rHTemp, lHTemp, objMat, temp;
//we have a point for the left arm to do IK with
for(S32 i=0; i<mDataBlock->mSkeleton->activeRegions.size(); i++){
if(mDataBlock->mSkeleton->activeRegions[i] == 1) //are we doing the left arm
{
//older
MatrixF lHandNodeT = getMountedObjectNodeTransform("leftHand", weaponSlot);
if (image.dataBlock) {
ShapeBaseImageData& data = *image.dataBlock;
//get all valid positioning/rotation data and pull us into world space
getRenderMountTransform(data.mountPoint,&worldMat); //Returns mount point to world space transform
//move the rear sight node's transform into worldspace
temp.mul(worldMat, lHandNodeT);
lHTemp.mul(mWorldToObj, temp);
//take the world-space sight transform and apply it against the mount transform
//(get the relative distance in worldspace)
lHand.mul(lHTemp,data.mountTransform);
//origin point for proper rotation
lHand.mulP(null);
//do the left arm's IK
mDataBlock->mSkeleton->CCDIK(1, lHand);
}
//older
}
if(mDataBlock->mSkeleton->activeRegions[i] == 2) //are we doing the right arm
{
//this was the main way of setting it now, the left hand method was the older one
S32 rHand = mDataBlock->shape->findNode("rHandMount");
MatrixF rHandNodeT = mShapeInstance->mNodeTransforms[rHand];
mDataBlock->mSkeleton->CCDIK(2, rHandNodeT);
}
}
}
//normal stuff here
}
void Player::updateAnimationTree(bool firstPerson)
{
S32 mode = 0;
//replace old stuff here
for (U32 i = 0; i < mDataBlock->mSkeleton->NumSpineNodes; i++)
if (mDataBlock->spineNode[i] != -1)
mShapeInstance->setNodeAnimationState(mDataBlock->spineNode[i],mode);
}
//C then A then B
//comes back as degrees
F32 Player::getFarAng(F32 c, F32 a, F32 b)
{
F32 angRad = mAcos(((a*a+b*b-c*c)/(2*a*b)));
return mRadToDeg(angRad);
}
ConsoleMethod(Player, setIK, void, 4, 4, "Setting the arms and/or legs to use IK 1 = left arm, 2 = right arm 5 = left leg 6 = right leg")
{
Con::printf("Called setIK! Region is %i and is set to %d", dAtoi(argv[2]), dAtob(argv[3]));
object->setIK(dAtoi(argv[2]), dAtob(argv[3]));
}
void Player::setIK(S32 region, bool set)
{
mDataBlock->mSkeleton->setIK(region, set);
}