aboutsummaryrefslogtreecommitdiff
path: root/src/Person.cpp
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2023-03-26 00:38:21 +0900
committerNguyễn Gia Phong <mcsinyx@disroot.org>2023-03-26 00:38:21 +0900
commit027e856c0f168b6c8c073de7899c8c5254716181 (patch)
tree018e90554243666f8a4e128052c848a8ca0a8800 /src/Person.cpp
parent41c669c1978bdf8f7d0bbde0d18d0b7b73a03bc1 (diff)
downloadblackshades-027e856c0f168b6c8c073de7899c8c5254716181.tar.gz
Convert a few linear algebra functions to Zig
Diffstat (limited to 'src/Person.cpp')
-rw-r--r--src/Person.cpp69
1 files changed, 35 insertions, 34 deletions
diff --git a/src/Person.cpp b/src/Person.cpp
index 292269a..c644aab 100644
--- a/src/Person.cpp
+++ b/src/Person.cpp
@@ -67,8 +67,8 @@ HitStruct Person::BulletCollideWithPlayer(int who, XYZ start, XYZ end){
if(skeleton.free<1){
start=start-playercoords;
end=end-playercoords;
- if(playerrotation)start=DoRotation(start,0,-playerrotation,0);
- if(playerrotation)end=DoRotation(end,0,-playerrotation,0);
+ if(playerrotation)start=rotate(start,0,-playerrotation,0);
+ if(playerrotation)end=rotate(end,0,-playerrotation,0);
}
tempbulletloc[0]=start;
tempbulletloc[1]=end;
@@ -176,7 +176,7 @@ HitStruct Person::BulletCollideWithPlayer(int who, XYZ start, XYZ end){
glRotatef(-skeleton.muscles[j].rotate1+90,0,1,0);
glRotatef(-skeleton.muscles[j].rotate2+90,0,0,1);
glRotatef(-skeleton.muscles[j].rotate3,0,1,0);
- glScalef(1,findDistance(skeleton.muscles[j].parent1->position,skeleton.muscles[j].parent2->position),1);
+ glScalef(1, len(skeleton.muscles[j].parent1->position - skeleton.muscles[j].parent2->position), 1);
glTranslatef(collisionpoint.x,collisionpoint.y,collisionpoint.z);
glGetFloatv(GL_MODELVIEW_MATRIX,M);
collisionpoint.x=M[12];
@@ -192,7 +192,7 @@ HitStruct Person::BulletCollideWithPlayer(int who, XYZ start, XYZ end){
}
}
if(skeleton.free<1){
- if(playerrotation)hitstruct.hitlocation=DoRotation(hitstruct.hitlocation,0,playerrotation,0);
+ if(playerrotation)hitstruct.hitlocation=rotate(hitstruct.hitlocation,0,playerrotation,0);
hitstruct.hitlocation=hitstruct.hitlocation+playercoords;
}
return hitstruct;
@@ -215,7 +215,7 @@ void Person::DoAnimations(int who)
if (targetanimation == zombieeatanim && targetframe == 3) {
auto& joints = skeleton.joints;
auto head_joint = joints[head];
- auto soundsrc = (DoRotation(head_joint.position,
+ auto soundsrc = (rotate(head_joint.position,
0, playerrotation, 0) + playercoords
- camera.position) / soundscalefactor;
playSound(gSourceID[bodyhitsound],
@@ -243,7 +243,7 @@ void Person::DoAnimations(int who)
targetanimation = getupfrontanim;
auto& joints = skeleton.joints;
auto head_joint = joints[head];
- auto soundsrc = (DoRotation(head_joint.position,
+ auto soundsrc = (rotate(head_joint.position,
0, playerrotation, 0) + playercoords
- camera.position) / soundscalefactor;
ALfloat gLoc[] {soundsrc.x, soundsrc.y, soundsrc.z};
@@ -259,11 +259,11 @@ void Person::DoAnimations(int who)
longdead = 1;
for (auto& joint : skeleton.joints) {
joint.position = playercoords
- + DoRotation(joint.position
+ + rotate(joint.position
+ joint.offset,
0, playerrotation, 0);
joint.realoldposition = joint.position;
- joint.velocity = DoRotation(joint.velocity,
+ joint.velocity = rotate(joint.velocity,
0, playerrotation, 0);
}
}
@@ -313,11 +313,11 @@ void Person::DoAnimations(int who)
if (who == 0)
playerrotation2 = camera.rotation2;
XYZ facing {0.0f, 0.0f, 1.0f};
- XYZ facinghalf = DoRotation(DoRotation(facing,
+ XYZ facinghalf = rotate(rotate(facing,
playerrotation2 / 2, 0, 0), 0, -7, 0);
- facing = DoRotation(facing, playerrotation2, 0, 0);
- XYZ facingright = DoRotation(facing, 0, -90, 0);
- XYZ facingdown = DoRotation(facing, 90, 0, 0);
+ facing = rotate(facing, playerrotation2, 0, 0);
+ XYZ facingright = rotate(facing, 0, -90, 0);
+ XYZ facingdown = rotate(facing, 90, 0, 0);
XYZ rotatearound;
XYZ oldpos;
switch (whichgun) {
@@ -367,14 +367,14 @@ void Person::DoAnimations(int who)
skeleton.joints[i].position-=(animation[idleanim].position[neck][0]-skeleton.joints[neck].position);
}
skeleton.joints[i].position+=facingright*0.1;
- skeleton.joints[i].position=rotatearound+DoRotation(skeleton.joints[i].position-rotatearound,(playerrotation2/2-10)*aimamount,0,0);
+ skeleton.joints[i].position=rotatearound+rotate(skeleton.joints[i].position-rotatearound,(playerrotation2/2-10)*aimamount,0,0);
skeleton.joints[i].position=skeleton.joints[i].position*(aimamount)+oldpos*(1-aimamount);
}
if(whichgun==shotgun){
oldpos=skeleton.joints[i].position;
skeleton.joints[i].position=animation[assaultrifleaimanim].position[i][0];
if(currentanimation==crouchanim||targetanimation==crouchanim)skeleton.joints[i].position-=(animation[idleanim].position[neck][0]-skeleton.joints[neck].position);
- skeleton.joints[i].position=rotatearound+DoRotation(skeleton.joints[i].position-rotatearound,(playerrotation2/2)*aimamount,0,0);
+ skeleton.joints[i].position=rotatearound+rotate(skeleton.joints[i].position-rotatearound,(playerrotation2/2)*aimamount,0,0);
if(currentanimation==crouchanim||targetanimation==crouchanim)skeleton.joints[i].position+=facingdown*.2;
else skeleton.joints[i].position-=facingdown*.02;
if(skeleton.joints[i].label==righthand)skeleton.joints[i].position=skeleton.joints[lefthand].position-facinghalf*2;
@@ -384,7 +384,7 @@ void Person::DoAnimations(int who)
oldpos=skeleton.joints[i].position;
skeleton.joints[i].position=animation[assaultrifleaimanim].position[i][0];
if(currentanimation==crouchanim||targetanimation==crouchanim)skeleton.joints[i].position-=(animation[idleanim].position[neck][0]-skeleton.joints[neck].position);
- skeleton.joints[i].position=rotatearound+DoRotation(skeleton.joints[i].position-rotatearound,(playerrotation2/2)*aimamount,0,0);
+ skeleton.joints[i].position=rotatearound+rotate(skeleton.joints[i].position-rotatearound,(playerrotation2/2)*aimamount,0,0);
if(currentanimation==crouchanim||targetanimation==crouchanim)skeleton.joints[i].position+=facingdown*.2;
else skeleton.joints[i].position-=facingdown*.02;
if(skeleton.joints[i].label==righthand)skeleton.joints[i].position=skeleton.joints[lefthand].position-facinghalf*2;
@@ -394,7 +394,7 @@ void Person::DoAnimations(int who)
oldpos=skeleton.joints[i].position;
skeleton.joints[i].position=animation[pistolaimanim].position[i][0];
if(currentanimation==crouchanim||targetanimation==crouchanim)skeleton.joints[i].position-=(animation[idleanim].position[neck][0]-skeleton.joints[neck].position);
- skeleton.joints[i].position=rotatearound+DoRotation(skeleton.joints[i].position-rotatearound,(playerrotation2/2)*aimamount,0,0);
+ skeleton.joints[i].position=rotatearound+rotate(skeleton.joints[i].position-rotatearound,(playerrotation2/2)*aimamount,0,0);
if(currentanimation==crouchanim||targetanimation==crouchanim){skeleton.joints[i].position+=facingright*.15;skeleton.joints[i].position+=facingdown*.3;}
else skeleton.joints[i].position-=facingdown*.1;
skeleton.joints[i].position=skeleton.joints[i].position*(aimamount)+oldpos*(1-aimamount);
@@ -403,7 +403,7 @@ void Person::DoAnimations(int who)
oldpos=skeleton.joints[i].position;
skeleton.joints[i].position=animation[pistolaimanim].position[i][0];
if(currentanimation==crouchanim||targetanimation==crouchanim)skeleton.joints[i].position-=(animation[idleanim].position[neck][0]-skeleton.joints[neck].position);
- skeleton.joints[i].position=rotatearound+DoRotation(skeleton.joints[i].position-rotatearound,(playerrotation2/2)*aimamount,0,0);
+ skeleton.joints[i].position=rotatearound+rotate(skeleton.joints[i].position-rotatearound,(playerrotation2/2)*aimamount,0,0);
if(currentanimation==crouchanim||targetanimation==crouchanim){skeleton.joints[i].position+=facingright*.15;skeleton.joints[i].position+=facingdown*.3;}
else skeleton.joints[i].position-=facingdown*.1;
skeleton.joints[i].position=skeleton.joints[i].position*(aimamount)+oldpos*(1-aimamount);
@@ -463,11 +463,11 @@ void Person::DoAnimations(int who)
}
if(attackframe==animation[grenadethrowanim].numframes-1&&ammo>0){
ammo=-1;
- sprites.MakeSprite(grenadesprite, 1, 1, 1, 1, DoRotation(skeleton.joints[righthand].position,0,playerrotation,0)+playercoords, DoRotation(facing,0,playerrotation,0)*30+velocity, 1);
- sprites.MakeSprite(spoonsprite, 1, 1, 1, 1, DoRotation(skeleton.joints[righthand].position,0,playerrotation,0)+playercoords, DoRotation(facing,0,playerrotation,0)*10+velocity, 1);
- sprites.MakeSprite(pinsprite, 1, 1, 1, 1, DoRotation(skeleton.joints[lefthand].position,0,playerrotation,0)+playercoords, facing*.1+velocity, 1);
+ sprites.MakeSprite(grenadesprite, 1, 1, 1, 1, rotate(skeleton.joints[righthand].position,0,playerrotation,0)+playercoords, rotate(facing,0,playerrotation,0)*30+velocity, 1);
+ sprites.MakeSprite(spoonsprite, 1, 1, 1, 1, rotate(skeleton.joints[righthand].position,0,playerrotation,0)+playercoords, rotate(facing,0,playerrotation,0)*10+velocity, 1);
+ sprites.MakeSprite(pinsprite, 1, 1, 1, 1, rotate(skeleton.joints[lefthand].position,0,playerrotation,0)+playercoords, facing*.1+velocity, 1);
- XYZ soundsrc = (DoRotation(skeleton.joints[righthand].position, 0, playerrotation, 0)
+ XYZ soundsrc = (rotate(skeleton.joints[righthand].position, 0, playerrotation, 0)
+ playercoords - camera.position) / soundscalefactor;
ALfloat gLoc[] {soundsrc.x, soundsrc.y, soundsrc.z};
alSourcefv(gSourceID[grenadethrowsound], AL_POSITION, gLoc);
@@ -481,12 +481,12 @@ void Person::DoAnimations(int who)
for (auto& joint : skeleton.joints)
if (!joint.lower)
joint.position = rotatearound
- + DoRotation(joint.position - rotatearound, playerrotation2 / 2, 0, 0);
+ + rotate(joint.position - rotatearound, playerrotation2 / 2, 0, 0);
else if (joint.label != groin)
- joint.position = DoRotation(joint.position, 0, playerlowrotation - playerrotation, 0);
+ joint.position = rotate(joint.position, 0, playerlowrotation - playerrotation, 0);
rotatearound = skeleton.joints[neck].position;
skeleton.joints[head].position = rotatearound
- + DoRotation(skeleton.joints[head].position - rotatearound, playerrotation2 / 2, 0, 0);
+ + rotate(skeleton.joints[head].position - rotatearound, playerrotation2 / 2, 0, 0);
}
skeleton.DoConstraints();
@@ -558,7 +558,7 @@ void Person::DoAnimationslite(int who)
if (targetanimation == zombieeatanim && targetframe == 3) {
auto& joints = skeleton.joints;
auto head_joint = joints[head];
- auto soundsrc = (DoRotation(head_joint.position,
+ auto soundsrc = (rotate(head_joint.position,
0, playerrotation, 0) + playercoords
- camera.position) / soundscalefactor;
playSound(gSourceID[bodyhitsound],
@@ -644,7 +644,7 @@ void Person::control()
if (!onground && (forwards || right)) {
auto rotation = playerrotation
- right * (forwards ? forwards * 45 : 90);
- facing = DoRotation({0, 0, 1}, 0, rotation, 0);
+ facing = rotate({0, 0, 1}, 0, rotation, 0);
velocity += facing * multiplier * 4;
}
}
@@ -688,7 +688,7 @@ void Person::DoStuff(int who)
&& currentanimation != getupfrontanim)
control();
- facing = DoRotation({0, 0, 1}, 0, playerlowrotation, 0);
+ facing = rotate({0, 0, 1}, 0, playerlowrotation, 0);
if (backwardsanim)
facing *= -1;
@@ -713,16 +713,17 @@ void Person::FindRotationGun(XYZ start, XYZ target)
temppoint1=start;
temppoint2=target;
- distance=findDistance(temppoint1,temppoint2);
+ distance = len(temppoint1 - temppoint2);
gunrotate2=asin((temppoint1.y-temppoint2.y)/distance)*rad2deg;
temppoint1.y=0;
temppoint2.y=0;
- gunrotate1=acos((temppoint1.z-temppoint2.z)/findDistance(temppoint1,temppoint2))*rad2deg;
+ gunrotate1 = rad2deg * acos((temppoint1.z - temppoint2.z)
+ / len(temppoint1 - temppoint2));
if(temppoint1.x>temppoint2.x)gunrotate1=360-gunrotate1;
tempforward=target-start;
- tempforward=DoRotation(tempforward,-90,0,0);
- tempforward=DoRotation(tempforward,0,gunrotate1-90,0);
- tempforward=DoRotation(tempforward,0,0,gunrotate2-90);
+ tempforward=rotate(tempforward,-90,0,0);
+ tempforward=rotate(tempforward,0,gunrotate1-90,0);
+ tempforward=rotate(tempforward,0,0,gunrotate2-90);
tempforward.y=0;
tempforward = normalize(tempforward);
gunrotate3=acos(0-tempforward.z)*rad2deg;
@@ -974,8 +975,8 @@ int Person::DrawSkeleton(int who)
//Facing
XYZ facing {0};
facing.z = 1;
- facing = DoRotation(facing, camera.rotation2, 0, 0);
- XYZ facingdown = DoRotation(facing, 90, 0, 0);
+ facing = rotate(facing, camera.rotation2, 0, 0);
+ XYZ facingdown = rotate(facing, 90, 0, 0);
skeleton.specialforward[1] *= 1 - aimamount;
skeleton.specialforward[1] += facingdown * aimamount;