Skip to content

Commit

Permalink
finished vehicles - closes #222
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed May 17, 2021
1 parent 963a461 commit b2e3643
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
16 changes: 16 additions & 0 deletions src/animation/editor/controller_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,17 @@ struct ControllerEditorImpl : ControllerEditor {
return universe->hasComponent(selected[0], reflection::getComponentType("animator"));
}

void updateSelectedEntity() {
const Array<EntityRef>& selected = m_app.getWorldEditor().getSelectedEntities();
if (selected.size() != 1) return;
Universe* universe = m_app.getWorldEditor().getUniverse();
ComponentType animator_type = reflection::getComponentType("animator");
if (!universe->hasComponent(selected[0], animator_type)) return;

AnimationScene* scene = (AnimationScene*)universe->getScene(animator_type);
scene->updateAnimator(selected[0], m_app.getEngine().getLastTimeDelta());
}

Path getPathFromEntity() const {
const Array<EntityRef>& selected = m_app.getWorldEditor().getSelectedEntities();
if (selected.size() != 1) return Path();
Expand Down Expand Up @@ -955,9 +966,13 @@ struct ControllerEditorImpl : ControllerEditor {
}
}

ImGui::Checkbox("Update", &m_update);

ImGui::EndMenuBar();
}

if (m_update) updateSelectedEntity();

if (hierarchy_ui(*m_controller->m_root)) {
pushUndo();
}
Expand Down Expand Up @@ -1230,6 +1245,7 @@ struct ControllerEditorImpl : ControllerEditor {
Action m_toggle_ui;
Action m_undo_action;
Action m_redo_action;
bool m_update = false;
StaticString<LUMIX_MAX_PATH> m_path;
Array<UniquePtr<EventType>> m_event_types;
}; // ControllerEditorImpl
Expand Down
6 changes: 2 additions & 4 deletions src/audio/audio_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,9 @@ struct AudioSceneImpl final : AudioScene
for (PlayingSound & sound : m_playing_sounds)
{
if (sound.buffer_id == AudioDevice::INVALID_BUFFER_HANDLE) continue;
if (!sound.entity.isValid()) continue;

if (sound.is_3d)
if (sound.is_3d && sound.entity.isValid())
{
auto pos = m_universe.getPosition((EntityRef)sound.entity);
const DVec3 pos = m_universe.getPosition((EntityRef)sound.entity);
m_device.setSourcePosition(sound.buffer_id, pos);
}

Expand Down
2 changes: 1 addition & 1 deletion src/audio/win/audio_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ struct AudioDeviceImpl final : AudioDevice
}
return 0;
}


void setCurrentTime(BufferHandle handle, float time_seconds) override
{
Expand Down
25 changes: 13 additions & 12 deletions src/physics/physics_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ static const ComponentType VEHICLE_TYPE = reflection::getComponentType("vehicle"
static const ComponentType WHEEL_TYPE = reflection::getComponentType("wheel");
static const u32 RENDERER_HASH = crc32("renderer");

enum class FilterFlags : u32 {
VEHICLE = 1 << 0
};

enum class PhysicsSceneVersion
{
REMOVED_RAGDOLLS,
Expand Down Expand Up @@ -419,14 +423,11 @@ struct PhysicsSceneImpl final : PhysicsScene

m_vehicle_results = desc.queryMemory.userRaycastResultBuffer;

auto f = [](PxFilterData queryFilterData, PxFilterData objectFilterData, const void* constantBlock, PxU32 constantBlockSize, PxHitFlags& hitFlags)->PxQueryHitType::Enum {
if (objectFilterData.word3 == 4) return PxQueryHitType::eNONE;
desc.preFilterShader = [](PxFilterData queryFilterData, PxFilterData objectFilterData, const void* constantBlock, PxU32 constantBlockSize, PxHitFlags& hitFlags) -> PxQueryHitType::Enum {
if (objectFilterData.word3 == (u32)FilterFlags::VEHICLE) return PxQueryHitType::eNONE;
return PxQueryHitType::eBLOCK;
};

desc.preFilterShader = f;
//desc.postFilterShader = vehicleSceneQueryData.mPostFilterShader;

return m_scene->createBatchQuery(desc);
}

Expand Down Expand Up @@ -1893,12 +1894,12 @@ struct PhysicsSceneImpl final : PhysicsScene
wheel_sim_data->setSuspForceAppPointOffset(idx, offsets[idx] + PxVec3(0, 0.1f, 0));
wheel_sim_data->setTireForceAppPointOffset(idx, offsets[idx] + PxVec3(0, 0.1f, 0));
wheel_sim_data->setWheelShapeMapping(idx, idx);
// TODO

physx::PxFilterData filter;
filter.word0 = 5;
filter.word1 = 5;
filter.word2 = 5;
filter.word3 = 4;
filter.word0 = 1 << vehicle.wheels_layer;
filter.word1 = m_layers.filter[vehicle.wheels_layer];
filter.word2 = 0;
filter.word3 = (u32)FilterFlags::VEHICLE;
wheel_sim_data->setSceneQueryFilterData(idx, filter);
}

Expand Down Expand Up @@ -1981,7 +1982,7 @@ struct PhysicsSceneImpl final : PhysicsScene
filter.word0 = 1 << vehicle.wheels_layer;
filter.word1 = m_layers.filter[vehicle.wheels_layer];
filter.word2 = 0;
filter.word3 = 4;
filter.word3 = (u32)FilterFlags::VEHICLE;
wheel_shape->setQueryFilterData(filter);
wheel_shape->setSimulationFilterData(filter);
wheel_shape->setLocalPose(toPhysx(transform.inverted() * wheel_transforms[i]));
Expand All @@ -1993,7 +1994,7 @@ struct PhysicsSceneImpl final : PhysicsScene
filter.word0 = 1 << vehicle.chassis_layer;
filter.word1 = m_layers.filter[vehicle.chassis_layer];
filter.word2 = 0;
filter.word3 = 4;
filter.word3 = (u32)FilterFlags::VEHICLE;
PxMeshScale pxscale(1.f);
PxConvexMeshGeometry convex_geom(vehicle.geom->convex_mesh, pxscale);
// TODO what if there's no geom or it's not ready
Expand Down

0 comments on commit b2e3643

Please sign in to comment.