Skip to content

Commit 9b2304b

Browse files
authored
Add camera entity (#120)
1 parent 813a3a8 commit 9b2304b

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

Diff for: src/level_gen.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,27 @@ void createPaddingEntities(Engine &ctx) {
315315
}
316316
}
317317

318+
void createCameraEntity(Engine &ctx)
319+
{
320+
auto camera = ctx.makeRenderableEntity<CameraAgent>();
321+
ctx.get<Position>(camera) = Vector3{.x = 0, .y = 0, .z = 20};
322+
ctx.get<Rotation>(camera) = (math::Quat::angleAxis(0, math::up) *
323+
math::Quat::angleAxis(-math::pi / 2.f, math::right)).normalize();
324+
325+
render::RenderingSystem::attachEntityToView(ctx,
326+
camera,
327+
150.f, 0.001f,
328+
1.5f * math::up);
329+
}
330+
318331
void createPersistentEntities(Engine &ctx, Map *map) {
319332
// createFloorPlane(ctx);
333+
334+
if (ctx.data().enableRender)
335+
{
336+
createCameraEntity(ctx);
337+
}
338+
320339
ctx.data().mean = {0, 0};
321340
ctx.data().mean.x = map->mean.x;
322341
ctx.data().mean.y = map->mean.y;

Diff for: src/mgr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static inline Optional<render::RenderManager> initRenderManager(
8181
.agentViewWidth = mgr_cfg.batchRenderViewWidth,
8282
.agentViewHeight = mgr_cfg.batchRenderViewHeight,
8383
.numWorlds = mgr_cfg.numWorlds,
84-
.maxViewsPerWorld = consts::kMaxAgentCount, // FIXME?
84+
.maxViewsPerWorld = consts::kMaxAgentCount + 1, // FIXME?
8585
.maxInstancesPerWorld = 3000,
8686
.execMode = mgr_cfg.execMode,
8787
.voxelCfg = {},

Diff for: src/sim.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ void Sim::registerTypes(ECSRegistry &registry, const Config &cfg)
5555

5656
registry.registerArchetype<Agent>();
5757
registry.registerArchetype<PhysicsEntity>();
58+
registry.registerArchetype<CameraAgent>();
5859

5960
registry.exportSingleton<WorldReset>(
6061
(uint32_t)ExportID::Reset);

Diff for: src/types.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,13 @@ static_assert(sizeof(AbsoluteSelfObservation) == sizeof(float) * AbsoluteSelfObs
217217

218218
/* ECS Archetypes for the game */
219219

220+
struct CameraAgent : public madrona::Archetype<
221+
Position,
222+
Rotation,
223+
madrona::render::RenderCamera,
224+
madrona::render::Renderable
225+
> {};
226+
220227
// There are 2 Agents in the environment trying to get to the destination
221228
struct Agent : public madrona::Archetype<
222229
// Basic components required for physics. Note that the current physics

0 commit comments

Comments
 (0)