projects
/
carveJwlIkooP6JGAAIwe30JlM.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
more physics shapes
[carveJwlIkooP6JGAAIwe30JlM.git]
/
character.h
diff --git
a/character.h
b/character.h
index c565fc436170fa7d20f5508a62daed0f48eb2f0f..3421d3a4df9117a648f5446182cf08811c3fa73a 100644
(file)
--- a/
character.h
+++ b/
character.h
@@
-63,7
+63,8
@@
struct character
{
glmesh mesh;
{
glmesh mesh;
- submodel parts[ PART_COUNT ];
+ mdl_submesh parts[ PART_COUNT ];
+ v3f origins[ PART_COUNT ];
m4x3f matrices[ PART_COUNT ];
/* Auxillary information */
m4x3f matrices[ PART_COUNT ];
/* Auxillary information */
@@
-96,7
+97,7
@@
struct character
static void character_offset( struct character *ch, enum character_part parent,
enum character_part child )
{
static void character_offset( struct character *ch, enum character_part parent,
enum character_part child )
{
- v3_sub( ch->
parts[ child ].pivot, ch->parts[ parent ].pivot
,
+ v3_sub( ch->
origins[ child ], ch->origins[ parent ]
,
ch->offsets[ child ] );
}
ch->offsets[ child ] );
}
@@
-105,35
+106,44
@@
static int character_load( struct character *ch, const char *name )
char buf[64];
snprintf( buf, sizeof(buf)-1, "models/%s.mdl", name );
char buf[64];
snprintf( buf, sizeof(buf)-1, "models/%s.mdl", name );
- m
odel *src = vg_asset_re
ad( buf );
+ m
dl_header *src = mdl_lo
ad( buf );
if( !src )
if( !src )
- {
- vg_error( "Could not open 'models/%s.mdl'", name );
return 0;
return 0;
- }
int error_count = 0;
for( int i=0; i<PART_COUNT; i++ )
{
snprintf( buf, sizeof(buf)-1, "%s_%s", name, character_part_strings[i] );
int error_count = 0;
for( int i=0; i<PART_COUNT; i++ )
{
snprintf( buf, sizeof(buf)-1, "%s_%s", name, character_part_strings[i] );
-
submodel *sm = submodel_get
( src, buf );
+
mdl_node *pnode = mdl_node_from_name
( src, buf );
- if( !sm )
+ memset( &ch->parts[i], 0, sizeof(mdl_submesh) );
+ v3_zero( ch->origins[i] );
+
+ if( !pnode )
{
vg_warn( "Character file does not contain an '_%s' part.\n",
character_part_strings[i] );
error_count ++;
{
vg_warn( "Character file does not contain an '_%s' part.\n",
character_part_strings[i] );
error_count ++;
-
- memset( &ch->parts[i], 0, sizeof(submodel) );
+ continue;
+ }
+
+ mdl_submesh *sm = mdl_node_submesh( src, pnode, 0 );
+
+ if( !sm )
+ {
+ vg_warn( "Character file's '_%s' part has no mesh.\n",
+ character_part_strings[i] );
+ error_count ++;
continue;
}
ch->parts[i] = *sm;
continue;
}
ch->parts[i] = *sm;
+ v3_copy( pnode->co, ch->origins[i] );
}
}
- m
odel_unpack
( src, &ch->mesh );
+ m
dl_unpack_glmesh
( src, &ch->mesh );
if( !error_count )
vg_success( "Loaded character file '%s' with no errors\n", name );
if( !error_count )
vg_success( "Loaded character file '%s' with no errors\n", name );
@@
-431,11
+441,14
@@
void character_final_pose( struct character *ch, v3f cog,
tilt = vg_clampf(cog[2], -1.0f, 1.0f) * 0.3f;
v4f rz; m4x3f tr;
tilt = vg_clampf(cog[2], -1.0f, 1.0f) * 0.3f;
v4f rz; m4x3f tr;
- q_axis_angle( rz, (v3f){0.0f,0.0f,1.0f}, -cog[0]*0.
6
f );
+ q_axis_angle( rz, (v3f){0.0f,0.0f,1.0f}, -cog[0]*0.
3
f );
q_m3x3( rz, tr );
q_m3x3( rz, tr );
- v3_copy( (v3f){0.0f,dip,tilt}, tr[3] );
+ m3x3_identity( tr );
+ //v3_copy( (v3f){0.0f,dip,tilt}, tr[3] );
+ v3_copy( cog, tr[3] );
- m4x3_mulv( tr, pose->b0, npose.b0 );
+ v3_muladd( pose->b0, tr[3], (v3f){0.85f,1.0f,1.0f}, npose.b0 );
+ //m4x3_mulv( tr, pose->b0, npose.b0 );
m4x3_mulv( tr, pose->b1, npose.b1 );
m4x3_mulv( tr, pose->p, npose.p );
m4x3_mulv( tr, pose->pl, npose.pl );
m4x3_mulv( tr, pose->b1, npose.b1 );
m4x3_mulv( tr, pose->p, npose.p );
m4x3_mulv( tr, pose->pl, npose.pl );
@@
-489,7
+502,7
@@
static void character_testpose( struct character *ch, float t )
*pole = ch->ik_body.pole;
hips[0] = cosf(t*1.325f)*0.25f;
*pole = ch->ik_body.pole;
hips[0] = cosf(t*1.325f)*0.25f;
- hips[1] = (sinf(t)*0.2f+0.6f) * ch->
parts[ k_chpart_body0 ].pivot
[1];
+ hips[1] = (sinf(t)*0.2f+0.6f) * ch->
origins[ k_chpart_body0 ]
[1];
hips[2] = 0.0f;
collar[0] = hips[0];
hips[2] = 0.0f;
collar[0] = hips[0];
@@
-543,8
+556,7
@@
static void character_testpose( struct character *ch, float t )
m4x3_identity( ch->matrices[k_chpart_wf] );
}
m4x3_identity( ch->matrices[k_chpart_wf] );
}
-static float *player_cam_pos(void);
-static void character_draw( struct character *ch, float temp )
+static void character_draw( struct character *ch, float temp, m4x3f camera )
{
shader_character_use();
shader_character_uPv( vg_pv );
{
shader_character_use();
shader_character_uPv( vg_pv );
@@
-552,7
+564,7
@@
static void character_draw( struct character *ch, float temp )
vg_tex2d_bind( &tex_pallet, 0 );
shader_character_uTexMain( 0 );
shader_character_uOpacity( temp );
vg_tex2d_bind( &tex_pallet, 0 );
shader_character_uTexMain( 0 );
shader_character_uOpacity( temp );
- shader_character_uCamera(
player_cam_pos()
);
+ shader_character_uCamera(
camera[3]
);
shader_link_standard_ub( _shader_character.id, 2 );
glEnable( GL_CULL_FACE );
shader_link_standard_ub( _shader_character.id, 2 );
glEnable( GL_CULL_FACE );
@@
-568,7
+580,7
@@
static void character_draw( struct character *ch, float temp )
#endif
shader_character_uMdl( ch->matrices[i] );
#endif
shader_character_uMdl( ch->matrices[i] );
-
submodel_draw
( &ch->parts[i] );
+
mdl_draw_submesh
( &ch->parts[i] );
}
for( int i=0; i<2; i++ )
}
for( int i=0; i<2; i++ )
@@
-576,14
+588,14
@@
static void character_draw( struct character *ch, float temp )
if( ch->shoes[i] )
{
shader_character_uMdl( ch->matrices[i] );
if( ch->shoes[i] )
{
shader_character_uMdl( ch->matrices[i] );
-
submodel_draw
( &ch->parts[i] );
+
mdl_draw_submesh
( &ch->parts[i] );
}
else
{
shader_character_uMdl( ch->matrices[i+2] );
}
else
{
shader_character_uMdl( ch->matrices[i+2] );
-
submodel_draw
( &ch->parts[i] );
+
mdl_draw_submesh
( &ch->parts[i] );
shader_character_uMdl( ch->matrices[i] );
shader_character_uMdl( ch->matrices[i] );
-
submodel_draw
( &ch->parts[i+2] );
+
mdl_draw_submesh
( &ch->parts[i+2] );
}
}
}
}
}
}
@@
-676,14
+688,14
@@
static void character_init_ragdoll_joints( struct character *ch )
{
struct rd_joint *joint = &rd_joints[i];
{
struct rd_joint *joint = &rd_joints[i];
- float *hinge = ch->
parts[joint->ib].pivot
;
+ float *hinge = ch->
origins[joint->ib]
;
v3_sub( hinge, ch->ragdoll[joint->ia].co, joint->lca );
v3_sub( hinge, ch->ragdoll[joint->ib].co, joint->lcb );
}
for( int i=0; i<PART_COUNT; i++ )
{
v3_sub( hinge, ch->ragdoll[joint->ia].co, joint->lca );
v3_sub( hinge, ch->ragdoll[joint->ib].co, joint->lcb );
}
for( int i=0; i<PART_COUNT; i++ )
{
- float *pivot = ch->
parts[i].pivot
;
+ float *pivot = ch->
origins[i]
;
v3_sub( ch->ragdoll[i].co, pivot, ch->ragdoll[i].delta );
}
}
v3_sub( ch->ragdoll[i].co, pivot, ch->ragdoll[i].delta );
}
}
@@
-700,27
+712,27
@@
static void character_init_ragdoll( struct character *ch )
v3f chest_dims = { chest_depth, chest_height, chest_width };
character_rd_box( ch, k_chpart_body1, chest_dims );
v3f chest_dims = { chest_depth, chest_height, chest_width };
character_rd_box( ch, k_chpart_body1, chest_dims );
- v3_copy( ch->
parts[k_chpart_body1].pivot
, rbs[k_chpart_body1].co );
+ v3_copy( ch->
origins[k_chpart_body1]
, rbs[k_chpart_body1].co );
rbs[k_chpart_body1].co[1] += chest_height*0.5f;
/* Torso */
v3f torso_dims = { chest_depth,
offs[k_chpart_body1][1]-offs[k_chpart_leg_l0][1],
chest_width*0.85f };
rbs[k_chpart_body1].co[1] += chest_height*0.5f;
/* Torso */
v3f torso_dims = { chest_depth,
offs[k_chpart_body1][1]-offs[k_chpart_leg_l0][1],
chest_width*0.85f };
- v3_copy( ch->
parts[k_chpart_body0].pivot
, rbs[k_chpart_body0].co );
+ v3_copy( ch->
origins[k_chpart_body0]
, rbs[k_chpart_body0].co );
character_rd_box( ch, k_chpart_body0, torso_dims );
/* Neck */
v3f neck_dims = { chest_depth*0.5f,
offs[k_chpart_head][1],
chest_depth*0.5f };
character_rd_box( ch, k_chpart_body0, torso_dims );
/* Neck */
v3f neck_dims = { chest_depth*0.5f,
offs[k_chpart_head][1],
chest_depth*0.5f };
- v3_copy( ch->
parts[k_chpart_neck].pivot
, rbs[k_chpart_neck].co );
+ v3_copy( ch->
origins[k_chpart_neck]
, rbs[k_chpart_neck].co );
rbs[k_chpart_neck].co[1] += neck_dims[1]*0.5f;
character_rd_box( ch, k_chpart_neck, neck_dims );
/* Head */
v3f head_dims = { chest_width*0.5f, chest_width*0.5f, chest_width*0.5f };
rbs[k_chpart_neck].co[1] += neck_dims[1]*0.5f;
character_rd_box( ch, k_chpart_neck, neck_dims );
/* Head */
v3f head_dims = { chest_width*0.5f, chest_width*0.5f, chest_width*0.5f };
- v3_copy( ch->
parts[k_chpart_head].pivot
, rbs[k_chpart_head].co );
+ v3_copy( ch->
origins[k_chpart_head]
, rbs[k_chpart_head].co );
rbs[k_chpart_head].co[1] += head_dims[1]*0.5f;
character_rd_box( ch, k_chpart_head, head_dims );
rbs[k_chpart_head].co[1] += head_dims[1]*0.5f;
character_rd_box( ch, k_chpart_head, head_dims );
@@
-738,18
+750,18
@@
static void character_init_ragdoll( struct character *ch )
character_rd_box( ch, k_chpart_hand_l, hand_dims );
character_rd_box( ch, k_chpart_hand_r, hand_dims );
character_rd_box( ch, k_chpart_hand_l, hand_dims );
character_rd_box( ch, k_chpart_hand_r, hand_dims );
- v3_copy( ch->
parts[k_chpart_arm_l0].pivot
, rbs[k_chpart_arm_l0].co );
+ v3_copy( ch->
origins[k_chpart_arm_l0]
, rbs[k_chpart_arm_l0].co );
rbs[k_chpart_arm_l0].co[2] += ua_dims[2] * 0.5f;
rbs[k_chpart_arm_l0].co[2] += ua_dims[2] * 0.5f;
- v3_copy( ch->
parts[k_chpart_arm_l1].pivot
, rbs[k_chpart_arm_l1].co );
+ v3_copy( ch->
origins[k_chpart_arm_l1]
, rbs[k_chpart_arm_l1].co );
rbs[k_chpart_arm_l1].co[2] += la_dims[2] * 0.5f;
rbs[k_chpart_arm_l1].co[2] += la_dims[2] * 0.5f;
- v3_copy( ch->
parts[k_chpart_hand_l].pivot
, rbs[k_chpart_hand_l].co );
+ v3_copy( ch->
origins[k_chpart_hand_l]
, rbs[k_chpart_hand_l].co );
rbs[k_chpart_hand_l].co[2] += hand_dims[2] * 0.5f;
rbs[k_chpart_hand_l].co[2] += hand_dims[2] * 0.5f;
- v3_copy( ch->
parts[k_chpart_arm_r0].pivot
, rbs[k_chpart_arm_r0].co );
+ v3_copy( ch->
origins[k_chpart_arm_r0]
, rbs[k_chpart_arm_r0].co );
rbs[k_chpart_arm_r0].co[2] -= ua_dims[2] * 0.5f;
rbs[k_chpart_arm_r0].co[2] -= ua_dims[2] * 0.5f;
- v3_copy( ch->
parts[k_chpart_arm_r1].pivot
, rbs[k_chpart_arm_r1].co );
+ v3_copy( ch->
origins[k_chpart_arm_r1]
, rbs[k_chpart_arm_r1].co );
rbs[k_chpart_arm_r1].co[2] -= la_dims[2] * 0.5f;
rbs[k_chpart_arm_r1].co[2] -= la_dims[2] * 0.5f;
- v3_copy( ch->
parts[k_chpart_hand_r].pivot
, rbs[k_chpart_hand_r].co );
+ v3_copy( ch->
origins[k_chpart_hand_r]
, rbs[k_chpart_hand_r].co );
rbs[k_chpart_hand_r].co[2] -= hand_dims[2] * 0.5f;
/* LEgs */
rbs[k_chpart_hand_r].co[2] -= hand_dims[2] * 0.5f;
/* LEgs */
@@
-766,19
+778,19
@@
static void character_init_ragdoll( struct character *ch )
character_rd_box( ch, k_chpart_foot_l, foot_dims );
character_rd_box( ch, k_chpart_foot_r, foot_dims );
character_rd_box( ch, k_chpart_foot_l, foot_dims );
character_rd_box( ch, k_chpart_foot_r, foot_dims );
- v3_copy( ch->
parts[k_chpart_leg_l0].pivot
, rbs[k_chpart_leg_l0].co );
+ v3_copy( ch->
origins[k_chpart_leg_l0]
, rbs[k_chpart_leg_l0].co );
rbs[k_chpart_leg_l0].co[1] -= ul_dims[1] * 0.5f;
rbs[k_chpart_leg_l0].co[1] -= ul_dims[1] * 0.5f;
- v3_copy( ch->
parts[k_chpart_leg_l1].pivot
, rbs[k_chpart_leg_l1].co );
+ v3_copy( ch->
origins[k_chpart_leg_l1]
, rbs[k_chpart_leg_l1].co );
rbs[k_chpart_leg_l1].co[1] -= ll_dims[1] * 0.5f;
rbs[k_chpart_leg_l1].co[1] -= ll_dims[1] * 0.5f;
- v3_copy( ch->
parts[k_chpart_foot_l].pivot
, rbs[k_chpart_foot_l].co );
+ v3_copy( ch->
origins[k_chpart_foot_l]
, rbs[k_chpart_foot_l].co );
rbs[k_chpart_foot_l].co[1] -= foot_dims[1] * 0.5f;
rbs[k_chpart_foot_l].co[0] -= foot_dims[0] * 0.5f;
rbs[k_chpart_foot_l].co[1] -= foot_dims[1] * 0.5f;
rbs[k_chpart_foot_l].co[0] -= foot_dims[0] * 0.5f;
- v3_copy( ch->
parts[k_chpart_leg_r0].pivot
, rbs[k_chpart_leg_r0].co );
+ v3_copy( ch->
origins[k_chpart_leg_r0]
, rbs[k_chpart_leg_r0].co );
rbs[k_chpart_leg_r0].co[1] -= ul_dims[1] * 0.5f;
rbs[k_chpart_leg_r0].co[1] -= ul_dims[1] * 0.5f;
- v3_copy( ch->
parts[k_chpart_leg_r1].pivot
, rbs[k_chpart_leg_r1].co );
+ v3_copy( ch->
origins[k_chpart_leg_r1]
, rbs[k_chpart_leg_r1].co );
rbs[k_chpart_leg_r1].co[1] -= ll_dims[1] * 0.5f;
rbs[k_chpart_leg_r1].co[1] -= ll_dims[1] * 0.5f;
- v3_copy( ch->
parts[k_chpart_foot_r].pivot
, rbs[k_chpart_foot_r].co );
+ v3_copy( ch->
origins[k_chpart_foot_r]
, rbs[k_chpart_foot_r].co );
rbs[k_chpart_foot_r].co[1] -= foot_dims[1] * 0.5f;
rbs[k_chpart_foot_r].co[0] -= foot_dims[0] * 0.5f;
rbs[k_chpart_foot_r].co[1] -= foot_dims[1] * 0.5f;
rbs[k_chpart_foot_r].co[0] -= foot_dims[0] * 0.5f;
@@
-812,8
+824,7
@@
static void character_ragdoll_copypose( struct character *ch, v3f v )
m4x3_mulv( ch->matrices[i], rb->delta, rb->co );
m3x3_q( ch->matrices[i], rb->q );
v3_copy( v, rb->v );
m4x3_mulv( ch->matrices[i], rb->delta, rb->co );
m3x3_q( ch->matrices[i], rb->q );
v3_copy( v, rb->v );
- v3_zero( rb->I );
- rb->manifold_count = 0; /* ? */
+ v3_zero( rb->w );
rb_update_transform( rb );
}
rb_update_transform( rb );
}
@@
-871,11
+882,14
@@
static void character_debug_ragdoll( struct character *ch )
static void character_ragdoll_iter( struct character *ch )
{
static void character_ragdoll_iter( struct character *ch )
{
+ rb_solver_reset();
+
for( int i=0; i<PART_COUNT; i++ )
{
for( int i=0; i<PART_COUNT; i++ )
{
- rb_manifold_reset( &ch->ragdoll[i] );
rb_build_manifold_terrain( &ch->ragdoll[i] );
rb_build_manifold_terrain( &ch->ragdoll[i] );
+ /* TODO: Cars, piece-to-piece collision */
+#if 0
u32 colliders[16];
int len = bh_select( &world.bhcubes, ch->ragdoll[i].bbx_world,
colliders, 16 );
u32 colliders[16];
int len = bh_select( &world.bhcubes, ch->ragdoll[i].bbx_world,
colliders, 16 );
@@
-883,22
+897,25
@@
static void character_ragdoll_iter( struct character *ch )
for( int j=0; j<len; j++ )
rb_build_manifold_rb_static( &ch->ragdoll[i],
&world.temp_rbs[colliders[j]] );
for( int j=0; j<len; j++ )
rb_build_manifold_rb_static( &ch->ragdoll[i],
&world.temp_rbs[colliders[j]] );
+#endif
}
}
+ rb_presolve_contacts( rb_contact_buffer, rb_contact_count );
+
v3f rv;
v3f rv;
- float shoe_vel[2];
+ float shoe_vel[2]
= {0.0f,0.0f}
;
for( int i=0; i<2; i++ )
if( ch->shoes[i] )
shoe_vel[i] = v3_length( ch->ragdoll[i].v );
for( int i=0; i<2; i++ )
if( ch->shoes[i] )
shoe_vel[i] = v3_length( ch->ragdoll[i].v );
-
- for( int i=0; i<20; i++ )
+
+ /* This used to be 20 iterations */
+ for( int i=0; i<5; i++ )
{
float const k_springfactor = 1.0f/20.0f;
{
float const k_springfactor = 1.0f/20.0f;
-
- for( int j=0; j<PART_COUNT; j++ )
- rb_constraint_manifold( &ch->ragdoll[j] );
-
+
+ rb_solve_contacts( rb_contact_buffer, rb_contact_count );
+
for( int j=0; j<vg_list_size(rd_joints); j++ )
{
struct rd_joint *joint = &rd_joints[j];
for( int j=0; j<vg_list_size(rd_joints); j++ )
{
struct rd_joint *joint = &rd_joints[j];
@@
-946,7
+963,7
@@
static void character_ragdoll_iter( struct character *ch )
v3_copy( src->co, dst->co );
v3_copy( src->v, dst->v );
v3_copy( src->q, dst->q );
v3_copy( src->co, dst->co );
v3_copy( src->v, dst->v );
v3_copy( src->q, dst->q );
- v3_copy( src->
I, dst->I
);
+ v3_copy( src->
w, dst->w
);
}
}
}
}
}
}