mirror of
https://git.coom.tech/drummyfish/small3dlib.git
synced 2024-11-23 20:59:58 +01:00
Continue city physics
This commit is contained in:
parent
504c664b82
commit
028de5c11a
1 changed files with 30 additions and 9 deletions
|
@ -238,29 +238,40 @@ int main()
|
||||||
|
|
||||||
int16_t step = velocity * frameDiff;
|
int16_t step = velocity * frameDiff;
|
||||||
int16_t stepFriction = 300 * frameDiff;
|
int16_t stepFriction = 300 * frameDiff;
|
||||||
int16_t stepRotation = 200 * frameDiff * velocity / ((float) MAX_VELOCITY);
|
int16_t stepRotation = 200 * frameDiff * S3L_abs(velocity) / ((float) MAX_VELOCITY);
|
||||||
int16_t stepVelocity = S3L_nonZero(1000 * frameDiff);
|
int16_t stepVelocity = S3L_nonZero(1000 * frameDiff);
|
||||||
|
|
||||||
|
if (stepRotation == 0 && S3L_abs(velocity) >= 200)
|
||||||
|
stepRotation = 1;
|
||||||
|
|
||||||
|
if (velocity < 0)
|
||||||
|
stepRotation *= -1;
|
||||||
|
|
||||||
if (state[SDL_SCANCODE_LEFT])
|
if (state[SDL_SCANCODE_LEFT])
|
||||||
|
{
|
||||||
models[1].transform.rotation.y += stepRotation;
|
models[1].transform.rotation.y += stepRotation;
|
||||||
|
models[1].transform.rotation.z = S3L_min(velocity / 64, models[1].transform.rotation.z + stepRotation);
|
||||||
|
}
|
||||||
else if (state[SDL_SCANCODE_RIGHT])
|
else if (state[SDL_SCANCODE_RIGHT])
|
||||||
|
{
|
||||||
models[1].transform.rotation.y -= stepRotation;
|
models[1].transform.rotation.y -= stepRotation;
|
||||||
|
models[1].transform.rotation.z = S3L_max(-velocity / 64, models[1].transform.rotation.z - stepRotation);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
models[1].transform.rotation.z = (models[1].transform.rotation.z * 3) / 4;
|
||||||
|
|
||||||
S3L_rotationToDirections(models[1].transform.rotation,S3L_FRACTIONS_PER_UNIT,&carDirection,0,0);
|
S3L_rotationToDirections(models[1].transform.rotation,S3L_FRACTIONS_PER_UNIT,&carDirection,0,0);
|
||||||
|
|
||||||
S3L_Vec4 previousPos = models[1].transform.translation;
|
S3L_Vec4 previousPos = models[1].transform.translation;
|
||||||
|
|
||||||
|
int16_t friction = 0;
|
||||||
|
|
||||||
if (state[SDL_SCANCODE_UP])
|
if (state[SDL_SCANCODE_UP])
|
||||||
velocity = S3L_min(MAX_VELOCITY,velocity + stepVelocity);
|
velocity = S3L_min(MAX_VELOCITY,velocity + (velocity < 0 ? (2 * stepVelocity) : stepVelocity));
|
||||||
else if (state[SDL_SCANCODE_DOWN])
|
else if (state[SDL_SCANCODE_DOWN])
|
||||||
velocity = S3L_max(-MAX_VELOCITY,velocity - stepVelocity);
|
velocity = S3L_max(-MAX_VELOCITY,velocity - (velocity > 0 ? (2 * stepVelocity) : stepVelocity));
|
||||||
else
|
else
|
||||||
{
|
friction = 1;
|
||||||
if (velocity > 0)
|
|
||||||
velocity = S3L_max(0,velocity - stepFriction);
|
|
||||||
else
|
|
||||||
velocity = S3L_min(0,velocity + stepFriction);
|
|
||||||
}
|
|
||||||
|
|
||||||
models[1].transform.translation.x += (carDirection.x * step) / S3L_FRACTIONS_PER_UNIT;
|
models[1].transform.translation.x += (carDirection.x * step) / S3L_FRACTIONS_PER_UNIT;
|
||||||
models[1].transform.translation.z += (carDirection.z * step) / S3L_FRACTIONS_PER_UNIT;
|
models[1].transform.translation.z += (carDirection.z * step) / S3L_FRACTIONS_PER_UNIT;
|
||||||
|
@ -273,6 +284,8 @@ int main()
|
||||||
{
|
{
|
||||||
S3L_Vec4 newPos = models[1].transform.translation;
|
S3L_Vec4 newPos = models[1].transform.translation;
|
||||||
newPos.x = previousPos.x;
|
newPos.x = previousPos.x;
|
||||||
|
|
||||||
|
friction = 8;
|
||||||
|
|
||||||
if (collision(newPos))
|
if (collision(newPos))
|
||||||
{
|
{
|
||||||
|
@ -280,7 +293,10 @@ int main()
|
||||||
newPos.z = previousPos.z;
|
newPos.z = previousPos.z;
|
||||||
|
|
||||||
if (collision(newPos))
|
if (collision(newPos))
|
||||||
|
{
|
||||||
newPos = previousPos;
|
newPos = previousPos;
|
||||||
|
velocity = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
models[1].transform.translation = newPos;
|
models[1].transform.translation = newPos;
|
||||||
|
@ -297,6 +313,11 @@ int main()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (velocity > 0)
|
||||||
|
velocity = S3L_max(0,velocity - stepFriction * friction);
|
||||||
|
else
|
||||||
|
velocity = S3L_min(0,velocity + stepFriction * friction);
|
||||||
|
|
||||||
scene.camera.transform.translation.x =
|
scene.camera.transform.translation.x =
|
||||||
scene.models[1].transform.translation.x - carDirection.x;
|
scene.models[1].transform.translation.x - carDirection.x;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue