MCPcopy Create free account
hub / github.com/crownengine/crown / create_instances

Method create_instances

src/world/scene_graph.cpp:114–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

112}
113
114void SceneGraph::create_instances(const void *components_data
115 , u32 num
116 , const UnitId *unit_lookup
117 , const u32 *unit_index
118 , const u32 *unit_parents
119 , u32 spawn_flags
120 , const Vector3 &pos
121 , const Quaternion &rot
122 , const Vector3 &scl
123 )
124{
125 const TransformDesc *transforms = (TransformDesc *)components_data;
126
127 for (u32 i = 0; i < num; ++i) {
128 UnitId unit = unit_lookup[unit_index[i]];
129 CE_ASSERT(!hash_map::has(_map, unit), "Unit already has a transform component");
130
131 if (_data.capacity == 0 || _data.capacity - 1 == _data.size)
132 grow();
133
134 const u32 last = _data.size;
135
136 Matrix4x4 pose;
137 set_identity(pose);
138 set_translation(pose, spawn_flags & SpawnFlags::OVERRIDE_POSITION ? pos : transforms[i].position);
139 set_rotation(pose, spawn_flags & SpawnFlags::OVERRIDE_ROTATION ? rot : transforms[i].rotation);
140 set_scale(pose, spawn_flags & SpawnFlags::OVERRIDE_SCALE ? scl : transforms[i].scale);
141
142 _data.unit[last] = unit;
143 _data.world[last] = pose;
144 _data.local[last] = pose;
145 _data.parent[last].i = UINT32_MAX;
146 _data.first_child[last].i = UINT32_MAX;
147 _data.next_sibling[last].i = UINT32_MAX;
148 _data.prev_sibling[last].i = UINT32_MAX;
149 _data.changed[last] = false;
150
151 ++_data.size;
152
153 hash_map::set(_map, unit, last);
154
155 if (unit_parents[unit_index[i]] != UINT32_MAX) {
156 TransformId parent_ti = instance(unit_lookup[unit_parents[unit_index[i]]]);
157 link(parent_ti, make_instance(last), transforms[i].position, transforms[i].rotation, transforms[i].scale);
158 }
159 }
160}
161
162TransformId SceneGraph::create(UnitId unit, const Vector3 &pos, const Quaternion &rot, const Vector3 &scale)
163{

Callers 1

create_componentsFunction · 0.45

Calls 4

setClass · 0.85
instanceFunction · 0.85
hasFunction · 0.70
make_instanceFunction · 0.70

Tested by

no test coverage detected