Skip to content

Commit bb91000

Browse files
committed
GetBoneOffset
1 parent 6145f77 commit bb91000

File tree

3 files changed

+124
-15
lines changed

3 files changed

+124
-15
lines changed

src/common/utility/quaternion.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,12 @@ class TQuaternion
357357
return (from * scale0 + to * scale1).Unit();
358358
}
359359
}
360+
361+
template<typename U>
362+
explicit operator TVector4<U>()
363+
{
364+
return TVector4<U>(U(X),U(Y),U(Z),U(W));
365+
}
360366
};
361367

362368
typedef TQuaternion<float> FQuaternion;

src/playsim/p_actionfunctions.cpp

Lines changed: 113 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5164,16 +5164,10 @@ FModel * SetGetBoneShared(AActor * self, int model_index)
51645164
}
51655165
}
51665166

5167-
FModel * SetBoneShared(AActor * self, int model_index, int &bone_index, FName * bone_name, int mode, double &interpolation_duration)
5167+
template<bool isSet>
5168+
FModel * SetGetBoneOffsetShared(AActor * self, int model_index, int &bone_index, FName * bone_name)
51685169
{
5169-
FModel * mdl = SetGetBoneShared<true, false>(self, model_index);
5170-
5171-
if(interpolation_duration < 0) interpolation_duration = 0;
5172-
5173-
if(mode < 0 || mode > 2)
5174-
{
5175-
ThrowAbortException(X_OTHER, "Invalid mode for setbone");
5176-
}
5170+
FModel * mdl = SetGetBoneShared<isSet, true>(self, model_index);
51775171

51785172
if(bone_name)
51795173
{
@@ -5196,6 +5190,23 @@ FModel * SetBoneShared(AActor * self, int model_index, int &bone_index, FName *
51965190
return mdl;
51975191
}
51985192

5193+
FModel * SetBoneOffsetShared(AActor * self, int model_index, int &bone_index, FName * bone_name, int mode, double &interpolation_duration)
5194+
{
5195+
if(interpolation_duration < 0) interpolation_duration = 0;
5196+
5197+
if(mode < 0 || mode > 2)
5198+
{
5199+
ThrowAbortException(X_OTHER, "Invalid mode for setbone");
5200+
}
5201+
5202+
return SetGetBoneOffsetShared<true>(self, model_index, bone_index, bone_name);
5203+
}
5204+
5205+
FModel * GetBoneOffsetShared(AActor * self, int model_index, int &bone_index, FName * bone_name)
5206+
{
5207+
return SetGetBoneOffsetShared<false>(self, model_index, bone_index, bone_name);
5208+
}
5209+
51995210
//================================================
52005211
//
52015212
// SetBoneRotation
@@ -5204,7 +5215,7 @@ FModel * SetBoneShared(AActor * self, int model_index, int &bone_index, FName *
52045215

52055216
static void SetModelBoneRotationNative(AActor * self, int model_index, int bone_index, double rot_x, double rot_y, double rot_z, double rot_w, int mode, double interpolation_duration, double ticFrac)
52065217
{
5207-
FModel * mdl = SetBoneShared(self, model_index, bone_index, nullptr, mode, interpolation_duration);
5218+
FModel * mdl = SetBoneOffsetShared(self, model_index, bone_index, nullptr, mode, interpolation_duration);
52085219

52095220
if(!mdl) return;
52105221

@@ -5222,7 +5233,7 @@ static void SetModelNamedBoneRotationNative(AActor * self, int model_index, int
52225233

52235234
int bone_index;
52245235

5225-
FModel * mdl = SetBoneShared(self, 0, bone_index, &bone_name, mode, interpolation_duration);
5236+
FModel * mdl = SetBoneOffsetShared(self, model_index, bone_index, &bone_name, mode, interpolation_duration);
52265237

52275238
if(!mdl) return;
52285239

@@ -5274,7 +5285,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, SetNamedBoneRotation, SetNamedBoneRotation
52745285

52755286
static void SetModelBoneTranslationNative(AActor * self, int model_index, int bone_index, double rot_x, double rot_y, double rot_z, int mode, double interpolation_duration, double ticFrac)
52765287
{
5277-
FModel * mdl = SetBoneShared(self, model_index, bone_index, nullptr, mode, interpolation_duration);
5288+
FModel * mdl = SetBoneOffsetShared(self, model_index, bone_index, nullptr, mode, interpolation_duration);
52785289

52795290
if(!mdl) return;
52805291

@@ -5292,7 +5303,7 @@ static void SetModelNamedBoneTranslationNative(AActor * self, int model_index, i
52925303

52935304
int bone_index;
52945305

5295-
FModel * mdl = SetBoneShared(self, 0, bone_index, &bone_name, mode, interpolation_duration);
5306+
FModel * mdl = SetBoneOffsetShared(self, model_index, bone_index, &bone_name, mode, interpolation_duration);
52965307

52975308
if(!mdl) return;
52985309

@@ -5342,7 +5353,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, SetNamedBoneTranslation, SetNamedBoneTrans
53425353

53435354
static void SetModelBoneScalingNative(AActor * self, int model_index, int bone_index, double rot_x, double rot_y, double rot_z, int mode, double interpolation_duration, double ticFrac)
53445355
{
5345-
FModel * mdl = SetBoneShared(self, model_index, bone_index, nullptr, mode, interpolation_duration);
5356+
FModel * mdl = SetBoneOffsetShared(self, model_index, bone_index, nullptr, mode, interpolation_duration);
53465357

53475358
if(!mdl) return;
53485359

@@ -5360,7 +5371,7 @@ static void SetModelNamedBoneScalingNative(AActor * self, int model_index, int b
53605371

53615372
int bone_index;
53625373

5363-
FModel * mdl = SetBoneShared(self, 0, bone_index, &bone_name, mode, interpolation_duration);
5374+
FModel * mdl = SetBoneOffsetShared(self, model_index, bone_index, &bone_name, mode, interpolation_duration);
53645375

53655376
if(!mdl) return;
53665377

@@ -5403,6 +5414,93 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, SetNamedBoneScaling, SetNamedBoneScalingNa
54035414
}
54045415

54055416

5417+
//================================================
5418+
//
5419+
// GetBoneOffset
5420+
//
5421+
//================================================
5422+
5423+
DEFINE_ACTION_FUNCTION_NATIVE(AActor, GetBoneOffset)
5424+
{
5425+
PARAM_SELF_PROLOGUE(AActor);
5426+
PARAM_INT(bone_index);
5427+
5428+
FModel * mdl = GetBoneOffsetShared(self, 0, bone_index, nullptr);
5429+
5430+
DVector3 translation(0,0,0);
5431+
DVector4 rotation(0,0,0,1);
5432+
DVector3 scaling(0,0,0);
5433+
5434+
if(mdl)
5435+
{
5436+
auto &mod = self->modelData->modelBoneOverrides[0][bone_index];
5437+
5438+
translation = DVector3(mod.translation.Get(FVector3(0,0,0), self->Level->totaltime + 1.0));
5439+
rotation = DVector4(mod.rotation.Get(FQuaternion(0,0,0,1), self->Level->totaltime + 1.0));
5440+
scaling = DVector3(mod.scaling.Get(FVector3(0,0,0), self->Level->totaltime + 1.0));
5441+
}
5442+
5443+
if(numret > 2)
5444+
{
5445+
ret[2].SetVector(scaling);
5446+
numret = 3;
5447+
}
5448+
5449+
if(numret > 1)
5450+
{
5451+
ret[1].SetVector(translation);
5452+
}
5453+
5454+
if(numret > 0)
5455+
{
5456+
ret[0].SetVector4(rotation);
5457+
}
5458+
5459+
return numret;
5460+
}
5461+
5462+
DEFINE_ACTION_FUNCTION_NATIVE(AActor, GetNamedBoneOffset)
5463+
{
5464+
PARAM_SELF_PROLOGUE(AActor);
5465+
PARAM_NAME(bone_name);
5466+
5467+
int bone_index;
5468+
5469+
FModel * mdl = GetBoneOffsetShared(self, 0, bone_index, &bone_name);
5470+
5471+
DVector3 translation(0,0,0);
5472+
DVector4 rotation(0,0,0,1);
5473+
DVector3 scaling(0,0,0);
5474+
5475+
if(mdl)
5476+
{
5477+
auto &mod = self->modelData->modelBoneOverrides[0][bone_index];
5478+
5479+
translation = DVector3(mod.translation.Get(FVector3(0,0,0), self->Level->totaltime + 1.0));
5480+
rotation = DVector4(mod.rotation.Get(FQuaternion(0,0,0,1), self->Level->totaltime + 1.0));
5481+
scaling = DVector3(mod.scaling.Get(FVector3(0,0,0), self->Level->totaltime + 1.0));
5482+
}
5483+
5484+
if(numret > 2)
5485+
{
5486+
ret[2].SetVector(scaling);
5487+
numret = 3;
5488+
}
5489+
5490+
if(numret > 1)
5491+
{
5492+
ret[1].SetVector(translation);
5493+
}
5494+
5495+
if(numret > 0)
5496+
{
5497+
ret[0].SetVector4(rotation);
5498+
}
5499+
5500+
return numret;
5501+
}
5502+
5503+
54065504
//================================================
54075505
// SetAnimation
54085506
//================================================

wadsrc/static/zscript/actors/actor.zs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,11 @@ class Actor : Thinker native
13681368
native version("4.15.1") void SetBoneScaling(int boneIndex, Vector3 scaling, int mode = 1, double interpolation_duration = 1.0);
13691369
native version("4.15.1") void SetNamedBoneScaling(Name boneName, Vector3 scaling, int mode = 1, double interpolation_duration = 1.0);
13701370

1371+
/* rotation, translation, scaling */
1372+
native version("4.15.1") FQuaternion, Vector3, Vector3 GetBoneOffset(int boneIndex);
1373+
native version("4.15.1") FQuaternion, Vector3, Vector3 GetNamedBoneOffset(Name boneName);
1374+
1375+
13711376
native version("4.12") void SetAnimation(Name animName, double framerate = -1, int startFrame = -1, int loopFrame = -1, int endFrame = -1, int interpolateTics = -1, int flags = 0);
13721377
native version("4.12") ui void SetAnimationUI(Name animName, double framerate = -1, int startFrame = -1, int loopFrame = -1, int endFrame = -1, int interpolateTics = -1, int flags = 0);
13731378

0 commit comments

Comments
 (0)