further physics improvements
parent
f804db82b7
commit
083b89abd3
|
@ -42,8 +42,8 @@ ActSpawnCirclingDriver(void) {
|
||||||
*dest = *origin;
|
*dest = *origin;
|
||||||
|
|
||||||
Input *input = ecs_get_mut(world_ecs(), e, Input, NULL);
|
Input *input = ecs_get_mut(world_ecs(), e, Input, NULL);
|
||||||
|
zpl_zero_item(input);
|
||||||
input->x = input->y = 1.0f;
|
input->x = input->y = 1.0f;
|
||||||
input->use = false;
|
|
||||||
|
|
||||||
Vehicle *veh = ecs_get_mut(world_ecs(), ve, Vehicle, NULL);
|
Vehicle *veh = ecs_get_mut(world_ecs(), ve, Vehicle, NULL);
|
||||||
veh->seats[0] = e;
|
veh->seats[0] = e;
|
||||||
|
|
|
@ -147,13 +147,13 @@ void renderer_debug_draw_v0(void) {
|
||||||
float y = e->a.y;
|
float y = e->a.y;
|
||||||
float x2 = e->b.x;
|
float x2 = e->b.x;
|
||||||
float y2 = e->b.y;
|
float y2 = e->b.y;
|
||||||
DrawLine(x, y, x2, y2, color);
|
DrawLineV((Vector2){x, y}, (Vector2){x2, y2}, color);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case DDRAW_CIRCLE:{
|
case DDRAW_CIRCLE:{
|
||||||
float x = e->a.x;
|
float x = e->a.x;
|
||||||
float y = e->a.y;
|
float y = e->a.y;
|
||||||
DrawCircleLines(x, y, e->radius, color);
|
DrawCircleLinesEco(x, y, e->radius, color);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case DDRAW_RECT:{
|
case DDRAW_RECT:{
|
||||||
|
@ -161,7 +161,7 @@ void renderer_debug_draw_v0(void) {
|
||||||
float y = e->bmin.y;
|
float y = e->bmin.y;
|
||||||
float w = e->bmax.x - e->bmin.x;
|
float w = e->bmax.x - e->bmin.x;
|
||||||
float h = e->bmax.y - e->bmin.y;
|
float h = e->bmax.y - e->bmin.y;
|
||||||
DrawRectangleLines(x, y, w, h, color);
|
DrawRectangleLinesEco(x, y, w, h, color);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
|
|
|
@ -330,3 +330,39 @@ Color GenerateRandomColor(float s, float v) {
|
||||||
h = fmodf((h + h*Phi), 360.0f);
|
h = fmodf((h + h*Phi), 360.0f);
|
||||||
return ColorFromHSV(h, s, v);
|
return ColorFromHSV(h, s, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Draw circle outline
|
||||||
|
void DrawCircleLinesEco(float centerX, float centerY, float radius, Color color)
|
||||||
|
{
|
||||||
|
rlCheckRenderBatchLimit(2*36);
|
||||||
|
|
||||||
|
rlBegin(RL_LINES);
|
||||||
|
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||||
|
|
||||||
|
// NOTE: Circle outline is drawn pixel by pixel every degree (0 to 360)
|
||||||
|
for (int i = 0; i < 360; i += 10)
|
||||||
|
{
|
||||||
|
rlVertex2f(centerX + sinf(DEG2RAD*i)*radius, centerY + cosf(DEG2RAD*i)*radius);
|
||||||
|
rlVertex2f(centerX + sinf(DEG2RAD*(i + 10))*radius, centerY + cosf(DEG2RAD*(i + 10))*radius);
|
||||||
|
}
|
||||||
|
rlEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawRectangleLinesEco(float posX, float posY, float width, float height, Color color)
|
||||||
|
{
|
||||||
|
rlBegin(RL_LINES);
|
||||||
|
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||||
|
rlVertex2f(posX + 1, posY + 1);
|
||||||
|
rlVertex2f(posX + width, posY + 1);
|
||||||
|
|
||||||
|
rlVertex2f(posX + width, posY + 1);
|
||||||
|
rlVertex2f(posX + width, posY + height);
|
||||||
|
|
||||||
|
rlVertex2f(posX + width, posY + height);
|
||||||
|
rlVertex2f(posX + 1, posY + height);
|
||||||
|
|
||||||
|
rlVertex2f(posX + 1, posY + height);
|
||||||
|
rlVertex2f(posX + 1, posY + 1);
|
||||||
|
rlEnd();
|
||||||
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
static block blocks[] = {
|
static block blocks[] = {
|
||||||
{.name = "base-ground", .flags = 0, .kind = BLOCK_KIND_GROUND, .biome = 0, .symbol = '.', .drag = 1.0f, .friction = 1.0f },
|
{.name = "base-ground", .flags = 0, .kind = BLOCK_KIND_GROUND, .biome = 0, .symbol = '.', .drag = 1.0f, .friction = 1.0f },
|
||||||
{.name = "base-dirt", .flags = 0, .kind = BLOCK_KIND_DIRT, .biome = 0, .symbol = ',', .drag = 2.1f , .friction = 1.0f },
|
{.name = "base-dirt", .flags = 0, .kind = BLOCK_KIND_DIRT, .biome = 0, .symbol = ',', .drag = 2.1f , .friction = 1.0f },
|
||||||
{.name = "base-wall", .flags = BLOCK_FLAG_COLLISION, .kind = BLOCK_KIND_WALL, .biome = 0, .symbol = '#', .drag = 1.0f , .friction = 1.0f, .bounce = 2.0f },
|
{.name = "base-wall", .flags = BLOCK_FLAG_COLLISION, .kind = BLOCK_KIND_WALL, .biome = 0, .symbol = '#', .drag = 1.0f , .friction = 1.0f, .bounce = 1.0f },
|
||||||
{.name = "base-hill", .flags = BLOCK_FLAG_COLLISION, .kind = BLOCK_KIND_HILL, .biome = 0, .symbol = '^', .drag = 1.0f , .friction = 1.0f },
|
{.name = "base-hill", .flags = BLOCK_FLAG_COLLISION, .kind = BLOCK_KIND_HILL, .biome = 0, .symbol = '^', .drag = 1.0f , .friction = 1.0f },
|
||||||
{.name = "base-hill-snow", .flags = BLOCK_FLAG_COLLISION, .kind = BLOCK_KIND_HILL_SNOW, .biome = 0, .symbol = '*', .drag = 1.0f , .friction = 1.0f },
|
{.name = "base-hill-snow", .flags = BLOCK_FLAG_COLLISION, .kind = BLOCK_KIND_HILL_SNOW, .biome = 0, .symbol = '*', .drag = 1.0f , .friction = 1.0f },
|
||||||
{.name = "base-water", .flags = 0, .kind = BLOCK_KIND_WATER, .biome = 0, .symbol = '~', .drag = 0.11f , .friction = 1.0f },
|
{.name = "base-water", .flags = 0, .kind = BLOCK_KIND_WATER, .biome = 0, .symbol = '~', .drag = 0.11f , .friction = 1.0f },
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
|
|
||||||
#define DEMO_NPC_MOVE_SPEED 150
|
#define DEMO_NPC_MOVE_SPEED 50
|
||||||
|
#define DEMO_NPC_STEER_SPEED 30
|
||||||
|
|
||||||
void DemoNPCMoveAround(ecs_iter_t *it) {
|
void DemoNPCMoveAround(ecs_iter_t *it) {
|
||||||
Velocity *v = ecs_column(it, Velocity, 1);
|
Velocity *v = ecs_column(it, Velocity, 1);
|
||||||
for (int i = 0; i < it->count; i++) {
|
for (int i = 0; i < it->count; i++) {
|
||||||
v[i].x += (rand()%3-1)*DEMO_NPC_MOVE_SPEED;
|
float d = zpl_quake_rsqrt(v[i].x*v[i].x + v[i].y*v[i].y);
|
||||||
v[i].y += (rand()%3-1)*DEMO_NPC_MOVE_SPEED;
|
v[i].x += (v[i].x*d*DEMO_NPC_MOVE_SPEED + zpl_cos(zpl_to_radians(rand()%360))*DEMO_NPC_STEER_SPEED);
|
||||||
|
v[i].y += (v[i].y*d*DEMO_NPC_MOVE_SPEED + zpl_sin(zpl_to_radians(rand()%360))*DEMO_NPC_STEER_SPEED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -135,6 +135,12 @@ void VehicleHandling(ecs_iter_t *it) {
|
||||||
v[i].y += (fr_y + bk_y) / 2.0f - p[i].y;
|
v[i].y += (fr_y + bk_y) / 2.0f - p[i].y;
|
||||||
car->heading = zpl_arctan2(fr_y - bk_y, fr_x - bk_x);
|
car->heading = zpl_arctan2(fr_y - bk_y, fr_x - bk_x);
|
||||||
|
|
||||||
|
world_block_lookup lookahead = world_block_from_realpos(p[i].x+PHY_LOOKAHEAD(v[i].x), p[i].y+PHY_LOOKAHEAD(v[i].y));
|
||||||
|
uint32_t flags = blocks_get_flags(lookahead.block_id);
|
||||||
|
if (flags & BLOCK_FLAG_COLLISION) {
|
||||||
|
car->force = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
for (int j = 0; j < 4; j++) {
|
for (int j = 0; j < 4; j++) {
|
||||||
if (!world_entity_valid(veh[i].seats[j])) continue;
|
if (!world_entity_valid(veh[i].seats[j])) continue;
|
||||||
ecs_entity_t pe = veh[i].seats[j];
|
ecs_entity_t pe = veh[i].seats[j];
|
||||||
|
|
Loading…
Reference in New Issue