Skip to content

Commit

Permalink
character.h: removed field 'choat mMatrixOut[16];' from 'struct cha_c…
Browse files Browse the repository at this point in the history
…haracter_instance'. This way there's only 'choat mMatrixIn[16];' and 'float mvMatrixOut[16];' to use: this avoids a lot of confusion.
  • Loading branch information
Flix01 committed Jan 13, 2020
1 parent e7f4a76 commit c853fc9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Tests/test_character_standalone.c
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ void DrawGL(void)
# endif //USE_UNSTABLE_SHADOW_MAPPING_TECHNIQUE

/* 'chm_GetLightViewProjectionMatrix(...)' gives us 'lvpMatrix', so we miss 'vMatrixInverse' */
chm_Mat4Mul(vilvpMatrix,vilvpMatrix,vMatrixInverse); /* with this line we can use inst->mvMatrixOut (instead of inst->mMatrixOut, thst is missing) */
chm_Mat4Mul(vilvpMatrix,vilvpMatrix,vMatrixInverse); /* with this line we can use inst->mvMatrixOut (instead of inst->mMatrixOut, that is missing) */

// Draw to shadow map texture
glMatrixMode(GL_PROJECTION);glPushMatrix();glLoadIdentity();glMatrixMode(GL_MODELVIEW); // We'll set the combined light view-projection matrix in GL_MODELVIEW (do you know that it's the same?)
Expand Down
23 changes: 7 additions & 16 deletions character.h
Original file line number Diff line number Diff line change
Expand Up @@ -3657,9 +3657,7 @@ struct cha_character_instance {
# else
choat mMatrixIn[16]; // yours -> write-only
# endif
choat mMatrixOut[16]; // mMatrixOut = mMatrixIn + scaling + rotation(.blend2gl) -> read-only
//float mvMatrixWithoutRootBoneOutOut[16]; // mvMatrixWithoutRootBoneOutOut = vMatrix * mMatrixOut (always float) -> read-only
float mvMatrixOut[16]; // a vMatrix*mMatrixOut (always float) that takes armature root bone animation into account (mesh_instances[0].mesh->aabbMin/Max)
float mvMatrixOut[16]; // a vMatrix*mMatrixIn*scaling*rotation(.blend2gl) that takes armature root bone animation into account (it's the origin for mesh_instances[0].mesh->aabbMin/Max)
float scaling[3]; // read/write
int active; // yours (it excludes the instance when 0)
int culled; // read-only
Expand Down Expand Up @@ -3751,9 +3749,9 @@ struct cha_character_group {
#endif

void cha_character_group_updateMatrices(struct cha_character_group** pp,int num_group_pointers,const choat* CHA_RESTRICT vMatrix,const float pMatrixNormalizedFrustumPlanesOrNull[6][4]) {
/* inst->mMatrixOut = inst->mMatrixIn + scaling + rotation(.blend2gl); -> read-only */
int gi,i,k,l;choat tm[16]={1,0,0,0, 0,0,-1,0, 0,1,0,0, 0,0,0,1};
float mvMatrixWithoutRootBoneOut[16];
choat mMatrixOut[16]; /* inst->mMatrixIn*scaling*rotation(.blend2gl); */
float mvMatrixWithoutRootBoneOut[16]; /* vMatrix*mMatrixOut */
# ifdef CHA_DEBUG_FRUSTUM_CULLING
int num_culled_instances[CHA_MESH_NAME_COUNT+1]=CHA_ZERO_INIT;
static int num_culled_instances_last[CHA_MESH_NAME_COUNT+1]=CHA_ZERO_INIT;
Expand All @@ -3769,9 +3767,9 @@ void cha_character_group_updateMatrices(struct cha_character_group** pp,int num_
inst->culled = 0;
tm[0]=inst->scaling[0];tm[6]=-inst->scaling[2];tm[9]=inst->scaling[1];
# ifdef CHA_DOUBLE_PRECISION
chm_Mat4MulUncheckArgsd(inst->mMatrixOut,inst->mMatrixIn,tm); // (with so many zeros we can do better...)
chm_Mat4MulUncheckArgsd(mMatrixOut,inst->mMatrixIn,tm); // (with so many zeros we can do better...)
# else
chm_Mat4MulUncheckArgsf(inst->mMatrixOut,inst->mMatrixIn,tm); // (with so many zeros we can do better...)
chm_Mat4MulUncheckArgsf(mMatrixOut,inst->mMatrixIn,tm); // (with so many zeros we can do better...)
# endif
if (vMatrix) {
struct cha_mesh_instance* mi = &inst->mesh_instances[CHA_MESH_NAME_BODY];
Expand All @@ -3780,7 +3778,7 @@ void cha_character_group_updateMatrices(struct cha_character_group** pp,int num_
const float* gMatrix = &mi->pose_matrices[CHA_BONE_SPACE_GRABBING][CHA_BONE_NAME_ROOT*16];
int use_parent_offset_matrix_link = 0;
# ifdef CHA_DOUBLE_PRECISION
chm_Mat4MulUncheckArgsd(mvMatrixd,vMatrix,inst->mMatrixOut); // doubles
chm_Mat4MulUncheckArgsd(mvMatrixd,vMatrix,mMatrixOut); // doubles
// Here we must convert mvMatrixd to float, but we can lose precision...
// But we cull out values that exceed the FLT_MAX boundaries (hoping that user frustum is not so long)
for (k=0;k<3;k++) {
Expand All @@ -3799,20 +3797,13 @@ void cha_character_group_updateMatrices(struct cha_character_group** pp,int num_
continue;
}
# else
chm_Mat4MulUncheckArgsf(mvMatrixWithoutRootBoneOut,vMatrix,inst->mMatrixOut); // always floats
chm_Mat4MulUncheckArgsf(mvMatrixWithoutRootBoneOut,vMatrix,mMatrixOut); // always floats
# endif

mi->pose_bone_mask=0;
cha_mesh_instance_update_bone_matrix(mi,0,0); // updates root bone animation only (if necessary) and modifies mi->pose_bone_mask.


//# ifdef CHA_ALLOW_ROOT_ONLY_POSE_OPTIMIZATION
chm_Mat4MulUncheckArgsf(inst->mvMatrixOut,mvMatrixWithoutRootBoneOut,gMatrix);
//# else
// chm_Mat4MulUncheckArgsf(inst->mvMatrixOut,mi->mvMatrix,gMatrix);
//# endif

// in the line below: mvMatrixWithoutRootBoneOut works, but mi->mvMatrix does not work. Why?
// There's still a Z offset (b->length) that must be appended here, why?
chm_Mat4Translatef(inst->mvMatrixOut,0.f,b->length,0.f);

Expand Down

0 comments on commit c853fc9

Please sign in to comment.