Skip to content

Instantly share code, notes, and snippets.

@Tomcc
Created February 1, 2016 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tomcc/f5e8d5b15ffea4cc5272 to your computer and use it in GitHub Desktop.
Save Tomcc/f5e8d5b15ffea4cc5272 to your computer and use it in GitHub Desktop.
void Level::makeScene() {
auto defaultMaterial = Phys::Material{ "default" };
defaultMaterial.density = 0.1f;
addChild([&] {
int side = 100;
auto heightmap = make_shared<std::vector<float>>(makeHeightmap(side, side));
auto obj = make_unique<Object>(self, Vector::Zero);
obj->addComponent([&] {
auto cube = make_unique<Renderable>(
*obj,
Layers::Scene,
_makeTerrainMesh(*heightmap, side, side),
getShader("normal").unwrap()
);
cube->cullMode = Renderable::CullMode::None;
cube->color = Color::fromRGB(0xffefae);
return cube;
}());
obj->addComponent([&] {
auto body = make_unique<Phys::Body>(*obj, *world, defaultMaterial, PhysGroup::Vehicle, Phys::BodyType::Static);
body->addHeightmap(heightmap, side, side);
return body;
}());
return obj;
}());
addChild([&] {
auto obj = make_unique<Object>(self, Vector(0, 10, -10));
auto size = Vector{ 1.8f, 1.5f, 4.f };
auto hs = size * 0.5f;
obj->addComponent([&] {
auto cube = make_unique<Renderable>(*obj, Layers::Scene, "texturedCube", "normal");
cube->color = Color::Blue;
cube->scale = size;
return cube;
}());
obj->addComponent([&] {
auto body = make_unique<Phys::Body>(*obj, *world, defaultMaterial, PhysGroup::Vehicle);
body->addBoxShape(size);
float depth = 0.5f;
const auto wheelPositions = {
Vector{ 1.f, -depth, 1.f },
Vector{ -1.f, -depth, 1.f },
Vector{ 1.f, -depth, -1.f },
Vector{ -1.f, -depth, -1.f },
};
for(auto&& pos : wheelPositions) {
auto& wheel = body->addWheel(pos, Vector::NegativeUnitY, Vector::NegativeUnitX, 0.5f, 0.6f);
wheel.childObject = &self.addChild([&]() {
auto obj = make_unique<Object>(self, Vector::Zero);
obj->addComponent([&] {
auto cube = make_unique<Renderable>(*obj, Layers::Scene, "texturedCube", "normal");
cube->color = Color::Red;
return cube;
}());
return obj;
}());
}
return body;
}());
return obj;
}());
}
@Galang23
Copy link

Galang23 commented Feb 1, 2016

what does this mean @Tomcc ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment