Created
February 1, 2016 00:02
-
-
Save Tomcc/f5e8d5b15ffea4cc5272 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}()); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what does this mean @Tomcc ?