matrix fixes and introduce IKJoint

This commit is contained in:
shibbo 2021-06-29 16:51:14 -04:00
parent 3be8cef3bd
commit d973eabe8b
6 changed files with 148 additions and 13 deletions

3
.gitignore vendored
View File

@ -16,4 +16,5 @@
*.a
*.d
*.map
build
build
compiler

View File

@ -62,15 +62,19 @@ rootPath = os.path.dirname(os.path.realpath(__file__))
path = os.path.dirname(os.path.realpath(__file__)) + "\\source\\"
asm_path = os.path.dirname(os.path.realpath(__file__)) + "\\asm\\"
gc_compiler_path = os.path.dirname(os.path.realpath(__file__)) + "\\compiler\\GC\\1.2.5\\"
flags = "-nodefaults -proc gekko -DRELEASE -Cpp_exceptions off -gccinc -O4,s -fp hardware -enum int -sdata 4 -sdata2 4 -lang=c99 -align powerpc -inline all,auto -W noimplicitconv -DEPPC -DHOLLYWOOD_REV -DTRK_INTEGRATION -DGEKKO -DMTX_USE_PS -D_MSL_USING_MW_C_HEADERS -MMD -rtti off -ipa file "
nw4r_flags = "-nodefaults -proc gekko -DRELEASE -Cpp_exceptions off -gccinc -O4,p -fp hardware -enum int -sdata 4 -sdata2 4 -lang=c99 -align powerpc -inline all,auto -W noimplicitconv -DEPPC -DHOLLYWOOD_REV -DTRK_INTEGRATION -DGEKKO -DMTX_USE_PS -D_MSL_USING_MW_C_HEADERS -MMD -rtti off -ipa file "
includes = "-i . -I- -i include "
gc_flags = f"-Cpp_exceptions off -proc gekko -fp hard -O4 -nodefaults -msgstyle gcc -enum int -D__USING_IEEE_MATH__ "
for inc in MW_INC:
includes += f"{inc} "
flags += f"{includes} -nosyspath"
nw4r_flags += f"{includes} -nosyspath"
gc_flags += f"{includes} -nosyspath"
as_flags = "-c -i . -I- -i include -proc gekko -d __MWERKS__"
@ -98,14 +102,16 @@ for f in cpp_files:
print(f"Compiling {file_name}.cpp...")
compilerFlags = ""
if "nw4r" in f:
if subprocess.call(f"{MW_TOOLS_PATH}/mwcceppc.exe {nw4r_flags} -o build/{file_name}.o {f}", shell=True) == 1:
compilerFlags = nw4r_flags
else:
compilerFlags = flags
if subprocess.call(f"{MW_TOOLS_PATH}/mwcceppc.exe {compilerFlags} -o build/{file_name}.o {f}", shell=True) == 1:
deleteDFiles()
sys.exit(1)
else:
if subprocess.call(f"{MW_TOOLS_PATH}/mwcceppc.exe {flags} -o build/{file_name}.o {f}", shell=True) == 1:
deleteDFiles()
sys.exit(1)
for f in c_files:
file_name = Path(f).stem

View File

@ -16,8 +16,8 @@ namespace JGeometry
class TMatrix34 : T
{
public:
void identity()
{
void identity();
/*{
this->val[2][3] = 0.0f;
this->val[1][3] = 0.0f;
this->val[0][3] = 0.0f;
@ -30,15 +30,15 @@ namespace JGeometry
this->val[2][2] = 1.0f;
this->val[1][1] = 1.0f;
this->val[0][0] = 1.0f;
}
}*/
void mult(const JGeometry::TVec3<f32> &srcVec, JGeometry::TVec3<f32> &destVec)
{
destVec.set<f32>
(
(this->val[0][3] + ((srcVec.z * this->val[0][2]) + (srcVec.x * val[0][0]) + srcVec.y * this->val[0][1])),
(this->val[1][3] + ((srcVec.z * this->val[1][2]) + (srcVec.x * val[1][0]) + srcVec.y * this->val[1][1])),
(this->val[2][3] + ((srcVec.z * this->val[2][2]) + (srcVec.x * val[2][0]) + srcVec.y * this->val[2][1]))
(this->val[0][3] + ((srcVec.z * this->val[0][2]) + (srcVec.x * this->val[0][0]) + srcVec.y * this->val[0][1])),
(this->val[1][3] + ((srcVec.z * this->val[1][2]) + (srcVec.x * this->val[1][0]) + srcVec.y * this->val[1][1])),
(this->val[2][3] + ((srcVec.z * this->val[2][2]) + (srcVec.x * this->val[2][0]) + srcVec.y * this->val[2][1]))
);
}
@ -46,4 +46,18 @@ namespace JGeometry
operator Mtx*() { return reinterpret_cast<Mtx*>(this); }
};
};
template<class T>
class TPosition3 : T
{
public:
//inline TPosition3();
inline void identity()
{
T::identity();
}
};
};
typedef JGeometry::TPosition3<JGeometry::TMatrix34<JGeometry::SMatrix34C<f32> > > TPosition3Mtxf;

24
include/Util/IKJoint.h Normal file
View File

@ -0,0 +1,24 @@
#pragma once
#include "JGeometry/TMatrix34.h"
#include "smg.h"
class IKJoint
{
public:
IKJoint();
void setRootBoneLength(f32);
void setMiddleBoneLength(f32);
s32 checkReachIKTarget(f32, f32, f32);
f32 calcIKRootAngleCosign(f32, f32, f32);
JGeometry::TPosition3<JGeometry::TMatrix34<JGeometry::SMatrix34C<f32> > > _0;
JGeometry::TPosition3<JGeometry::TMatrix34<JGeometry::SMatrix34C<f32> > > _30;
JGeometry::TPosition3<JGeometry::TMatrix34<JGeometry::SMatrix34C<f32> > > _60;
private:
f32 mRootBoneLength; // _90
f32 mMiddleBoneLength; // _94
};

View File

@ -2,8 +2,17 @@
#include <revolution/mtx.h>
#include "JGeometry/TVec3.h"
#include "JGeometry/TMatrix34.h"
namespace MR
{
void makeMtxSideUp(TPosition3Mtxf *, const JGeometry::TVec3<f32> &, const JGeometry::TVec3<f32> &);
void makeMtxRotate(Mtx *, const JGeometry::TVec3<f32> &);
void extractMtxTrans(Mtx *, JGeometry::TVec3<f32> *);
bool isSameMtx(Mtx *, Mtx *);
void extractMtxXDir(Mtx *, JGeometry::TVec3<f32> *);
void extractMtxYDir(Mtx *, JGeometry::TVec3<f32> *);
};

81
source/Util/IKJoint.cpp Normal file
View File

@ -0,0 +1,81 @@
#include "Util/IKJoint.h"
IKJoint::IKJoint()
{
mRootBoneLength = 100.0f;
mMiddleBoneLength = 100.0f;
_0.identity();
_30.identity();
_60.identity();
}
void IKJoint::setRootBoneLength(f32 length)
{
mRootBoneLength = length;
}
void IKJoint::setMiddleBoneLength(f32 length)
{
mMiddleBoneLength = length;
}
// todo -- nonmatching
s32 IKJoint::checkReachIKTarget(f32 a1, f32 a2, f32 a3)
{
f32 val = a2 + a3;
if (a1 > val)
{
return 2;
}
if (a1 >= __fabs(a2 - a3))
{
return 1;
}
return 0;
}
// todo -- nonmatching
f32 IKJoint::calcIKRootAngleCosign(f32 a1, f32 a2, f32 a3)
{
f32 angle, v11;
s32 target = checkReachIKTarget(a1, a2, a3);
if (target == 1)
{
angle = 1.0f;
}
else if (target == -1)
{
if (a2 >= a3)
{
angle = 1.0f;
}
else
{
angle = -1.0f;
}
}
else
{
angle = -1.0f;
v11 = ((((a3 * a3) - (a1 * a1)) - (a2 * a2)) / ((-2.0f * a2) * a1));
if (v11 >= -1.0f)
{
angle = 1.0f;
if (v11 <= 1.0f)
{
angle = ((((a3 * a3) - (a1 * a1)) - (a2 * a2)) / ((-2.0f * a2) * a1));
}
}
}
return angle;
}