diff --git a/3dcam-cosTable-lerp-atantable-psqrt-nodpq-quads.c b/3dcam-cosTable-lerp-atantable-psqrt-nodpq-quads.c index c3c9c0d..30e153f 100644 --- a/3dcam-cosTable-lerp-atantable-psqrt-nodpq-quads.c +++ b/3dcam-cosTable-lerp-atantable-psqrt-nodpq-quads.c @@ -411,8 +411,6 @@ int main() { applyAcceleration(meshes[k]->body); - - //~ VECTOR col_lvl, col_sphere = {0}; // Get col with level ( modelgnd_body ) @@ -432,32 +430,66 @@ int main() { if ( col_lvl.vx ) { meshes[k]->body->gForce.vx *= -1; } - if ( col_lvl.vy ) { meshes[k]->body->gForce.vy *= -1; } + if ( col_lvl.vy ) { + //~ meshes[k]->body->gForce.vy *= -1; + + } if ( col_lvl.vz ) { meshes[k]->body->gForce.vz *= -1; } // If col, reset velocity - if ( col_lvl.vx || - col_lvl.vy || - col_lvl.vz - ) { - //~ meshes[k]->body->velocity.vy = meshes[k]->body->velocity.vx = meshes[k]->body->velocity.vz = 0; + //~ if ( col_lvl.vx || + //~ col_lvl.vy || + //~ col_lvl.vz + //~ ) { //~ meshes[k]->body->velocity.vy = meshes[k]->body->velocity.vz = 0; + //~ } + + ResolveCollision( &modelobject_body, &modelSphere_body); + //~ FntPrint("Vel: %d\n", modelSphere_body.velocity.vx); + if (col_sphere.vx){ + + int w = (ONE / (( modelSphere_body.velocity.vx * ONE ) / ( (modelSphere_body.max.vx - modelSphere_body.min.vx) / 2 ))) ; + + if (modelSphere_body.velocity.vx){ + + //~ int w = (ONE / (( modelSphere_body.velocity.vx * ONE ) / ( (modelSphere_body.max.vx - modelSphere_body.min.vx) / 2 ))) * modelSphere_body.velocity.vx ; + //~ FntPrint("W %d\n",w); + FntPrint("Vel %d\n",modelSphere_body.velocity.vx); + + modelSphere_rot.vz += w; + + //~ if ( col_sphere.vx ) { + //~ meshes[k]->body->gForce.vx *= -1; + //modelSphere_body.gForce.vx = -meshes[k]->body->gForce.vx/4; //~ ResolveCollision(&modelobject_body, &modelSphere_body); + //~ } + } } + if (!col_sphere.vx){ + modelSphere_body.velocity.vx = 0; + } + + //~ if (w && !modelSphere_body.velocity.vx) + //~ { + //~ FntPrint("W %d\n",w); + //~ w --; + //~ } - if ( col_sphere.vx ) { meshes[k]->body->gForce.vx *= -1; modelSphere_body.gForce.vx = -meshes[k]->body->gForce.vx/4; //~ ResolveCollision(&modelobject_body, &modelSphere_body); - } - if ( col_sphere.vz ) { meshes[k]->body->gForce.vz *= -1; } + + //~ if ( col_sphere.vz ) { meshes[k]->body->gForce.vz *= -1; } //~ if ( col_sphere.vy ) { meshes[k]->body->gForce.vy *= -1; } //~ if (modelSphere_body.gForce.vx){modelSphere_body.gForce.vx -= 5;} - meshes[k]->body->position.vx = meshes[k]->pos->vx; - meshes[k]->body->position.vy = meshes[k]->pos->vy; - meshes[k]->body->position.vz = meshes[k]->pos->vz; + meshes[k]->pos->vx = meshes[k]->body->position.vx; + //~ meshes[k]->pos->vy = meshes[k]->body->position.vy ; + meshes[k]->pos->vz = meshes[k]->body->position.vz; + } + meshes[k]->body->velocity.vy = meshes[k]->body->velocity.vx = meshes[k]->body->velocity.vz = 0; + } } } @@ -963,11 +995,11 @@ void applyAcceleration(BODY * actor){ short dt = 1; - VECTOR acceleration = {actor->gForce.vx / actor->mass, actor->gForce.vy / actor->mass, actor->gForce.vz / actor->mass}; + VECTOR acceleration = {actor->invMass * actor->gForce.vx , actor->invMass * actor->gForce.vy, actor->invMass * actor->gForce.vz}; - actor->velocity.vx += (acceleration.vx * dt); - actor->velocity.vy += (acceleration.vy * dt); - actor->velocity.vz += (acceleration.vz * dt); + actor->velocity.vx += (acceleration.vx * dt) / 4096; + actor->velocity.vy += (acceleration.vy * dt) / 4096; + actor->velocity.vz += (acceleration.vz * dt) / 4096; actor->position.vx += (actor->velocity.vx * dt); actor->position.vy += (actor->velocity.vy * dt); @@ -979,13 +1011,18 @@ void applyAcceleration(BODY * actor){ void ResolveCollision( BODY * one, BODY * two ){ // Calculate relative velocity - VECTOR rv = { subVector(two->velocity, one->velocity) }; + VECTOR rv = { subVector( one->velocity, two->velocity) }; //~ FntPrint("rv: %d, %d, %d\n", rv.vx,rv.vy,rv.vz); // Collision normal VECTOR normal = { subVector( two->position, one->position ) }; + // Normalize collision normal + normal.vx = normal.vx > 32 ? 1 : normal.vx < -32 ? -1 : 0 ; + normal.vy = normal.vy > 256 ? 1 : normal.vy < -256 ? -1 : 0 ; + normal.vz = normal.vz > 32 ? 1 : normal.vz < -32 ? -1 : 0 ; + //~ FntPrint("norm: %d, %d, %d\n", normal.vx,normal.vy,normal.vz); // Calculate relative velocity in terms of the normal direction @@ -1003,30 +1040,33 @@ void ResolveCollision( BODY * one, BODY * two ){ //~ FntPrint("e: %d\n", e); //~ // Calculate impulse scalar - long j = -(1 + e) * velAlongNormal; - long k = ONE / one->mass; - long l = ONE / two->mass; - j /= k + l; - j /= ONE; + long j = -(1 + e) * velAlongNormal * ONE; + j /= one->invMass + two->invMass; + //~ j /= ONE; //~ FntPrint("j: %d\n", j); // Apply impulse applyVector(&normal, j, j, j, *=); + //~ FntPrint("Cnormal %d %d %d\n",normal.vx,normal.vy,normal.vz); + VECTOR velOne = normal; VECTOR velTwo = normal; - FntPrint("vel1: %d, %d, %d\n", velOne.vx,velOne.vy,velOne.vz); - FntPrint("vel2: %d, %d, %d\n", velTwo.vx,velTwo.vy,velTwo.vz); + applyVector(&velOne,one->invMass,one->invMass,one->invMass, *=); + applyVector(&velTwo,two->invMass,two->invMass,two->invMass, *=); - applyVector(&velOne,k/ONE,k/ONE,k/ONE, *=); - applyVector(&velTwo,l/ONE,l/ONE,l/ONE, *=); + //~ FntPrint("V1 %d %d %d\n", velOne.vx/4096/4096,velOne.vy/4096/4096,velOne.vz/4096/4096); + //~ FntPrint("V2 %d %d %d\n", velTwo.vx/4096/4096,velTwo.vy/4096/4096,velTwo.vz/4096/4096); - applyVector(&one->velocity, velOne.vx, velOne.vy, velOne.vz, -=); - applyVector(&two->velocity, velTwo.vx, velTwo.vy, velTwo.vz, +=); -} + applyVector(&one->velocity, velOne.vx/4096/4096, velOne.vy/4096/4096, velOne.vz/4096/4096, -=); + applyVector(&two->velocity, velTwo.vx/4096/4096, velTwo.vy/4096/4096, velTwo.vz/4096/4096, +=); + //~ FntPrint("V1 %d %d %d\n", velOne.vx/4096/4096,velOne.vy/4096/4096,velOne.vz/4096/4096); + //~ FntPrint("V2 %d %d %d\n", velTwo.vx/4096/4096,velTwo.vy/4096/4096,velTwo.vz/4096/4096); + +} // A few notes on the following code : diff --git a/coridor.c b/coridor.c index 1118861..5829af2 100644 --- a/coridor.c +++ b/coridor.c @@ -1,10 +1,11 @@ typedef struct { - VECTOR gForce; + VECTOR gForce; VECTOR position; SVECTOR velocity; - int mass; + int invMass; VECTOR min; VECTOR max; + int restitution; } BODY; typedef struct { @@ -42,8 +43,8 @@ typedef struct { } CAMPATH; CAMPOS camStartPos = { - {-62,176,-15}, - {537,459,0}, + {-177,90,121}, + {78,459,0}, }; CAMPATH camPath = { @@ -868,12 +869,13 @@ short modelCylindre_isPrism =0; short modelCylindre_isAnim =1; long modelCylindre_p = 0; BODY modelCylindre_body = { - {0, 981, 0, 0}, + {0, 981, 0, 0}, -53,-108,18, 0, 0,0,0, 0, - 1000, + ONE/1000, 13,-3,14, 0, 90,62,91, 0, + 4096, }; TMESH modelCylindre = { @@ -2103,12 +2105,13 @@ short modelgnd_isPrism =0; short modelgnd_isAnim =0; long modelgnd_p = 0; BODY modelgnd_body = { - {0, 981, 0, 0}, + {0, 981, 0, 0}, 0,0,0, 0, 0,0,0, 0, - 1000, + ONE/1000, -580,-195,-98, 0, 200,0,682, 0, + 4096, }; TMESH modelgnd = { @@ -2256,19 +2259,20 @@ int modelobject_index[] = { }; MATRIX modelobject_matrix = {0}; -VECTOR modelobject_pos = {-160,-141,58, 0}; +VECTOR modelobject_pos = {-200,-179,57, 0}; SVECTOR modelobject_rot = {0,0,0}; short modelobject_isRigidBody =1; short modelobject_isPrism =0; short modelobject_isAnim =0; long modelobject_p = 0; BODY modelobject_body = { - {0, 981, 100, 0}, - -160,-141,58, 0, + {100, 981, 0, 0}, + -200,-179,57, 0, 0,0,0, 0, - 50, + ONE/64, -20,1,-22, 0, 19,53,18, 0, + 2048 }; TMESH modelobject = { @@ -2301,102 +2305,102 @@ MESH meshobject = { }; SVECTOR modelSphere_mesh[] = { - {0,-50,42}, - {0,-30,58}, - {0,-6,65}, - {0,19,62}, - {15,13,63}, - {13,-50,40}, - {17,-26,58}, - {14,42,49}, - {23,53,32}, - {47,-6,46}, - {36,7,55}, - {38,-33,42}, - {49,-21,38}, - {48,21,39}, - {41,42,30}, - {32,-51,26}, - {30,-58,6}, - {55,-30,17}, - {63,-7,18}, - {61,13,20}, - {55,31,17}, - {12,-63,14}, - {39,52,5}, - {64,-15,-6}, - {58,31,-5}, - {24,60,5}, - {9,-64,-9}, - {50,-43,-8}, - {64,7,-13}, - {28,-58,-11}, - {46,42,-21}, - {40,-42,-31}, - {53,17,-35}, - {46,-26,-40}, - {37,31,-45}, - {22,55,-28}, - {0,65,0}, - {30,-6,-58}, - {23,18,-59}, - {15,-58,-27}, - {20,-43,-46}, - {17,-30,-56}, - {13,-7,-64}, - {23,47,-40}, - {13,63,-13}, - {0,-50,-41}, - {0,-31,-57}, - {0,-6,-65}, - {0,19,-62}, - {11,47,-46}, - {-17,-30,-56}, - {-13,-7,-64}, - {-17,36,-52}, - {-20,-43,-46}, - {-30,-6,-58}, - {-23,18,-59}, - {0,-65,11}, - {-15,-58,-27}, - {-40,-42,-31}, - {-37,31,-45}, - {-23,47,-40}, - {-46,-26,-40}, - {-54,-8,-37}, - {-53,17,-35}, - {-46,42,-21}, - {-22,55,-28}, - {-9,-64,-9}, - {-64,7,-13}, - {-28,-58,-11}, - {-64,-15,-6}, - {-58,31,-5}, - {-50,-43,-8}, - {-61,13,20}, - {-13,63,-13}, - {-55,-30,17}, - {-63,-7,18}, - {-55,31,17}, - {-39,52,5}, - {-30,-58,6}, - {-24,60,5}, - {-49,-21,38}, - {-48,21,39}, - {-41,42,30}, - {-32,-51,26}, - {-38,-33,42}, - {-47,-6,46}, - {-29,29,51}, - {-36,7,55}, - {-10,63,16}, - {-12,-63,14}, - {-13,-50,40}, - {-17,-26,58}, - {-15,13,63}, - {-14,42,49}, - {-23,53,32}, - {0,47,46} + {0,-19,15}, + {0,-11,21}, + {0,-2,24}, + {0,7,23}, + {6,5,23}, + {5,-19,15}, + {6,-10,22}, + {5,15,18}, + {8,20,12}, + {17,-2,17}, + {13,3,20}, + {14,-12,16}, + {18,-8,14}, + {18,8,14}, + {15,15,11}, + {12,-19,10}, + {11,-22,2}, + {20,-11,6}, + {23,-3,7}, + {23,5,7}, + {20,11,6}, + {4,-23,5}, + {15,19,2}, + {24,-5,-2}, + {21,11,-2}, + {9,22,2}, + {3,-24,-3}, + {18,-16,-3}, + {24,2,-5}, + {10,-21,-4}, + {17,16,-8}, + {15,-15,-12}, + {20,6,-13}, + {17,-10,-15}, + {14,11,-17}, + {8,21,-10}, + {0,24,0}, + {11,-2,-21}, + {8,7,-22}, + {5,-21,-10}, + {7,-16,-17}, + {6,-11,-21}, + {5,-3,-23}, + {8,17,-15}, + {5,23,-5}, + {0,-19,-15}, + {0,-12,-21}, + {0,-2,-24}, + {0,7,-23}, + {4,17,-17}, + {-6,-11,-21}, + {-5,-3,-23}, + {-6,13,-19}, + {-7,-16,-17}, + {-11,-2,-21}, + {-8,7,-22}, + {0,-24,4}, + {-5,-21,-10}, + {-15,-15,-12}, + {-14,11,-17}, + {-8,17,-15}, + {-17,-10,-15}, + {-20,-3,-14}, + {-20,6,-13}, + {-17,16,-8}, + {-8,21,-10}, + {-3,-24,-3}, + {-24,2,-5}, + {-10,-21,-4}, + {-24,-5,-2}, + {-21,11,-2}, + {-18,-16,-3}, + {-23,5,7}, + {-5,23,-5}, + {-20,-11,6}, + {-23,-3,7}, + {-20,11,6}, + {-15,19,2}, + {-11,-22,2}, + {-9,22,2}, + {-18,-8,14}, + {-18,8,14}, + {-15,15,11}, + {-12,-19,10}, + {-14,-12,16}, + {-17,-2,17}, + {-11,11,19}, + {-13,3,20}, + {-4,23,6}, + {-4,-23,5}, + {-5,-19,15}, + {-6,-10,22}, + {-6,5,23}, + {-5,15,18}, + {-8,20,12}, + {0,17,17} }; SVECTOR modelSphere_normal[] = { @@ -3824,19 +3828,20 @@ int modelSphere_index[] = { }; MATRIX modelSphere_matrix = {0}; -VECTOR modelSphere_pos = {-24,-41,238, 0}; +VECTOR modelSphere_pos = {-103,-22,54, 0}; SVECTOR modelSphere_rot = {0,0,0}; short modelSphere_isRigidBody =1; short modelSphere_isPrism =0; short modelSphere_isAnim =0; long modelSphere_p = 0; BODY modelSphere_body = { - {0, 981, 0, 0}, - -24,-41,238, 0, + {0, 981, 0, 0}, + -103,-22,54, 0, 0,0,0, 0, - 1000, - -64,-65,-65, 0, - 64,65,65, 0, + ONE/128, + -24,-24,-24, 0, + 24,24,24, 0, + 1024 }; TMESH modelSphere = {